DGtal  1.5.beta
TensorVotingFeatureExtraction.h
1 
17 #pragma once
18 
34 #if defined(TensorVotingFeatureExtraction_RECURSES)
35 #error Recursive header files inclusion detected in TensorVotingFeatureExtraction.h
36 #else // defined(TensorVotingFeatureExtraction_RECURSES)
38 #define TensorVotingFeatureExtraction_RECURSES
39 
40 #if !defined TensorVotingFeatureExtraction_h
42 #define TensorVotingFeatureExtraction_h
43 
45 // Inclusions
46 #include <iostream>
47 #include <DGtal/base/Common.h>
48 #include <DGtal/topology/SCellsFunctors.h>
49 #include <vector>
50 #include "DGtal/math/linalg/SimpleMatrix.h"
51 #include "DGtal/math/linalg/EigenDecomposition.h"
53 
54 namespace DGtal
55 {
56  namespace functors
57  {
59  // template class TensorVotingFeatureExtraction
80  template <typename TSurfel, typename TEmbedder>
82  {
83  public:
84 
85  typedef TSurfel Surfel;
86  typedef TEmbedder SCellEmbedder;
88  typedef double Quantity;
89 
97  const double h):
98  myEmbedder(&anEmbedder), myH(h)
99  {
100  myId.identity();
101  myArea = 0.0;
102  myFirstSurfel = true;
103  myAccum.constant(0.0);
104  }
105 
113  void pushSurfel(const Surfel & aSurf,
114  const double aDistance)
115  {
116  if (myFirstSurfel)
117  {
118  myReceiver = myEmbedder->operator()(aSurf);
119  myFirstSurfel = false;
120  }
121  else
122  {
123  myArea+= aDistance;
124  const RealPoint p = myEmbedder->operator()(aSurf);
125  const RealPoint v = p - myReceiver;
126 
127  double maxcol = 0.0;
128  double matnorm = 0.0;
129 
130  // I - vv^t/||vv^t||
131  for(DGtal::Dimension i= 0; i <3; i++)
132  {
133  maxcol = 0.0;
134  for(DGtal::Dimension j=0; j < 3; j++)
135  {
136  myVote.setComponent(i,j, v(i)*v(j));
137  if (std::abs(v(i)*v(j)) > maxcol)
138  maxcol = std::abs(v(i)*v(j));
139  }
140  matnorm += maxcol;
141  }
142 
143  myAccum += (myId - myVote/matnorm)*aDistance;
144  }
145  }
146 
155  {
156  SimpleMatrix<double, 3, 3> eigenvectors;
157  RealPoint eigenvalues;
158 
159  myAccum /= myArea;
161 
162 #ifdef DEBUG
163  for( Dimension i_dim = 1; i_dim < 3; ++i_dim )
164  ASSERT ( std::abs(eigenvalues[i_dim - 1]) <= std::abs(eigenvalues[i_dim]) );
165 #endif
166 
167  return ((eigenvalues[0] + eigenvalues[1])/(eigenvalues[2]));
168  }
169 
174  void reset()
175  {
176  myArea = 0.0;
177  myFirstSurfel = true;
178  myAccum.constant(0.0);
179  }
180 
181 
182  private:
183 
186 
189 
190  //Grid step
191  double myH;
192 
195 
198 
200  double myArea;
201 
202  }; // end of class TensorVotingFeatureExtraction
203  }//namespace functors
204 }// namespace DGtal
205 
206 
207 // //
209 
210 #endif // !defined TensorVotingFeatureExtraction_h
211 
212 #undef TensorVotingFeatureExtraction_RECURSES
213 #endif // else defined(TensorVotingFeatureExtraction_RECURSES)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
static void getEigenDecomposition(const Matrix &matrix, Matrix &eigenVectors, Vector &eigenValues)
Compute both eigen vectors and eigen values from an input matrix.
void setComponent(const DGtal::Dimension i, const DGtal::Dimension j, const Component &aValue)
void constant(const Component &aScalar)
Aim: Implements a functor to detect feature points from normal tensor voting strategy.
const SCellEmbedder * myEmbedder
Alias of the geometrical embedder.
void pushSurfel(const Surfel &aSurf, const double aDistance)
TensorVotingFeatureExtraction(ConstAlias< SCellEmbedder > anEmbedder, const double h)
SimpleMatrix< double, 3, 3 > myAccum
Covariance accumulator.
RealPoint myReceiver
Receiver (embedding of the starting surfel)
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Definition: Common.h:136
PointVector< 3, double > RealPoint