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>
34 #include <DGtal/io/writers/GenericWriter.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;
71 void missingParam (
const std::string ¶m )
73 trace.
error() <<
" Parameter: "<<param<<
" is required..";
86 template <
typename Word>
88 std::istream& read_word( std::istream& fin, Word& aValue )
92 for (
auto size = 0; size <
sizeof( Word ); ++size)
95 unsigned char cc=
static_cast<unsigned char>(c);
96 aValue |= (cc << (8 * size));
100 template <
typename Word>
102 std::ostream& write_word( std::ostream& outs, Word value )
104 for (
unsigned size =
sizeof( Word ); size; --size, value >>= 8)
105 outs.put( static_cast <char> (value & 0xFF) );
114 return (static_cast<DGtal::uint32_t>((
unsigned char)a) +
115 ((static_cast<DGtal::uint32_t>((
unsigned char) b)) <<8) +
116 ((static_cast<DGtal::uint32_t>((
unsigned char) c)) <<16) +
117 ((static_cast<DGtal::uint32_t>((
unsigned char) d)) <<24));
121 int main(
int argc,
char**argv)
125 po::options_description general_opt (
"Allowed options are: " );
126 general_opt.add_options()
127 (
"help,h",
"display this message." )
128 (
"input,i", po::value<std::string>(),
"Input vox file." )
129 (
"output,o", po::value<string>(),
"Output vol filename." );
131 po::variables_map vm;
133 po::store(po::parse_command_line(argc, argv, general_opt), vm);
134 }
catch(
const std::exception& ex){
136 trace.
info()<<
"Error checking program options: "<< ex.what()<< endl;
139 if ( !parseOK || vm.count (
"help" ) ||argc<=1 )
141 trace.
info() <<
"Convert a vox file to a vol."<<std::endl
142 << std::endl <<
"Basic usage: "<<std::endl
143 <<
"\tvox2vol --input <volFileName> --o <volOutputFileName> "<<std::endl
144 << general_opt <<
"\n";
149 if ( ! ( vm.count (
"input" ) ) ) missingParam (
"--input" );
150 std::string filename = vm[
"input"].as<std::string>();
151 if ( ! ( vm.count (
"output" ) ) ) missingParam (
"--output" );
152 std::string outputFileName = vm[
"output"].as<std::string>();
157 myfile.open (filename, ios::in | ios::binary);
189 if ( ( a !=
'V' || (b !=
'O') || (c!=
'X') || (d !=
' ')))
191 trace.
error() <<
"Magic number error"<<std::endl;
192 trace.
error() << (int)a<<
" "<<(
int)b<<
" "<<(int) c<<
" "<<(
int)d<<
std::endl;
193 trace.error() << a<<" "<<b<<" "<< c<<" "<<d<<
std::endl;
203 trace.info()<<"Version = "<<version<<
std::endl;
207 trace.
error() <<
"Version error "<<version<<std::endl;
208 trace.
error() << (
unsigned int)a<<
" "<<(
int)b<<
" "<<(int) c<<
" "<<(
int)d<<
std::endl;
209 trace.error() << a<<" "<<b<<" "<< c<<" "<<d<<
std::endl;
213 read_word(myfile, version);
215 trace.info()<< main <<
std::endl;
216 trace.info() <<version <<
std::endl;
217 if ( version != main)
219 trace.
error() <<
"MAIN number error"<<std::endl;
220 trace.
error() << (int)a<<
" "<<(
int)b<<
" "<<(int) c<<
" "<<(
int)d<<
std::endl;
221 trace.error() << a<<" "<<b<<" "<< c<<" "<<d<<
std::endl;
226 read_word(myfile,version);
227 while ( version != XYZI)
228 read_word(myfile,version);
231 read_word(myfile,version);
232 read_word(myfile,version);
234 read_word(myfile,cpt);
236 Z3i::
Domain domain(Z3i::
Point(0,0,0), Z3i::Point(126,126,126));
238 trace.info()<< "Number of voxels in this chunk = "<<version<<
std::endl;
239 for(auto i=0 ; i<cpt; ++i)
245 image.setValue(
Z3i::Point((
unsigned int)(
unsigned char)a,
246 (
unsigned int)(
unsigned char)b,
247 (
unsigned int)(
unsigned char)c),
251 image >> outputFileName;
void beginBlock(const std::string &keyword="")
Trace trace(traceWriterTerm)
typename Self::Point Point
typename Self::Domain Domain