]> git.treefish.org Git - seamulator.git/commitdiff
Added basic command line arguments
authorAlexander Schmidt <alex@treefish.org>
Wed, 20 Jul 2016 22:14:50 +0000 (00:14 +0200)
committerAlexander Schmidt <alex@treefish.org>
Wed, 20 Jul 2016 22:14:50 +0000 (00:14 +0200)
src/CMakeLists.txt
src/seamulator.cpp

index 75b9bcba13caea14690753ff769801c9272ca71f..f859744f9c4dd88e473db7e8b94b794e9660b0ca 100644 (file)
@@ -3,14 +3,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
 find_package(OpenGL REQUIRED)
 find_package(GLUT REQUIRED)
 find_package(fftw3 REQUIRED)
+find_package(Boost 1.40 COMPONENTS program_options REQUIRED)
 
 include_directories(${seamulator_SOURCE_DIR}/include
                    ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS}
-                   ${FFTW_INCLUDES})
+                   ${FFTW_INCLUDES} ${Boost_INCLUDE_DIR})
 
 add_executable(seamulator seamulator.cpp
                          sea.cpp watersurface.cpp surfacepoint.cpp
                          seaview.cpp)
 
 target_link_libraries(seamulator ${OPENGL_LIBRARIES} ${GLUT_LIBRARY}
-                                ${FFTW_LIBRARIES})
+                                ${FFTW_LIBRARIES} ${Boost_LIBRARIES})
index 92dfac608d383a97c9b345729d44e3990c3a4bc8..98e92df2b793be60836328152be73591ce6f9e62 100644 (file)
@@ -1,20 +1,19 @@
 #include <ctime>
 #include <cmath>
+#include <iostream>
 #include <memory>
 
+#include <boost/program_options.hpp>
 #include <GL/glut.h>
 
 #include "sea.h"
 #include "seaview.h"
 #include "watersurface.h"
 
-const int LATTICE_SIZE{128};
-const double LATTICE_EXTEND{10};
 const int INIT_WINDOW_POS_X{50};
 const int INIT_WINDOW_POS_Y{50};
 const int INIT_WINDOW_WIDTH{800};
 const int INIT_WINDOW_HEIGHT{600};
-const double INIT_VIEW_DISTANCE{LATTICE_EXTEND * 1.5};
 const double INIT_VIEW_AZIMUTH{0};
 const double INIT_VIEW_ALTITUDE{M_PI / 4};
 const char WINDOW_TITLE[]{"seamulator"};
@@ -23,18 +22,44 @@ SeaPtr sea;
 WaterSurfacePtr surface;
 std::unique_ptr<SeaView> seaView;
 
+struct Settings {
+  double windSpeed;
+  int latticeSize;
+  double latticeExtend;
+  double amplitudeFactor;
+};
+
+namespace po = boost::program_options;
+
 void glDisplayFunc();
 void glReshapeFunc(int width, int height);
 void glMouseFunc(int button, int state, int x, int y);
 void glMotionFunc(int x, int y);
+Settings parseArguments(int argc, char** argv, po::options_description desc);
 
 int main(int argc, char** argv)
 {
-  std::srand(std::time(0));
+  po::options_description desc("Available options");
+  desc.add_options()
+    ("help,h", "produce help message")
+    ("windspeed,w", po::value<double>()->default_value(10),
+     "wind speed given in m/s")
+    ("size,s", po::value<std::string>()->default_value("small"),
+     "lattice size (small/large)")
+    ("amplitude,a", po::value<double>()->default_value(1),
+     "amplitude multiplicator")
+    ;
+
+  Settings settings = parseArguments(argc, argv, desc);
 
-  surface = std::make_shared<WaterSurface>(LATTICE_SIZE, LATTICE_EXTEND);
-  sea = std::make_shared<Sea>(surface, 10, 0.0000001);
-  seaView = std::make_unique<SeaView>(INIT_VIEW_DISTANCE, INIT_VIEW_AZIMUTH,
+  std::srand(std::time(0));
+  surface = std::make_shared<WaterSurface>(settings.latticeSize,
+                                          settings.latticeExtend);
+  sea = std::make_shared<Sea>(surface,
+                             settings.windSpeed,
+                             settings.amplitudeFactor);
+  seaView = std::make_unique<SeaView>(settings.latticeExtend * 1.5,
+                                     INIT_VIEW_AZIMUTH,
                                      INIT_VIEW_ALTITUDE);
 
   glutInit(&argc, argv);
@@ -54,6 +79,35 @@ int main(int argc, char** argv)
   return 0;
 }
 
+Settings parseArguments(int argc, char** argv, po::options_description desc)
+{
+  po::variables_map vm;
+  po::store(po::parse_command_line(argc, argv, desc), vm);
+  po::notify(vm);
+
+  if (vm.count("help")) {
+    std::cout << desc << "\n";
+    exit(1);
+  }
+
+  Settings settings;
+
+  settings.windSpeed = vm["windspeed"].as<double>();
+
+  if (vm["size"].as<std::string>() == "large") {
+    settings.latticeSize = 256;
+    settings.latticeExtend = 20;
+    settings.amplitudeFactor = vm["amplitude"].as<double>() * 0.00000004;
+  }
+  else {
+    settings.latticeSize = 128;
+    settings.latticeExtend = 10;
+    settings.amplitudeFactor = vm["amplitude"].as<double>() * 0.0000001;
+  }
+
+  return settings;
+}
+
 void glDisplayFunc()
 {
   glClear(GL_COLOR_BUFFER_BIT);