DGtal  0.9.3
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/Ellipse2D.h"
#include "DGtal/shapes/parametric/Flower2D.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"
Include dependency graph for testGaussDigitizer.cpp:

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 186 of file testGaussDigitizer.cpp.

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

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

◆ testConcept()

bool testConcept ( )

Gaussdigitizer is a model of CDigitalBoundedShape and CDigitalOrientedShape.

Definition at line 62 of file testGaussDigitizer.cpp.

Referenced by main().

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

◆ testDigitization()

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

Definition at line 73 of file testGaussDigitizer.cpp.

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::BIG_DS, DGtal::GridCurve< TKSpace >::className(), DGtal::HyperRectDomain< TSpace >::className(), domain(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getDomain(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getLowerBound(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getUpperBound(), DGtal::HIGH_BEL_DS, DGtal::HIGH_ITER_DS, DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), DGtal::GridCurve< TKSpace >::initFromVector(), K, LibBoard::Board::saveEPS(), LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), and LibBoard::Board::UCentimeter.

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 }
HyperRectDomain< Space > Domain
const Domain domain(Point(1, 2), Point(6, 5))
const Point & getLowerBound() const
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
const Point & getUpperBound() const
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
void attach(const EuclideanShape &shape)
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
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
MyPointD Point
Definition: testClone2.cpp:383
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...
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
Space::RealPoint RealPoint
Definition: StdDefs.h:97
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...
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70

◆ testGaussDigitizer()

bool testGaussDigitizer ( )

Example of a test. To be completed.

Definition at line 145 of file testGaussDigitizer.cpp.

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

Referenced by main().

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition: Ellipse2D.h:64
double endBlock()
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
std::ostream & info()