31 #include <DGtal/base/Common.h>    32 #include <DGtal/io/readers/GenericReader.h>    33 #include <DGtal/io/writers/GenericWriter.h>    34 #include <DGtal/helpers/StdDefs.h>    35 #include <DGtal/images/ImageContainerBySTLVector.h>    36 #include <DGtal/images/ConstImageAdapter.h>    37 #include <boost/program_options/options_description.hpp>    38 #include <boost/program_options/parsers.hpp>    39 #include <boost/program_options/variables_map.hpp>    43 using namespace DGtal;
    46 namespace po = boost::program_options;
    97 void missingParam ( std::string param )
    99   trace.error() <<
" Parameter: "<<param<<
" is required..";
   100   trace.info() <<std::endl;
   105 int main(
int argc, 
char**argv)
   109   po::options_description general_opt ( 
"Allowed options are: " );
   110   general_opt.add_options()
   111     ( 
"help,h", 
"display this message." )
   112     ( 
"input,i", po::value<std::string>(), 
"Input vol file." )
   113     ( 
"output,o", po::value<std::string>()->default_value(
"output.vol"),
"Output filename." )
   114     (
"inputVals,s", po::value<std::vector<unsigned int > >()->multitoken(), 
"specify the values which will be transformed with the output values (given with --outputVals)." ) 
   115     (
"outputVals,r", po::value<std::vector<unsigned int > >()->multitoken(), 
"specify the output values to transformed accordint the input values (given with --inputVals)." ) ;
   118   po::variables_map vm;
   122     po::store ( po::parse_command_line ( argc, argv, general_opt ), vm );
   123   }
catch(
const std::exception& ex){
   125     trace.info()<< 
"Error checking program options: "<< ex.what()<< endl;
   128   if (!parseOK || !vm.count(
"inputVals")|| !vm.count(
"outputVals") || !vm.count(
"input") || !vm.count(
"output")   || vm.count ( 
"help" ))
   130       trace.info() << 
"Apply basic vol image transform from the input values to output values."<<std::endl
   131                    << std::endl << 
"Basic usage: "<<std::endl
   132                    << 
"\t volTrValues --input <volFileName> --o <volOutputFileName> -s 1 99 -r 100 200  "<<std::endl
   133                    << 
"\t => all voxel of values 1 (resp. 99) will be 100 (resp. 200) in the resulting image.   "<<std::endl
   134                    << general_opt << 
"\n";
   135       if( !vm.count(
"inputVals")){
   136         missingParam(
"inputVals");
   138       if( !vm.count(
"outputVals")){
   139         missingParam(
"outputVals");
   141       if( !vm.count(
"input")){
   142         missingParam(
"input");
   144       if( !vm.count(
"output")){
   145         missingParam(
"output");
   154   std::string filename = vm[
"input"].as<std::string>();
   155   if ( ! ( vm.count ( 
"output" ) ) ) missingParam ( 
"--output" );
   156   std::string outputFileName = vm[
"output"].as<std::string>();
   159   std::vector<unsigned int> inputVals = vm[
"inputVals"].as<std::vector<unsigned int > >();
   160   std::vector<unsigned int>  outputVals = vm[
"outputVals"].as<std::vector<unsigned int > >();
   162   if(inputVals.size()!=outputVals.size()){
   163     trace.error()<< 
"Transformation not possible the two sets of input/output values should have the same size." << std::endl;
   167   trace.beginBlock(
"Loading file");
   168   typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char>  MyImageC;
   169   MyImageC  image = GenericReader< MyImageC >::import( filename );
   172   for(MyImageC::Domain::ConstIterator it = image.domain().begin(),
   173         itend = image.domain().end(); it != itend; ++it)
   176       for(
unsigned int i = 0; i< inputVals.size(); i++){
   177         if(inputVals.at(i)==val){
   178           image.setValue( *it , outputVals.at(i));
   184   trace.beginBlock(
"Exporting...");
   185   bool res =  GenericWriter<MyImageC>::exportFile(outputFileName, image);
   188   if (res) 
return 0; 
else return 1;