Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
testSphericalHoughNormalVectorEstimator.cpp
Go to the documentation of this file.
1
16
29
31#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#include "DGtal/geometry/volumes/distance/LpMetric.h"
44#include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
45#include "DGtal/geometry/surfaces/estimation/estimationFunctors/SphericalHoughNormalVectorEstimator.h"
46
47#ifdef DGTAL_WITH_POLYSCOPE
48 #include "DGtal/io/viewers/PolyscopeViewer.h"
49#endif
50
52
53using namespace std;
54using namespace DGtal;
55using namespace Z3i;
56
58// Functions for testing class SphericalHoughNormalVectorEstimator.
60
61TEST_CASE( "Testing SphericalHoughNormalVectorEstimator" )
62{
64 typedef GaussDigitizer<Space,Shape> Gauss;
65
66 typedef LightImplicitDigitalSurface<KSpace,Gauss> SurfaceContainer;
68 typedef Surface::Surfel Surfel;
69
70
71 Point p1( -50, -50, -50 );
72 Point p2( 50, 50, 50 );
73 KSpace K;
74 REQUIRE( K.init( p1, p2, true ) );
75
76
77 //Shape
78 Shape shape(RealPoint::diagonal(0.0), 10.0 );
79 Gauss gauss;
80 gauss.attach(shape);
81 gauss.init(p1,p2,1.0);
82
83 //Surface
84 Surfel bel = Surfaces<KSpace>::findABel( K, gauss, 10000 );
85 SurfaceContainer* surfaceContainer = new SurfaceContainer( K, gauss, SurfelAdjacency<KSpace::dimension>( true ), bel );
86 Surface surface( surfaceContainer ); // acquired
87
88
90 typedef functors::ConstValue<double> ConstFunctor;
91 typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>, SphericalHough, ConstFunctor> Reporter;
92
93 CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
94 SphericalHough estimator(embedder,1.0 , 0.001, 1000 , 10, 1);
95
97 ConstFunctor constFunc(1.0);
98 Reporter reporter(surface, l2, estimator , constFunc);
99 reporter.attach(surface);
100 reporter.setParams(l2, 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 DGTAL_WITH_POLYSCOPE_TESTS
119 for(Surface::ConstIterator it = surface.begin(), itend=surface.end(); it != itend ;
120 ++it)
121 {
122 Quantity normal = reporter.eval( it );
123 viewer << DGtal::Color(static_cast<unsigned char>(255*abs(normal[0])),
124 static_cast<unsigned char>(255*abs(normal[1])),
125 static_cast<unsigned char>(255*abs(normal[2])));
126 viewer << K.unsigns(*it) ;
127
128 Point center = K.sCoords ( *it );
129 }
130 viewer.show();
131#endif
132}
133
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
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....
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: implements l_p metrics.
Definition LpMetric.h:75
static Self diagonal(Component val=1)
void show() override
Starts the event loop and display of elements.
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...
Aim: Define a simple functor that returns a constant value (0 by default).
Aim: This functor estimates normal vector for a collection of surfels using spherical accumulator bas...
CountedPtr< SH3::DigitalSurface > surface
SH3::DigitalSurface Surface
Z3i this namespace gathers the standard of types for 3D imagery.
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
Space::RealPoint RealPoint
Definition StdDefs.h:170
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
Aim: A trivial embedder for signed cell, which corresponds to the canonic injection of cell centroids...
Wrapper for array of quantities.
Definition Display3D.h:223
Astroid2D< Space > Shape
KSpace K
REQUIRE(domain.isInside(aPoint))
TEST_CASE("Testing SphericalHoughNormalVectorEstimator")