DGtal  0.9.2
testTensorVotingViewer.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"
51 
52 #include "DGtal/io/viewers/Viewer3D.h"
53 #include "DGtal/io/colormaps/GradientColorMap.h"
54 
56 
57 using namespace std;
58 using namespace DGtal;
59 
61 // Functions for testing class LocalEstimatorFromFunctorAdapter.
63 
68 template<typename Shape>
69 bool testLocalEstimatorFromFunctorAdapter(int argc, char **argv)
70 {
71  unsigned int nbok = 0;
72  unsigned int nb = 0;
73  trace.beginBlock ( "Testing init ..." );
74 
75  using namespace Z3i;
76 
77  typedef GaussDigitizer<Space,Shape> Gauss;
78 
79  typedef LightImplicitDigitalSurface<KSpace,Gauss> SurfaceContainer;
80  typedef DigitalSurface<SurfaceContainer> Surface;
81  //typedef Surface::SurfelConstIterator ConstIterator;
82  //typedef Surface::Tracker Tracker;
83  typedef typename Surface::Surfel Surfel;
84 
85 
86  trace.beginBlock("Creating Surface");
87  Point p1( -100, -100, -100 );
88  Point p2( 100, 100, 100 );
89  KSpace K;
90  nbok += K.init( p1, p2, true ) ? 1 : 0;
91  nb++;
92  trace.info() << "(" << nbok << "/" << nb << ") "
93  << "K.init() is ok" << std::endl;
94 
95  //Shape
96  Shape shape(RealPoint::diagonal(0.0), 30.0 );
97  Gauss gauss;
98  gauss.attach(shape);
99  gauss.init(p1,p2,1.0);
100 
101  //Surface
102  Surfel bel = Surfaces<KSpace>::findABel( K, gauss, 10000 );
103  SurfaceContainer* surfaceContainer = new SurfaceContainer
104  ( K, gauss, SurfelAdjacency<KSpace::dimension>( true ), bel );
105  Surface surface( surfaceContainer ); // acquired
106  trace.endBlock();
107 
108  trace.beginBlock("Creating adapters");
110 
111  typedef functors::GaussianKernel ConvFunctor;
113 
114  CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
115  FunctorVoting estimator(embedder,1);
116 
117  ConvFunctor convFunc(4.0);
118  Reporter reporter;
119  reporter.attach(surface);
120  reporter.setParams(l2Metric, estimator , convFunc, 5.0);
121 
122  reporter.init(1, surface.begin() , surface.end());
123 
124  std::vector<double> values;
125  reporter.eval( surface.begin(), surface.end(), std::back_insert_iterator<std::vector<double> >(values));
126 
127  double maxval = *std::max_element(values.begin(), values.end());
128  double minval = *std::min_element(values.begin(), values.end());
129  trace.info() << "Min/max= "<< minval<<"/"<<maxval<<std::endl;
130  QApplication application( argc, argv );
132  Viewer viewer( K );
133  viewer.setWindowTitle("Features from Tensor Voting");
134  viewer.show();
135 
136  typedef GradientColorMap< double > Gradient;
137  Gradient cmap_grad( minval, maxval );
138  cmap_grad.addColor( Color( 50, 50, 255 ) );
139  cmap_grad.addColor( Color( 255, 0, 0 ) );
140  cmap_grad.addColor( Color( 255, 255, 10 ) );
141 
142 
143  viewer << SetMode3D((*(surface.begin())).className(), "Basic" );
144  unsigned int i=0;
145 
146  for(typename Surface::ConstIterator it = surface.begin(), itend=surface.end();
147  it!= itend;
148  ++it, ++i)
149  {
150  viewer << CustomColors3D( Color::Black, cmap_grad( values[ i ] ))
151  << *it ;
152  }
153 
154 
155  viewer << Viewer3D<>::updateDisplay;
156 
157  trace.endBlock();
158  application.exec();
159 
160  return true;
161 }
162 
164 // Standard services - public :
165 
166 int main( int argc, char** argv )
167 {
168  trace.beginBlock ( "Testing class TensorVotingFeatureExtraction" );
169  trace.info() << "Args:";
170  for ( int i = 0; i < argc; ++i )
171  trace.info() << " " << argv[ i ];
172  trace.info() << endl;
173 
174  bool res = testLocalEstimatorFromFunctorAdapter<ImplicitHyperCube<Z3i::Space> >(argc,argv)
175  && testLocalEstimatorFromFunctorAdapter<ImplicitBall<Z3i::Space> >(argc,argv);
176 
177  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
178  trace.endBlock();
179  return res ? 0 : 1;
180 }
181 // //
void beginBlock(const std::string &keyword="")
Aim: defines a functor on double numbers which corresponds to a Gaussian convolution kernel...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
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
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
Aim: Implements a functor to detect feature points from normal tensor voting strategy.
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.