DGtal  1.5.beta
testEstimatorCache.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "ConfigTest.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/surfaces/estimation/EstimatorCache.h"
#include "DGtal/shapes/implicit/ImplicitBall.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/graph/DepthFirstVisitor.h"
#include "DGtal/graph/GraphVisitorRange.h"
#include "DGtal/geometry/surfaces/estimation/IIGeometricFunctors.h"
#include "DGtal/geometry/surfaces/estimation/IntegralInvariantCovarianceEstimator.h"
Include dependency graph for testEstimatorCache.cpp:

Go to the source code of this file.

Functions

bool testEstimatorCache (double h)
 
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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2014/09/30

Functions for testing class EstimatorCache.

This file is part of the DGtal library.

Definition in file testEstimatorCache.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 194 of file testEstimatorCache.cpp.

195 {
196  trace.beginBlock ( "Testing class EstimatorCache" );
197  trace.info() << "Args:";
198  for ( int i = 0; i < argc; ++i )
199  trace.info() << " " << argv[ i ];
200  trace.info() << endl;
201 
202  bool res = testEstimatorCache( 0.8 ); // && ... other tests
203  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
204  trace.endBlock();
205  return res ? 0 : 1;
206 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testEstimatorCache(double h)

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

◆ testEstimatorCache()

bool testEstimatorCache ( double  h)

Example of a test. To be completed.

Definition at line 64 of file testEstimatorCache.cpp.

65 {
66  unsigned int nbok = 0;
67  unsigned int nb = 0;
68 
74  typedef GraphVisitorRange< Visitor > VisitorRange;
75  typedef VisitorRange::ConstIterator VisitorConstIterator;
76 
77  typedef functors::IIGaussianCurvature3DFunctor<Z3i::Space> MyIICurvatureFunctor;
79 // typedef MyIICurvatureFunctor::Value Value;
80 
81  double re = 5.0;
82  double radius = 5.0;
83 
84  trace.beginBlock( "Shape initialisation ..." );
85 
86  ImplicitShape ishape( Z3i::RealPoint( 0, 0, 0 ), radius );
87  DigitalShape dshape;
88  dshape.attach( ishape );
89  dshape.init( Z3i::RealPoint( -10.0, -10.0, -10.0 ), Z3i::RealPoint( 10.0, 10.0, 10.0 ), h );
90 
91  Z3i::KSpace K;
92  if ( !K.init( dshape.getLowerBound(), dshape.getUpperBound(), true ) )
93  {
94  trace.error() << "Problem with Khalimsky space" << std::endl;
95  return false;
96  }
97 
99  Boundary boundary( K, dshape, SurfelAdjacency<Z3i::KSpace::dimension>( true ), bel );
100  MyDigitalSurface surf ( boundary );
101 
102  trace.endBlock();
103 
104  trace.beginBlock( "Curvature estimator computation ...");
105 
106  VisitorRange range( new Visitor( surf, *surf.begin() ));
107  VisitorConstIterator ibegin = range.begin();
108  VisitorConstIterator iend = range.end();
109 
110  MyIICurvatureFunctor curvatureFunctor;
111  curvatureFunctor.init( h, re );
112 
113  MyIICurvatureEstimator curvatureEstimator( curvatureFunctor );
114  curvatureEstimator.attach( K, dshape );
115  curvatureEstimator.setParams( re/h );
116  curvatureEstimator.init( h, ibegin, iend );
117 
118  std::vector<MyIICurvatureEstimator::Quantity> results;
119  std::back_insert_iterator< std::vector<MyIICurvatureEstimator::Quantity> > itback(results);
120 
121  curvatureEstimator.eval(ibegin,iend,itback);
122  trace.info() << "Number of values = "<< results.size()<<std::endl;
123  trace.endBlock();
124 
125  trace.beginBlock( "Caching values ...");
126  VisitorRange range2( new Visitor( surf, *surf.begin() ));
127  VisitorConstIterator ibegin2 = range2.begin();
128  VisitorConstIterator iend2 = range2.end();
129 
130  typedef EstimatorCache<MyIICurvatureEstimator> GaussianCache;
131 
132  BOOST_CONCEPT_ASSERT(( concepts::CSurfelLocalEstimator<GaussianCache> ));
133 
134  GaussianCache cache( curvatureEstimator );
135  cache.init( h, ibegin2, iend2 );
136  trace.info() << "Number of cached values = "<< cache.size()<<std::endl;
137 
138  trace.info() << "Value at begin="<< cache.eval(surf.begin())<<" expected = "<< curvatureEstimator.eval(surf.begin())<<std::endl;
139  trace.endBlock();
140 
141 
142  trace.beginBlock( "Complete test ...");
143  bool ok=true;
144  for(MyDigitalSurface::ConstIterator it = surf.begin(), itend=surf.end(); it != itend; ++it)
145  {
146  if ( cache.eval(it) != curvatureEstimator.eval(it) )
147  {
148  ok=false;
149  trace.error() << "Incorrect values at "<<*it<<" read " <<cache.eval(it)<< " and expecting "<<curvatureEstimator.eval(it)<<std::endl;
150  }
151  }
152  trace.endBlock();
153 
154  trace.beginBlock( "Timing cache access ...");
155  for(MyDigitalSurface::ConstIterator it = surf.begin(), itend=surf.end(); it != itend; ++it)
156  {
157  if ( cache.eval(it) == 12345678 ) //making sure to visit
158  //all surfels
159  {
160  ok=false;
161  trace.error() << "Incorrect values at "<<*it<<std::endl;
162  }
163  }
164  trace.endBlock();
165 
166  trace.beginBlock( "Copy construction and timing cache access ...");
167  GaussianCache cache2(cache);
168  trace.info() << "Number of cached values = "<< cache.size()<<std::endl;
169  trace.info() << "Value at begin="<< cache2.eval(surf.begin())<<" expected = "<< curvatureEstimator.eval(surf.begin())<<std::endl;
170  for(MyDigitalSurface::ConstIterator it = surf.begin(), itend=surf.end(); it != itend; ++it)
171  {
172  if ( cache.eval(it) == 12345678 ) //making sure to visit
173  //all surfels
174  {
175  ok=false;
176  trace.error() << "Incorrect values at "<<*it<<std::endl;
177  }
178  }
179  trace.endBlock();
180 
181 
182 
183  nbok += ok ? 1 : 0;
184  nb++;
185  trace.info() << "(" << nbok << "/" << nb << ") "
186  << "cache == eval" << std::endl;
187 
188  return nbok == nb;
189 }
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Aim: this class adapts any local surface estimator to cache the estimated values in a associative con...
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
const Point & getLowerBound() const
void attach(ConstAlias< EuclideanShape > shape)
const Point & getUpperBound() const
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Aim: Transforms a graph visitor into a single pass input range.
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition: ImplicitBall.h:65
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
Aim: This class implement an Integral Invariant estimator which computes for each surfel the covarian...
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: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
std::ostream & error()
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::ConstIterator ConstIterator
BreadthFirstVisitor< MyDigitalSurface > Visitor
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: This concept describes an object that can process a range of surfels (that are supposed to belon...
Aim: A functor Matrix -> Real that returns the Gaussian curvature by diagonalizing the given covarian...
KSpace K

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::end(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getLowerBound(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getUpperBound(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), K, and DGtal::trace.

Referenced by main().