DGtal 1.3.0
Loading...
Searching...
No Matches
testGaussDigitizer.cpp
Go to the documentation of this file.
1
31#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/Ball2D.h"
39#include "DGtal/shapes/parametric/Astroid2D.h"
40#include "DGtal/shapes/parametric/Ellipse2D.h"
41#include "DGtal/shapes/parametric/Flower2D.h"
42#include "DGtal/shapes/parametric/Lemniscate2D.h"
43#include "DGtal/shapes/Shapes.h"
44#include "DGtal/topology/helpers/Surfaces.h"
45#include "DGtal/geometry/curves/GridCurve.h"
46#include "DGtal/shapes/CDigitalOrientedShape.h"
47#include "DGtal/shapes/CDigitalBoundedShape.h"
48
50
51using namespace std;
52using namespace DGtal;
53
55// Functions for testing class GaussDigitizer.
57
58
66{
68 BOOST_CONCEPT_ASSERT((concepts::CDigitalBoundedShape<Dig>));
69 BOOST_CONCEPT_ASSERT((concepts::CDigitalOrientedShape<Dig>));
70 return true;
71}
72
73
74template <typename Space, typename Shape>
75bool
76testDigitization( const Shape & aShape, double h,
77 const string & fileName )
78{
79 typedef typename Space::Point Point;
80 typedef typename Space::RealPoint RealPoint;
82 typedef typename DigitalSetSelector
83 < Domain, BIG_DS + HIGH_ITER_DS + HIGH_BEL_DS >::Type MySet;
84
85 // Creates a digitizer on the window (xLow, xUp).
86 RealPoint xLow( -5.3, -4.3 );
87 RealPoint xUp( 7.4, 4.7 );
89 dig.attach( aShape ); // attaches the shape.
90 dig.init( aShape.getLowerBound(), aShape.getUpperBound(), h );
91
92 // The domain size is given by the digitizer according to the window
93 // and the step.
94 Domain domain = dig.getDomain();
95 MySet aSet( domain );
96 // Creates a set from the digitizer.
98
99 // Create cellular space
100 typedef Z2i::KSpace KSpace;
101 typedef Z2i::SCell SCell;
102 KSpace K;
103 bool ok = K.init( dig.getLowerBound(), dig.getUpperBound(), true );
104
105 if (!ok)
106 return false;
107
108
110
111
112
113 // Extracts shape boundary
114 SCell bel = Surfaces<KSpace>::findABel( K, dig, 10000 );
115 // Getting the consecutive surfels of the 2D boundary
116 std::vector<Point> points;
117 Surfaces<KSpace>::track2DBoundaryPoints( points, K, SAdj, dig, bel );
118 GridCurve<KSpace> gridcurve;
119 gridcurve.initFromVector( points );
120
121 // Display all
122 Board2D board;
124 board << SetMode( domain.className(), "Paving" )
125 << domain << aSet;
126
127 board << SetMode( gridcurve.className(), "Edges" )
128 << CustomStyle( bel.className(),
129 new CustomColors( DGtal::Color( 255, 0, 0 ),
130 DGtal::Color( 200, 0, 0 ) ) )
131 << gridcurve;
132
133 board.saveEPS( ( fileName + ".eps" ).c_str() );
134 board.saveSVG( ( fileName + ".svg" ).c_str() );
135
136 return true;
137}
138
144{
145 unsigned int nbok = 0;
146 unsigned int nb = 0;
147
148 trace.beginBlock ( "Testing GaussDigitizer as a Digital Shape functor." );
149
150 typedef Astroid2D< Z2i::Space > MyAstroid;
151 MyAstroid astroid( 6.2, -2.1, 7.3, 4.9 );
152 nbok += testDigitization<Z2i::Space,MyAstroid>
153 ( astroid, 1.0, "gauss-astroid-1" ) ? 1 : 0;
154 nb++;
155 nbok += testDigitization<Z2i::Space,MyAstroid>
156 ( astroid, 0.5, "gauss-astroid-0_5" ) ? 1 : 0;
157 nb++;
158 nbok += testDigitization<Z2i::Space,MyAstroid>
159 ( astroid, 0.25, "gauss-astroid-0_25" ) ? 1 : 0;
160 nb++;
161
162 typedef Ball2D< Z2i::Space > MyBall;
163 MyBall ball( 6.2, -2.1, 7.3 );
164 nbok += testDigitization<Z2i::Space,MyBall>
165 ( ball, 1.0, "gauss-ball-1" ) ? 1 : 0;
166 nb++;
167 nbok += testDigitization<Z2i::Space,MyBall>
168 ( ball, 0.5, "gauss-ball-0_5" ) ? 1 : 0;
169 nb++;
170 nbok += testDigitization<Z2i::Space,MyBall>
171 ( ball, 0.25, "gauss-ball-0_25" ) ? 1 : 0;
172 nb++;
173
174 typedef Ellipse2D< Z2i::Space > MyEllipse;
175 MyEllipse ellipse( 1.2, 0.1, 4.0, 3.0, 0.3 );
176 nbok += testDigitization<Z2i::Space,MyEllipse>
177 ( ellipse, 1.0, "gauss-ellipse-1" ) ? 1 : 0;
178 nb++;
179 nbok += testDigitization<Z2i::Space,MyEllipse>
180 ( ellipse, 0.5, "gauss-ellipse-0_5" ) ? 1 : 0;
181 nb++;
182 nbok += testDigitization<Z2i::Space,MyEllipse>
183 ( ellipse, 0.25, "gauss-ellipse-0_25" ) ? 1 : 0;
184 nb++;
185
186 typedef Flower2D< Z2i::Space > MyFlower;
187 MyFlower flower( 0.5, -2.3, 5.0, 0.7, 6, 0.3 );
188 nbok += testDigitization<Z2i::Space,MyFlower>
189 ( flower, 1.0, "gauss-flower-1" ) ? 1 : 0;
190 nb++;
191 nbok += testDigitization<Z2i::Space,MyFlower>
192 ( flower, 0.5, "gauss-flower-0_5" ) ? 1 : 0;
193 nb++;
194 nbok += testDigitization<Z2i::Space,MyFlower>
195 ( flower, 0.25, "gauss-flower-0_25" ) ? 1 : 0;
196 nb++;
197
198 typedef Lemniscate2D< Z2i::Space > MyLemniscate;
199 MyLemniscate lemniscate( 0.5, -2.3, 5.0 );
200 nbok += testDigitization<Z2i::Space,MyLemniscate>
201 ( lemniscate, 1.0, "gauss-lemniscate-1" ) ? 1 : 0;
202 nb++;
203 nbok += testDigitization<Z2i::Space,MyLemniscate>
204 ( lemniscate, 0.5, "gauss-lemniscate-0_5" ) ? 1 : 0;
205 nb++;
206 nbok += testDigitization<Z2i::Space,MyLemniscate>
207 ( lemniscate, 0.25, "gauss-lemniscate-0_25" ) ? 1 : 0;
208 nb++;
209
210 trace.info() << "(" << nbok << "/" << nb << ") "
211 << "true == true" << std::endl;
212 trace.endBlock();
213
214 return nbok == nb;
215}
216
218// Standard services - public :
219
220int main( int argc, char** argv )
221{
222 trace.beginBlock ( "Testing class GaussDigitizer" );
223 trace.info() << "Args:";
224 for ( int i = 0; i < argc; ++i )
225 trace.info() << " " << argv[ i ];
226 trace.info() << endl;
227
228 bool res = testConcept() && testGaussDigitizer(); // && ... other tests
229 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
230 trace.endBlock();
231 return res ? 0 : 1;
232}
233// //
RealPoint getLowerBound() const
Definition: Astroid2D.h:122
RealPoint getUpperBound() const
Definition: Astroid2D.h:131
Aim: Model of the concept StarShaped represents any circle in the plane.
Definition: Ball2D.h:61
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition: Ellipse2D.h:65
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:65
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
const Point & getUpperBound() const
void attach(ConstAlias< EuclideanShape > shape)
const Point & getLowerBound() const
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Domain getDomain() const
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:173
std::string className() const
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
std::string className() 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: Model of the concept StarShaped represents a lemniscate.
Definition: Lemniscate2D.h:62
static void digitalShaper(TDigitalSet &aSet, const TShapeFunctor &aFunctor)
static void track2DBoundaryPoints(std::vector< Point > &aVectorOfPoints, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void setUnit(Unit unit)
Definition: Board.cpp:240
Z3i::SCell SCell
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
Aim: Automatically defines an adequate digital set type according to the hints given by the user.
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
std::string className() const
Return the style name used for drawing this object.
Aim: designs the concept of bounded shapes in DGtal (shape for which upper and lower bounding bounds ...
Aim: characterizes models of digital oriented shapes. For example, models should provide an orientati...
Z2i::RealPoint RealPoint
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383
KSpace K
bool testDigitization(const Shape &aShape, double h, const string &fileName)
bool testConcept()
bool testGaussDigitizer()
Domain domain
HyperRectDomain< Space > Domain