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>
35 #include <boost/program_options/options_description.hpp>
36 #include <boost/program_options/parsers.hpp>
37 #include <boost/program_options/variables_map.hpp>
40 using namespace DGtal;
43 namespace po = boost::program_options;
75 void missingParam (
const std::string ¶m )
77 trace.
error() <<
" Parameter: "<<param<<
" is required..";
82 template <
typename Word>
84 std::ostream& write_word( std::ostream& outs, Word value )
86 for (
unsigned size =
sizeof( Word ); size; --size, value >>= 8)
87 outs.put( static_cast <char> (value & 0xFF) );
92 int main(
int argc,
char**argv)
96 po::options_description general_opt (
"Allowed options are: " );
97 general_opt.add_options()
98 (
"help,h",
"display this message." )
99 (
"input,i", po::value<std::string>(),
"Input vol file." )
100 (
"output,o", po::value<string>(),
"Output filename." );
102 po::variables_map vm;
104 po::store(po::parse_command_line(argc, argv, general_opt), vm);
105 }
catch(
const std::exception& ex){
107 trace.
info()<<
"Error checking program options: "<< ex.what()<< endl;
110 if ( !parseOK || vm.count (
"help" ) ||argc<=1 )
112 trace.
info() <<
"Convert a vol (up to [0,126]^3) to a vox. The current exporter does not support custom colormaps, only the voxel values are exported." <<std::endl
113 << std::endl <<
"Basic usage: "<<std::endl
114 <<
"\tvol2vox --input <volFileName> --o <volOutputFileName> "<<std::endl
115 << general_opt <<
"\n";
120 if ( ! ( vm.count (
"input" ) ) ) missingParam (
"--input" );
121 std::string filename = vm[
"input"].as<std::string>();
122 if ( ! ( vm.count (
"output" ) ) ) missingParam (
"--output" );
123 std::string outputFileName = vm[
"output"].as<std::string>();
131 if ( (imageL.domain().upperBound() - imageL.domain().lowerBound()).max() > 126 )
133 trace.
error() <<
"Vol file too large (width > 126)."<<std::endl;
140 myfile.open (outputFileName, ios::out | ios::binary);
143 for(
auto it = imageL.range().begin(), itend = imageL.range().end();
148 Point size = imageL.domain().upperBound() - imageL.domain().lowerBound();
176 myfile <<
'V'<<
'O'<<
'X'<<
' ';
181 myfile <<
'M'<<
'A'<<
'I'<<
'N';
183 write_word(myfile,
DGtal::uint32_t( (4+4+4 + 12 ) + ((4+ 4 + 4) + (4+ cpt*4))));
186 myfile <<
'S'<<
'I'<<
'Z'<<
'E';
194 myfile <<
'X'<<
'Y'<<
'Z'<<
'I';
199 trace.
info() <<
"Number of voxels= "<<cpt<<std::endl;
202 for(
auto it = imageL.domain().begin(), itend = imageL.domain().end();
204 if (imageL(*it) != 0)
206 Point p = (*it) - imageL.domain().lowerBound();
210 myfile.put(imageL(*it));
void beginBlock(const std::string &keyword="")
Trace trace(traceWriterTerm)
typename Self::Point Point