DGtal  1.3.beta
testTensorVoting.cpp
Go to the documentation of this file.
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/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 
53 using namespace std;
54 using namespace DGtal;
55 
57 // Functions for testing class LocalEstimatorFromFunctorAdapter.
59 
64 template<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 }
137 bool testCube()
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 
212 int 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 
220  bool res = testLocalEstimatorFromFunctorAdapter<ImplicitHyperCube<Z3i::Space> >()
222  && testCube();// && ... other tests
223  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
224  trace.endBlock();
225  return res ? 0 : 1;
226 }
227 // //
DGtal::ImplicitHyperCube
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create an hypercube in n...
Definition: ImplicitHyperCube.h:59
DGtal::GaussDigitizer
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Definition: GaussDigitizer.h:79
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
DGtal::Astroid2D< Space >
DGtal::DigitalSurface::ConstIterator
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Definition: DigitalSurface.h:163
DGtal::Trace::endBlock
double endBlock()
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:139
DGtal::SurfelAdjacency< KSpace::dimension >
testCube
bool testCube()
Definition: testTensorVoting.cpp:137
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::trace
Trace trace
Definition: Common.h:154
testLocalEstimatorFromFunctorAdapter
bool testLocalEstimatorFromFunctorAdapter()
Definition: testTensorVoting.cpp:65
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::functors::GaussianKernel
Aim: defines a functor on double numbers which corresponds to a Gaussian convolution kernel....
Definition: BasicFunctors.h:946
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::functors::TensorVotingFeatureExtraction
Aim: Implements a functor to detect feature points from normal tensor voting strategy.
Definition: TensorVotingFeatureExtraction.h:81
DGtal::PointVector::diagonal
static Self diagonal(Component val=1)
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
Surface
SH3::DigitalSurface Surface
Definition: exampleMaximalSegmentSliceEstimation.cpp:45
DGtal::Trace::info
std::ostream & info()
Surfel
KSpace::SCell Surfel
Definition: testArithmeticalDSSComputerOnSurfels.cpp:50
DGtal::LightImplicitDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Definition: LightImplicitDigitalSurface.h:115
DGtal::DigitalSurface::begin
ConstIterator begin() const
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::ImplicitBall
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition: ImplicitBall.h:64
DGtal::KhalimskySpaceND::sKCoords
const Point & sKCoords(const SCell &c) const
Return its Khalimsky coordinates.
Shape
Astroid2D< Space > Shape
Definition: testAstroid2D.cpp:48
main
int main(int argc, char **argv)
Definition: testTensorVoting.cpp:212
DGtal::DigitalSurface::end
ConstIterator end() const
DGtal::DigitalSurface::Surfel
DigitalSurfaceContainer::Surfel Surfel
Definition: DigitalSurface.h:162
DGtal::PointVector< dim, Integer >
DGtal::LpMetric
Aim: implements l_p metrics.
Definition: LpMetric.h:74
DGtal::DigitalSurface::container
const DigitalSurfaceContainer & container() const
DGtal::LocalEstimatorFromSurfelFunctorAdapter
Aim: this class adapts any local functor on digital surface element to define a local estimator....
Definition: LocalEstimatorFromSurfelFunctorAdapter.h:103
DGtal::CanonicSCellEmbedder< KSpace >
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64