DGtalTools  1.5.beta
vol2obj.cpp
1 
28 #include <iostream>
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"
35 
36 #include "DGtal/images/ImageSelector.h"
37 
38 #include "CLI11.hpp"
39 
40 
41 using namespace std;
42 using namespace DGtal;
43 using namespace Z3i;
44 
78 
79 
80 int main( int argc, char** argv )
81 {
82 
83  // parse command line using CLI ----------------------------------------------
84  CLI::App app;
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};
91 
92 
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." )
95  ->required()
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);
102 
103 
104  app.get_formatter()->column_width(40);
105  CLI11_PARSE(app, argc, argv);
106  // END parse command line using CLI ----------------------------------------------
107 
108 
109  Board3D<> board;
110 
112  string extension = inputFileName.substr(inputFileName.find_last_of(".") + 1);
113 
114  if(extension!="sdp")
115  {
117  Image image = GenericReader< Image >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
118  rescaleInputMax,
119  0, 255) );
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){
125  board << *it;
126  }
127  }
128  }
129  else
130  if(extension=="sdp")
131  {
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);
135  }
136  }
137 
138  board.saveOBJ(outputFileName);
139  return EXIT_SUCCESS;
140 }
int main(int argc, char **argv)
void saveOBJ(const std::string &filename, const bool isNormalized=false)
const Domain & domain() const
typename Self::Domain Domain
std::ostream & info()
boost::int64_t int64_t
Trace trace(traceWriterTerm)