DGtalTools  0.9.4
raw2vol.cpp
1 
28 #include <iostream>
29 #include <DGtal/base/Common.h>
30 #include <DGtal/io/readers/RawReader.h>
31 #include <DGtal/io/writers/VolWriter.h>
32 #include <DGtal/io/readers/VolReader.h>
33 #include <DGtal/io/writers/RawWriter.h>
34 #include <DGtal/helpers/StdDefs.h>
35 #include "DGtal/io/colormaps/GrayscaleColorMap.h"
36 #include <DGtal/images/Image.h>
37 #include <DGtal/images/ImageContainerBySTLVector.h>
38 
39 #include <boost/program_options/options_description.hpp>
40 #include <boost/program_options/parsers.hpp>
41 #include <boost/program_options/variables_map.hpp>
42 
43 using namespace std;
44 using namespace DGtal;
45 using namespace Z3i;
46 
47 namespace po = boost::program_options;
81 void missingParam ( std::string param )
82 {
83  trace.error() <<" Parameter: "<<param<<" is required..";
84  trace.info() <<std::endl;
85  exit ( 1 );
86 }
87 
88 
89 int main(int argc, char**argv)
90 {
91 
92  // parse command line ----------------------------------------------
93  po::options_description general_opt ( "Allowed options are: " );
94  general_opt.add_options()
95  ( "help,h", "display this message." )
96  ( "input,i", po::value<std::string>(), "Input raw file." )
97  ( "output,o", po::value<string>(),"Output vol filename." )
98  ( "x,x", po::value<unsigned int>(),"x extent." )
99  ( "y,y", po::value<unsigned int >(),"y extent." )
100  ( "z,z", po::value<unsigned int>(),"z extent." );
101 
102  bool parseOK=true;
103  po::variables_map vm;
104  try{
105  po::store(po::parse_command_line(argc, argv, general_opt), vm);
106  }catch(const std::exception& ex){
107  parseOK=false;
108  trace.info()<< "Error checking program options: "<< ex.what()<< endl;
109  }
110 
111  po::notify ( vm );
112  if (!parseOK || vm.count ( "help" ) ||argc<=1 )
113  {
114  trace.info() << "Converts a 8-bit raw file to vol."<<std::endl
115  << std::endl << "Basic usage: "<<std::endl
116  << "\traw2vol -x 128 -y 128 -z 128 --input <RawFileName> --output <VolOutputFileName> "<<std::endl
117  << general_opt << "\n";
118  return 0;
119  }
120 
121  //Parse options
122  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
123  std::string filename = vm["input"].as<std::string>();
124  if ( ! ( vm.count ( "output" ) ) ) missingParam ( "--output" );
125  std::string outputFileName = vm["output"].as<std::string>();
126  if ( ! ( vm.count ( "x" ) ) ) missingParam ( "--x" );
127  unsigned int x = vm["x"].as<unsigned int>();
128  if ( ! ( vm.count ( "y" ) ) ) missingParam ( "--y" );
129  unsigned int y = vm["y"].as<unsigned int>();
130  if ( ! ( vm.count ( "z" ) ) ) missingParam ( "--z" );
131  unsigned int z = vm["z"].as<unsigned int>();
132 
133 
135 
136  MyImageC imageC = RawReader< MyImageC >::importRaw8 ( filename, Z3i::Vector(x,y,z) );
137  bool res = VolWriter< MyImageC>::exportVol(outputFileName, imageC);
138 
139  if (res)
140  return 0;
141  else
142  {
143  trace.error()<< "Error while exporting the volume."<<std::endl;
144  return 1;
145  }
146 }
STL namespace.
Trace trace(traceWriterTerm)
std::ostream & info()
std::ostream & error()