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/readers/PointListReader.h"
46#include "DGtal/io/readers/GenericReader.h"
48#include "DGtal/io/readers/DicomReader.h"
50#include "DGtal/io/Color.h"
51#include "DGtal/io/colormaps/GradientColorMap.h"
53#include "DGtal/helpers/StdDefs.h"
54#include "DGtal/helpers/Shortcuts.h"
55#include "DGtal/helpers/ShortcutsGeometry.h"
109int main(
int argc,
char** argv )
116 typedef Shortcuts<Z3i::KSpace> SH3;
117 typedef ShortcutsGeometry<Z3i::KSpace> SHG3;
118 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
120 int thresholdMin {128};
121 int thresholdMax {255};
122 string inputFilename;
123 DGtal::int64_t rescaleInputMin {0};
124 DGtal::int64_t rescaleInputMax {255};
125 std::vector<unsigned int > vectCol= {230, 230, 230, 255};
126 bool triangulatedSurface {
false};
127 std::string outputFilename =
"result.obj";
129 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)");
131 app.add_option(
"-i,--input,1", inputFilename,
"vol file (.vol, .longvol .p3d, .pgm3d and if DGTAL_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." )
133 ->check(CLI::ExistingFile);
134 app.add_option(
"--output,-o,2",outputFilename ,
"output file (.obj or .off).");
135 app.add_option(
"--thresholdMin,-m", thresholdMin,
"threshold min (excluded) to define binary shape.");
136 app.add_option(
"--thresholdMax,-M", thresholdMax,
"threshold max (included) to define binary shape.");
137 app.add_option(
"--rescaleInputMin", rescaleInputMin,
"min value used to rescale the input intensity (to avoid basic cast into 8 bits image).");
138 app.add_option(
"--rescaleInputMax", rescaleInputMax,
"max value used to rescale the input intensity (to avoid basic cast into 8 bits image).");
139 app.add_option(
"--customDiffuse,-c", vectCol,
"set the R, G, B, A components of the diffuse colors of the mesh faces.")
141 app.add_flag(
"--triangulatedSurface,-t", triangulatedSurface,
"save the dual triangulated surface instead instead the default digital surface.");
142 app.get_formatter()->column_width(40);
143 CLI11_PARSE(app, argc, argv);
147 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
148 RescalFCT f (rescaleInputMin, rescaleInputMax,0, 255);
150 trace.beginBlock(
"Loading file.." );
151 SH3::GrayScaleImage image =
152 GenericReader< SH3::GrayScaleImage >::importWithValueFunctor(inputFilename, f );
154 auto gimage = CountedPtr<SH3::GrayScaleImage>(
new SH3::GrayScaleImage( image ) );
155 auto bimage = SH3::makeBinaryImage(gimage,params(
"thresholdMin", thresholdMin )
156 (
"thresholdMax", thresholdMax ) );
159 trace.info() <<
"Image loaded: "<<gimage<< std::endl;
161 params(
"faceSubdivision",
"Centroid" )(
"surfelAdjacency", 1);
162 auto K = SH3::getKSpace( bimage);
164 SH3::Color cD (vectCol[0], vectCol[1], vectCol[2], vectCol[3]);
167 auto surface = SH3::makeDigitalSurface( bimage, K );
168 const std::string extension = outputFilename.substr( outputFilename.find_last_of(
".") + 1 );
169 if (extension !=
"obj" && extension !=
"off")
171 trace.warning() <<
"File extension not recognized, saving by default in objg format"<< std::endl;
173 if (triangulatedSurface)
175 auto tr = SH3::makeTriangulatedSurface(surface);
177 if (extension!=
"off")
179 ok = SH3::saveOBJ( tr, SH3::RealVectors(), SH3::Colors(), outputFilename, Color( 32, 32, 32 ), cD );
183 ok = SH3::saveOFF( tr, outputFilename, cD);
185 return ok ? EXIT_SUCCESS : EXIT_FAILURE ;
190 if (extension!=
"off")
192 ok = SH3::saveOBJ( surface, SH3::RealVectors(), SH3::Colors(), outputFilename, Color( 32, 32, 32 ), cD);
195 ok = SH3::saveOFF( surface, outputFilename, cD);
197 return ok ? EXIT_SUCCESS : EXIT_FAILURE;