DGtalTools 2.1.0
Loading...
Searching...
No Matches
volBoundary2obj.cpp
1
32#include <iostream>
33#include <set>
34#include "CLI11.hpp"
35
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"
47#ifdef DGTAL_WITH_ITK
48#include "DGtal/io/readers/DicomReader.h"
49#endif
50#include "DGtal/io/Color.h"
51#include "DGtal/io/colormaps/GradientColorMap.h"
52
53#include "DGtal/helpers/StdDefs.h"
54#include "DGtal/helpers/Shortcuts.h"
55#include "DGtal/helpers/ShortcutsGeometry.h"
56
57using namespace std;
58using namespace DGtal;
59
61
62
109int main( int argc, char** argv )
110{
111
112 CLI::App app;
113
114
115 // Using standard 3D digital space.
116 typedef Shortcuts<Z3i::KSpace> SH3;
117 typedef ShortcutsGeometry<Z3i::KSpace> SHG3;
118 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
119
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";
128
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)");
130
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." )
132 ->required()
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.")
140 ->expected(4);
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);
144
145
146
147 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
148 RescalFCT f (rescaleInputMin, rescaleInputMax,0, 255);
149
150 trace.beginBlock( "Loading file.." );
151 SH3::GrayScaleImage image =
152 GenericReader< SH3::GrayScaleImage >::importWithValueFunctor(inputFilename, f );
153
154 auto gimage = CountedPtr<SH3::GrayScaleImage>( new SH3::GrayScaleImage( image ) );
155 auto bimage = SH3::makeBinaryImage(gimage,params( "thresholdMin", thresholdMin )
156 ( "thresholdMax", thresholdMax ) );
157
158
159 trace.info() << "Image loaded: "<<gimage<< std::endl;
160 trace.endBlock();
161 params( "faceSubdivision", "Centroid" )( "surfelAdjacency", 1);
162 auto K = SH3::getKSpace( bimage);
163
164 SH3::Color cD (vectCol[0], vectCol[1], vectCol[2], vectCol[3]);
165
166
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")
170 {
171 trace.warning() << "File extension not recognized, saving by default in objg format"<< std::endl;
172 }
173 if (triangulatedSurface)
174 {
175 auto tr = SH3::makeTriangulatedSurface(surface);
176 bool ok = true;
177 if (extension!="off")
178 {
179 ok = SH3::saveOBJ( tr, SH3::RealVectors(), SH3::Colors(), outputFilename, Color( 32, 32, 32 ), cD );
180 }
181 else
182 {
183 ok = SH3::saveOFF( tr, outputFilename, cD);
184 }
185 return ok ? EXIT_SUCCESS : EXIT_FAILURE ;
186 }
187 else
188 {
189 bool ok = true;
190 if (extension!="off")
191 {
192 ok = SH3::saveOBJ( surface, SH3::RealVectors(), SH3::Colors(), outputFilename, Color( 32, 32, 32 ), cD);
193 } else
194 {
195 ok = SH3::saveOFF( surface, outputFilename, cD);
196 }
197 return ok ? EXIT_SUCCESS : EXIT_FAILURE;
198 }
199 return EXIT_SUCCESS;
200}
201
202
Definition ATu0v1.h:57