Skip to content
Snippets Groups Projects
Select Git revision
  • 41152a2bce44a7634c472cc0d064c0837b82a52c
  • main default protected
  • oleg-alexandrov-patch-1
  • radtan
  • 2.0
  • Kelvinrr-patch-1
  • acpaquette-patch-1
  • gxp_testing
  • 2.0.2
  • 2.0.1
  • 2.0.0
  • 1.7.0
  • 1.6.0
  • 1.5.2
  • 1.5.1
  • 1.5.0
  • 1.4.1
  • 1.4.0
  • 1.3.1
  • 1.3.0
  • 1.2.0
  • 1.1.1
  • 1.1.0
  • 1.0.0
24 results

usgscsm_cam_test.cc

Blame
  • usgscsm_cam_test.cc 8.55 KiB
    // A tool to perform some basic tests and operations on a CSM camera model.
    // 
    // Functionality:
    //--------------
    //
    // - Load a CSM model in ISD format or model state format, via:
    //   --model <model file>
    //
    // - Save the model state if invoked with:
    //   --output-model-state <model state .json file>
    // 
    // - Test projecting rays from the camera to ground, then back,
    //   and compare with the original pixel values.  
    
    #include <UsgsAstroPlugin.h>
    #include <RasterGM.h>
    #include <UsgsAstroLsSensorModel.h>
    
    #include <iostream>
    #include <fstream>
    
    struct Options {
      std::string model;              // the .json file in isd or model state format
      std::string output_model_state; // the output model state in .json format
      int sample_rate;
      double subpixel_offset, height_above_datum;
      Options(): sample_rate(0), subpixel_offset(0.0), height_above_datum(0.0) {}
    };
    
    void printUsage(std::string const& progName) {
      std::cout << "Usage: " << progName << " --model <model file> [other options]"
                << "\nSee the documentation for more information.\n";
    }
    
    // Do some naive parsing. Every option is assumed to start with two
    // dashes and have a string value.  The --help option is handled
    // separately.
    bool parseOptions(int argc, char **argv, Options & opt) {
    
      std::vector<std::string> params;
      for (int it = 1; it < argc; it++) {
        if (std::string(argv[it]) == std::string("--help")) {
          printUsage(argv[0]);
          return false;
        }
        params.push_back(argv[it]);
      }
    
      if (params.size() %2 != 0 || params.empty()) {
        std::cout << "Could not parse correctly the input arguments.\n";
        printUsage(argv[0]);
        return false;
      }
    
      // Collect the parsed options in a map
      std::map<std::string, std::string> parsed_options;
      int num = params.size() / 2;
      for (int it = 0; it < num; it++) {
        std::string opt = params[2*it + 0];
        std::string val = params[2*it + 1];
        if (opt.size() <= 2 || opt[0] != '-' || opt[1] != '-' || val.empty() || val[0] == '-' ) {
          std::cout << "Could not parse correctly the input arguments.\n";
          printUsage(argv[0]);
          return false;
        }
        opt = opt.substr(2); // wipe the dashes
        parsed_options[opt] = val;
      }
      
      // It is safe to access non-existent values from a map, the result