contrib/mul/mbl/tools/mbl_mask_on_mask.cxx
Go to the documentation of this file.
00001 /*
00002  * Tool to replace 'true' values in B with values taken from A.
00003  *  Size of A must match 'true' count in B
00004  */
00005 
00006 #include <vcl_string.h>
00007 #include <vcl_exception.h>
00008 #include <vcl_iostream.h>
00009 #include <vul/vul_arg.h>
00010 #include <mbl/mbl_mask.h>
00011 
00012 int main(int argc, char **argv)
00013 {
00014   vul_arg_base::set_help_description(
00015     "DESCRIPTION:\n"
00016     "Input mask B has n elements (of which m are TRUE) and thus transforms a vector X of n elements to a vector Y of m elements.\n"
00017     "Input mask A has m elements (of which l are TRUE) and thus transforms a vector Y of m elements to a vector Z of l elements.\n"
00018     "Output mask C has n elements (of which l are TRUE) and thus transforms a vector X of n elements to a vector Z of l elements.\n");
00019   vul_arg<vcl_string> maskA_filename(0,"Filename of mask A");
00020   vul_arg<vcl_string> maskB_filename(0,"Filename of mask B");
00021   vul_arg<vcl_string> maskout_filename(0,"Filename of the output mask");
00022   vul_arg_parse(argc, argv);
00023 
00024   mbl_mask maskA, maskB;
00025   mbl_load_mask(maskA, maskA_filename().c_str());
00026   mbl_load_mask(maskB, maskB_filename().c_str());
00027   
00028   try { mbl_mask_on_mask(maskA, maskB); }
00029   catch (vcl_exception & e)
00030   {
00031     vcl_cout << "An error occurred while applying the mask.\n" << e.what() << vcl_endl;
00032     return 1;
00033   }
00034   catch (...)
00035   {
00036     vcl_cout << "An unknown error occurred while applying the mask." << vcl_endl;
00037     return 1;
00038   }
00039 
00040   mbl_save_mask(maskB, maskout_filename().c_str());
00041 }