DGtalTools 2.0.0
Loading...
Searching...
No Matches
raw2HDF5.cpp
1
29#include <iostream>
30#include <DGtal/base/Common.h>
31#include <DGtal/io/readers/RawReader.h>
32#include <DGtal/io/writers/HDF5Writer.h>
33#include <DGtal/helpers/StdDefs.h>
34#include <DGtal/images/Image.h>
35#include <DGtal/images/ImageContainerBySTLVector.h>
36
37#include "CLI11.hpp"
38
39
40using namespace std;
41using namespace DGtal;
42using namespace Z3i;
43
44
45
85void missingParam ( std::string param )
86{
87 trace.error() <<" Parameter: "<<param<<" is required..";
88 trace.info() <<std::endl;
89 exit ( 1 );
90}
91
92
93int main(int argc, char**argv)
94{
95
96
97// parse command line using CLI ----------------------------------------------
98 CLI::App app;
99 std::string inputFileName;
100 std::string outputFileName {"result.hdf5"};
101 unsigned int x, y, z;
102
103 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>");
104
105 app.add_option("-i,--input,1", inputFileName, "Input raw file." )
106 ->required()
107 ->check(CLI::ExistingFile);
108 app.add_option("-o,--output,2",outputFileName,"Output hdf5 filename.");
109 app.add_option("--x,-x", x, "x extent." )
110 ->required();
111 app.add_option("--y,-y", y, "y extent." )
112 ->required();
113 app.add_option("--z,-z", z, "z extent." )
114 ->required();
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
123 MyImageC imageC = RawReader< MyImageC >::importRaw8 ( inputFileName, Z3i::Vector(x,y,z) );
124 bool res = HDF5Writer< MyImageC>::exportHDF5_3D(outputFileName, imageC, "/UInt8Array3D");
125
126
127 if (res)
128 return EXIT_SUCCESS;
129 else
130 {
131 trace.error()<< "Error while exporting the volume."<<std::endl;
132 return EXIT_FAILURE;
133 }
134
135}
Definition ATu0v1.h:57