33#include "DGtal/io/Color.h"
34#include "DGtal/shapes/Shapes.h"
35#include "DGtal/helpers/StdDefs.h"
36#include "DGtal/io/viewers/PolyscopeViewer.h"
37#include "DGtal/io/readers/PointListReader.h"
39#include "DGtal/io/readers/GenericReader.h"
40#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
41#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
42#include "DGtal/images/ImageSelector.h"
46#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
105void missingParam ( std::string param )
107 trace.error() <<
" Parameter: "<<param<<
" is required..";
108 trace.info() <<std::endl;
113int main(
int argc,
char** argv )
117 std::string inputFileName;
118 std::string exportSDPName;
119 std::string fixedPointSDPName;
123 std::vector<int> vectFixedPoints;
125 app.description(
"Applies an homotopic thinning of a 3d image file (vol,longvol,pgm3d...) with 3D viewer. \n Basic usage: \t homotopicThinning3D [options] --input <3dImageFileName> {vol,longvol,pgm3d...} \n Usage by forcing point to be left by the thinning: \n homotopicThinning3D --input ${DGtal}/examples/samples/Al.100.vol --fixedPoints 56 35 5 56 61 5 57 91 38 58 8 38 45 50 97 \n");
126 app.add_option(
"-i,--input,1", inputFileName,
"Input volumetric file (.vol, .pgm3d or p3d)" )
128 ->check(CLI::ExistingFile);
129 app.add_option(
"--min,-m", min,
"Minimum (excluded) value for threshold.");
130 app.add_option(
"--max,-M", max,
"Maximum (included) value for threshold.");
131 app.add_option(
"--exportSDP,-e",exportSDPName,
"Export the resulting set of points in a simple (sequence of discrete point (sdp)).");
132 app.add_option(
"--fixedPoints",vectFixedPoints,
"defines the coordinates of points which should not be removed.");
133 app.add_option(
"--fixedPointSDP,-s",fixedPointSDPName,
"use fixed points from a file.")
134 ->check(CLI::ExistingFile);
137 app.get_formatter()->column_width(40);
138 CLI11_PARSE(app, argc, argv);
142 typedef ImageSelector < Z3i::Domain, unsigned char>::Type Image;
143 Image image = GenericReader<Image>::import ( inputFileName );
145 trace.beginBlock(
"DT Computation");
146 typedef functors::IntervalForegroundPredicate<Image> Predicate;
147 Predicate aPredicate(image, min, max );
149 const Z3i::L2Metric aMetric{};
150 DistanceTransformation<Z3i::Space, Predicate , Z3i::L2Metric> dt(image.domain(), aPredicate, aMetric );
152 trace.info() <<image<<std::endl;
155 trace.beginBlock(
"Constructing Set");
156 DigitalSet shape_set( image.domain() );
157 DigitalSet fixedSet( image.domain() );
160 if(vectFixedPoints.size() > 0){
161 if(vectFixedPoints.size()%3==0){
162 for(
unsigned int i=0; i < vectFixedPoints.size()-2; i=i+3)
164 Z3i::Point pt(vectFixedPoints.at(i), vectFixedPoints.at(i+1), vectFixedPoints.at(i+2));
165 fixedSet.insertNew(pt);
170 trace.error()<<
" The coordinates should be 3d coordinates, ignoring fixedPoints option." << std::endl;
174 if(fixedPointSDPName !=
"")
176 std::vector<Z3i::Point> vPt = PointListReader<Z3i::Point>::getPointsFromFile(fixedPointSDPName);
183 SetFromImage<DigitalSet>::append<Image>(shape_set, image, min, max );
184 trace.info() << shape_set<<std::endl;
187 trace.beginBlock(
"Computing skeleton");
190 Object26_6 shape( dt26_6, shape_set );
193 std::queue<DigitalSet::Iterator> Q;
196 trace.info() <<
"Layer: "<< layer << std::endl;
198 DigitalSet & S = shape.pointSet();
200 trace.progressBar(0, (
double)S.size());
201 for ( DigitalSet::Iterator it = S.begin(); it != S.end(); ++it )
203 if ( nb % 100 == 0 ) trace.progressBar((
double)nb, (double)S.size());
205 if (dt( *it ) <= layer)
207 if ( shape.isSimple( *it ) )
211 trace.progressBar( (
double)S.size(), (double)S.size() );
213 while ( ! Q.empty() )
215 DigitalSet::Iterator it = Q.front();
217 if ( shape.isSimple( *it ) && fixedSet.find(*it) == fixedSet.end() )
223 trace.info() <<
"Nb simple points : "<<nb_simple<<
" " << std::endl;
226 while ( nb_simple != 0 );
229 DigitalSet & S = shape.pointSet();
231 trace.info() <<
"Skeleton--> "<<S<<std::endl;
234 polyscope::options::programName =
"DGtalTools: homotopicThinning3D";
236 PolyscopeViewer<> viewer;
240 viewer << Color(25,25,255, 255);
242 viewer << Color(255,25,255, 255);
244 viewer << Color(250, 0,0, 25);
247 if (exportSDPName !=
"")
250 out.open(exportSDPName.c_str());
253 out << p[0] <<
" " << p[1] <<
" " << p[2] << std::endl;