30#include <DGtal/base/Common.h>
31#include <DGtal/io/readers/VolReader.h>
32#include <DGtal/helpers/StdDefs.h>
33#include <DGtal/images/Image.h>
34#include <DGtal/images/ImageContainerBySTLVector.h>
35#include <DGtal/io/writers/GenericWriter.h>
79void missingParam (
const std::string ¶m )
81 trace.error() <<
" Parameter: "<<param<<
" is required..";
82 trace.info() <<std::endl;
94template <
typename Word>
96std::istream& read_word( std::istream& fin, Word& aValue )
100 for (
auto size = 0; size <
sizeof( Word ); ++size)
103 unsigned char cc=
static_cast<unsigned char>(c);
104 aValue |= (cc << (8 * size));
108template <
typename Word>
110std::ostream& write_word( std::ostream& outs, Word value )
112 for (
unsigned size =
sizeof( Word ); size; --size, value >>= 8)
113 outs.put(
static_cast <char> (value & 0xFF) );
117DGtal::uint32_t toInt(
const char a,
122 return (
static_cast<DGtal::uint32_t
>((
unsigned char)a) +
123 ((
static_cast<DGtal::uint32_t
>((
unsigned char) b)) <<8) +
124 ((
static_cast<DGtal::uint32_t
>((
unsigned char) c)) <<16) +
125 ((
static_cast<DGtal::uint32_t
>((
unsigned char) d)) <<24));
129int main(
int argc,
char**argv)
134 std::string inputFileName;
135 std::string outputFileName {
"result.vol"};
136 app.description(
"Convert a vox file to a vol. Basic usage:\n vox2vol <volFileName> <volOutputFileName> ");
137 app.add_option(
"-i,--input,1", inputFileName,
"" )
139 ->check(CLI::ExistingFile);
140 app.add_option(
"-o,--ouput,2", outputFileName,
"" );
142 app.get_formatter()->column_width(40);
143 CLI11_PARSE(app, argc, argv);
146 trace.beginBlock(
"Loading...");
148 myfile.open (inputFileName, ios::in | ios::binary);
180 if ( ( a !=
'V' || (b !=
'O') || (c!=
'X') || (d !=
' ')))
182 trace.error() <<
"Magic number error"<<std::endl;
183 trace.error() << (int)a<<
" "<<(
int)b<<
" "<<(int) c<<
" "<<(
int)d<<std::endl;
184 trace.error() << a<<
" "<<b<<
" "<< c<<
" "<<d<<std::endl;
193 DGtal::uint32_t version = toInt(a,b,c,d);
194 trace.info()<<
"Version = "<<version<<std::endl;
198 trace.error() <<
"Version error "<<version<<std::endl;
199 trace.error() << (
unsigned int)a<<
" "<<(
int)b<<
" "<<(int) c<<
" "<<(
int)d<<std::endl;
200 trace.error() << a<<
" "<<b<<
" "<< c<<
" "<<d<<std::endl;
204 read_word(myfile, version);
205 DGtal::uint32_t main = toInt(
'M',
'A',
'I',
'N');
206 trace.info()<< main << std::endl;
207 trace.info() <<version <<std::endl;
208 if ( version != main)
210 trace.error() <<
"MAIN number error"<<std::endl;
211 trace.error() << (int)a<<
" "<<(
int)b<<
" "<<(int) c<<
" "<<(
int)d<<std::endl;
212 trace.error() << a<<
" "<<b<<
" "<< c<<
" "<<d<<std::endl;
216 DGtal::uint32_t XYZI= toInt(
'X',
'Y',
'Z',
'I');
217 read_word(myfile,version);
218 while ( version != XYZI)
219 read_word(myfile,version);
222 read_word(myfile,version);
223 read_word(myfile,version);
225 read_word(myfile,cpt);
227 Z3i::Domain domain(Z3i::Point(0,0,0), Z3i::Point(126,126,126));
228 ImageContainerBySTLVector<Z3i::Domain, unsigned char> image(domain);
229 trace.info()<<
"Number of voxels in this chunk = "<<version<<std::endl;
230 for(
auto i=0 ; i<cpt; ++i)
236 image.setValue(Z3i::Point((
unsigned int)(
unsigned char)a,
237 (
unsigned int)(
unsigned char)b,
238 (
unsigned int)(
unsigned char)c),
242 image >> outputFileName;