From 47180fa3cd4db7e198ec56bec87e920943f5cbd3 Mon Sep 17 00:00:00 2001 From: Oleg Alexandrov Date: Wed, 20 Aug 2014 16:05:23 -0700 Subject: [PATCH] stereo: Tweaks in parsing options for multiview stereo: Minor tweak to display the usage all the time stereo: Minor tweak to display the usage all the time More tweaks for parsing options --- src/asp/Sessions/StereoSession.cc | 4 +++- src/asp/Tools/stereo.cc | 40 ++++++++++++++++++------------- src/asp/Tools/stereo.h | 3 ++- src/asp/Tools/stereo_fltr.cc | 4 +--- src/asp/Tools/stereo_pprc.cc | 15 +++++------- src/asp/Tools/stereo_rfne.cc | 1 - src/asp/Tools/stereo_utils.py.in | 4 ++++ 7 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/asp/Sessions/StereoSession.cc b/src/asp/Sessions/StereoSession.cc index 5f4d57973..69280f357 100644 --- a/src/asp/Sessions/StereoSession.cc +++ b/src/asp/Sessions/StereoSession.cc @@ -117,7 +117,9 @@ namespace asp { actual_session_type = "pinhole"; } if ( boost::iends_with(boost::to_lower_copy(left_image_file), ".cub") || - boost::iends_with(boost::to_lower_copy(right_image_file), ".cub") ) { + boost::iends_with(boost::to_lower_copy(right_image_file), ".cub") || + boost::iends_with(boost::to_lower_copy(left_camera_file), ".cub") || + boost::iends_with(boost::to_lower_copy(right_camera_file), ".cub") ) { actual_session_type = "isis"; } if (boost::iends_with(boost::to_lower_copy(left_camera_file), ".xml") || diff --git a/src/asp/Tools/stereo.cc b/src/asp/Tools/stereo.cc index 76603a6b3..67118fbff 100644 --- a/src/asp/Tools/stereo.cc +++ b/src/asp/Tools/stereo.cc @@ -98,8 +98,9 @@ namespace asp { vector files; bool allow_unregistered = true; Options opt; + std::string usage; handle_arguments(argc, argv, opt, additional_options, - allow_unregistered, files); + allow_unregistered, files, usage); // Store the elements in argv which are not files or output prefix. // Note that argv[0] is the program name. @@ -116,7 +117,8 @@ namespace asp { vector cameras = asp::extract_cameras( files ); if (files.size() < 3) - vw_throw( ArgumentErr() << "Missing all of the correct input files.\n" ); + vw_throw( ArgumentErr() << "Missing all of the correct input files.\n\n" + << usage ); // Find the input DEM, if any string input_dem; @@ -142,7 +144,8 @@ namespace asp { << ". Perhaps this was not intended." << endl; if (files.size() != cameras.size() && !cameras.empty()) - vw_throw( ArgumentErr() << "Expecting the number of images and cameras to agree.\n" ); + vw_throw( ArgumentErr() << "Expecting the number of images and " + << "cameras to agree.\n" ); int num_pairs = (int)files.size() - 1; if (num_pairs <= 0) @@ -231,9 +234,8 @@ namespace asp { Options opt; bool allow_unregistered = false; vector unregistered; - handle_arguments( largc, &largv[0], opt, - additional_options, - allow_unregistered, unregistered); + handle_arguments( largc, &largv[0], opt, additional_options, + allow_unregistered, unregistered, usage); opt_vec.push_back(opt); if (verbose){ @@ -260,9 +262,8 @@ namespace asp { void handle_arguments( int argc, char *argv[], Options& opt, boost::program_options::options_description const& additional_options, - bool allow_unregistered, - vector & unregistered - ) { + bool allow_unregistered, vector & unregistered, + std::string & usage ){ po::options_description general_options_sub(""); general_options_sub.add_options() @@ -301,20 +302,13 @@ namespace asp { positional_desc.add("output-prefix", 1); positional_desc.add("input-dem", 1); - string usage("[options] [] [DEM]\n Extensions are automaticaly added to the output files.\n Camera model arguments may be optional for some stereo session types (e.g., isis).\n Stereo parameters should be set in the stereo.default file."); + usage = "[options] [] [DEM]\n Extensions are automaticaly added to the output files.\n Camera model arguments may be optional for some stereo session types (e.g., isis).\n Stereo parameters should be set in the stereo.default file."; po::variables_map vm = asp::check_command_line( argc, argv, opt, general_options, all_general_options, positional_options, positional_desc, usage, allow_unregistered, unregistered ); - // If we allow unregistered options, the logic below won't apply correctly. - if (allow_unregistered) return; - - if ( opt.in_file1.empty() || opt.in_file2.empty() || opt.cam_file1.empty() ) - vw_throw( ArgumentErr() << "Missing all of the correct input files.\n\n" - << usage << general_options ); - // Read the config file try { po::options_description cfg_options; @@ -335,6 +329,18 @@ namespace asp { } asp::stereo_settings().validate(); + // Add the options to the usage + std::ostringstream os; + os << usage << general_options; + usage = os.str(); + + // If we allow unregistered options, the logic below won't apply correctly. + if (allow_unregistered) return; + + if ( opt.in_file1.empty() || opt.in_file2.empty() || opt.cam_file1.empty() ) + vw_throw( ArgumentErr() << "Missing all of the correct input files.\n\n" + << usage ); + /// There are 3 valid methods of input into this application /// 1.) /// 2.) diff --git a/src/asp/Tools/stereo.h b/src/asp/Tools/stereo.h index c6b3f87a7..27855212c 100644 --- a/src/asp/Tools/stereo.h +++ b/src/asp/Tools/stereo.h @@ -81,7 +81,8 @@ namespace asp { boost::program_options::options_description const& additional_options, bool allow_unregistered, - std::vector & unregistered); + std::vector & unregistered, + std::string & usage); // Register Session types void stereo_register_sessions(); diff --git a/src/asp/Tools/stereo_fltr.cc b/src/asp/Tools/stereo_fltr.cc index 1e5439b19..1b9eda463 100644 --- a/src/asp/Tools/stereo_fltr.cc +++ b/src/asp/Tools/stereo_fltr.cc @@ -18,8 +18,6 @@ /// \file stereo_fltr.cc /// -//#define USE_GRAPHICS - #include #include @@ -267,7 +265,7 @@ void stereo_filtering( Options& opt ) { } // This is only turned on for apollo. Blob detection doesn't - // work to great when tracking a whole lot of spots. HiRISE + // work too great when tracking a whole lot of spots. HiRISE // seems to keep breaking this so I've keep it turned off. // // The crash happens inside Boost Graph when dealing with diff --git a/src/asp/Tools/stereo_pprc.cc b/src/asp/Tools/stereo_pprc.cc index c26996b6c..edb8509a7 100644 --- a/src/asp/Tools/stereo_pprc.cc +++ b/src/asp/Tools/stereo_pprc.cc @@ -18,8 +18,6 @@ /// \file stereo_pprc.cc /// -//#define USE_GRAPHICS - #include #include #include @@ -194,9 +192,7 @@ void stereo_preprocessing(bool adjust_left_image_size, Options& opt) { // skipped image normalization, so we are still using the original // input images, and the user wants to use a custom no-data value, // this is the time to apply it. - if (skip_img_norm && - !isnan(stereo_settings().nodata_value) - ){ + if (skip_img_norm && !isnan(stereo_settings().nodata_value)){ left_nodata_value = stereo_settings().nodata_value; right_nodata_value = stereo_settings().nodata_value; } @@ -232,7 +228,8 @@ void stereo_preprocessing(bool adjust_left_image_size, Options& opt) { } if ( !isnan(nodata_fraction) ){ // Declare a fixed proportion of low-value pixels to be no-data. - math::CDFAccumulator< PixelGray > left_cdf(1024, 1024), right_cdf(1024, 1024); + math::CDFAccumulator< PixelGray > left_cdf(1024, 1024), + right_cdf(1024, 1024); for_each_pixel( left_image, left_cdf ); for_each_pixel( right_image, right_cdf ); left_threshold = left_cdf.quantile(nodata_fraction); @@ -307,8 +304,8 @@ void stereo_preprocessing(bool adjust_left_image_size, Options& opt) { DiskImageView testrm(rmsub); vw_out() << "\t--> Using cached subsampled images.\n"; } catch (vw::Exception const& e) { - // Produce subsampled images, these will be used later for Auto - // search range. They're also a handy debug tool. + // Produce subsampled images, these will be used later for auto + // search range detection. double s = 1500.0; float sub_scale = sqrt(s * s / (float(left_image.cols()) * float(left_image.rows()))); @@ -333,7 +330,7 @@ void stereo_preprocessing(bool adjust_left_image_size, Options& opt) { sub_tile_size = vw_settings().default_tile_size(); vw_out() << "\t--> Creating previews. Subsampling by " << sub_scale - << " by using " << sub_tile_size << " tile size and " + << " by using a tile of size " << sub_tile_size << " and " << sub_threads << " threads.\n"; // Resample the images and the masks. We must use the masks when diff --git a/src/asp/Tools/stereo_rfne.cc b/src/asp/Tools/stereo_rfne.cc index 6ea5a2244..2fd17db0b 100644 --- a/src/asp/Tools/stereo_rfne.cc +++ b/src/asp/Tools/stereo_rfne.cc @@ -18,7 +18,6 @@ /// \file stereo_rfne.cc /// -//#define USE_GRAPHICS #include #include diff --git a/src/asp/Tools/stereo_utils.py.in b/src/asp/Tools/stereo_utils.py.in index 7dd09b907..ae507587b 100644 --- a/src/asp/Tools/stereo_utils.py.in +++ b/src/asp/Tools/stereo_utils.py.in @@ -97,6 +97,10 @@ def run_and_parse_output(cmd, args, sep, verbose, **kw ): raise Exception('Failed executing: ' + " ".join(call)) data = {} for line in stdout.split('\n'): + + # Print warning messages to stdout + if re.match("^Warning", line): print(line) + if sep in line: keywords = line.split(sep) for index, item in enumerate(keywords):