contrib/mul/mbl/tools/mbl_mask_logic.cxx
Go to the documentation of this file.
00001 /*
00002  * Tool to apply any logical operations on pairs of masks
00003  * using a general 'truth table' rule
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     "Apply a logical operation on a pair of mask files.\n"
00016     "--------------------------------------------------\n"
00017     "Uses an 'operation' string that defines the 'rule' that is applied between the two masks\n"
00018     "The operation must consist of 4 characters, each either 0 or 1\n"
00019     "This will be applied to each possible combination of A and B values\n"
00020     "For example, the truth table below performs an AND operation:\n"
00021     "\n"
00022     "        |-A-|-B-|-OUT-|\n"
00023     "        | 0 | 0 |  0  |\n"
00024     "        | 0 | 1 |  0  |\n"
00025     "        | 1 | 0 |  0  |\n"
00026     "        | 1 | 1 |  1  |\n"
00027     "\n"
00028     "The rule in this case would be '0001'\n"
00029     "\n"
00030     "Some of the more common logical operations:\n"
00031     "   A AND B  = 0001\n"
00032     "   A OR B   = 0111\n"
00033     "   NOT A    = 1100 (Note: Mask B must still exist despite not being used in NOT A\n"
00034     "   NOT B    = 0011        and vice versa)\n"
00035     "   A XOR B  = 0110\n"
00036     "   A NOR B  = 1000\n"
00037     "   A XNOR B = 1001\n"
00038     "   A NAND B = 1110\n"
00039     "\n"
00040   );
00041 
00042   vul_arg<vcl_string> maskA_filename(0,"Filename of mask A");
00043   vul_arg<vcl_string> maskB_filename(0,"Filename of mask B");
00044   vul_arg<vcl_string> operation(0,"Operation to apply - see help text for explanation");
00045   vul_arg<vcl_string> maskout_filename(0,"Filename of the output mask");
00046   vul_arg_parse(argc, argv);
00047 
00048   mbl_mask maskA, maskB;
00049   mbl_load_mask(maskA, maskA_filename().c_str());
00050   mbl_load_mask(maskB, maskB_filename().c_str());
00051 
00052   try { mbl_mask_logic(maskA, maskB, operation()); }
00053   catch (vcl_exception & e)
00054   {
00055     vcl_cout << "An error occurred while carrying out the logic operation.\n" << e.what() << vcl_endl;
00056     return 1;
00057   }
00058   catch (...)
00059   {
00060     vcl_cout << "An unknown error occurred while carrying out the logic operation." << vcl_endl;
00061     return 1;
00062   }
00063   
00064   mbl_save_mask(maskB, maskout_filename().c_str());
00065 }