Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added isis_adjust_cnet_clip

This is a tool for clipping bad control points. The previous tool
kinda stinked. I will be removing since I think I'm the only user.
  • Loading branch information...
commit dc218f38eaf19e42a513bc9f51dd26fbc9457d83 1 parent 02bb2c9
@zmoratto zmoratto authored
View
2  configure.ac
@@ -378,6 +378,7 @@ AX_APP(PLATEORTHOPROJECT,[src/asp/Tools], no, [SESSIONS ISISIO VW_PLATE])
AX_APP(HSVMERGE, [src/asp/Tools], yes, [VW_CARTOGRAPHY VW])
AX_APP(ISISADJUSTWRITE, [src/asp/Tools], no, [ISISIO CORE])
AX_APP(ISISADJUSTCAMERAERR, [src/asp/Tools], no, [ISISIO CORE VW_BUNDLEADJUSTMENT])
+AX_APP(ISISADJUSTCNETCLIP, [src/asp/Tools], no, [ISISIO CORE VW_BUNDLEADJUSTMENT])
# Toolkits (like module, but doesn't build a library)
AX_MODULE(PHOTOMETRYTK, [src/asp/PhotometryTK], [libaspPhotometryTK.la], no, [RABBITMQ_C PROTOBUF VW_PLATE], [BOOST])
@@ -414,6 +415,7 @@ AM_CONDITIONAL(MAKE_APP_PLATEORTHOPROJECT, [test "$MAKE_APP_PLATEORTHOPROJECT" =
AM_CONDITIONAL(MAKE_APP_HSVMERGE, [test "$MAKE_APP_HSVMERGE" = "yes"])
AM_CONDITIONAL(MAKE_APP_ISISADJUSTWRITE, [test "$MAKE_APP_ISISADJUSTWRITE" = "yes"])
AM_CONDITIONAL(MAKE_APP_ISISADJUSTCAMERAERR, [test "$MAKE_APP_ISISADJUSTCAMERAERR" = "yes"])
+AM_CONDITIONAL(MAKE_APP_ISISADJUSTCNETCLIP, [test "$MAKE_APP_ISISADJUSTCNETCLIP" = "yes"])
##################################################
# final processing
View
6 src/asp/Tools/Makefile.am
@@ -139,6 +139,12 @@ if MAKE_APP_ISISADJUSTCAMERAERR
isis_adjust_camera_err_LDADD = $(APP_ISISADJUSTCAMERAERR_LIBS)
endif
+if MAKE_APP_ISISADJUSTCNETCLIP
+ bin_PROGRAMS += isis_adjust_cnet_clip
+ isis_adjust_cnet_clip_SOURCES = isis_adjust_cnet_clip.cc
+ isis_adjust_cnet_clip_LDADD = $(APP_ISISADJUSTCNETCLIP_LIBS)
+endif
+
##############################################################################
# Tests #
##############################################################################
View
182 src/asp/Tools/isis_adjust_cnet_clip.cc
@@ -0,0 +1,182 @@
+// __BEGIN_LICENSE__
+// Copyright (C) 2006-2010 United States Government as represented by
+// the Administrator of the National Aeronautics and Space Administration.
+// All Rights Reserved.
+// __END_LICENSE__
+
+/// This application finds the error statistics of all control points
+/// in a control network. It then modifies the control network to
+/// remove high error control points.
+
+#include <vw/Core/ProgressCallback.h>
+#include <vw/BundleAdjustment/ControlNetwork.h>
+#include <asp/Core/Macros.h>
+#include <asp/IsisIO/IsisAdjustCameraModel.h>
+
+#include <boost/algorithm/string.hpp>
+#include <boost/program_options.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/foreach.hpp>
+
+using namespace vw;
+namespace po = boost::program_options;
+namespace fs = boost::filesystem;
+
+struct Options {
+ std::string cnet_file;
+ std::vector<std::string> input_names;
+ double std_dev_clip;
+};
+
+void handle_arguments( int argc, char *argv[], Options& opt ) {
+ po::options_description general_options("");
+ general_options.add_options()
+ ("s,std-dev-clip", po::value(&opt.std_dev_clip)->default_value(2),
+ "How many std_dev away must a control point be to be clipped.")
+ ("help,h", "Display this help message");
+
+ po::options_description positional("");
+ positional.add_options()
+ ("cnet-file", po::value(&opt.cnet_file))
+ ("input-files", po::value(&opt.input_names));
+
+ po::positional_options_description positional_desc;
+ positional_desc.add("cnet-file", 1);
+ positional_desc.add("input-files", -1);
+
+ po::options_description all_options;
+ all_options.add(general_options).add(positional);
+
+ po::variables_map vm;
+ try {
+ po::store( po::command_line_parser( argc, argv ).options(all_options).positional(positional_desc).run(), vm );
+ po::notify( vm );
+ } catch (po::error &e ) {
+ vw_throw( ArgumentErr() << "Error parsing input:\n\t"
+ << e.what() << general_options );
+ }
+
+ std::ostringstream usage;
+ usage << "Usage: " << argv[0] << " [options] <cnet_file> <isis cube files> ...\n";
+
+ if ( vm.count("help") )
+ vw_throw( ArgumentErr() << usage.str() << general_options );
+ if ( opt.input_names.empty() )
+ vw_throw( ArgumentErr() << "Missing input cube files!\n"
+ << usage.str() << general_options );
+ if ( opt.cnet_file.empty() )
+ vw_throw( ArgumentErr() << "Missing input control network!\n"
+ << usage.str() << general_options );
+}
+
+int main( int argc, char* argv[] ) {
+ Options opt;
+ try {
+ handle_arguments( argc, argv, opt );
+
+ // Loading the image data into the camera models. Also applying
+ // blank equations to define the cameras
+ std::vector< camera::IsisAdjustCameraModel > camera_models;
+ std::map<std::string,size_t> serial_to_camera_model;
+ std::map<size_t,std::string> id_to_filename;
+ {
+ vw_out() << "Loading Camera Models:\n";
+ vw_out() << "----------------------\n";
+ TerminalProgressCallback progress("asp","Camera Models:");
+ progress.report_progress(0);
+ double tpc_inc = 1/double(opt.input_names.size());
+ BOOST_FOREACH( std::string const& input, opt.input_names ) {
+ progress.report_incremental_progress( tpc_inc );
+ vw_out(DebugMessage,"asp") << "Loading: " << input << "\n";
+
+ std::string adjust_file =
+ fs::path( input ).replace_extension("isis_adjust").string();
+
+ typedef boost::shared_ptr<asp::BaseEquation> shared_eq;
+ shared_eq posF, poseF;
+ if ( fs::exists( adjust_file ) ) {
+ std::ifstream input( adjust_file.c_str() );
+ posF = asp::read_equation(input);
+ poseF = asp::read_equation(input);
+ input.close();
+ } else {
+ posF = shared_eq( new asp::PolyEquation( 0 ) );
+ poseF = shared_eq( new asp::PolyEquation( 0 ) );
+ }
+ camera::IsisAdjustCameraModel camera( input, posF, poseF );
+ camera_models.push_back( camera );
+
+ serial_to_camera_model[ camera_models.back().serial_number() ] =
+ camera_models.size() - 1;
+ id_to_filename[ camera_models.size() - 1 ] = input;
+ }
+ progress.report_finished();
+ }
+
+ ba::ControlNetwork cnet("");
+ std::vector<std::string> tokens;
+ boost::split( tokens, opt.cnet_file, boost::is_any_of(".") );
+ if ( tokens[tokens.size()-1] == "net" ) {
+ cnet.read_isis( opt.cnet_file );
+ } else if ( tokens[tokens.size()-1] == "cnet" ) {
+ cnet.read_binary( opt.cnet_file );
+ } else {
+ vw_throw( IOErr() << "Unknown Control Network file extension, \""
+ << tokens[tokens.size()-1] << "\"." );
+ }
+
+ vw_out() << "Iterating through control points.\n";
+ std::vector<double> cp_error( cnet.size() );
+ std::fill( cp_error.begin(), cp_error.end(), 0 );
+ {
+ std::vector<double>::iterator error_it = cp_error.begin();
+ ba::ControlNetwork::iterator cp_it = cnet.begin();
+ while ( cp_it != cnet.end() ) {
+ BOOST_FOREACH( ba::ControlMeasure& cm, *cp_it ) {
+ cm.set_image_id( serial_to_camera_model[cm.serial()] );
+ Vector2 reprojection =
+ camera_models[cm.image_id()].point_to_pixel( cp_it->position() );
+ *error_it += norm_2(reprojection-cm.position());
+ }
+ *error_it /= cp_it->size();
+
+ error_it++; cp_it++;
+ }
+ }
+
+ // So getting mean and std dev
+ MeanAccumulator<double> mean_acc;
+ StdDevAccumulator<double> stddev_acc;
+ BOOST_FOREACH( double& meas, cp_error ) {
+ mean_acc( meas );
+ stddev_acc( meas );
+ }
+
+ double mean = mean_acc.value();
+ double stddev = stddev_acc.value();
+ vw_out() << "Mean error : " << mean << " px\n";
+ vw_out() << "StdDev error : " << stddev << " px\n";
+
+ std::vector<double>::reverse_iterator error_it = cp_error.rbegin();
+ size_t error_index = cp_error.size()-1;
+ size_t delete_count = 0;
+ while ( error_it != cp_error.rend() ) {
+
+ if ( *error_it - mean > opt.std_dev_clip*stddev ) {
+ cnet.delete_control_point( error_index );
+ delete_count++;
+ }
+
+ error_index--;
+ error_it++;
+ }
+
+ vw_out() << "Removed " << delete_count << " of " << cp_error.size()
+ << " control points.\n";
+
+ cnet.write_binary(fs::path(opt.cnet_file).stem()+"-clipped.cnet");
+
+ } ASP_STANDARD_CATCHES;
+
+ return 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.