32 #include <QImageReader>
34 #include "DGtal/io/viewers/Viewer3D.h"
35 #include "DGtal/io/DrawWithDisplay3DModifier.h"
36 #include "DGtal/io/Color.h"
37 #include "DGtal/shapes/Shapes.h"
38 #include "DGtal/helpers/StdDefs.h"
39 #include "DGtal/io/readers/PointListReader.h"
41 #include "DGtal/io/readers/GenericReader.h"
42 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
43 #include "DGtal/images/SimpleThresholdForegroundPredicate.h"
44 #include "DGtal/images/ImageSelector.h"
48 #include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
53 using namespace DGtal;
107 void missingParam ( std::string param )
109 trace.error() <<
" Parameter: "<<param<<
" is required..";
110 trace.info() <<std::endl;
115 int main(
int argc,
char** argv )
119 std::string inputFileName;
120 std::string exportSDPName;
121 std::string fixedPointSDPName;
125 std::vector<int> vectFixedPoints;
127 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");
128 app.add_option(
"-i,--input,1", inputFileName,
"Input volumetric file (.vol, .pgm3d or p3d)" )
130 ->check(CLI::ExistingFile);
131 app.add_option(
"--min,-m", min,
"Minimum (excluded) value for threshold.",
true);
132 app.add_option(
"--max,-M", max,
"Maximum (included) value for threshold.",
true);
133 app.add_option(
"--exportSDP,-e",exportSDPName,
"Export the resulting set of points in a simple (sequence of discrete point (sdp)).");
134 app.add_option(
"--fixedPoints",vectFixedPoints,
"defines the coordinates of points which should not be removed.");
135 app.add_option(
"--fixedPointSDP,-s",fixedPointSDPName,
"use fixed points from a file.")
136 ->check(CLI::ExistingFile);
139 app.get_formatter()->column_width(40);
140 CLI11_PARSE(app, argc, argv);
144 typedef ImageSelector < Z3i::Domain, unsigned char>::Type Image;
145 Image image = GenericReader<Image>::import ( inputFileName );
147 trace.beginBlock(
"DT Computation");
148 typedef functors::IntervalForegroundPredicate<Image> Predicate;
149 Predicate aPredicate(image, min, max );
151 const Z3i::L2Metric aMetric{};
152 DistanceTransformation<Z3i::Space, Predicate , Z3i::L2Metric> dt(image.domain(), aPredicate, aMetric );
154 trace.info() <<image<<std::endl;
157 trace.beginBlock(
"Constructing Set");
158 DigitalSet shape_set( image.domain() );
159 DigitalSet fixedSet( image.domain() );
162 if(vectFixedPoints.size() > 0){
163 if(vectFixedPoints.size()%3==0){
164 for(
unsigned int i=0; i < vectFixedPoints.size()-2; i=i+3)
166 Z3i::Point pt(vectFixedPoints.at(i), vectFixedPoints.at(i+1), vectFixedPoints.at(i+2));
167 fixedSet.insertNew(pt);
172 trace.error()<<
" The coordinates should be 3d coordinates, ignoring fixedPoints option." << std::endl;
176 if(fixedPointSDPName !=
"")
178 std::vector<Z3i::Point> vPt = PointListReader<Z3i::Point>::getPointsFromFile(fixedPointSDPName);
185 SetFromImage<DigitalSet>::append<Image>(shape_set, image, min, max );
186 trace.info() << shape_set<<std::endl;
189 trace.beginBlock(
"Computing skeleton");
192 Object26_6 shape( dt26_6, shape_set );
195 std::queue<DigitalSet::Iterator> Q;
198 trace.info() <<
"Layer: "<< layer << std::endl;
200 DigitalSet & S = shape.pointSet();
202 trace.progressBar(0, (
double)S.size());
203 for ( DigitalSet::Iterator it = S.begin(); it != S.end(); ++it )
205 if ( nb % 100 == 0 ) trace.progressBar((
double)nb, (
double)S.size());
207 if (dt( *it ) <= layer)
209 if ( shape.isSimple( *it ) )
213 trace.progressBar( (
double)S.size(), (
double)S.size() );
215 while ( ! Q.empty() )
217 DigitalSet::Iterator it = Q.front();
219 if ( shape.isSimple( *it ) && fixedSet.find(*it) == fixedSet.end() )
225 trace.info() <<
"Nb simple points : "<<nb_simple<<
" " << std::endl;
228 while ( nb_simple != 0 );
231 DigitalSet & S = shape.pointSet();
233 trace.info() <<
"Skeleton--> "<<S<<std::endl;
236 QApplication application(argc,argv);
238 viewer.setWindowTitle(
"homotopicThinning3D");
241 viewer << SetMode3D( shape_set.className(),
"Paving" );
242 viewer << CustomColors3D(Color(25,25,255, 255), Color(25,25,255, 255));
244 viewer << CustomColors3D(Color(255,25,255, 255), Color(255,25,255, 255));
246 viewer << SetMode3D( shape_set.className(),
"PavingTransp" );
247 viewer << CustomColors3D(Color(250, 0,0, 25), Color(250, 0,0, 5));
249 viewer<< Viewer3D<>::updateDisplay;
251 if (exportSDPName !=
"")
254 out.open(exportSDPName.c_str());
257 out << p[0] <<
" " << p[1] <<
" " << p[2] << std::endl;
260 return application.exec();