diff --git a/src/asp/Core/DemDisparity.cc b/src/asp/Core/DemDisparity.cc index 9b2751d22..22e64a630 100644 --- a/src/asp/Core/DemDisparity.cc +++ b/src/asp/Core/DemDisparity.cc @@ -40,43 +40,47 @@ using namespace vw::cartography; namespace asp { template - class DemDisparity : public ImageViewBase > { + class DemDisparity: public ImageViewBase> { ImageT m_left_image; double m_dem_error; GeoReference m_dem_georef; const DEMImageT & m_dem; Vector2f m_downsample_scale; + vw::TransformPtr m_tx_left, m_tx_right; boost::shared_ptr m_left_camera_model; boost::shared_ptr m_right_camera_model; bool m_do_align; Matrix m_align_left_matrix, m_align_right_matrix; int m_pixel_sample; - ImageView > & m_disparity_spread; + ImageView> & m_disp_spread; public: - DemDisparity( ImageViewBase const& left_image, - double dem_error, GeoReference dem_georef, - DEMImageT const& dem, - Vector2f const& downsample_scale, - boost::shared_ptr left_camera_model, - boost::shared_ptr right_camera_model, - bool do_align, - Matrix const& align_left_matrix, Matrix const& align_right_matrix, - int pixel_sample, ImageView > & disparity_spread) - :m_left_image(left_image.impl()), + DemDisparity(ImageViewBase const& left_image, + double dem_error, GeoReference dem_georef, + DEMImageT const& dem, + Vector2f const& downsample_scale, + vw::TransformPtr tx_left, vw::TransformPtr tx_right, + boost::shared_ptr left_camera_model, + boost::shared_ptr right_camera_model, + bool do_align, + vw::Matrix const& align_left_matrix, + vw::Matrix const& align_right_matrix, + int pixel_sample, ImageView> & disp_spread): + m_left_image(left_image.impl()), m_dem_error(dem_error), m_dem_georef(dem_georef), m_dem(dem), m_downsample_scale(downsample_scale), + m_tx_left(tx_left), m_tx_right(tx_right), m_left_camera_model(left_camera_model), m_right_camera_model(right_camera_model), m_do_align(do_align), m_align_left_matrix(align_left_matrix), m_align_right_matrix(align_right_matrix), m_pixel_sample(pixel_sample), - m_disparity_spread(disparity_spread){} + m_disp_spread(disp_spread) {} - // Image View interface + // ImageView interface typedef PixelMask pixel_type; typedef pixel_type result_type; typedef ProceduralPixelAccessor pixel_accessor; @@ -85,31 +89,30 @@ namespace asp { inline int32 rows () const { return m_left_image.rows(); } inline int32 planes() const { return 1; } - inline pixel_accessor origin() const { return pixel_accessor( *this, 0, 0 ); } + inline pixel_accessor origin() const { return pixel_accessor(*this, 0, 0); } - inline pixel_type operator()( double /*i*/, double /*j*/, int32 /*p*/ = 0 ) const { - vw_throw(NoImplErr() << "DemDisparity::operator()(...) is not implemented"); + inline pixel_type operator()(double /*i*/, double /*j*/, int32 /*p*/ = 0) const { + vw_throw(NoImplErr() << "DemDisparity::operator()(...) is not implemented.\n"); return pixel_type(); } - typedef CropView > prerasterize_type; + typedef CropView> prerasterize_type; inline prerasterize_type prerasterize(BBox2i const& bbox) const { - prerasterize_type lowres_disparity = prerasterize_type(ImageView(bbox.width(), - bbox.height()), - -bbox.min().x(), -bbox.min().y(), - cols(), rows() ); + prerasterize_type lowres_disparity + = prerasterize_type(ImageView(bbox.width(), bbox.height()), + -bbox.min().x(), -bbox.min().y(), cols(), rows()); - for (int row = bbox.min().y(); row < bbox.max().y(); row++){ - for (int col = bbox.min().x(); col < bbox.max().x(); col++){ + for (int row = bbox.min().y(); row < bbox.max().y(); row++) { + for (int col = bbox.min().x(); col < bbox.max().x(); col++) { lowres_disparity(col, row).invalidate(); - m_disparity_spread(col, row).invalidate(); + m_disp_spread(col, row).invalidate(); } } double height_error_tol = std::max(m_dem_error/4.0, 1.0); // height error in meters - double max_abs_tol = height_error_tol/4.0; // abs cost function change b/w iterations - double max_rel_tol = 1e-14; // rel cost function change b/w iterations + double max_abs_tol = height_error_tol/4.0; // abs cost function change + double max_rel_tol = 1e-14; // rel cost function change int num_max_iter = 50; bool treat_nodata_as_zero = false; @@ -122,19 +125,19 @@ namespace asp { // the current tile. std::vector diagonals; - int wid = bbox.width() - 1, hgt = bbox.height() - 1, dim = std::max(1, std::max(wid, hgt)/10); + int wid = bbox.width() - 1, hgt = bbox.height() - 1; + int dim = std::max(1, std::max(wid, hgt)/10); for (int i = 0; i <= dim; i++) diagonals.push_back(bbox.min() + Vector2(double(i)*wid/dim, double(i)*hgt/dim)); for (int i = 0; i <= dim; i++) diagonals.push_back(bbox.min() + Vector2(double(i)*wid/dim, hgt - double(i)*hgt/dim)); BBox2i dem_box; - for (unsigned k = 0; k < diagonals.size(); k++){ + for (unsigned k = 0; k < diagonals.size(); k++) { Vector2 left_lowres_pix = diagonals[k]; - Vector2 left_fullres_pix = elem_quot(left_lowres_pix, m_downsample_scale); - if (m_do_align){ + if (m_do_align) { // Need to go to the image pixel in the untransformed image left_fullres_pix = HomographyTransform(m_align_left_matrix).reverse(left_fullres_pix); } @@ -154,10 +157,10 @@ namespace asp { height_error_tol, max_abs_tol, max_rel_tol, num_max_iter, prev_xyz); - if ( !has_intersection || xyz == Vector3() ) continue; + if (!has_intersection || xyz == Vector3()) continue; prev_xyz = xyz; - Vector3 llh = m_dem_georef.datum().cartesian_to_geodetic( xyz ); + Vector3 llh = m_dem_georef.datum().cartesian_to_geodetic(xyz); Vector2 pix = round(m_dem_georef.lonlat_to_pixel(subvector(llh, 0, 2))); dem_box.grow(pix); } @@ -170,23 +173,24 @@ namespace asp { // Crop the georef, read the DEM region in memory GeoReference georef_crop = crop(m_dem_georef, dem_box); - ImageView > dem_crop = crop(m_dem, dem_box); + ImageView > dem_crop = crop(m_dem, dem_box); // Compute the DEM disparity. Use one in every 'm_pixel_sample' pixels. + for (int row = bbox.min().y(); row < bbox.max().y(); row++) { - for (int row = bbox.min().y(); row < bbox.max().y(); row++){ - if (row%m_pixel_sample != 0) continue; + if (row%m_pixel_sample != 0) + continue; // Must wipe the previous guess since we are now too far from it prev_xyz = Vector3(); - for (int col = bbox.min().x(); col < bbox.max().x(); col++){ - if (col%m_pixel_sample != 0) continue; + for (int col = bbox.min().x(); col < bbox.max().x(); col++) { + if (col%m_pixel_sample != 0) + continue; Vector2 left_lowres_pix = Vector2(col, row); - Vector2 left_fullres_pix = elem_quot(left_lowres_pix, m_downsample_scale); - if (m_do_align){ + if (m_do_align) { // Need to go to the image pixel in the untransformed image left_fullres_pix = HomographyTransform(m_align_left_matrix).reverse(left_fullres_pix); } @@ -205,9 +209,9 @@ namespace asp { has_intersection, height_error_tol, max_abs_tol, max_rel_tol, num_max_iter, - prev_xyz - ); - if ( !has_intersection || xyz == Vector3() ) continue; + prev_xyz); + if (!has_intersection || xyz == Vector3()) + continue; prev_xyz = xyz; // Since our DEM is only known approximately, the true @@ -216,11 +220,11 @@ namespace asp { // xyz. Use that to get an estimate of the disparity // error. - ImageView< PixelMask > curr_pixel_disp_range(3, 1); + ImageView> curr_pixel_disp_range(3, 1); double bias[] = {-1.0, 1.0, 0.0}; int success[] = {0, 0, 0}; - for (int k = 0; k < curr_pixel_disp_range.cols(); k++){ + for (int k = 0; k < curr_pixel_disp_range.cols(); k++) { Vector2 right_fullres_pix; try { @@ -229,7 +233,7 @@ namespace asp { curr_pixel_disp_range(k, 0).invalidate(); continue; } - if (m_do_align){ + if (m_do_align) { right_fullres_pix = HomographyTransform(m_align_right_matrix).forward(right_fullres_pix); } @@ -243,11 +247,11 @@ namespace asp { } BBox2f search_range = stereo::get_disparity_range(curr_pixel_disp_range); - if (search_range == BBox2f(0,0,0,0)) continue; - - lowres_disparity(col, row) = round( (search_range.min() + search_range.max())/2.0 ); - m_disparity_spread(col, row) = ceil( (search_range.max() - search_range.min())/2.0 ); + if (search_range == BBox2f(0,0,0,0)) + continue; + lowres_disparity(col, row) = round((search_range.min() + search_range.max())/2.0); + m_disp_spread(col, row) = ceil((search_range.max() - search_range.min())/2.0); } } @@ -262,33 +266,33 @@ namespace asp { template DemDisparity - dem_disparity( ImageViewBase const& left, - double dem_error, GeoReference dem_georef, - DEMImageT const& dem, - Vector2f const& downsample_scale, - boost::shared_ptr left_camera_model, - boost::shared_ptr right_camera_model, - bool do_align, - Matrix const& align_left_matrix, - Matrix const& align_right_matrix, - int pixel_sample, - ImageView > & disparity_spread - ) { + dem_disparity(ImageViewBase const& left, + double dem_error, GeoReference dem_georef, + DEMImageT const& dem, + Vector2f const& downsample_scale, + vw::TransformPtr tx_left, vw::TransformPtr tx_right, + boost::shared_ptr left_camera_model, + boost::shared_ptr right_camera_model, + bool do_align, + Matrix const& align_left_matrix, + Matrix const& align_right_matrix, + int pixel_sample, + ImageView> & disp_spread) { typedef DemDisparity return_type; - return return_type( left.impl(), - dem_error, dem_georef, - dem, downsample_scale, - left_camera_model, right_camera_model, - do_align, align_left_matrix, align_right_matrix, - pixel_sample, disparity_spread - ); + return return_type(left.impl(), + dem_error, dem_georef, + dem, downsample_scale, + tx_left, tx_right, + left_camera_model, right_camera_model, + do_align, align_left_matrix, align_right_matrix, + pixel_sample, disp_spread); } - void produce_dem_disparity( ASPGlobalOptions & opt, - boost::shared_ptr left_camera_model, - boost::shared_ptr right_camera_model, - std::string session_name - ) { + void produce_dem_disparity(ASPGlobalOptions & opt, + vw::TransformPtr tx_left, vw::TransformPtr tx_right, + boost::shared_ptr left_camera_model, + boost::shared_ptr right_camera_model, + std::string const& session_name) { if (stereo_settings().is_search_defined()) vw_out(WarningMessage) << "Computing low-resolution disparity from DEM. " @@ -298,43 +302,43 @@ namespace asp { // Skip pixels to speed things up, particularly for ISIS and DG. int pixel_sample = 2; - DiskImageView > left_image(opt.out_prefix+"-L.tif"); - DiskImageView > left_image_sub(opt.out_prefix+"-L_sub.tif"); + DiskImageView> left_image(opt.out_prefix+"-L.tif"); + DiskImageView> left_image_sub(opt.out_prefix+"-L_sub.tif"); + // The DEM to use to estimate the disparity std::string dem_file = stereo_settings().disparity_estimation_dem; - if (dem_file == ""){ - vw_throw( ArgumentErr() << "dem_disparity: No value was provided for " - << "disparity-estimation-dem.\n" ); - } + if (dem_file == "") + vw::vw_throw(vw::ArgumentErr() << "dem_disparity: No value was provided for " + << "disparity-estimation-dem.\n"); double dem_error = stereo_settings().disparity_estimation_dem_error; - if (dem_error < 0.0){ - vw_throw( ArgumentErr() << "dem_disparity: Invalid value for " - << "disparity-estimation-dem-error: " << dem_error << ".\n" ); - } + if (dem_error < 0.0) + vw::vw_throw(vw::ArgumentErr() << "dem_disparity: Invalid value for " + << "disparity-estimation-dem-error: " << dem_error << ".\n"); GeoReference dem_georef; bool has_georef = cartography::read_georeference(dem_georef, dem_file); if (!has_georef) - vw_throw( ArgumentErr() << "There is no georeference information in: " << dem_file << ".\n" ); + vw::vw_throw(vw::ArgumentErr() << "There is no georeference information in: " + << dem_file << ".\n"); DiskImageView dem_disk_image(dem_file); - ImageViewRef > dem = pixel_cast >(dem_disk_image); - boost::shared_ptr rsrc( DiskImageResourcePtr(dem_file) ); - if ( rsrc->has_nodata_read() ){ + ImageViewRef> dem = pixel_cast>(dem_disk_image); + boost::shared_ptr rsrc(DiskImageResourcePtr(dem_file)); + if (rsrc->has_nodata_read()) { double nodata_value = rsrc->nodata_read(); - if ( !std::isnan(nodata_value) ) + if (!std::isnan(nodata_value)) dem = create_mask(dem_disk_image, nodata_value); } - Vector2f downsample_scale( float(left_image_sub.cols()) / float(left_image.cols()), - float(left_image_sub.rows()) / float(left_image.rows())); + Vector2f downsample_scale(float(left_image_sub.cols()) / float(left_image.cols()), + float(left_image_sub.rows()) / float(left_image.rows())); Matrix align_left_matrix = math::identity_matrix<3>(); Matrix align_right_matrix = math::identity_matrix<3>(); bool do_align = (stereo_settings().alignment_method == "homography" || stereo_settings().alignment_method == "affineepipolar" || stereo_settings().alignment_method == "local_epipolar"); - if (do_align){ + if (do_align) { // We used a transform to align the images, so we have to make // sure to apply that transform to the disparity we are about to // compute as well. @@ -352,60 +356,38 @@ namespace asp { opt.raster_tile_size = Vector2i(64, 64); // This image is small enough that we can keep it in memory - ImageView > disparity_spread(left_image_sub.cols(), left_image_sub.rows()); - - ImageViewRef > lowres_disparity - = pixel_cast >(dem_disparity(left_image_sub, - dem_error, dem_georef, - dem, downsample_scale, - left_camera_model, right_camera_model, - do_align, - align_left_matrix, align_right_matrix, - pixel_sample, disparity_spread - )); + ImageView> disp_spread(left_image_sub.cols(), left_image_sub.rows()); + + ImageViewRef> lowres_disparity + = pixel_cast>(dem_disparity(left_image_sub, + dem_error, dem_georef, + dem, downsample_scale, + tx_left, tx_right, + left_camera_model, right_camera_model, + do_align, + align_left_matrix, align_right_matrix, + pixel_sample, disp_spread)); std::string disparity_file = opt.out_prefix + "-D_sub.tif"; vw_out() << "Writing low-resolution disparity: " << disparity_file << "\n"; - if ( session_name == "isis" ){ + auto tpc1 = TerminalProgressCallback("asp", "\t--> Low-resolution disparity:"); + if (session_name == "isis") { // ISIS does not support multi-threading - boost::scoped_ptr drsrc(vw::cartography::build_gdal_rsrc( disparity_file, - lowres_disparity, opt)); - write_image(*drsrc, lowres_disparity, - TerminalProgressCallback("asp", "\t--> Low-resolution disparity: ")); - }else{ - vw::cartography::block_write_gdal_image(disparity_file, - lowres_disparity, - opt, - TerminalProgressCallback - ("asp", "\t--> Low-resolution disparity:") ); + boost::scoped_ptr + drsrc(vw::cartography::build_gdal_rsrc(disparity_file, lowres_disparity, opt)); + vw::write_image(*drsrc, lowres_disparity, tpc1); + } else { + vw::cartography::block_write_gdal_image(disparity_file, lowres_disparity, + opt, tpc1); } - + + // The disparity spread is in memory by now, so can be written with multiple threads std::string disp_spread_file = opt.out_prefix + "-D_sub_spread.tif"; vw_out() << "Writing low-resolution disparity spread: " << disp_spread_file << "\n"; - vw::cartography::block_write_gdal_image(disp_spread_file, - disparity_spread, - opt, - TerminalProgressCallback - ("asp", "\t--> Low-resolution disparity spread:") ); + auto tpc2 = TerminalProgressCallback("asp", "\t--> Low-resolution disparity spread:"); + vw::cartography::block_write_gdal_image(disp_spread_file, disp_spread, opt, tpc2); // Go back to the original tile size opt.raster_tile_size = orig_tile_size; - -#if 0 // Debug code - ImageView > lowres_disparity_disk; - read_image( lowres_disparity_disk, opt.out_prefix + "-D_sub.tif" ); - ImageView > lowres_disparity2(lowres_disparity_disk.cols()/pixel_sample, lowres_disparity_disk.rows()/pixel_sample); - for (int col = 0; col < lowres_disparity2.cols(); col++){ - for (int row = 0; row < lowres_disparity2.rows(); row++){ - lowres_disparity2(col, row) = lowres_disparity_disk(pixel_sample*col, pixel_sample*row); - } - } - vw::cartography::block_write_gdal_image( opt.out_prefix + "-D_sub2.tif", - lowres_disparity2, - opt, - TerminalProgressCallback - ("asp", "\t--> Low-resolution disparity:") ); -#endif - } - + } diff --git a/src/asp/Core/DemDisparity.h b/src/asp/Core/DemDisparity.h index 8034a6f9a..641646802 100644 --- a/src/asp/Core/DemDisparity.h +++ b/src/asp/Core/DemDisparity.h @@ -38,10 +38,11 @@ namespace asp { /// Use a DEM to get the low-res disparity void produce_dem_disparity(ASPGlobalOptions & opt, + vw::TransformPtr tx_left, + vw::TransformPtr tx_right, boost::shared_ptr left_camera_model, boost::shared_ptr right_camera_model, - std::string session_name - ); + std::string const& session_name); } diff --git a/src/asp/Tools/stereo.cc b/src/asp/Tools/stereo.cc index 078e79be5..82c122991 100644 --- a/src/asp/Tools/stereo.cc +++ b/src/asp/Tools/stereo.cc @@ -84,8 +84,9 @@ BBox2i transformed_crop_win(ASPGlobalOptions const& opt){ } // Handle the arguments for the multiview case. The logic used to break up the -// command line arguments for all images/cameras into command line arguments for -// pairs of image/cameras is fragile. +// command line arguments for all images/cameras into command line arguments for +// pairs of image/cameras is fragile. + void handle_multiview(int argc, char* argv[], int num_pairs, std::vector const& files, @@ -104,6 +105,11 @@ void handle_multiview(int argc, char* argv[], // If a file shows up more than once as input, that will confuse // the logic at the next step, so forbid that. + // TODO(oalexan1): It is possible to determine the command line options and + // their values from boost program options, right after parsing and before it + // stores them in a map. Then this hack is not needed. The current approach + // will fail with the option --disparity-estimation-dem dem.tif if dem.tif is + // also the mapprojection DEM. std::map vals; for (int s = 1; s < argc; s++) vals[argv[s]]++; @@ -111,7 +117,7 @@ void handle_multiview(int argc, char* argv[], if (vals[files[s]] > 1) { vw_throw(ArgumentErr() << "The following input argument shows up more than " << "once and hence cannot be parsed correctly: " - << files[s] << ".\n\n" << usage); + << files[s] << ".\n"); } } @@ -125,13 +131,12 @@ void handle_multiview(int argc, char* argv[], // Must signal to the children runs that they are part of a multiview run std::string opt_str = "--part-of-multiview-run"; - std::vector::iterator it = find(options.begin(), options.end(), - opt_str); + auto it = find(options.begin(), options.end(), opt_str); if (it == options.end()) options.push_back(opt_str); // Multiview is very picky about alignment method - if (stereo_settings().alignment_method != "none" && + if (stereo_settings().alignment_method != "none" && stereo_settings().alignment_method != "homography") { std::string new_alignment; @@ -146,28 +151,24 @@ void handle_multiview(int argc, char* argv[], << stereo_settings().alignment_method << "' to '" << new_alignment << "'.\n"; stereo_settings().alignment_method = new_alignment; - // Set this for future runs as well - if (num_pairs > 1) { - - std::string align_opt = "--alignment-method"; - auto it = std::find(options.begin(), options.end(), align_opt); - if (it != options.end() && it + 1 != options.end()){ - // Modify existing alignment - *(it+1) = new_alignment; - }else{ - // Set new alignment - options.push_back(align_opt); - options.push_back(new_alignment); - } + // Set this for future pairwise runs as well + std::string align_opt = "--alignment-method"; + auto it = std::find(options.begin(), options.end(), align_opt); + if (it != options.end() && it + 1 != options.end()) { + // Modify existing alignment + *(it+1) = new_alignment; + } else { + // Set new alignment + options.push_back(align_opt); + options.push_back(new_alignment); } } - std::string prog_name = extract_prog_name(argv[0]); - // Generate the stereo command for each of the pairs made up of the first // image and each subsequent image, with corresponding cameras. opt_vec.resize(num_pairs); - for (int p = 1; p <= num_pairs; p++){ + std::string prog_name = extract_prog_name(argv[0]); + for (int p = 1; p <= num_pairs; p++) { std::vector cmd; cmd.push_back(prog_name); @@ -179,16 +180,16 @@ void handle_multiview(int argc, char* argv[], cmd.push_back(images[0]); // left image cmd.push_back(images[p]); // right image - if (!cameras.empty()){ + if (!cameras.empty()) { // Don't append the camera names if they are the same as the image names - if ((images[0] != cameras[0]) && (images[p] != cameras[p])){ + if ((images[0] != cameras[0]) && (images[p] != cameras[p])) { cmd.push_back(cameras[0]); // left camera cmd.push_back(cameras[p]); // right camera } } - std::string local_prefix = output_prefix; // Need to have a separate output prefix for each pair + std::string local_prefix = output_prefix; std::ostringstream os; os << local_prefix << "-pair" << p << "/" << p; local_prefix = os.str(); @@ -205,7 +206,7 @@ void handle_multiview(int argc, char* argv[], bool is_multiview = false; // single image and camera pair std::vector local_files; handle_arguments(largc, &largv[0], opt_vec[p-1], additional_options, - is_multiview, local_files, usage, exit_early); + is_multiview, local_files, usage, exit_early); if (verbose) { // Needed for stereo_parse @@ -218,8 +219,10 @@ void handle_multiview(int argc, char* argv[], vw_out() << std::endl; } - } + } // end loop through pairs + // Sanity checks specific to multiview + if (stereo_settings().propagate_errors) vw::vw_throw(vw::ArgumentErr() << "Error propagation is not " << "implemented for more than two images.\n"); @@ -230,7 +233,7 @@ void handle_multiview(int argc, char* argv[], << " is not meant to be used directly with more than two images. Use " << "instead the stereo/parallel_stereo scripts with desired entry points.\n"); - // This must not happen earlier as StereoSession is not initialized yet + // This must happen after StereoSession is initialized if (opt_vec[0].session->do_bathymetry()) vw_throw(ArgumentErr() << "Bathymetry correction does not work with " << "multiview stereo.\n"); @@ -267,7 +270,7 @@ void parse_multiview(int argc, char* argv[], opt_vec.push_back(opt); if (files.size() < 3) - vw_throw(ArgumentErr() << "Missing the input files and/or output prefix.\n\n" << usage); + vw_throw(ArgumentErr() << "Missing the input files and/or output prefix.\n"); // Add note on the alignment method. If done in handle_arguments, it will be // printed twice. @@ -279,7 +282,7 @@ void parse_multiview(int argc, char* argv[], std::vector images, cameras; std::string input_dem; if (!parse_multiview_cmd_files(files, images, cameras, output_prefix, input_dem)) - vw_throw(ArgumentErr() << "Missing the input files and/or output prefix.\n\n" << usage); + vw_throw(ArgumentErr() << "Missing the input files and/or output prefix.\n"); int num_pairs = (int)images.size() - 1; if (num_pairs <= 0) @@ -294,9 +297,9 @@ void parse_multiview(int argc, char* argv[], handle_arguments(argc, argv, opt_vec[0], additional_options, is_multiview, files, usage, exit_early); } else { - handle_multiview(argc, argv, num_pairs, files, images, cameras, - output_prefix, input_dem, additional_options, verbose, exit_early, - usage, opt_vec); + handle_multiview(argc, argv, num_pairs, files, images, cameras, output_prefix, input_dem, + additional_options, verbose, exit_early, usage, + opt_vec); // output } @@ -367,7 +370,7 @@ void handle_arguments(int argc, char *argv[], ASPGlobalOptions& opt, positional_options.add_options() ("input-files", po::value< std::vector>(), "Input files"); positional_desc.add("input-files", -1); - }else{ + } else { // Two-view, have left and right. positional_options.add_options() ("left-input-image", po::value(&opt.in_file1), "Left input image") @@ -385,7 +388,11 @@ void handle_arguments(int argc, char *argv[], ASPGlobalOptions& opt, positional_desc.add("input-dem", 1); } - usage = "[options] [] [DEM]\n Extensions are automatically 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 automatically 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."; bool allow_unregistered = false; std::vector unregistered; po::variables_map vm = asp::check_command_line(argc, argv, opt, general_options, @@ -444,12 +451,13 @@ void handle_arguments(int argc, char *argv[], ASPGlobalOptions& opt, os << usage << general_options; usage = os.str(); - // For multiview, just store the files and return. Must happen after - // logging starts, as logging for multiview is done in subdirectories. + // For multiview, just store the files and return. Must happen after logging + // starts, as logging for multiview is done in subdirectories. In multiview + // mode, the logic further down will be later called for each pair. if (is_multiview) { if (vm.count("input-files") == 0) vw_throw(ArgumentErr() << "Missing input arguments.\n"); - input_files = vm["input-files"].as< std::vector>(); + input_files = vm["input-files"].as>(); return; } @@ -789,24 +797,25 @@ void user_safety_checks(ASPGlobalOptions const& opt) { const bool dem_provided = !opt.input_dem.empty(); // Seed mode valid values - if (stereo_settings().seed_mode > 3){ + if (stereo_settings().seed_mode > 3) { vw_throw(ArgumentErr() << "Invalid value for --corr-seed-mode: " << stereo_settings().seed_mode << ".\n"); } - // D_sub from DEM needs a positive disparity_estimation_dem_error - if (stereo_settings().seed_mode == 2 && - stereo_settings().disparity_estimation_dem_error <= 0.0){ - vw_throw(ArgumentErr() - << "For --corr-seed-mode 2, the value of disparity-estimation-dem-error " - << "must be positive."); - } + if (stereo_settings().seed_mode == 2) { - // D_sub from DEM needs a DEM - if (stereo_settings().seed_mode == 2 && - stereo_settings().disparity_estimation_dem.empty()) { - vw_throw(ArgumentErr() - << "For --corr-seed-mode 2, must set --disparity-estimation-dem.\n"); + if (stereo_settings().disparity_estimation_dem_error <= 0.0) + vw_throw(ArgumentErr() + << "For --corr-seed-mode 2, the value of disparity-estimation-dem-error " + << "must be positive."); + + if (stereo_settings().disparity_estimation_dem.empty()) + vw_throw(ArgumentErr() + << "For --corr-seed-mode 2, must set --disparity-estimation-dem.\n"); + + if (stereo_settings().alignment_method == "epipolar") + vw_throw(ArgumentErr() + << "For --corr-seed-mode 2, cannot use epipolar alignment.\n"); } // Must use map-projected images if input DEM is provided diff --git a/src/asp/Tools/stereo_corr.cc b/src/asp/Tools/stereo_corr.cc index 14ff33ff6..042125129 100644 --- a/src/asp/Tools/stereo_corr.cc +++ b/src/asp/Tools/stereo_corr.cc @@ -263,9 +263,12 @@ void produce_lowres_disparity(ASPGlobalOptions & opt) { // Use a DEM to get the low-res disparity boost::shared_ptr left_camera_model, right_camera_model; opt.session->camera_models(left_camera_model, right_camera_model); - produce_dem_disparity(opt, left_camera_model, right_camera_model, opt.session->name()); + vw::TransformPtr tx_left = opt.session->tx_left(); + vw::TransformPtr tx_right = opt.session->tx_right(); + produce_dem_disparity(opt, tx_left, tx_right, left_camera_model, right_camera_model, + opt.session->name()); - }else if (stereo_settings().seed_mode == 3) { + } else if (stereo_settings().seed_mode == 3) { // D_sub is already generated by now by sparse_disp }