DGtal  0.9.2
exampleFMM3D.cpp
1 
33 #include <iostream>
34 
35 #include "DGtal/io/DrawWithDisplay3DModifier.h"
36 #include "DGtal/io/Color.h"
37 #include "DGtal/base/Common.h"
38 #include "DGtal/helpers/StdDefs.h"
39 #include "DGtal/shapes/Shapes.h"
40 #include "DGtal/io/colormaps/HueShadeColorMap.h"
41 #include "DGtal/io/colormaps/GradientColorMap.h"
42 #include "ConfigExamples.h"
43 #include "DGtal/io/viewers/Viewer3D.h"
44 
45 
46 using namespace std;
47 using namespace DGtal;
48 using namespace Z3i;
49 
50 
51 //image
52 #include "DGtal/io/readers/VolReader.h"
53 #include "DGtal/images/ImageContainerBySTLVector.h"
54 #include "DGtal/images/ImageContainerBySTLMap.h"
55 #include "DGtal/images/ConstImageAdapter.h"
56 #include "DGtal/base/BasicFunctors.h"
57 #include "DGtal/kernel/BasicPointPredicates.h"
58 
59 //frontier
60 #include "DGtal/topology/SurfelAdjacency.h"
61 #include "DGtal/topology/helpers/FrontierPredicate.h"
62 #include "DGtal/topology/LightExplicitDigitalSurface.h"
63 
64 // FMM
65 #include "DGtal/geometry/volumes/distance/FMM.h"
66 
67 // Standard services - public :
68 int main( int argc, char** argv )
69 {
70 
71 
72  //Parse options
73  //threshold
74  int t =0;
75  //width
76  double maximalDistance = 3.0;
77 
78 
80  // image binarization and surface extraction
81  //types
86 
87  //reading image
88  std::string imageFileName = examplesPath + "samples/Al.100.vol";
89 
90  trace.emphase() << imageFileName <<std::endl;
91  DGtal::trace.beginBlock("image reading...");
92  LabelImage labelImage = VolReader<LabelImage>::importVol( imageFileName);
94 
95  DGtal::trace.beginBlock("binarization...");
96 
99  BinaryImage binaryImage(labelImage, labelImage.domain(), g, thresholder);
100  trace.info() << "threshold: "
101  << t
102  << std::endl;
103 
104  //space and starting bel
105  KSpace ks;
106  Domain domain = labelImage.domain();
107  ks.init( domain.lowerBound(), domain.upperBound(), true );
108  KSpace::SCell bel;
109 
110  try {
111  //getting a bel
112  bel = Surfaces<KSpace>::findABel( ks, binaryImage, domain.size() );
113 
114  trace.info() << "starting bel: "
115  << bel
116  << std::endl;
117 
118  } catch (DGtal::InputException i) {
119  trace.emphase() << "starting bel not found" << std::endl;
120  return 0;
121  }
122 
123  //implicit frontier
125  std::pair<Point,Point> bpair = functor(bel);
126  SurfelPredicate surfelPredicate( ks, binaryImage,
127  binaryImage( bpair.first ),
128  binaryImage( bpair.second ) );
129  Frontier frontier( ks, surfelPredicate,
130  SurfelAdjacency<KSpace::dimension>( true ), bel );
131 
133 
137  typedef ImageContainerBySTLMap<Domain,double> DistanceImage;
138  typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
139  typedef Domain::Predicate DomainPredicate;
142 
143  DGtal::trace.beginBlock("FMM...");
144 
147  DistanceImage imageDistance( domain, 0.0 );
148  AcceptedPointSet initialPointSet( imageDistance );
149  FMM::initFromBelsRange( ks, frontier.begin(), frontier.end(),
150  imageDistance, initialPointSet, 0.5 );
152 
155  FMM fmm( imageDistance, initialPointSet, domain.predicate(),
156  domain.size(), maximalDistance );
157  fmm.compute();
158  trace.info() << fmm << std::endl;
160 
162 
164  //visualisation
165  QApplication application(argc,argv);
166  Viewer3D<> viewer;
167  viewer.show();
168 
169  //
170  GradientColorMap<double> colorMap( 0, 2*maximalDistance );
171  colorMap.addColor( Color( 255, 0, 0 ) );
172  colorMap.addColor( Color( 0, 250, 0 ) );
173  for (DistanceImage::const_iterator it = imageDistance.begin(), itEnd = imageDistance.end();
174  it != itEnd; ++it)
175  {
176  Point p = it->first;
177  viewer << CustomColors3D( colorMap(it->second), colorMap(it->second) ) ;
178  viewer << p;
179  }
180  Point p = Point::diagonal(1);
181  Vector extent = (domain.upperBound() - domain.lowerBound()) + p;
182  double a = -extent[0]/2, b = extent[1]/2;
183  double c = 0, mu = (a+b);
184  trace.info() << "clipping plane ("
185  << a << ", " << b << ", " << c << ", " << mu << ")"
186  << std::endl;
187  viewer << CustomColors3D(Color(200, 200, 200, 100),Color(200, 200,200, 20));
188  viewer << ClippingPlane(a,b,c,mu);
189 
190  viewer << Viewer3D<>::updateDisplay;
191  return application.exec();
192 }
193 // //
void beginBlock(const std::string &keyword="")
Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple di...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: The predicate on surfels that represents the frontier between two regions in an image...
Trace trace
Definition: Common.h:130
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
STL namespace.
double endBlock()
const Predicate & predicate() const
Aim: Define a simple default functor that just returns its argument.
Aim: Fast Marching Method (FMM) for nd distance transforms.
Definition: FMM.h:150
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
std::ostream & emphase()
bool init(const Point &lower, const Point &upper, bool isClosed)
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:88
const Point & upperBound() const
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
const Point & lowerBound() const
Class for adding a Clipping plane through the Viewer3D stream. Realizes the concept CDrawableWithView...
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels...
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...