29 #include <DGtal/base/Common.h>
30 #include <DGtal/io/readers/VolReader.h>
31 #include <DGtal/helpers/StdDefs.h>
32 #include <DGtal/images/Image.h>
33 #include <DGtal/images/ImageContainerBySTLVector.h>
39 using namespace DGtal;
78 void missingParam (
const std::string ¶m )
80 trace.error() <<
" Parameter: "<<param<<
" is required..";
81 trace.info() <<std::endl;
85 template <
typename Word>
87 std::ostream& write_word( std::ostream& outs, Word value )
89 for (
unsigned size =
sizeof( Word ); size; --size, value >>= 8)
90 outs.put(
static_cast <char> (value & 0xFF) );
95 int main(
int argc,
char**argv)
102 std::string inputFileName;
103 std::string outputFileName{
"result.vox"};
104 app.description(
"Convert a vol (up to [0,126]^3) to a vox.\n The current exporter does not support custom colormaps, only the voxel values are exported \n Example: vol2vox -i ${DGtal}/examples/samples/Al.100.vol -o Al.100.vox");
105 app.add_option(
"-i,--input,1", inputFileName,
"Input vol file.")
107 ->check(CLI::ExistingFile);
108 app.add_option(
"-o,--output,2", outputFileName,
"Output filename.",
true);
109 app.get_formatter()->column_width(40);
110 CLI11_PARSE(app, argc, argv);
113 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
114 trace.beginBlock(
"Loading..");
115 MyImageC imageL = VolReader< MyImageC >::importVol ( inputFileName );
118 if ( (imageL.domain().upperBound() - imageL.domain().lowerBound()).max() > 126 )
120 trace.error() <<
"Vol file too large (width > 126)."<<std::endl;
121 trace.info() << std::endl;
125 trace.beginBlock(
"Exporting...");
127 myfile.open (outputFileName, ios::out | ios::binary);
129 DGtal::uint32_t cpt=0;
130 for(
auto it = imageL.range().begin(), itend = imageL.range().end();
135 Point size = imageL.domain().upperBound() - imageL.domain().lowerBound();
160 trace.info()<<size<<std::endl;
163 myfile <<
'V'<<
'O'<<
'X'<<
' ';
165 write_word(myfile, (DGtal::uint32_t)150);
168 myfile <<
'M'<<
'A'<<
'I'<<
'N';
169 write_word(myfile,DGtal::uint32_t(0));
170 write_word(myfile,DGtal::uint32_t( (4+4+4 + 12 ) + ((4+ 4 + 4) + (4+ cpt*4))));
173 myfile <<
'S'<<
'I'<<
'Z'<<
'E';
174 write_word(myfile,DGtal::uint32_t(12));
175 write_word(myfile,DGtal::uint32_t(0));
176 write_word(myfile,DGtal::uint32_t(size[0]+1));
177 write_word(myfile,DGtal::uint32_t(size[1]+1));
178 write_word(myfile,DGtal::uint32_t(size[2]+1));
181 myfile <<
'X'<<
'Y'<<
'Z'<<
'I';
182 write_word(myfile, (DGtal::uint32_t)(4+cpt*4));
183 write_word(myfile,DGtal::uint32_t(0));
184 write_word(myfile, DGtal::uint32_t(cpt));
186 trace.info() <<
"Number of voxels= "<<cpt<<std::endl;
189 for(
auto it = imageL.domain().begin(), itend = imageL.domain().end();
191 if (imageL(*it) != 0)
193 Point p = (*it) - imageL.domain().lowerBound();
194 myfile.put((DGtal::uint8_t)p[0]);
195 myfile.put( (DGtal::uint8_t)p[1]);
196 myfile.put( (DGtal::uint8_t)p[2]);
197 myfile.put(imageL(*it));