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>
41 using namespace DGtal;
77 void missingParam (
const std::string ¶m )
79 trace.error() <<
" Parameter: "<<param<<
" is required..";
80 trace.info() <<std::endl;
92 template <
typename Word>
94 std::istream& read_word( std::istream& fin, Word& aValue )
98 for (
auto size = 0; size <
sizeof( Word ); ++size)
101 unsigned char cc=
static_cast<unsigned char>(c);
102 aValue |= (cc << (8 * size));
106 template <
typename Word>
108 std::ostream& write_word( std::ostream& outs, Word value )
110 for (
unsigned size =
sizeof( Word ); size; --size, value >>= 8)
111 outs.put(
static_cast <char> (value & 0xFF) );
115 DGtal::uint32_t toInt(
const char a,
120 return (
static_cast<DGtal::uint32_t
>((
unsigned char)a) +
121 ((
static_cast<DGtal::uint32_t
>((
unsigned char) b)) <<8) +
122 ((
static_cast<DGtal::uint32_t
>((
unsigned char) c)) <<16) +
123 ((
static_cast<DGtal::uint32_t
>((
unsigned char) d)) <<24));
127 int main(
int argc,
char**argv)
132 std::string inputFileName;
133 std::string outputFileName {
"result.vol"};
134 app.description(
"Convert a vox file to a vol. Basic usage:\n vox2vol <volFileName> <volOutputFileName> ");
135 app.add_option(
"-i,--input,1", inputFileName,
"" )
137 ->check(CLI::ExistingFile);
138 app.add_option(
"-o,--ouput,2", outputFileName,
"",
true );
140 app.get_formatter()->column_width(40);
141 CLI11_PARSE(app, argc, argv);
144 trace.beginBlock(
"Loading...");
146 myfile.open (inputFileName, ios::in | ios::binary);
178 if ( ( a !=
'V' || (b !=
'O') || (c!=
'X') || (d !=
' ')))
180 trace.error() <<
"Magic number error"<<std::endl;
181 trace.error() << (int)a<<
" "<<(
int)b<<
" "<<(int) c<<
" "<<(
int)d<<std::endl;
182 trace.error() << a<<
" "<<b<<
" "<< c<<
" "<<d<<std::endl;
191 DGtal::uint32_t version = toInt(a,b,c,d);
192 trace.info()<<
"Version = "<<version<<std::endl;
196 trace.error() <<
"Version error "<<version<<std::endl;
197 trace.error() << (
unsigned int)a<<
" "<<(
int)b<<
" "<<(int) c<<
" "<<(
int)d<<std::endl;
198 trace.error() << a<<
" "<<b<<
" "<< c<<
" "<<d<<std::endl;
202 read_word(myfile, version);
203 DGtal::uint32_t main = toInt(
'M',
'A',
'I',
'N');
204 trace.info()<< main << std::endl;
205 trace.info() <<version <<std::endl;
206 if ( version != main)
208 trace.error() <<
"MAIN number error"<<std::endl;
209 trace.error() << (int)a<<
" "<<(
int)b<<
" "<<(int) c<<
" "<<(
int)d<<std::endl;
210 trace.error() << a<<
" "<<b<<
" "<< c<<
" "<<d<<std::endl;
214 DGtal::uint32_t XYZI= toInt(
'X',
'Y',
'Z',
'I');
215 read_word(myfile,version);
216 while ( version != XYZI)
217 read_word(myfile,version);
220 read_word(myfile,version);
221 read_word(myfile,version);
223 read_word(myfile,cpt);
225 Z3i::Domain domain(Z3i::Point(0,0,0), Z3i::Point(126,126,126));
226 ImageContainerBySTLVector<Z3i::Domain, unsigned char> image(domain);
227 trace.info()<<
"Number of voxels in this chunk = "<<version<<std::endl;
228 for(
auto i=0 ; i<cpt; ++i)
234 image.setValue(Z3i::Point((
unsigned int)(
unsigned char)a,
235 (
unsigned int)(
unsigned char)b,
236 (
unsigned int)(
unsigned char)c),
240 image >> outputFileName;