DGtalTools  1.2.0
raw2HDF5.cpp
1 
28 #include <iostream>
29 #include <DGtal/base/Common.h>
30 #include <DGtal/io/readers/RawReader.h>
31 #include <DGtal/io/writers/HDF5Writer.h>
32 #include <DGtal/helpers/StdDefs.h>
33 #include <DGtal/images/Image.h>
34 #include <DGtal/images/ImageContainerBySTLVector.h>
35 
36 #include "CLI11.hpp"
37 
38 
39 using namespace std;
40 using namespace DGtal;
41 using namespace Z3i;
42 
43 
44 
83 void missingParam ( std::string param )
84 {
85  trace.error() <<" Parameter: "<<param<<" is required..";
86  trace.info() <<std::endl;
87  exit ( 1 );
88 }
89 
90 
91 int main(int argc, char**argv)
92 {
93 
94 
95 // parse command line using CLI ----------------------------------------------
96  CLI::App app;
97  std::string inputFileName;
98  std::string outputFileName {"result.hdf5"};
99  unsigned int x, y, z;
100 
101  app.description("Converts a 3D 8-bit raw file to HDF5.\n Basic usage \n \traw2HDF5 -x 128 -y 128 -z 128 --input <RawFileName> --output <HDF5OutputFileName>");
102 
103  app.add_option("-i,--input,1", inputFileName, "Input raw file." )
104  ->required()
105  ->check(CLI::ExistingFile);
106  app.add_option("-o,--output,2",outputFileName,"Output hdf5 filename.", true);
107  app.add_option("--x,-x", x, "x extent." )
108  ->required();
109  app.add_option("--y,-y", y, "y extent." )
110  ->required();
111  app.add_option("--z,-z", z, "z extent." )
112  ->required();
113 
114  app.get_formatter()->column_width(40);
115  CLI11_PARSE(app, argc, argv);
116  // END parse command line using CLI ----------------------------------------------
117 
118 
119  typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
120 
121  MyImageC imageC = RawReader< MyImageC >::importRaw8 ( inputFileName, Z3i::Vector(x,y,z) );
122  bool res = HDF5Writer< MyImageC>::exportHDF5_3D(outputFileName, imageC, "/UInt8Array3D");
123 
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 
133 }
Definition: ATu0v1.h:57