Skip to content

Commit 4fcee11

Browse files
committed
Merge commit maybe
(And added posibility to set resolution)
1 parent f414bf7 commit 4fcee11

File tree

6 files changed

+84
-28
lines changed

6 files changed

+84
-28
lines changed

README.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Flags:
1818
| simulate: simulation time
1919
| moveshutter: time at which the shutter is moved
2020
-v | followed by 3 numbers x y z, who stand for the coordinates of a point in 3D space
21-
-h | for addsink which determines the sink height
21+
-h | for addsink which determines the sink height or for render sets the height of the output image
22+
-w | for render sets the width of the output image
2223

2324
Commands:
2425
print
@@ -45,10 +46,10 @@ Commands:
4546
addsink -h
4647
Add a sink at a given height.
4748

48-
simulate -t
49+
simulate [-t]
4950
Start a sph-simulation. Simulated time can be set with '-t' parameter.
5051

51-
render -v
52+
render [-v] [-w -h]
5253
Start the rendering process. The camera can be set with '-v' parameter. Camera is looking roughly towards (0,0,0)
5354

5455
help

SphWaterfall/SphWaterfall/src/cui/CUI.cpp

+33-17
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void CUI::parseCommand(std::string input_line) {
4040

4141
while (command_token_stream >> command) {
4242
if (!first_loop_done) {
43+
// Reads the name of the command
4344
std::transform(command.begin(), command.end(), command.begin(), ::tolower);
4445
current_command = CUICommand(command, input_line);
4546
first_loop_done = true;
@@ -49,25 +50,32 @@ void CUI::parseCommand(std::string input_line) {
4950
// is new parameter when string starts with '-' and there are no numbers in it
5051
bool isNewParameter = ((command.front() == '-') && (command.find_first_of("0123456789") == std::string::npos));
5152

52-
if (!isNewParameter) {
53-
if (!last_read_parameter_value.isNull()) {
54-
last_read_parameter_value.set(last_read_parameter_value.getInternal() + " " + command);
55-
}
56-
else {
57-
last_read_parameter_value.set(command);
58-
}
59-
}
6053

61-
if ((command_token_stream.rdbuf()->in_avail() == 0) || (!last_read_parameter_name.isNull() && isNewParameter)) {
62-
current_command.addParameter(CUICommandParameter(last_read_parameter_name.getInternal(), trimQuotemarks(last_read_parameter_value.getInternal())));
63-
last_read_parameter_name.reset();
64-
last_read_parameter_value.reset();
65-
}
6654
if (isNewParameter) {
55+
// Are we reding a new parameter...
56+
if (!last_read_parameter_name.isNull()) {
57+
current_command.addParameter(
58+
CUICommandParameter(last_read_parameter_name.getInternal(), trimQuotemarks(last_read_parameter_value.getInternal()))
59+
);
60+
}
61+
6762
last_read_parameter_name.set(command);
6863
last_read_parameter_value.reset();
64+
} else {
65+
// ...or a value for the current parameter
66+
last_read_parameter_value.set(
67+
(last_read_parameter_value.isNull()) ?
68+
command :
69+
last_read_parameter_value.getInternal() + " " + command
70+
);
6971
}
7072
}
73+
74+
if (!last_read_parameter_name.isNull()) {
75+
current_command.addParameter(
76+
CUICommandParameter(last_read_parameter_name.getInternal(), trimQuotemarks(last_read_parameter_value.getInternal()))
77+
);
78+
}
7179
}
7280

7381
void CUI::cleanAndExecuteCommand(bool is_config_execution, bool& exit_program) {
@@ -196,7 +204,8 @@ void CUI::showHelp() {
196204
<< " | simulate: simulation time" << endl
197205
<< " | moveshutter: time at which the shutter is moved" << endl
198206
<< " -v | followed by 3 numbers x y z, who stand for the coordinates of a point in 3D space" << endl
199-
<< " -h | for addsink which determines the sink height" << endl << endl
207+
<< " -h | for addsink which determines the sink height or for render sets the height of the output image" << endl << endl
208+
<< " -w | for render sets the width of the output image" << endl << endl
200209

201210
<< "Commands:" << endl
202211
<< " print" << endl
@@ -223,11 +232,11 @@ void CUI::showHelp() {
223232
<< " addsink -h" << endl
224233
<< " Add a senk at a given height" << endl << endl
225234

226-
<< " simulate -t" << endl
235+
<< " simulate [-t]" << endl
227236
<< " Start a sph-simulation. Time can be set with '-t' parameter." << endl << endl
228237

229-
<< " render -v" << endl
230-
<< " Start the rendering process. The camera position can be set with '-v' parameter. Camera is looking roughly towards (0,0,0)." << endl << endl
238+
<< " render [-v] [-w -h]" << endl
239+
<< " Start the rendering process. The camera position can be set with '-v' parameter. Camera is looking roughly towards (0,0,0). -w and -h can be used to set the reolution of the output images." << endl << endl
231240

232241
<< " help" << endl
233242
<< " Show help" << endl << endl
@@ -410,6 +419,13 @@ bool CUI::cleanRender()
410419
hasOnlyValidParameters = false;
411420
}
412421
}
422+
else if (parameter.getParameterName() == "-w" || parameter.getParameterName() == "-h"){
423+
std::string resolution_value = parameter.getValue();
424+
if (resolution_value.find_first_not_of("+-,.0123456789") != std::string::npos) {
425+
hasOnlyValidParameters = false;
426+
std::cout << "'" << resolution_value << "' is not a number" << std::endl;
427+
}
428+
}
413429
else {
414430
current_command.removeParameter(parameter);
415431
}

SphWaterfall/SphWaterfall/src/cui/CUICommand.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ CUICommandParameter CUICommand::getParameter(int index) const {
5858
return parameter_list.at(index);
5959
}
6060

61+
int CUICommand::getParameterIndex(std::string parameter_name)
62+
{
63+
for (int i = 0; i < parameter_list.size(); i++) {
64+
CUICommandParameter& parameter = parameter_list.at(i);
65+
if (parameter.getParameterName() == parameter_name) {
66+
return i;
67+
}
68+
}
69+
return -1;
70+
}
71+
6172
void CUICommand::addParameter(CUICommandParameter parameter) {
6273
parameter_list.push_back(parameter);
6374
}

SphWaterfall/SphWaterfall/src/cui/CUICommand.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CUICommand {
3333
std::string getCommandName() const;
3434
std::vector<CUICommandParameter> getParameterList() const;
3535
CUICommandParameter getParameter(int index) const;
36+
int getParameterIndex(std::string parameter_name);
3637
void addParameter(CUICommandParameter parameter);
3738
bool removeParameter(CUICommandParameter parameter);
3839
bool removeParameter(std::string parameter_name);

SphWaterfall/SphWaterfall/src/cui/CommandHandler.cpp

+33-7
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void CommandHandler::executeCommand(CUICommand& cui_command) {
138138
std::string file_path, time_for_move, source_position, sink_height;
139139
int simulation_timesteps;
140140
Vector3 camera_position = Vector3(0, 5, -5);
141+
unsigned int width = 800, height = 600;
141142

142143
switch (cui_command.getCommand()) {
143144
case CUICommand::LOAD_MESH:
@@ -205,10 +206,15 @@ void CommandHandler::executeCommand(CUICommand& cui_command) {
205206
break;
206207
case CUICommand::RENDER:
207208
if (cui_command.hasParameter("-v")) {
208-
camera_position = parseToVector3(cui_command.getParameter(0).getValue());
209+
camera_position = parseToVector3(cui_command.getParameter(cui_command.getParameterIndex("-v")).getValue());
209210
}
210211

211-
render(loaded_mesh, loaded_shutter, 0, camera_position);
212+
if (cui_command.hasParameter("-w") && cui_command.hasParameter("-h")) {
213+
width = parseToUInteger(cui_command.getParameter(cui_command.getParameterIndex("-w")).getValue());
214+
height = parseToUInteger(cui_command.getParameter(cui_command.getParameterIndex("-h")).getValue());
215+
}
216+
217+
render(loaded_mesh, loaded_shutter, 0, camera_position, width, height);
212218
MPI_Barrier(MPI_COMM_WORLD);
213219

214220
// console feedback
@@ -245,13 +251,19 @@ void CommandHandler::executeCommand(CUICommand& cui_command) {
245251
}
246252
}
247253

254+
248255
int CommandHandler::parseToInteger(std::string input) {
249256
std::istringstream input_parse_stream(input);
250257
int output;
251258
input_parse_stream >> output;
252259
return output;
253260
}
254261

262+
unsigned int CommandHandler::parseToUInteger(std::string input) {
263+
int result = this->parseToInteger(input);
264+
return (result > 0) ? result : 0;
265+
}
266+
255267
double CommandHandler::parseToDouble(std::string input) {
256268
std::istringstream input_parse_stream(input);
257269
double output;
@@ -363,14 +375,28 @@ void CommandHandler::simulate(int simulation_timesteps) {
363375
sph_manager.simulate(simulation_timesteps);
364376
}
365377

366-
void CommandHandler::render(Terrain loaded_mesh, Terrain loaded_shutter, int shutter_time, Vector3 cameraPosition) {
367-
if (mpi_rank == 0) {
368-
cout << "Rendering in progress..." << endl;
369-
}
378+
void CommandHandler::render(Terrain loaded_mesh, Terrain loaded_shutter, int shutter_time, Vector3 cameraPosition, unsigned int width, unsigned int height) {
379+
int worldSize;
380+
MPI_Comm_size(MPI_COMM_WORLD, &worldSize);
381+
370382
VisualizationManager::importTerrain(loaded_mesh, false);
371383
VisualizationManager::importTerrain(loaded_shutter, true);
372384

373-
VisualizationManager::init(cameraPosition, 800, 600, mpi_rank);
385+
if (mpi_rank == 0) {
386+
387+
for (int i = 1; i < worldSize; i++) {
388+
MPI_Send(&width, 1, MPI_UNSIGNED, i, 0, MPI_COMM_WORLD);
389+
MPI_Send(&height, 1, MPI_UNSIGNED, i, 0, MPI_COMM_WORLD);
390+
}
391+
392+
cout << "Rendering in progress with (" << width << " * " << height << ") ..." << endl;
393+
}
394+
else {
395+
MPI_Recv(&width, 1, MPI_UNSIGNED, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
396+
MPI_Recv(&height, 1, MPI_UNSIGNED, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
397+
}
398+
399+
VisualizationManager::init(cameraPosition, width, height, mpi_rank);
374400
//VisualizationManager::renderFrames("sph.ptcl");
375401
VisualizationManager::renderFramesDistributed("sph.ptcl", mpi_rank);
376402

SphWaterfall/SphWaterfall/src/cui/CommandHandler.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class CommandHandler {
3232
void executeCommand(CUICommand&);
3333

3434
int parseToInteger(std::string);
35+
unsigned int parseToUInteger(std::string);
3536
double parseToDouble(std::string);
3637
Vector3 parseToVector3(std::string);
3738

@@ -40,7 +41,7 @@ class CommandHandler {
4041
void createExport(int simulation_timesteps);
4142
void moveShutter(std::string);
4243
void simulate(int simulation_timesteps);
43-
void render(Terrain, Terrain, int, Vector3);
44+
void render(Terrain, Terrain, int, Vector3, unsigned int, unsigned int);
4445
void addSource(std::string);
4546
void addSink(std::string);
4647
};

0 commit comments

Comments
 (0)