DGtal  0.9.3
testGaussDigitizer.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/io/boards/Board2D.h"
34 #include "DGtal/io/colormaps/GradientColorMap.h"
35 #include "DGtal/kernel/sets/DigitalSetSelector.h"
36 #include "DGtal/shapes/GaussDigitizer.h"
37 #include "DGtal/helpers/StdDefs.h"
38 #include "DGtal/shapes/parametric/Ellipse2D.h"
39 #include "DGtal/shapes/parametric/Flower2D.h"
40 #include "DGtal/shapes/Shapes.h"
41 #include "DGtal/topology/helpers/Surfaces.h"
42 #include "DGtal/geometry/curves/GridCurve.h"
43 #include "DGtal/shapes/CDigitalOrientedShape.h"
44 #include "DGtal/shapes/CDigitalBoundedShape.h"
45 
47 
48 using namespace std;
49 using namespace DGtal;
50 
52 // Functions for testing class GaussDigitizer.
54 
55 
63 {
65  BOOST_CONCEPT_ASSERT((concepts::CDigitalBoundedShape<Dig>));
66  BOOST_CONCEPT_ASSERT((concepts::CDigitalOrientedShape<Dig>));
67  return true;
68 }
69 
70 
71 template <typename Space, typename Shape>
72 bool
73 testDigitization( const Shape & aShape, double h,
74  const string & fileName )
75 {
76  typedef typename Space::Point Point;
77  typedef typename Space::RealPoint RealPoint;
79  typedef typename DigitalSetSelector
80  < Domain, BIG_DS + HIGH_ITER_DS + HIGH_BEL_DS >::Type MySet;
81 
82  // Creates a digitizer on the window (xLow, xUp).
83  RealPoint xLow( -5.3, -4.3 );
84  RealPoint xUp( 7.4, 4.7 );
86  dig.attach( aShape ); // attaches the shape.
87  dig.init( xLow, xUp, h );
88 
89  // The domain size is given by the digitizer according to the window
90  // and the step.
91  Domain domain = dig.getDomain();
92  MySet aSet( domain );
93  // Creates a set from the digitizer.
94  Shapes<Domain>::digitalShaper( aSet, dig );
95 
96  // Create cellular space
97  typedef Z2i::KSpace KSpace;
98  typedef Z2i::SCell SCell;
99  KSpace K;
100  bool ok = K.init( dig.getLowerBound(), dig.getUpperBound(), true );
101 
102  if (!ok)
103  return false;
104 
105 
107 
108 
109 
110  // Extracts shape boundary
111  SCell bel = Surfaces<KSpace>::findABel( K, dig, 10000 );
112  // Getting the consecutive surfels of the 2D boundary
113  std::vector<Point> points;
114  Surfaces<KSpace>::track2DBoundaryPoints( points, K, SAdj, dig, bel );
115  GridCurve<KSpace> gridcurve;
116  gridcurve.initFromVector( points );
117 
118  // Display all
119  Board2D board;
121  board << SetMode( domain.className(), "Paving" )
122  << domain << aSet;
123 
124  board << SetMode( gridcurve.className(), "Edges" )
125  << CustomStyle( bel.className(),
126  new CustomColors( DGtal::Color( 0, 0, 0 ),
127  DGtal::Color( 0, 192, 0 ) ) )
128  << gridcurve;
129  board << SetMode( gridcurve.className(), "Points" )
130  << CustomStyle( bel.className(),
131  new CustomColors( DGtal::Color( 255, 0, 0 ),
132  DGtal::Color( 200, 0, 0 ) ) )
133  << gridcurve;
134 
135  board.saveEPS( ( fileName + ".eps" ).c_str() );
136  board.saveSVG( ( fileName + ".svg" ).c_str() );
137 
138  return true;
139 }
140 
146 {
147  unsigned int nbok = 0;
148  unsigned int nb = 0;
149 
150  trace.beginBlock ( "Testing GaussDigitizer as a Digital Shape functor." );
151 
152  typedef Ellipse2D< Z2i::Space > MyEllipse;
153  MyEllipse ellipse( 1.2, 0.1, 4.0, 3.0, 0.3 );
154  nbok += testDigitization<Z2i::Space,MyEllipse>
155  ( ellipse, 1.0, "gauss-ellipse-1" ) ? 1 : 0;
156  nb++;
157  nbok += testDigitization<Z2i::Space,MyEllipse>
158  ( ellipse, 0.5, "gauss-ellipse-0_5" ) ? 1 : 0;
159  nb++;
160  nbok += testDigitization<Z2i::Space,MyEllipse>
161  ( ellipse, 0.25, "gauss-ellipse-0_25" ) ? 1 : 0;
162  nb++;
163 
164  typedef Flower2D< Z2i::Space > MyFlower;
165  MyFlower flower( 0.5, -2.3, 5.0, 0.7, 6, 0.3 );
166  nbok += testDigitization<Z2i::Space,MyFlower>
167  ( flower, 1.0, "gauss-flower-1" ) ? 1 : 0;
168  nb++;
169  nbok += testDigitization<Z2i::Space,MyFlower>
170  ( flower, 0.5, "gauss-flower-0_5" ) ? 1 : 0;
171  nb++;
172  nbok += testDigitization<Z2i::Space,MyFlower>
173  ( flower, 0.25, "gauss-flower-0_25" ) ? 1 : 0;
174  nb++;
175 
176  trace.info() << "(" << nbok << "/" << nb << ") "
177  << "true == true" << std::endl;
178  trace.endBlock();
179 
180  return nbok == nb;
181 }
182 
184 // Standard services - public :
185 
186 int main( int argc, char** argv )
187 {
188  trace.beginBlock ( "Testing class GaussDigitizer" );
189  trace.info() << "Args:";
190  for ( int i = 0; i < argc; ++i )
191  trace.info() << " " << argv[ i ];
192  trace.info() << endl;
193 
194  bool res = testConcept() && testGaussDigitizer(); // && ... other tests
195  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
196  trace.endBlock();
197  return res ? 0 : 1;
198 }
199 // //
void beginBlock(const std::string &keyword="")
HyperRectDomain< Space > Domain
const Domain domain(Point(1, 2), Point(6, 5))
const Point & getLowerBound() const
Trace trace
Definition: Common.h:137
bool testGaussDigitizer()
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
const Point & getUpperBound() const
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition: Ellipse2D.h:64
STL namespace.
double endBlock()
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
Aim: designs the concept of bounded shapes in DGtal (shape for which upper and lower bounding bounds ...
void attach(const EuclideanShape &shape)
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
Aim: characterizes models of digital oriented shapes. For example, models should provide an orientati...
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
int main(int argc, char **argv)
std::ostream & emphase()
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
std::string className() const
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
std::string className() const
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
Aim: Automatically defines an adequate digital set type according to the hints given by the user...
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
bool testDigitization(const Shape &aShape, double h, const string &fileName)
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
void setUnit(Unit unit)
Definition: Board.cpp:240
KSpace K
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:172
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Domain getDomain() const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
bool testConcept()
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70