DGtal  1.5.beta
testSphereFitting.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/graph/GraphVisitorRange.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/shapes/implicit/ImplicitBall.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/topology/CanonicSCellEmbedder.h"
#include "DGtal/graph/DistanceBreadthFirstVisitor.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/BasicEstimatorFromSurfelsFunctors.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/SphereFittingEstimator.h"
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/ElementaryConvolutionNormalVectorEstimator.h"
#include "DGtal/geometry/surfaces/estimation/EstimatorCache.h"
Include dependency graph for testSphereFitting.cpp:

Go to the source code of this file.

Functions

bool testFitting ()
 
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/10/07

Functions for testing class SphereFitting.

This file is part of the DGtal library.

Definition in file testSphereFitting.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 155 of file testSphereFitting.cpp.

156 {
157  trace.beginBlock ( "Testing class SphereFitting" );
158  trace.info() << "Args:";
159  for ( int i = 0; i < argc; ++i )
160  trace.info() << " " << argv[ i ];
161  trace.info() << endl;
162 
163  bool res = testFitting(); // && ... other tests
164  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
165  trace.endBlock();
166  return res ? 0 : 1;
167 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testFitting()

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

◆ testFitting()

bool testFitting ( )

Example of a test. To be completed.

Definition at line 67 of file testSphereFitting.cpp.

68 {
69  unsigned int nbok = 0;
70  unsigned int nb = 0;
71  trace.beginBlock ( "Testing init ..." );
72 
73  using namespace Z3i;
74 
75  trace.beginBlock("Creating Surface");
76  Point p1( -20, -20, -20 );
77  Point p2( 20, 20, 20 );
78 
79  ImplicitBall<Z3i::Space> shape( RealPoint(6.0,0,0), 4);
81  Gauss gauss;
82  gauss.attach(shape);
83  gauss.init(p1, p2, 1);
84 
85  typedef LightImplicitDigitalSurface<KSpace, Gauss > SurfaceContainer;
87  typedef Surface::Surfel Surfel;
88 
89 
90  KSpace K;
91  nbok += K.init( p1, p2, true ) ? 1 : 0;
92  nb++;
93  trace.info() << "(" << nbok << "/" << nb << ") "
94  << "K.init() is ok" << std::endl;
95  Surfel bel = Surfaces<KSpace>::findABel( K, gauss, 10000 );
96  SurfaceContainer* surfaceContainer = new SurfaceContainer
97  ( K, gauss, SurfelAdjacency<KSpace::dimension>( true ), bel );
98  Surface surface( surfaceContainer ); // acquired
99  CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
100  trace.endBlock();
101 
102  trace.beginBlock("Normal vector field computation");
104  typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric,
105  FunctorNormal,
106  DGtal::functors::GaussianKernel> ReporterNormal;
107  typedef EstimatorCache<ReporterNormal> NormalCache;
108 
109  //estimator
110  DGtal::functors::GaussianKernel gaussKernelFunc(5.0);
111  FunctorNormal functorNormal(embedder, 1.0);
112  ReporterNormal reporterNormal;
113  reporterNormal.attach(surface);
114  reporterNormal.setParams(l2Metric, functorNormal, gaussKernelFunc, 5.0);
115 
116  //caching normal field
117  NormalCache normalCache(reporterNormal);
118  normalCache.init( 1, surface.begin(), surface.end());
119  trace.info() << "Normal vector field cached... "<< normalCache << std::endl;
120  trace.endBlock();
121 
122  trace.beginBlock("Creating sphere fitting adapter from normal vector field");
124  typedef functors::ConstValue< double > ConvFunctor;
126 
127  Functor fitter(embedder,1.0, 5.0, normalCache);
128  ConvFunctor convFunc(1.0);
129  Reporter reporter;
130  reporter.attach(surface);
131  reporter.setParams(l2Metric, fitter , convFunc, 15.0);
132 
133  reporter.init(1, surface.begin(), surface.end());
134  for(Surface::ConstIterator it = surface.begin(), ite=surface.end(); it!=ite; ++it)
135  {
136  Functor::Quantity val = reporter.eval( it );
137  trace.info() << "Fitting = "<<val.center <<" rad="<<val.radius<<std::endl;
138  }
139  trace.endBlock();
140 
141 
142  trace.endBlock();
143 
144  nbok += true ? 1 : 0;
145  nb++;
146  trace.info() << "(" << nbok << "/" << nb << ") "
147  << "true == true" << std::endl;
148 
149  return nbok == nb;
150 }
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::Surfel Surfel
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Aim: this class adapts any local surface estimator to cache the estimated values in a associative con...
Aim: implements separable l_p metrics with exact predicates.
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
void attach(ConstAlias< EuclideanShape > shape)
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition: ImplicitBall.h:65
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: this class adapts any local functor on digital surface element to define a local estimator....
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
Aim: Define a simple functor that returns a constant value (0 by default).
Aim: Estimates normal vector by convolution of elementary normal vector to adjacent surfel.
Aim: Use Patate library to perform a local sphere fitting.
CountedPtr< SH3::DigitalSurface > surface
SH3::DigitalSurface Surface
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: defines a functor on double numbers which corresponds to a Gaussian convolution kernel....
MyPointD Point
Definition: testClone2.cpp:383
InHalfPlaneBySimple3x3Matrix< Point, double > Functor
KSpace K
PointVector< 3, double > RealPoint

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), K, surface, and DGtal::trace.

Referenced by main().