DGtal 1.3.0
Loading...
Searching...
No Matches
testEstimatorCache.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "ConfigTest.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/geometry/surfaces/estimation/EstimatorCache.h"
38#include "DGtal/shapes/implicit/ImplicitBall.h"
39
41#include "DGtal/shapes/GaussDigitizer.h"
42#include "DGtal/topology/LightImplicitDigitalSurface.h"
43#include "DGtal/topology/DigitalSurface.h"
44#include "DGtal/graph/DepthFirstVisitor.h"
45#include "DGtal/graph/GraphVisitorRange.h"
46
48#include "DGtal/geometry/surfaces/estimation/IIGeometricFunctors.h"
49#include "DGtal/geometry/surfaces/estimation/IntegralInvariantCovarianceEstimator.h"
50
51
53
54using namespace std;
55using namespace DGtal;
56
58// Functions for testing class EstimatorCache.
60
64bool testEstimatorCache(double h)
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
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}
190
192// Standard services - public :
193
194int main( int argc, char** argv )
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}
207// //
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
ConstIterator begin() const
ConstIterator end() const
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 & getUpperBound() const
void attach(ConstAlias< EuclideanShape > shape)
const Point & getLowerBound() 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
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 & error()
std::ostream & info()
double endBlock()
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
BreadthFirstVisitor< MyDigitalSurface > Visitor
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
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...
int main()
Definition: testBits.cpp:56
KSpace K
bool testEstimatorCache(double h)
std::default_random_engine re