cli.cpp 2.5 KB
Newer Older
1
#include <iostream>
Christoph Saffer's avatar
Christoph Saffer committed
2 3
#include <vector>

4
#include <boost/program_options.hpp>
Christoph Saffer's avatar
Christoph Saffer committed
5

6
#include "compute.hpp"
plgruener's avatar
plgruener committed
7

8
int main(int argc, char* argv[]) {
plgruener's avatar
plgruener committed
9
  // get arguments from CLI
10 11
  // these can be input by user
  int num_iterations;
plgruener's avatar
plgruener committed
12
  float threshold;
13 14 15 16 17 18
  float alphamin;
  float alphamax;
  int alpha_num_intervals;
  float betamin;
  float betamax;
  int beta_num_intervals;
19
  int num_seedpoints;
20
  bool output_csv;
21
  std::vector<float> seedpoints;
22 23 24 25

  namespace po = boost::program_options;
  try {
    po::options_description desc("Options");
plgruener's avatar
plgruener committed
26 27 28 29 30 31 32 33
    desc.add_options()
      ("help", "Help message")
      ("iterations,n", po::value<int>(&num_iterations)->default_value(100),
      " Number of iterations")
      ("width,w", po::value<int>(&alpha_num_intervals)->default_value(100),
      " width of image (alpha resolution)")
      ("height,h", po::value<int>(&beta_num_intervals)->default_value(100),
      " height of image (beta resolution)")
plgruener's avatar
plgruener committed
34
      ("threshold,t", po::value<float>(&threshold)->default_value(1), 
plgruener's avatar
plgruener committed
35 36 37 38 39 40 41 42 43
      " Threshold above that computation is stopped")
      ("amin,a", po::value<float>(&alphamin)->default_value(0),
      " alpha lower bound")
      ("amax,A", po::value<float>(&alphamax)->default_value(1),
      " alpha upper bound")
      ("bmin,b", po::value<float>(&betamin)->default_value(0),
      " beta lower bound")
      ("bmax,B", po::value<float>(&betamax)->default_value(1),
      " beta upper bound")
plgruener's avatar
plgruener committed
44
      ("num_seedpoints,m", po::value<int>(&num_seedpoints)->default_value(8),
plgruener's avatar
plgruener committed
45 46 47
      " Number of seedpoints (uniformly distributed in (0,1) )")
      ("seedpoints,S", po::value<std::vector<float>>(&seedpoints)->multitoken(),
      " Values for explicit seedpoints")
48
      ("csv,O", po::value<bool>(&output_csv)->default_value(false),
49
      " Boolean flag for output a csv file")
plgruener's avatar
plgruener committed
50
      ;
51
      
52 53 54 55 56 57 58 59

    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);

    if (vm.count("help")) {
      std::cout << desc << std::endl;
      return 0;
    }
60

61 62 63
    po::notify(vm);

    // check if our integers are >0, else throw invalid-argument-error
64 65
    if ((num_iterations < 1) || (alpha_num_intervals < 1) ||
        (beta_num_intervals < 1)) {
66 67 68
      throw po::validation_error(po::validation_error::invalid_option_value);
    }

69
  } catch (po::error& e) {
70
    std::cerr << e.what() << std::endl;
plgruener's avatar
plgruener committed
71 72
    return -1;
  }
73

74 75 76 77 78 79 80 81 82 83 84 85 86
  compute_all(
    num_iterations,
    threshold,
    alphamin,
    alphamax,
    alpha_num_intervals,
    betamin,
    betamax,
    beta_num_intervals,
    num_seedpoints,
    output_csv,
    seedpoints
  );
87

plgruener's avatar
plgruener committed
88
}