DGtal 2.1.1
Loading...
Searching...
No Matches
testParallelIntegralInvariantEstimator.cpp
1
32#include <iostream>
33#include <type_traits>
34#include "DGtal/base/Common.h"
35
37#include "DGtal/shapes/implicit/ImplicitBall.h"
38
40#include "DGtal/shapes/GaussDigitizer.h"
41#include "DGtal/topology/LightImplicitDigitalSurface.h"
42#include "DGtal/topology/DigitalSurface.h"
43#include "DGtal/graph/DepthFirstVisitor.h"
44#include "DGtal/graph/GraphVisitorRange.h"
45
47#include "DGtal/geometry/surfaces/estimation/IIGeometricFunctors.h"
48#include "DGtal/geometry/surfaces/estimation/IntegralInvariantVolumeEstimator.h"
49#include "DGtal/geometry/surfaces/estimation/ParallelIIEstimator.h"
50#include "DGtal/kernel/domains/DomainSplitter.h"
51
52
54
55
56using namespace DGtal;
57
59// Functions for testing class IntegralInvariantVolumeEstimator and IIGeometricFunctor.
61
62bool testCurvature2dP ( double h )
63{
69 typedef GraphVisitorRange< Visitor > VisitorRange;
70 typedef VisitorRange::ConstIterator VisitorConstIterator;
71
72 typedef functors::IICurvatureFunctor<Z2i::Space> MyIICurvatureFunctor;
74
77 typedef ParallelIIEstimator<MyIICurvatureEstimator, Splitter> MyIICurvatureEstimatorP;
79
80 typedef MyIICurvatureEstimator::Quantity Value;
81
82 static_assert(std::is_same_v<typename MyIICurvatureEstimator::Quantity, typename MyIICurvatureEstimatorP::Quantity>);
83
84 double re = 10;
85 double radius = 15;
86
87 trace.beginBlock( "[PARALLEL] Shape initialisation ..." );
88
89 ImplicitShape ishape( Z2i::RealPoint( 0, 0 ), radius );
90 DigitalShape dshape;
91 dshape.attach( ishape );
92 dshape.init( Z2i::RealPoint( -20.0, -20.0 ), Z2i::RealPoint( 20.0, 20.0 ), h );
93
95 if ( !K.init( dshape.getLowerBound(), dshape.getUpperBound(), true ) )
96 {
97 trace.error() << "Problem with Khalimsky space" << std::endl;
98 return false;
99 }
100
102 Boundary boundary( K, dshape, SurfelAdjacency<Z2i::KSpace::dimension>( true ), bel );
103 MyDigitalSurface surf ( boundary );
104
105 trace.endBlock();
106
107 trace.beginBlock( "Curvature estimator initialisation ...");
108
109 // Visitor ranges are typically unique and single pass. We need
110 // to create one for each estimator in this case
111 VisitorRange range( new Visitor( surf, *surf.begin() ));
112 VisitorConstIterator ibegin = range.begin();
113 VisitorConstIterator iend = range.end();
114 // Parallel iterations
115 VisitorRange rangeP( new Visitor( surf, *surf.begin() ));
116 VisitorConstIterator ibeginP = rangeP.begin();
117 VisitorConstIterator iendP = rangeP.end();
118
119 MyIICurvatureFunctor curvatureFunctor;
120 curvatureFunctor.init( h, re );
121
123 MyIICurvatureEstimator curvatureEstimator ( curvatureFunctor);
124 curvatureEstimator.attach( K, dshape );
125 curvatureEstimator.setParams( re/h );
126 curvatureEstimator.init( h, ibegin, iend );
127
128 // Parallel version expects a domain splitter instance and a number of
129 // threads. Subsequent arguments are forwarded to the underlying estimator.
131 MyIICurvatureEstimatorP curvatureEstimatorP( splitter, 4, curvatureFunctor );
132 curvatureEstimatorP.attach( K, dshape );
133 curvatureEstimatorP.setParams( re/h );
134 curvatureEstimatorP.init( h, ibeginP, iendP );
136
137 trace.endBlock();
138
139 trace.beginBlock( "Curvature estimator evaluation ...");
140
141 std::vector< Value > results, resultsP;
142 std::back_insert_iterator< std::vector< Value > > resultsIt ( results );
143 std::back_insert_iterator< std::vector< Value > > resultsItP( resultsP );
144
145 curvatureEstimator .eval( ibegin , iend , resultsIt );
146 curvatureEstimatorP.eval( ibeginP, iendP, resultsItP );
147
148 trace.endBlock();
149
150 trace.beginBlock ( "Comparing results of integral invariant 2D curvature ..." );
151
152 unsigned int rsize = results.size();
153 unsigned int rsizeP = resultsP.size();
154
155 if (rsize != rsizeP)
156 {
157 trace.error() << "Size mismatch between parallel and non-parallel versions: " << rsize << " / " << rsizeP;
158 trace.endBlock();
159 return false;
160 }
161
162 for ( unsigned int i = 0; i < rsize; ++i )
163 {
164 if (std::abs(results[i] - resultsP[i]) >= 1e-2)
165 {
166 trace.error() << "Result mismatch between parallel and non-parallel versions at voxel " << i << ": " << results[i] << " / " << resultsP[i] << "\n";
167 trace.endBlock();
168 return false;
169 }
170 }
171 trace.endBlock();
172 return true;
173}
174
176// Standard services - public :
177int main( int /*argc*/, char** /*argv*/ )
178{
179 trace.beginBlock ( "Testing class ParrallelIIEstimator with IntegralInvariantVolumeEstimator in 2d" );
180
181 bool res = testCurvature2dP( 0.05 );
182 trace.emphase() << ( res ? "Passed." : "Error." ) << std::endl;
183 trace.endBlock();
184 return res ? 0 : 1;
185}
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...
Aim: Transforms a graph visitor into a single pass input range.
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
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...
Run an Integral Invariant estimator in parallel.
Aim: Implements basic operations that will be used in Point and Vector classes.
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()
double endBlock()
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
BreadthFirstVisitor< MyDigitalSurface > Visitor
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Splits a domain evenly along all dimensions.
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....
int main()
Definition testBits.cpp:56
KSpace K
AxisDomainSplitter< Domain > splitter
GaussDigitizer< Space, ImplicitShape > DigitalShape
ImplicitPolynomial3Shape< Space > ImplicitShape