DGtalTools  0.9.4
volAddBorder.cpp
1 
28 #include <iostream>
29 #include <DGtal/base/Common.h>
30 #include <DGtal/io/readers/VolReader.h>
31 #include <DGtal/io/writers/VolWriter.h>
32 #include <DGtal/helpers/StdDefs.h>
33 #include <DGtal/images/Image.h>
34 #include <DGtal/images/ImageContainerBySTLVector.h>
35 
36 #include <boost/program_options/options_description.hpp>
37 #include <boost/program_options/parsers.hpp>
38 #include <boost/program_options/variables_map.hpp>
39 
40 using namespace std;
41 using namespace DGtal;
42 using namespace Z3i;
43 
44 namespace po = boost::program_options;
45 
46 
47 
48 
89 void missingParam ( std::string param )
90 {
91  trace.error() <<" Parameter: "<<param<<" is required..";
92  trace.info() <<std::endl;
93  exit ( 1 );
94 }
95 
96 
97 int main(int argc, char**argv)
98 {
99 
100  // parse command line ----------------------------------------------
101  po::options_description general_opt ( "Allowed options are " );
102  general_opt.add_options()
103  ( "help,h", "display this message." )
104  ( "input,i", po::value<std::string>(), "Input vol file." )
105  ( "output,o", po::value<string>(),"Output filename." );
106  bool parseOK=true;
107  po::variables_map vm;
108  try{
109  po::store(po::parse_command_line(argc, argv, general_opt), vm);
110  }catch(const std::exception& ex){
111  parseOK=false;
112  trace.info()<< "Error checking program options: "<< ex.what()<< endl;
113  }
114  po::notify ( vm );
115  if ( !parseOK || vm.count ( "help" ) ||argc<=1 )
116  {
117  trace.info() << "Add a border of one voxel with value 0 around a vol file."<<std::endl
118  << std::endl << "Basic usage: "<<std::endl
119  << "\tvolAddBorder --input <volFileName> --o <volOutputFileName> "<<std::endl
120  << general_opt << "\n"
121  << "Example: \n \t volAddBorder -i $DGtal/examples/samples/Al.100.vol -o Al.100border.vol";
122  return 0;
123  }
124 
125  //Parse options
126  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
127  std::string filename = vm["input"].as<std::string>();
128  if ( ! ( vm.count ( "output" ) ) ) missingParam ( "--output" );
129  std::string outputFileName = vm["output"].as<std::string>();
130 
132 
133  MyImageC imageC = VolReader< MyImageC >::importVol ( filename );
134  MyImageC outputImage( Z3i::Domain( imageC.domain().lowerBound() - Vector().diagonal(1),
135  imageC.domain().upperBound() + Vector().diagonal(1)));
136 
137  //Fast Copy
138  for(MyImageC::Domain::ConstIterator it = imageC.domain().begin(),
139  itend = imageC.domain().end(); it != itend; ++it)
140  outputImage.setValue( *it , imageC(*it));
141 
142 
143  bool res = VolWriter< MyImageC>::exportVol(outputFileName, outputImage);
144  if (res) return 0; else return 1;
145 }
static Self diagonal(Component val=1)
STL namespace.
Trace trace(traceWriterTerm)
std::ostream & info()
std::ostream & error()