DGtalTools  1.2.0
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 "CLI11.hpp"
40 
41 using namespace std;
42 using namespace DGtal;
43 using namespace Z3i;
44 
45 
86 void missingParam ( std::string param )
87 {
88  trace.error() <<" Parameter: "<<param<<" is required..";
89  trace.info() <<std::endl;
90  exit ( 1 );
91 }
92 
93 
94 int main(int argc, char**argv)
95 {
96 
97 
98 // parse command line using CLI ----------------------------------------------
99  CLI::App app;
100  std::string inputFileName;
101  std::string outputFileName {"result.vol"};
102  unsigned int x, y, z;
103  app.description("Converts a 8-bit raw file to vol.\n Basic example:\n \t raw2vol <RawFileName> <VolOutputFileName> -x 128 -y 128 -z 128");
104  app.add_option("-i,--input,1", inputFileName, "Input raw file." )
105  ->required()
106  ->check(CLI::ExistingFile);
107  app.add_option("-o,--output,2",outputFileName,"Output vol filename.", true);
108  app.add_option("--x,-x", x, "x extent." )
109  ->required();
110  app.add_option("--y,-y", y, "y extent." )
111  ->required();
112  app.add_option("--z,-z", z, "z extent." )
113  ->required();
114 
115 
116  app.get_formatter()->column_width(40);
117  CLI11_PARSE(app, argc, argv);
118  // END parse command line using CLI ----------------------------------------------
119 
120 
121  typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
122  MyImageC imageC = RawReader< MyImageC >::importRaw8 ( inputFileName, Z3i::Vector(x,y,z));
123  bool res = VolWriter< MyImageC>::exportVol(outputFileName, imageC);
124 
125  if (res)
126  return EXIT_SUCCESS;
127  else
128  {
129  trace.error()<< "Error while exporting the volume."<<std::endl;
130  return EXIT_FAILURE;
131  }
132 }
Definition: ATu0v1.h:57