DGtal  0.9.2
testSphericalHoughNormalVectorEstimator.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "ConfigTest.h"
34 #include "DGtalCatch.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/shapes/implicit/ImplicitHyperCube.h"
37 #include "DGtal/shapes/implicit/ImplicitBall.h"
38 #include "DGtal/shapes/GaussDigitizer.h"
39 #include "DGtal/topology/LightImplicitDigitalSurface.h"
40 #include "DGtal/topology/DigitalSurface.h"
41 #include "DGtal/topology/CanonicSCellEmbedder.h"
42 #include "DGtal/base/BasicFunctors.h"
43 
44 #include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
45 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/SphericalHoughNormalVectorEstimator.h"
46 
47 #ifdef WITH_VISU3D_QGLVIEWER
48 #include "DGtal/io/viewers/Viewer3D.h"
49 #endif
50 #include "DGtal/io/boards/Board3D.h"
51 
53 
54 using namespace std;
55 using namespace DGtal;
56 using namespace Z3i;
57 
59 // Functions for testing class SphericalHoughNormalVectorEstimator.
61 
62 TEST_CASE( "Testing SphericalHoughNormalVectorEstimator" )
63 {
64  typedef ImplicitBall<Space> Shape;
65  typedef GaussDigitizer<Space,Shape> Gauss;
66 
67  typedef LightImplicitDigitalSurface<KSpace,Gauss> SurfaceContainer;
68  typedef DigitalSurface<SurfaceContainer> Surface;
69  typedef Surface::Surfel Surfel;
70 
71 
72  Point p1( -50, -50, -50 );
73  Point p2( 50, 50, 50 );
74  KSpace K;
75  REQUIRE( K.init( p1, p2, true ) );
76 
77 
78  //Shape
79  Shape shape(RealPoint::diagonal(0.0), 10.0 );
80  Gauss gauss;
81  gauss.attach(shape);
82  gauss.init(p1,p2,1.0);
83 
84  //Surface
85  Surfel bel = Surfaces<KSpace>::findABel( K, gauss, 10000 );
86  SurfaceContainer* surfaceContainer = new SurfaceContainer( K, gauss, SurfelAdjacency<KSpace::dimension>( true ), bel );
87  Surface surface( surfaceContainer ); // acquired
88 
89 
91  typedef functors::ConstValue<double> ConstFunctor;
93 
94  CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
95  SphericalHough estimator(embedder,1.0 , 0.001, 1000 , 10, 1);
96 
97  ConstFunctor constFunc(1.0);
98  Reporter reporter(surface, l2Metric, estimator , constFunc);
99  reporter.attach(surface);
100  reporter.setParams(l2Metric, estimator , constFunc, 10.0);
101  reporter.init(1, surface.begin(),surface.end());
102 
103  REQUIRE( reporter.isValid() );
104 
105  typedef Reporter::Quantity Quantity;
106 
107  Quantity result = reporter.eval( surface.begin() );
108  trace.info() << "Result at begin = "<< result <<std::endl;
109 
110  //true normal (implicitBall)
111  RealPoint res = embedder( *(surface.begin()) ).getNormalized();
112  trace.info() << "Expecting = "<< res <<std::endl;
113 
114  REQUIRE( std::abs(result.dot(res)) > 0.9 );
115 
116 
117 #ifdef WITH_VISU3D_QGLVIEWER_TESTS
118  int argc=0;
119  char **argv;
120  QApplication application(argc,argv);
122  viewer.show();
123  for(Surface::ConstIterator it = surface.begin(), itend=surface.end(); it != itend ;
124  ++it)
125  {
126  Quantity normal = reporter.eval( it );
127  viewer << CustomColors3D( DGtal::Color(static_cast<unsigned char>(255*abs(normal[0])),
128  static_cast<unsigned char>(255*abs(normal[1])),
129  static_cast<unsigned char>(255*abs(normal[2]))),
130  DGtal::Color(static_cast<unsigned char>(255*abs(normal[0])),
131  static_cast<unsigned char>(255*abs(normal[1])),
132  static_cast<unsigned char>(255*abs(normal[2]))));
133 
134  viewer << K.unsigns(*it) ;
135 
136  Point center = K.sCoords ( *it );
137  }
138  viewer<< Viewer3D<>::updateDisplay;
139  application.exec();
140 #endif
141 }
142 
Aim: Define a simple functor that returns a constant value (0 by default).
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: This functor estimates normal vector for a collection of surfels using spherical accumulator bas...
Trace trace
Definition: Common.h:130
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
STL namespace.
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
bool init(const Point &lower, const Point &upper, bool isClosed)
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD...
Definition: ImplicitBall.h:64
Point sCoords(const SCell &c) const
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
Aim: this class adapts any local functor on digital surface element to define a local estimator...
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Cell unsigns(const SCell &p) const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
PointVector< dim, double, std::array< double, dim > > getNormalized() const