DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testGaussDigitizer.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/kernel/sets/DigitalSetSelector.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/shapes/parametric/Ball2D.h"
#include "DGtal/shapes/parametric/Astroid2D.h"
#include "DGtal/shapes/parametric/Ellipse2D.h"
#include "DGtal/shapes/parametric/Flower2D.h"
#include "DGtal/shapes/parametric/Lemniscate2D.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/geometry/curves/GridCurve.h"
#include "DGtal/shapes/CDigitalOrientedShape.h"
#include "DGtal/shapes/CDigitalBoundedShape.h"

Go to the source code of this file.

Functions

bool testConcept ()
 
template<typename Space , typename Shape >
bool testDigitization (const Shape &aShape, double h, const string &fileName)
 
bool testGaussDigitizer ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
Date
2011/07/01

Functions for testing class GaussDigitizer.

This file is part of the DGtal library.

Definition in file testGaussDigitizer.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 220 of file testGaussDigitizer.cpp.

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}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool testConcept()
bool testGaussDigitizer()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testConcept(), testGaussDigitizer(), and DGtal::trace.

◆ testConcept()

bool testConcept ( )

Gaussdigitizer is a model of CDigitalBoundedShape and CDigitalOrientedShape.

Definition at line 65 of file testGaussDigitizer.cpp.

66{
68 BOOST_CONCEPT_ASSERT((concepts::CDigitalBoundedShape<Dig>));
69 BOOST_CONCEPT_ASSERT((concepts::CDigitalOrientedShape<Dig>));
70 return true;
71}
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
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...

Referenced by main().

◆ testDigitization()

template<typename Space , typename Shape >
bool testDigitization ( const Shape aShape,
double  h,
const string &  fileName 
)

Definition at line 76 of file testGaussDigitizer.cpp.

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}
RealPoint getLowerBound() const
Definition: Astroid2D.h:122
RealPoint getUpperBound() const
Definition: Astroid2D.h:131
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
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.
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 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
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.
Z2i::RealPoint RealPoint
MyPointD Point
Definition: testClone2.cpp:383
KSpace K
Domain domain
HyperRectDomain< Space > Domain

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::BIG_DS, DGtal::GridCurve< TKSpace >::className(), DGtal::HyperRectDomain< TSpace >::className(), DGtal::SignedKhalimskyCell< dim, TInteger >::className(), DGtal::Shapes< TDomain >::digitalShaper(), domain, DGtal::Surfaces< TKSpace >::findABel(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getDomain(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getLowerBound(), DGtal::Astroid2D< TSpace >::getLowerBound(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getUpperBound(), DGtal::Astroid2D< TSpace >::getUpperBound(), DGtal::HIGH_BEL_DS, DGtal::HIGH_ITER_DS, DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), DGtal::GridCurve< TKSpace >::initFromVector(), K, LibBoard::Board::saveEPS(), LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), DGtal::Surfaces< TKSpace >::track2DBoundaryPoints(), and LibBoard::Board::UCentimeter.

◆ testGaussDigitizer()

bool testGaussDigitizer ( )

Example of a test. To be completed.

Definition at line 143 of file testGaussDigitizer.cpp.

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}
Aim: Model of the concept StarShaped represents an astroid.
Definition: Astroid2D.h:62
Aim: Model of the concept StarShaped represents any circle in the plane.
Definition: Ball2D.h:61
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: Model of the concept StarShaped represents a lemniscate.
Definition: Lemniscate2D.h:62

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().