DGtal  0.9.2
testTensorVoting.cpp
1 
30 #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/ExactPredicateLpSeparableMetric.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 
53 using namespace std;
54 using namespace DGtal;
55 
57 // Functions for testing class LocalEstimatorFromFunctorAdapter.
59 
64 template<typename Shape>
65 bool testLocalEstimatorFromFunctorAdapter()
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;
76  typedef DigitalSurface<SurfaceContainer> Surface;
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;
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  reporter.setParams(l2Metric, estimator , convFunc, 2.0);
115 
116  reporter.init(1, surface.begin(), surface.end());
117 
118  typename FunctorVoting::Quantity val = reporter.eval( surface.begin());
119  trace.info() << "probing at "<< *(surface.begin())<<std::endl;
120 
121  trace.info() << "Voting = "<<val <<std::endl;
122 
123  trace.endBlock();
124  trace.endBlock();
125 
126  nbok += true ? 1 : 0;
127  nb++;
128  trace.info() << "(" << nbok << "/" << nb << ") "
129  << "true == true" << std::endl;
130 
131  return nbok == nb;
132 }
136 bool testCube()
137 {
138  unsigned int nbok = 0;
139  unsigned int nb = 0;
140  trace.beginBlock ( "Testing cube ..." );
141 
142  using namespace Z3i;
143  typedef ImplicitHyperCube<Space> Shape;
144  typedef GaussDigitizer<Space,Shape> Gauss;
145 
146  typedef LightImplicitDigitalSurface<KSpace,Gauss> SurfaceContainer;
147  typedef DigitalSurface<SurfaceContainer> Surface;
148  typedef Surface::Surfel Surfel;
149 
150 
151  trace.beginBlock("Creating Surface");
152  Point p1( -10, -10, -10 );
153  Point p2( 10, 10, 10 );
154  KSpace K;
155  nbok += K.init( p1, p2, true ) ? 1 : 0;
156  nb++;
157  trace.info() << "(" << nbok << "/" << nb << ") "
158  << "K.init() is ok" << std::endl;
159 
160  //Shape
161  Shape shape(RealPoint::diagonal(0.0), 6.0 );
162  Gauss gauss;
163  gauss.attach(shape);
164  gauss.init(p1,p2,1.0);
165 
166  //Surface
167  Surfel bel = Surfaces<KSpace>::findABel( K, gauss, 10000 );
168  SurfaceContainer* surfaceContainer = new SurfaceContainer
169  ( K, gauss, SurfelAdjacency<KSpace::dimension>( true ), bel );
170  Surface surface( surfaceContainer ); // acquired
171  trace.endBlock();
172 
173  trace.beginBlock("Creating adapters");
175 
176  typedef functors::GaussianKernel ConvFunctor;
178 
179  CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
180  FunctorVoting estimator(embedder,1);
181 
182  ConvFunctor convFunc(1.0);
183  Reporter reporter(surface, l2Metric, estimator , convFunc);
184  reporter.attach(surface);
185  reporter.setParams(l2Metric, estimator , convFunc, 2.0);
186  reporter.init(1, surface.begin(),surface.end());
187  trace.endBlock();
188 
189  trace.beginBlock("Probing ...");
190  Z3i::KSpace::Point p(11,-12,1);
191  for(Surface::ConstIterator it = surface.begin(), itend = surface.end(); it!= itend; ++it)
192  {
193  if (K.sKCoords(*it) == p)
194  {
195  Reporter::Quantity val = reporter.eval( it );
196  trace.info() << "probing at "<< *it<<std::endl;
197  trace.info() << "Voting = "<<val <<std::endl;
198  }
199  }
200  trace.endBlock();
201  trace.endBlock();
202 
203  nbok += true ? 1 : 0;
204  nb++;
205  trace.info() << "(" << nbok << "/" << nb << ") "
206  << "true == true" << std::endl;
207 
208  return nbok == nb;
209 }
210 
212 // Standard services - public :
213 
214 int main( int argc, char** argv )
215 {
216  trace.beginBlock ( "Testing class TensorVotingFeatureExtraction" );
217  trace.info() << "Args:";
218  for ( int i = 0; i < argc; ++i )
219  trace.info() << " " << argv[ i ];
220  trace.info() << endl;
221 
222  bool res = testLocalEstimatorFromFunctorAdapter<ImplicitHyperCube<Z3i::Space> >()
223  && testLocalEstimatorFromFunctorAdapter<ImplicitBall<Z3i::Space> >()
224  && testCube();// && ... other tests
225  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
226  trace.endBlock();
227  return res ? 0 : 1;
228 }
229 // //
void beginBlock(const std::string &keyword="")
Aim: defines a functor on double numbers which corresponds to a Gaussian convolution kernel...
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Trace trace
Definition: Common.h:130
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
STL namespace.
double endBlock()
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
std::ostream & emphase()
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
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create an hypercube in n...
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...
Aim: Implements a functor to detect feature points from normal tensor voting strategy.