36 #include "DGtal/base/Common.h"
37 #include "DGtal/base/BasicFunctors.h"
38 #include "DGtal/kernel/SpaceND.h"
39 #include "DGtal/kernel/domains/HyperRectDomain.h"
40 #include "DGtal/images/ImageSelector.h"
41 #include "DGtal/images/IntervalForegroundPredicate.h"
42 #include "DGtal/topology/KhalimskySpaceND.h"
43 #include "DGtal/topology/DigitalSurface.h"
44 #include "DGtal/topology/SetOfSurfels.h"
45 #include "DGtal/io/boards/Board3D.h"
46 #include "DGtal/io/readers/PointListReader.h"
47 #include "DGtal/io/readers/GenericReader.h"
49 #include "DGtal/io/readers/DicomReader.h"
51 #include "DGtal/io/Color.h"
52 #include "DGtal/io/colormaps/GradientColorMap.h"
54 #include "DGtal/helpers/StdDefs.h"
55 #include "DGtal/helpers/Shortcuts.h"
56 #include "DGtal/helpers/ShortcutsGeometry.h"
59 using namespace DGtal;
108 int main(
int argc,
char** argv )
115 typedef Shortcuts<Z3i::KSpace> SH3;
116 typedef ShortcutsGeometry<Z3i::KSpace> SHG3;
117 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
119 int thresholdMin {128};
120 int thresholdMax {255};
121 string inputFilename;
122 DGtal::int64_t rescaleInputMin {0};
123 DGtal::int64_t rescaleInputMax {255};
124 std::vector<unsigned int > vectCol= {230, 230, 230, 255};
125 bool triangulatedSurface {
false};
126 std::string outputFilename =
"result.obj";
128 app.description(
"Export the boundary of a volume file to OBJ format. By default the resulting mesh is defined from the surfels of the surface elements, a triangulated (dual)");
130 app.add_option(
"-i,--input,1", inputFilename,
"vol file (.vol, .longvol .p3d, .pgm3d 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." )
132 ->check(CLI::ExistingFile);
133 app.add_option(
"--output,-o,2",outputFilename ,
"output file (.obj or .off).");
134 app.add_option(
"--thresholdMin,-m", thresholdMin,
"threshold min (excluded) to define binary shape.",
true);
135 app.add_option(
"--thresholdMax,-M", thresholdMax,
"threshold max (included) to define binary shape.",
true);
136 app.add_option(
"--rescaleInputMin", rescaleInputMin,
"min value used to rescale the input intensity (to avoid basic cast into 8 bits image).",
true);
137 app.add_option(
"--rescaleInputMax", rescaleInputMax,
"max value used to rescale the input intensity (to avoid basic cast into 8 bits image).",
true);
138 app.add_option(
"--customDiffuse,-c", vectCol,
"set the R, G, B, A components of the diffuse colors of the mesh faces.",
true)
140 app.add_flag(
"--triangulatedSurface,-t", triangulatedSurface,
"save the dual triangulated surface instead instead the default digital surface.");
141 app.get_formatter()->column_width(40);
142 CLI11_PARSE(app, argc, argv);
146 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
147 RescalFCT f (rescaleInputMin, rescaleInputMax,0, 255);
149 trace.beginBlock(
"Loading file.." );
150 SH3::GrayScaleImage image =
151 GenericReader< SH3::GrayScaleImage >::importWithValueFunctor(inputFilename, f );
153 auto gimage = CountedPtr<SH3::GrayScaleImage>(
new SH3::GrayScaleImage( image ) );
154 auto bimage = SH3::makeBinaryImage(gimage,params(
"thresholdMin", thresholdMin )
155 (
"thresholdMax", thresholdMax ) );
158 trace.info() <<
"Image loaded: "<<gimage<< std::endl;
160 params(
"faceSubdivision",
"Centroid" )(
"surfelAdjacency", 1);
161 auto K = SH3::getKSpace( bimage);
163 SH3::Color cD (vectCol[0], vectCol[1], vectCol[2], vectCol[3]);
166 auto surface = SH3::makeDigitalSurface( bimage, K );
167 const std::string extension = outputFilename.substr( outputFilename.find_last_of(
".") + 1 );
168 if (extension !=
"obj" && extension !=
"off")
170 trace.warning() <<
"File extension not recognized, saving by default in objg format"<< std::endl;
172 if (triangulatedSurface)
174 auto tr = SH3::makeTriangulatedSurface(surface);
176 if (extension!=
"off")
178 ok = SH3::saveOBJ( tr, SH3::RealVectors(), SH3::Colors(), outputFilename, Color( 32, 32, 32 ), cD );
182 ok = SH3::saveOFF( tr, outputFilename, cD);
184 return ok ? EXIT_SUCCESS : EXIT_FAILURE ;
189 if (extension!=
"off")
191 ok = SH3::saveOBJ( surface, SH3::RealVectors(), SH3::Colors(), outputFilename, Color( 32, 32, 32 ), cD);
194 ok = SH3::saveOFF( surface, outputFilename, cD);
196 return ok ? EXIT_SUCCESS : EXIT_FAILURE;