DGtal 2.1.1
Loading...
Searching...
No Matches
testParallelIntegralInvariantEstimator.cpp File Reference
#include <iostream>
#include <type_traits>
#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"
#include "DGtal/geometry/surfaces/estimation/ParallelIIEstimator.h"
#include "DGtal/kernel/domains/DomainSplitter.h"
#include "DGtal/io/boards/Board2D.h"
Include dependency graph for testParallelIntegralInvariantEstimator.cpp:

Go to the source code of this file.

Functions

bool testCurvature2dP (double h)
 
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
Bastien DOIGNIES (basti.nosp@m.en.d.nosp@m.oigni.nosp@m.es@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 testParallelIntegralInvariantEstimator.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 196 of file testParallelIntegralInvariantEstimator.cpp.

197{
198 trace.beginBlock ( "Testing class ParrallelIIEstimator with IntegralInvariantVolumeEstimator in 2d" );
199
200 bool res = testCurvature2dP( 0.4 );
201 trace.emphase() << ( res ? "Passed." : "Error." ) << std::endl;
202 trace.endBlock();
203 return res ? 0 : 1;
204}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
Trace trace
bool testCurvature2dP(double h)

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

◆ testCurvature2dP()

bool testCurvature2dP ( double  h)

[exampleParallelII-type]

[exampleParallelII-type]

[exampleParallelII-construction]

[exampleParallelII-construction]

Definition at line 64 of file testParallelIntegralInvariantEstimator.cpp.

65{
71 typedef GraphVisitorRange< Visitor > VisitorRange;
72 typedef VisitorRange::ConstIterator VisitorConstIterator;
73
74 typedef functors::IICurvatureFunctor<Z2i::Space> MyIICurvatureFunctor;
76
78 //typedef AxisDomainSplitter<Z2i::Domain> Splitter;
80 typedef ParallelIIEstimator<MyIICurvatureEstimator, Splitter> MyIICurvatureEstimatorP;
82
83 typedef MyIICurvatureEstimator::Quantity Value;
84
85 static_assert(std::is_same_v<typename MyIICurvatureEstimator::Quantity, typename MyIICurvatureEstimatorP::Quantity>);
86
87 double re = 10;
88 double radius = 15;
89
90 trace.beginBlock( "[PARALLEL] Shape initialisation ..." );
91
92 ImplicitShape ishape( Z2i::RealPoint( 0, 0 ), radius );
93 DigitalShape dshape;
94 dshape.attach( ishape );
95 dshape.init( Z2i::RealPoint( -20.0, -20.0 ), Z2i::RealPoint( 20.0, 20.0 ), h );
96
98 if ( !K.init( dshape.getLowerBound(), dshape.getUpperBound(), true ) )
99 {
100 trace.error() << "Problem with Khalimsky space" << std::endl;
101 return false;
102 }
103
105 Boundary boundary( K, dshape, SurfelAdjacency<Z2i::KSpace::dimension>( true ), bel );
106 MyDigitalSurface surf ( boundary );
107
108
109
110 trace.endBlock();
111
112 trace.beginBlock( "Curvature estimator initialisation ...");
113
114 // Visitor ranges are typically unique and single pass. We need
115 // to create one for each estimator in this case
116 VisitorRange range( new Visitor( surf, *surf.begin() ));
117 VisitorConstIterator ibegin = range.begin();
118 VisitorConstIterator iend = range.end();
119 // Parallel iterations
120 VisitorRange rangeP( new Visitor( surf, *surf.begin() ));
121 VisitorConstIterator ibeginP = rangeP.begin();
122 VisitorConstIterator iendP = rangeP.end();
123
124 MyIICurvatureFunctor curvatureFunctor;
125 curvatureFunctor.init( h, re );
126
128 MyIICurvatureEstimator curvatureEstimator ( curvatureFunctor);
129 curvatureEstimator.attach( K, dshape );
130 curvatureEstimator.setParams( re/h );
131 curvatureEstimator.init( h, ibegin, iend );
132
133 // Parallel version expects a domain splitter instance and a number of
134 // threads. Subsequent arguments are forwarded to the underlying estimator.
136 MyIICurvatureEstimatorP curvatureEstimatorP( splitter, 4, curvatureFunctor );
137 curvatureEstimatorP.attach( K, dshape );
138 curvatureEstimatorP.setParams( re/h );
139 curvatureEstimatorP.init( h, ibeginP, iendP );
141
142 trace.endBlock();
143
144 trace.beginBlock( "Curvature estimator evaluation ...");
145
146 std::vector< Value > results, resultsP;
147 std::back_insert_iterator< std::vector< Value > > resultsIt ( results );
148 std::back_insert_iterator< std::vector< Value > > resultsItP( resultsP );
149
150 curvatureEstimator .eval( ibegin , iend , resultsIt );
151 curvatureEstimatorP.eval( ibeginP, iendP, resultsItP );
152
153 trace.endBlock();
154
155 trace.beginBlock ( "Comparing results of integral invariant 2D curvature ..." );
156 // Debugging
157 Board2D board;
158 board << dshape.getDomain();
159 for(auto p: dshape.getDomain())
160 if (dshape(p))
161 board << p;
162 board.saveSVG("debugging-para.svg");
163
164 trace.info() << dshape.getDomain() << std::endl;
165 trace.info() << "Splits: "<<std::endl;
166 auto splits = splitter(dshape.getDomain(), 4);
167 for(const auto &sd: splits)
168 trace.info() << sd.domain << std::endl;
169
170
171 auto rsize = results.size();
172 auto rsizeP = resultsP.size();
173
174 if (rsize != rsizeP)
175 {
176 trace.error() << "Size mismatch between parallel and non-parallel versions: " << rsize << " / " << rsizeP;
177 trace.endBlock();
178 return false;
179 }
180
181 for ( unsigned int i = 0; i < rsize; ++i )
182 {
183 if (std::abs(results[i] - resultsP[i]) >= 1e-6)
184 {
185 trace.error() << "Result mismatch between parallel and non-parallel versions at linel " << i << ": " << results[i] << " / " << resultsP[i] << "\n";
186 trace.endBlock();
187 return false;
188 }
189 }
190 trace.endBlock();
191 return true;
192}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
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...
std::ostream & error()
std::ostream & info()
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1011
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
BreadthFirstVisitor< MyDigitalSurface > Visitor
STL namespace.
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....
KSpace K
AxisDomainSplitter< Domain > splitter
GaussDigitizer< Space, ImplicitShape > DigitalShape
ImplicitPolynomial3Shape< Space > ImplicitShape
Domain domain

References DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), K, LibBoard::Board::saveSVG(), splitter, and DGtal::trace.

Referenced by main().