DGtal  1.1.0
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)
37 
38 #define TensorVotingFeatureExtraction_RECURSES
39 
40 #if !defined TensorVotingFeatureExtraction_h
41 
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)
DGtal::functors::TensorVotingFeatureExtraction::myArea
double myArea
Convolution kernel area.
Definition: TensorVotingFeatureExtraction.h:200
DGtal::ConstAlias
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
DGtal::functors::TensorVotingFeatureExtraction::Quantity
double Quantity
Definition: TensorVotingFeatureExtraction.h:88
DGtal::functors::TensorVotingFeatureExtraction::myId
SimpleMatrix< double, 3, 3 > myId
Definition: TensorVotingFeatureExtraction.h:197
DGtal::EigenDecomposition::getEigenDecomposition
static void getEigenDecomposition(const Matrix &matrix, Matrix &eigenVectors, Vector &eigenValues)
Compute both eigen vectors and eigen values from an input matrix.
DGtal::Dimension
DGtal::uint32_t Dimension
Definition: Common.h:133
DGtal::SimpleMatrix::setComponent
void setComponent(const DGtal::Dimension i, const DGtal::Dimension j, const Component &aValue)
DGtal::functors::TensorVotingFeatureExtraction::Surfel
TSurfel Surfel
Definition: TensorVotingFeatureExtraction.h:85
DGtal::functors::TensorVotingFeatureExtraction
Aim: Implements a functor to detect feature points from normal tensor voting strategy.
Definition: TensorVotingFeatureExtraction.h:82
DGtal::functors::TensorVotingFeatureExtraction::eval
Quantity eval()
Definition: TensorVotingFeatureExtraction.h:154
DGtal::functors::TensorVotingFeatureExtraction::reset
void reset()
Definition: TensorVotingFeatureExtraction.h:174
DGtal::SimpleMatrix< double, 3, 3 >
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::functors::TensorVotingFeatureExtraction::myH
double myH
Definition: TensorVotingFeatureExtraction.h:191
DGtal::functors::TensorVotingFeatureExtraction::myVote
SimpleMatrix< double, 3, 3 > myVote
Definition: TensorVotingFeatureExtraction.h:197
DGtal::SimpleMatrix::identity
void identity()
DGtal::functors::TensorVotingFeatureExtraction::myReceiver
RealPoint myReceiver
Receiver (embedding of the starting surfel)
Definition: TensorVotingFeatureExtraction.h:194
DGtal::functors::TensorVotingFeatureExtraction::myAccum
SimpleMatrix< double, 3, 3 > myAccum
Covariance accumulator.
Definition: TensorVotingFeatureExtraction.h:197
DGtal::functors::TensorVotingFeatureExtraction::myEmbedder
const SCellEmbedder * myEmbedder
Alias of the geometrical embedder.
Definition: TensorVotingFeatureExtraction.h:188
DGtal::functors::TensorVotingFeatureExtraction::myFirstSurfel
bool myFirstSurfel
First surfel flag.
Definition: TensorVotingFeatureExtraction.h:185
DGtal::functors::TensorVotingFeatureExtraction::SCellEmbedder
TEmbedder SCellEmbedder
Definition: TensorVotingFeatureExtraction.h:86
DGtal::functors::TensorVotingFeatureExtraction::RealPoint
SCellEmbedder::RealPoint RealPoint
Definition: TensorVotingFeatureExtraction.h:87
DGtal::functors::TensorVotingFeatureExtraction::pushSurfel
void pushSurfel(const Surfel &aSurf, const double aDistance)
Definition: TensorVotingFeatureExtraction.h:113
RealPoint
Z2i::RealPoint RealPoint
Definition: testAstroid2D.cpp:46
DGtal::SimpleMatrix::constant
void constant(const Component &aScalar)
DGtal::functors::TensorVotingFeatureExtraction::TensorVotingFeatureExtraction
TensorVotingFeatureExtraction(ConstAlias< SCellEmbedder > anEmbedder, const double h)
Definition: TensorVotingFeatureExtraction.h:96