DGtal  1.3.beta
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/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 
51 using namespace std;
52 using 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 
74 template <typename Space, typename Shape>
75 bool
76 testDigitization( 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.
97  Shapes<Domain>::digitalShaper( aSet, dig );
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 
220 int 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 // //
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition: Board.cpp:240
DGtal::GaussDigitizer
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Definition: GaussDigitizer.h:79
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
DGtal::GaussDigitizer::getDomain
Domain getDomain() const
DGtal::Astroid2D< Space >
DGtal::GridCurve::initFromVector
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::GaussDigitizer::getUpperBound
const Point & getUpperBound() const
DGtal::DigitalSetSelector
Aim: Automatically defines an adequate digital set type according to the hints given by the user.
Definition: DigitalSetSelector.h:88
DGtal::GridCurve::className
std::string className() const
LibBoard::Board::UCentimeter
@ UCentimeter
Definition: Board.h:43
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::Astroid2D::getLowerBound
RealPoint getLowerBound() const
Definition: Astroid2D.h:122
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::HyperRectDomain::className
std::string className() const
DGtal::GaussDigitizer::attach
void attach(ConstAlias< EuclideanShape > shape)
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::GridCurve
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:172
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::HIGH_BEL_DS
@ HIGH_BEL_DS
Definition: DigitalSetSelector.h:63
DGtal::Ball2D
Aim: Model of the concept StarShaped represents any circle in the plane.
Definition: Ball2D.h:60
DGtal::GaussDigitizer::init
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
KSpace
Z3i::KSpace KSpace
Definition: testArithmeticalDSSComputerOnSurfels.cpp:48
DGtal::CustomStyle
Definition: Board2D.h:217
DGtal::Trace::info
std::ostream & info()
DGtal::SignedKhalimskyCell::className
std::string className() const
Return the style name used for drawing this object.
testDigitization
bool testDigitization(const Shape &aShape, double h, const string &fileName)
Definition: testGaussDigitizer.cpp:76
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
testConcept
bool testConcept()
Definition: testGaussDigitizer.cpp:65
Domain
HyperRectDomain< Space > Domain
Definition: testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::concepts::CDigitalOrientedShape
Aim: characterizes models of digital oriented shapes. For example, models should provide an orientati...
Definition: CDigitalOrientedShape.h:90
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
testGaussDigitizer
bool testGaussDigitizer()
Definition: testGaussDigitizer.cpp:143
DGtal::BIG_DS
@ BIG_DS
Definition: DigitalSetSelector.h:60
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
DGtal::Ellipse2D
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition: Ellipse2D.h:64
DGtal::Shapes
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Definition: DGtal/shapes/Shapes.h:71
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::PointVector< dim, Integer >
DGtal::HIGH_ITER_DS
@ HIGH_ITER_DS
Definition: DigitalSetSelector.h:62
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
DGtal::Flower2D
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
DGtal::Lemniscate2D
Aim: Model of the concept StarShaped represents a lemniscate.
Definition: Lemniscate2D.h:61
main
int main(int argc, char **argv)
Definition: testGaussDigitizer.cpp:220
DGtal::concepts::CDigitalBoundedShape
Aim: designs the concept of bounded shapes in DGtal (shape for which upper and lower bounding bounds ...
Definition: CDigitalBoundedShape.h:90
Point
MyPointD Point
Definition: testClone2.cpp:383
RealPoint
Z2i::RealPoint RealPoint
Definition: testAstroid2D.cpp:46
DGtal::GaussDigitizer::getLowerBound
const Point & getLowerBound() const
DGtal::Astroid2D::getUpperBound
RealPoint getUpperBound() const
Definition: Astroid2D.h:131
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64