DGtal 1.4.0
Loading...
Searching...
No Matches
testTensorVoting.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/helpers/StdDefs.h"
34#include "DGtal/base/BasicFunctors.h"
35#include "DGtal/graph/GraphVisitorRange.h"
36#include "DGtal/io/boards/Board2D.h"
37#include "DGtal/io/Color.h"
38#include "DGtal/io/colormaps/GradientColorMap.h"
39#include "DGtal/shapes/Shapes.h"
40#include "DGtal/topology/CanonicSCellEmbedder.h"
41#include "DGtal/graph/DistanceBreadthFirstVisitor.h"
42#include "DGtal/geometry/volumes/distance/LpMetric.h"
43#include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
44#include "DGtal/geometry/surfaces/estimation/estimationFunctors/BasicEstimatorFromSurfelsFunctors.h"
45#include "DGtal/topology/LightImplicitDigitalSurface.h"
46#include "DGtal/geometry/surfaces/estimation/estimationFunctors/TensorVotingFeatureExtraction.h"
47
48#include "DGtal/shapes/implicit/ImplicitHyperCube.h"
49#include "DGtal/shapes/implicit/ImplicitBall.h"
50#include "DGtal/shapes/GaussDigitizer.h"
52
53using namespace std;
54using namespace DGtal;
55
57// Functions for testing class LocalEstimatorFromFunctorAdapter.
59
64template<typename Shape>
66{
67 unsigned int nbok = 0;
68 unsigned int nb = 0;
69 trace.beginBlock ( "Testing init ..." );
70
71 using namespace Z3i;
72
73 typedef GaussDigitizer<Space,Shape> Gauss;
74
75 typedef LightImplicitDigitalSurface<KSpace,Gauss> SurfaceContainer;
77 typedef typename Surface::Surfel Surfel;
78
79
80 trace.beginBlock("Creating Surface");
81 Point p1( -10, -10, -10 );
82 Point p2( 10, 10, 10 );
83 KSpace K;
84 nbok += K.init( p1, p2, true ) ? 1 : 0;
85 nb++;
86 trace.info() << "(" << nbok << "/" << nb << ") "
87 << "K.init() is ok" << std::endl;
88
89 //Shape
90 Shape shape(RealPoint::diagonal(0.0), 6.0 );
91 Gauss gauss;
92 gauss.attach(shape);
93 gauss.init(p1,p2,1.0);
94
95 //Surface
96 Surfel bel = Surfaces<KSpace>::findABel( K, gauss, 10000 );
97 SurfaceContainer* surfaceContainer = new SurfaceContainer
98 ( K, gauss, SurfelAdjacency<KSpace::dimension>( true ), bel );
99 Surface surface( surfaceContainer ); // acquired
100 trace.endBlock();
101
102 trace.beginBlock("Creating adapters");
104
105 typedef functors::GaussianKernel ConvFunctor;
106 typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>, FunctorVoting, ConvFunctor> Reporter;
107
108 CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
109 FunctorVoting estimator(embedder,1);
110
111 ConvFunctor convFunc(1.0);
112 Reporter reporter;
113 reporter.attach(surface);
114 LpMetric<Z3i::Space> l2double(2.0);
115 reporter.setParams(l2double, estimator , convFunc, 2.0);
116
117 reporter.init(1, surface.begin(), surface.end());
118
119 typename FunctorVoting::Quantity val = reporter.eval( surface.begin());
120 trace.info() << "probing at "<< *(surface.begin())<<std::endl;
121
122 trace.info() << "Voting = "<<val <<std::endl;
123
124 trace.endBlock();
125 trace.endBlock();
126
127 nbok += true ? 1 : 0;
128 nb++;
129 trace.info() << "(" << nbok << "/" << nb << ") "
130 << "true == true" << std::endl;
131
132 return nbok == nb;
133}
138{
139 unsigned int nbok = 0;
140 unsigned int nb = 0;
141 trace.beginBlock ( "Testing cube ..." );
142
143 using namespace Z3i;
145 typedef GaussDigitizer<Space,Shape> Gauss;
146
147 typedef LightImplicitDigitalSurface<KSpace,Gauss> SurfaceContainer;
149 typedef Surface::Surfel Surfel;
150
151
152 trace.beginBlock("Creating Surface");
153 Point p1( -10, -10, -10 );
154 Point p2( 10, 10, 10 );
155 KSpace K;
156 nbok += K.init( p1, p2, true ) ? 1 : 0;
157 nb++;
158 trace.info() << "(" << nbok << "/" << nb << ") "
159 << "K.init() is ok" << std::endl;
160
161 //Shape
162 Shape shape(RealPoint::diagonal(0.0), 6.0 );
163 Gauss gauss;
164 gauss.attach(shape);
165 gauss.init(p1,p2,1.0);
166
167 //Surface
168 Surfel bel = Surfaces<KSpace>::findABel( K, gauss, 10000 );
169 SurfaceContainer* surfaceContainer = new SurfaceContainer
170 ( K, gauss, SurfelAdjacency<KSpace::dimension>( true ), bel );
171 Surface surface( surfaceContainer ); // acquired
172 trace.endBlock();
173
174 trace.beginBlock("Creating adapters");
176
177 typedef functors::GaussianKernel ConvFunctor;
178 typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>, FunctorVoting, ConvFunctor> Reporter;
179
180 CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
181 FunctorVoting estimator(embedder,1);
182
183 LpMetric<Z3i::Space> l2(2.0);
184
185 ConvFunctor convFunc(1.0);
186 Reporter reporter(surface, l2, estimator , convFunc);
187 reporter.attach(surface);
188 reporter.setParams(l2, estimator , convFunc, 2.0);
189 reporter.init(1, surface.begin(),surface.end());
190 trace.endBlock();
191
192 trace.beginBlock("Probing ...");
193 Z3i::KSpace::Point p(11,-12,1);
194 for(Surface::ConstIterator it = surface.begin(), itend = surface.end(); it!= itend; ++it)
195 {
196 if (K.sKCoords(*it) == p)
197 {
198 Reporter::Quantity val = reporter.eval( it );
199 trace.info() << "probing at "<< *it<<std::endl;
200 trace.info() << "Voting = "<<val <<std::endl;
201 }
202 }
203 trace.endBlock();
204 trace.endBlock();
205
206 return nbok == nb;
207}
208
210// Standard services - public :
211
212int main( int argc, char** argv )
213{
214 trace.beginBlock ( "Testing class TensorVotingFeatureExtraction" );
215 trace.info() << "Args:";
216 for ( int i = 0; i < argc; ++i )
217 trace.info() << " " << argv[ i ];
218 trace.info() << endl;
219
222 && testCube();// && ... other tests
223 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
224 trace.endBlock();
225 return res ? 0 : 1;
226}
227// //
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: 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: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create an hypercube in n...
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.
const Point & sKCoords(const SCell &c) const
Return its Khalimsky coordinates.
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)
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 & info()
double endBlock()
Aim: Implements a functor to detect feature points from normal tensor voting strategy.
CountedPtr< SH3::DigitalSurface > surface
SH3::DigitalSurface Surface
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
Aim: A trivial embedder for signed cell, which corresponds to the canonic injection of cell centroids...
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....
Astroid2D< Space > Shape
int main()
Definition testBits.cpp:56
MyPointD Point
KSpace K
bool testCube()
bool testLocalEstimatorFromFunctorAdapter()