DGtal  0.9.2
exampleFMM2D.cpp
1 
29 #include <iostream>
31 #include <iomanip>
32 #include <functional>
33 #include <iostream>
34 
35 #include "DGtal/base/Common.h"
36 
37 //space, domain and image
38 #include "DGtal/kernel/SpaceND.h"
39 #include "DGtal/kernel/domains/HyperRectDomain.h"
40 #include "DGtal/kernel/sets/DigitalSetFromMap.h"
41 #include "DGtal/images/ImageContainerBySTLMap.h"
42 #include "DGtal/topology/SCellsFunctors.h"
43 
44 //shape and tracking
45 #include "DGtal/shapes/ShapeFactory.h"
46 #include "DGtal/shapes/Shapes.h"
47 #include "DGtal/helpers/StdDefs.h"
48 #include "DGtal/topology/helpers/Surfaces.h"
49 #include "DGtal/shapes/GaussDigitizer.h"
50 
51 
52 //FMM
54 #include "DGtal/geometry/volumes/distance/FMM.h"
56 
57 //Display
58 #include "DGtal/io/colormaps/HueShadeColorMap.h"
59 #include "DGtal/io/boards/Board2D.h"
60 
62 
63 using namespace std;
64 using namespace DGtal;
65 
66 
68 
75 template< typename TImage >
76 void draw( const TImage aImg, const double& aMaxValue, std::string aBasename)
77 {
78  typedef typename TImage::Domain::ConstIterator ConstIteratorOnPoints;
79  typedef typename TImage::Domain::Point Point;
80  HueShadeColorMap<double, 2> colorMap(0,aMaxValue);
81 
82  Board2D b;
84 
85  for (ConstIteratorOnPoints it = aImg.domain().begin(), itEnd = aImg.domain().end();
86  it != itEnd; ++it)
87  {
88  Point p = *it;
89  b << CustomStyle( p.className(), new CustomFillColor( colorMap( aImg(p) ) ) );
90  b << p;
91  }
92 
93  {
94  std::stringstream s;
95  s << aBasename << ".eps";
96  b.saveEPS(s.str().c_str());
97  }
98  #ifdef WITH_CAIRO
99  {
100  std::stringstream s;
101  s << aBasename << ".png";
102  b.saveCairo(s.str().c_str(), Board2D::CairoPNG);
103  }
104  #endif
105 }
106 
108 
111 void example()
112 {
113 
114  trace.beginBlock ( "DT by FMM from one point" );
115 
116  //Typedefs
118  typedef ImageContainerBySTLMap<Z2i::Domain,double> DistanceImage;
119  typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
120  typedef Z2i::Domain::Predicate DomainPredicate;
123 
124  //Constructions
125  int size = 25;
127  Z2i::Domain domain(Z2i::Point::diagonal(-size),
128  Z2i::Point::diagonal(size) );
129  DistanceImage distanceImage( domain );
130  AcceptedPointSet set( distanceImage );
132 
134  Z2i::Point origin = Z2i::Point::diagonal(0);
135  set.insert( origin );
136  distanceImage.setValue( origin, 0.0 );
138 
140  FMM fmm( distanceImage, set, domain.predicate() );
142 
143  trace.info() << "Init: " << fmm << std::endl;
144 
146  fmm.compute();
148 
149  trace.info() << "End: " << fmm << std::endl;
150 
151  //display - you should see concentric circles
152  //around the center point.
153  std::stringstream s;
154  s << "DTbyFMM-" << size;
155  draw(distanceImage, fmm.max(), s.str());
156 
157  trace.endBlock();
158 }
159 
160 
161 
162 
163 
164 
166 // Standard services - public :
167 
168 int main ( int argc, char** argv )
169 {
170  trace.beginBlock ( "Example 2d FMM" );
171  trace.info() << "Args:";
172  for ( int i = 0; i < argc; ++i )
173  trace.info() << " " << argv[ i ];
174  trace.info() << endl;
175 
176  //computation
177  example();
178 
179  trace.endBlock();
180  return 1;
181 }
182 // //
void beginBlock(const std::string &keyword="")
Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple di...
Trace trace
Definition: Common.h:130
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color...
Definition: Board2D.h:342
STL namespace.
double endBlock()
const Predicate & predicate() const
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
Aim: Fast Marching Method (FMM) for nd distance transforms.
Definition: FMM.h:150
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
void setUnit(Unit unit)
Definition: Board.cpp:240
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70