DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testIntegralInvariantVolumeEstimator.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.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/IntegralInvariantVolumeEstimator.h"

Go to the source code of this file.

Functions

bool testCurvature2d (double h, double delta)
 
bool testMeanCurvature3d (double h, double delta)
 
int main (int, char **)
 

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
Jérémy Levallois (jerem.nosp@m.y.le.nosp@m.vallo.nosp@m.is@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), INSA-Lyon, France LAboratoire de MAthématiques - LAMA (CNRS, UMR 5127), Université de Savoie, France
Date
2014/06/26

Functions for testing class IntegralInvariantVolumeEstimator and IIGeometricFunctor.

This file is part of the DGtal library.

Definition in file testIntegralInvariantVolumeEstimator.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 267 of file testIntegralInvariantVolumeEstimator.cpp.

268{
269 trace.beginBlock ( "Testing class IntegralInvariantVolumeEstimator and 2d/3d mean curvature functors" );
270 bool res = testCurvature2d( 0.05, 0.002 ) && testMeanCurvature3d( 0.6, 0.008 );
271 trace.emphase() << ( res ? "Passed." : "Error." ) << std::endl;
272 trace.endBlock();
273 return res ? 0 : 1;
274}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
Trace trace
Definition: Common.h:154
bool testCurvature2d(double h, double delta)
bool testMeanCurvature3d(double h, double delta)

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), testCurvature2d(), testMeanCurvature3d(), and DGtal::trace.

◆ testCurvature2d()

bool testCurvature2d ( double  h,
double  delta 
)

Definition at line 59 of file testIntegralInvariantVolumeEstimator.cpp.

60{
66 typedef GraphVisitorRange< Visitor > VisitorRange;
67 typedef VisitorRange::ConstIterator VisitorConstIterator;
68
69 typedef functors::IICurvatureFunctor<Z2i::Space> MyIICurvatureFunctor;
71 typedef MyIICurvatureFunctor::Value Value;
72
73 double re = 10;
74 double radius = 15;
75 double realValue = 1.0/radius;
76
77 trace.beginBlock( "Shape initialisation ..." );
78
79 ImplicitShape ishape( Z2i::RealPoint( 0, 0 ), radius );
80 DigitalShape dshape;
81 dshape.attach( ishape );
82 dshape.init( Z2i::RealPoint( -20.0, -20.0 ), Z2i::RealPoint( 20.0, 20.0 ), h );
83
85 if ( !K.init( dshape.getLowerBound(), dshape.getUpperBound(), true ) )
86 {
87 trace.error() << "Problem with Khalimsky space" << std::endl;
88 return false;
89 }
90
92 Boundary boundary( K, dshape, SurfelAdjacency<Z2i::KSpace::dimension>( true ), bel );
93 MyDigitalSurface surf ( boundary );
94
96
97 trace.beginBlock( "Curvature estimator initialisation ...");
98
99 VisitorRange range( new Visitor( surf, *surf.begin() ));
100 VisitorConstIterator ibegin = range.begin();
101 VisitorConstIterator iend = range.end();
102
103 MyIICurvatureFunctor curvatureFunctor;
104 curvatureFunctor.init( h, re );
105
106 MyIICurvatureEstimator curvatureEstimator( curvatureFunctor );
107 curvatureEstimator.attach( K, dshape );
108 curvatureEstimator.setParams( re/h );
109 curvatureEstimator.init( h, ibegin, iend );
110
111 trace.endBlock();
112
113 trace.beginBlock( "Curvature estimator evaluation ...");
114
115 std::vector< Value > results;
116 std::back_insert_iterator< std::vector< Value > > resultsIt( results );
117 curvatureEstimator.eval( ibegin, iend, resultsIt );
118
119 trace.endBlock();
120
121 trace.beginBlock ( "Comparing results of integral invariant 2D curvature ..." );
122
123 double mean = 0.0;
124 double rsize = static_cast<double>(results.size());
125
126 if( rsize == 0 )
127 {
128 trace.error() << "ERROR: surface is empty" << std::endl;
129 trace.endBlock();
130 return false;
131 }
132
133 for ( unsigned int i = 0; i < rsize; ++i )
134 {
135 mean += results[ i ];
136 }
137 mean /= rsize;
138
139 if( mean != mean ) //NaN
140 {
141 trace.error() << "ERROR: result is NaN" << std::endl;
142 trace.endBlock();
143 return false;
144 }
145
146 double v = std::abs ( realValue - mean );
147
148 trace.warning() << "True value: " << realValue << std::endl;
149 trace.warning() << "Mean value: " << mean << std::endl;
150 trace.warning() << "Delta: " << delta << " |true - mean|: " << v << std::endl;
151
152 if( v > delta )
153 {
154 trace.endBlock();
155 return false;
156 }
157 trace.endBlock();
158 return true;
159}
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...
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 volume o...
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...
std::ostream & warning()
std::ostream & error()
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
BreadthFirstVisitor< MyDigitalSurface > Visitor
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: A functor Real -> Real that returns the 2d curvature by transforming the given volume....
KSpace K
std::default_random_engine re

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

Referenced by main().

◆ testMeanCurvature3d()

bool testMeanCurvature3d ( double  h,
double  delta 
)

Definition at line 161 of file testIntegralInvariantVolumeEstimator.cpp.

162{
168 typedef GraphVisitorRange< Visitor > VisitorRange;
169 typedef VisitorRange::ConstIterator VisitorConstIterator;
170
171 typedef functors::IIMeanCurvature3DFunctor<Z3i::Space> MyIICurvatureFunctor;
173 typedef MyIICurvatureFunctor::Value Value;
174
175 double re = 5;
176 double radius = 5;
177 double realValue = 1.0/radius;
178
179 trace.beginBlock( "Shape initialisation ..." );
180
181 ImplicitShape ishape( Z3i::RealPoint( 0, 0, 0 ), radius );
182 DigitalShape dshape;
183 dshape.attach( ishape );
184 dshape.init( Z3i::RealPoint( -10.0, -10.0, -10.0 ), Z3i::RealPoint( 10.0, 10.0, 10.0 ), h );
185
187 if ( !K.init( dshape.getLowerBound(), dshape.getUpperBound(), true ) )
188 {
189 trace.error() << "Problem with Khalimsky space" << std::endl;
190 return false;
191 }
192
194 Boundary boundary( K, dshape, SurfelAdjacency<Z3i::KSpace::dimension>( true ), bel );
195 MyDigitalSurface surf ( boundary );
196
197 trace.endBlock();
198
199 trace.beginBlock( "Curvature estimator initialisation ...");
200
201 VisitorRange range( new Visitor( surf, *surf.begin() ));
202 VisitorConstIterator ibegin = range.begin();
203 VisitorConstIterator iend = range.end();
204
205 MyIICurvatureFunctor curvatureFunctor;
206 curvatureFunctor.init( h, re );
207
208 MyIICurvatureEstimator curvatureEstimator( curvatureFunctor );
209 curvatureEstimator.attach( K, dshape );
210 curvatureEstimator.setParams( re/h );
211 curvatureEstimator.init( h, ibegin, iend );
212
213 trace.endBlock();
214
215 trace.beginBlock( "Curvature estimator evaluation ...");
216
217 std::vector< Value > results;
218 std::back_insert_iterator< std::vector< Value > > resultsIt( results );
219 curvatureEstimator.eval( ibegin, iend, resultsIt );
220
221 trace.endBlock();
222
223 trace.beginBlock ( "Comparing results of integral invariant 3D mean curvature ..." );
224
225 double mean = 0.0;
226 unsigned int rsize = results.size();
227
228 if( rsize == 0 )
229 {
230 trace.error() << "ERROR: surface is empty" << std::endl;
231 trace.endBlock();
232 return false;
233 }
234
235 for ( unsigned int i = 0; i < rsize; ++i )
236 {
237 mean += results[ i ];
238 }
239 mean /= rsize;
240
241 if( mean != mean ) //NaN
242 {
243 trace.error() << "ERROR: result is NaN" << std::endl;
244 trace.endBlock();
245 return false;
246 }
247
248 double v = std::abs ( realValue - mean );
249
250 trace.warning() << "True value: " << realValue << std::endl;
251 trace.warning() << "Mean value: " << mean << std::endl;
252 trace.warning() << "Delta: " << delta << " |true - mean|: " << v << std::endl;
253
254 if ( v > delta )
255 {
256 trace.endBlock();
257 return false;
258 }
259
260 trace.endBlock();
261 return true;
262}
Aim: A functor Real -> Real that returns the 3d mean curvature by transforming the given volume....

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

Referenced by main().