29 #include "DGtal/base/Common.h"
30 #include "DGtal/helpers/StdDefs.h"
31 #include "DGtal/io/readers/GenericReader.h"
32 #include "DGtal/io/boards/Board3D.h"
33 #include "DGtal/io/DrawWithDisplay3DModifier.h"
34 #include "DGtal/io/readers/PointListReader.h"
36 #include "DGtal/images/ImageSelector.h"
42 using namespace DGtal;
80 int main(
int argc,
char** argv )
85 std::string inputFileName;
86 std::string outputFileName {
"result.obj"};
87 int thresholdMin {128};
88 int thresholdMax {255};
89 DGtal::int64_t rescaleInputMin {0};
90 DGtal::int64_t rescaleInputMax {255};
93 app.description(
" Converts any volumetric file (or .sdp file) to an OBJ one. Each grid point with value between [thresholdMin, thresholdMax] is exported as a unit cube.");
94 app.add_option(
"-i,--input,1", inputFileName,
"vol file (.vol, .longvol .p3d, .pgm3d or .sdp and if WITH_ITK is selected: dicom, dcm, mha, mhd). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255." )
96 ->check(CLI::ExistingFile);
97 app.add_option(
"--output,-o,2",outputFileName ,
"output file (.obj or .off).");
98 app.add_option(
"--thresholdMin,-m", thresholdMin,
"threshold min (excluded) to define binary shape.",
true);
99 app.add_option(
"--thresholdMax,-M", thresholdMax,
"threshold max (included) to define binary shape.",
true);
100 app.add_option(
"--rescaleInputMin", rescaleInputMin,
"min value used to rescale the input intensity (to avoid basic cast into 8 bits image).",
true);
101 app.add_option(
"--rescaleInputMax", rescaleInputMax,
"max value used to rescale the input intensity (to avoid basic cast into 8 bits image).",
true);
104 app.get_formatter()->column_width(40);
105 CLI11_PARSE(app, argc, argv);
111 typedef ImageSelector<Domain, unsigned char>::Type Image;
112 string extension = inputFileName.substr(inputFileName.find_last_of(
".") + 1);
116 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
117 Image image = GenericReader< Image >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
120 trace.info() <<
"Image loaded: "<<image<< std::endl;
121 Domain domain = image.domain();
122 for(Domain::ConstIterator it = domain.begin(), itend=domain.end(); it!=itend; ++it){
123 unsigned char val= image( (*it) );
124 if(val<=thresholdMax && val >=thresholdMin){
132 vector<Z3i::Point> vectVoxels = PointListReader<Z3i::Point>::getPointsFromFile(inputFileName);
133 for(
unsigned int i=0;i< vectVoxels.size(); i++){
134 board << vectVoxels.at(i);
138 board.saveOBJ(outputFileName);