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