DGtal  0.9.3beta
Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder > Class Template Reference

#include <DGtal/geometry/surfaces/estimation/estimationFunctors/SphericalHoughNormalVectorEstimator.h>

Collaboration diagram for DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >:
[legend]

Public Types

typedef TSurfel Surfel
 
typedef TEmbedder SCellEmbedder
 
typedef SCellEmbedder::RealPoint RealPoint
 
typedef RealPoint Quantity
 
typedef SimpleMatrix< double, 3, 3 > Matrix
 

Public Member Functions

 SphericalHoughNormalVectorEstimator (ConstAlias< SCellEmbedder > anEmbedder, const double h, const double minimalAspectRatio=0.001, const unsigned int nbTrials=100, const unsigned int accumulatorSize=10, const unsigned int nbAccumulators=5)
 
 SphericalHoughNormalVectorEstimator ()=delete
 
void pushSurfel (const Surfel &aSurf, const double aDistance)
 
Quantity eval ()
 
void reset ()
 

Private Member Functions

Matrix randomRotation () const
 
Quantity getNormal (const unsigned int i, const unsigned int j, const unsigned int k, double &aspect) const
 

Private Attributes

const SCellEmbeddermyEmbedder
 
const double myH
 
const double myAspectRatio
 
const unsigned int myNbTrials
 
const unsigned int mySize
 
const unsigned int myNbAccumulators
 
std::vector< RealPointmyPoints
 
std::vector< SphericalAccumulator< RealPoint > > myAccumulators
 
std::vector< MatrixmyRotations
 
std::vector< MatrixmyInverseRotations
 

Detailed Description

template<typename TSurfel, typename TEmbedder>
class DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >

Aim: This functor estimates normal vector for a collection of surfels using spherical accumulator based Hough voting.

Description of template class 'SphericalHoughNormalVectorEstimator'

This functors implements [10] algorithm:

To avoid aliasing artefacts of the spherical accumulator, several randomly rotated accumulators are used.

Given a random triple of surfels, a threshold on the triangle aspect ratio can be specified to discard bad aspect triangles (e.g. thin ones).

This functor is a model of concepts::CLocalEstimatorFromSurfelFunctor

Template Parameters
TSurfeltype of surfels
TEmbeddertype of functors which embed surfel to \( \mathbb{R}^3\)

Definition at line 84 of file SphericalHoughNormalVectorEstimator.h.

Member Typedef Documentation

template<typename TSurfel , typename TEmbedder >
typedef SimpleMatrix<double,3,3> DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::Matrix

Definition at line 92 of file SphericalHoughNormalVectorEstimator.h.

template<typename TSurfel , typename TEmbedder >
typedef RealPoint DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::Quantity

Definition at line 91 of file SphericalHoughNormalVectorEstimator.h.

template<typename TSurfel , typename TEmbedder >
typedef SCellEmbedder::RealPoint DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::RealPoint

Definition at line 90 of file SphericalHoughNormalVectorEstimator.h.

template<typename TSurfel , typename TEmbedder >
typedef TEmbedder DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::SCellEmbedder

Definition at line 89 of file SphericalHoughNormalVectorEstimator.h.

template<typename TSurfel , typename TEmbedder >
typedef TSurfel DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::Surfel

Definition at line 88 of file SphericalHoughNormalVectorEstimator.h.

Constructor & Destructor Documentation

template<typename TSurfel , typename TEmbedder >
DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::SphericalHoughNormalVectorEstimator ( ConstAlias< SCellEmbedder anEmbedder,
const double  h,
const double  minimalAspectRatio = 0.001,
const unsigned int  nbTrials = 100,
const unsigned int  accumulatorSize = 10,
const unsigned int  nbAccumulators = 5 
)
inline

Constructor.

Parameters
[in]anEmbedderembedder to map surfel to R^n.
[in]hgrid step
[in]minimalAspectRatiothe minimal aspect ratio of triangles to be considered in the accumulator (default=0.001).
[in]nbTrialsnumber of random triangles in the neighborhood to consider (default=100).
[in]accumulatorSizesize of the spherical accumulators (see SphericalAccumulator, default=10).
[in]nbAccumulatorsnumber of randomly rotated spherical accumulators to consider in order to avoid aliasing artefacts. (default=5)

Definition at line 104 of file SphericalHoughNormalVectorEstimator.h.

References DGtal::SimpleMatrix< TComponent, TM, TN >::inverse(), DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myAccumulators, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myInverseRotations, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myNbAccumulators, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myRotations, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::mySize, and DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::randomRotation().

109  :
110  myEmbedder(&anEmbedder),myH(h), myAspectRatio(minimalAspectRatio),
111  myNbTrials( nbTrials), mySize(accumulatorSize) , myNbAccumulators(nbAccumulators)
112  {
113  SphericalAccumulator<RealPoint> accum(mySize);
114 
115  //We precompute the random rotations and accumulators
116  for(auto i = 0u; i < myNbAccumulators; ++i)
117  {
118  Matrix m = randomRotation();
119  myAccumulators.push_back( accum );
120  myRotations.push_back( m );
121  myInverseRotations.push_back( m.inverse() );
122  }
123  }
std::vector< Matrix > myInverseRotations
Random inverse rotations.
std::vector< SphericalAccumulator< RealPoint > > myAccumulators
Spherical Accumulators.
const unsigned int myNbTrials
Number of trials in the neignborhood.
const SCellEmbedder * myEmbedder
Alias of the geometrical embedder.
const double myAspectRatio
Minimal aspect ratio (norm of the cross-product) to consider a given triangle.
const unsigned int myNbAccumulators
Number of randomly shifted spherical accumulators to consider.
template<typename TSurfel , typename TEmbedder >
DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::SphericalHoughNormalVectorEstimator ( )
delete

Disable default constructor.

Member Function Documentation

template<typename TSurfel , typename TEmbedder >
Quantity DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::eval ( )
inline

Estimate normal vector using spherical accumulator voting.

Returns
the feature score

Definition at line 152 of file SphericalHoughNormalVectorEstimator.h.

References DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::getNormal(), DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myAccumulators, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myAspectRatio, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myInverseRotations, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myNbAccumulators, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myNbTrials, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myPoints, and DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myRotations.

153  {
154  std::default_random_engine generator;
155  std::uniform_int_distribution<int> distribution(0, myPoints.size() - 1 );
156  double aspect;
157 
158  for(auto t = 0u; t < myNbTrials ; ++t)
159  {
160  unsigned int i,j,k;
161 
162  //We pick 3 distinct point indices.
163  i = distribution(generator);
164  j = distribution(generator);
165  while ( (j = distribution(generator)) == i);
166  while (( (k = distribution(generator)) == i) || (k == j) );
167 
168  RealPoint vector = getNormal(i,j,k,aspect);
169  if ((vector.norm() > 0.00001) && (aspect > myAspectRatio))
170  {
171  //we have an admissible triangle, we push both normal vectors
172  for(auto acc = 0u; acc < myNbAccumulators; ++acc)
173  {
174  RealPoint shifted = myRotations[acc]*vector;
175  myAccumulators[acc].addDirection( shifted );
176  myAccumulators[acc].addDirection( -shifted );
177  }
178  }
179  }
180  //We return the max bin orientation summing up all accumulators vote
181  typename SphericalAccumulator<RealPoint>::Size posPhi,posTheta;
182  RealPoint vote;
183  for(auto acc = 0u; acc < myNbAccumulators; ++acc)
184  {
185  myAccumulators[acc].maxCountBin(posPhi, posTheta);
186  RealPoint dir = myInverseRotations[acc]*myAccumulators[acc].representativeDirection(posPhi, posTheta).getNormalized() ;
187 
188  //We only consider z-oriented normals (since we pushed vector and -vector)
189  if ( dir.dot(RealPoint(0,0,1)) > 0.0 )
190  vote += dir;
191  else
192  vote += -dir;
193  }
194  return vote.getNormalized();
195  }
std::vector< Matrix > myInverseRotations
Random inverse rotations.
Quantity getNormal(const unsigned int i, const unsigned int j, const unsigned int k, double &aspect) const
std::vector< SphericalAccumulator< RealPoint > > myAccumulators
Spherical Accumulators.
const unsigned int myNbTrials
Number of trials in the neignborhood.
DGtal::uint32_t Size
Type to represent bin indexes.
const double myAspectRatio
Minimal aspect ratio (norm of the cross-product) to consider a given triangle.
const unsigned int myNbAccumulators
Number of randomly shifted spherical accumulators to consider.
std::vector< RealPoint > myPoints
vector of embedded surfels
template<typename TSurfel , typename TEmbedder >
Quantity DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::getNormal ( const unsigned int  i,
const unsigned int  j,
const unsigned int  k,
double &  aspect 
) const
inlineprivate

Computes the (unnormalized) normal vector of a triangle defined by triangle (i,j,k). The variable aspect returns the aspect ratio of the triangle.

Parameters
[in]ia first vertex index.
[in]ja second vertex index.
[in]ka third vertex index.
[out]aspectaspect ratio of the triangle.
Returns
a random rotation matrix.

Definition at line 267 of file SphericalHoughNormalVectorEstimator.h.

References DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myPoints.

Referenced by DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::eval().

271  {
272  ASSERT( i < myPoints.size());
273  ASSERT( j < myPoints.size());
274  ASSERT( k < myPoints.size());
275 
276  const RealPoint v = myPoints[i] - myPoints[j];
277  const RealPoint u = myPoints[i] - myPoints[k];
278  const RealPoint w = myPoints[j] - myPoints[k];
279 
280  //aspect ratio
281  const double a = u.norm() , b = v.norm();
282  const double c = w.norm();
283  const double s = (a+b+c)/2.0;
284  aspect = a*b*c/(8.0*(s-a)*(s-b)*(s-c));
285 
286  return v.crossProduct(u);
287  }
std::vector< RealPoint > myPoints
vector of embedded surfels
template<typename TSurfel , typename TEmbedder >
void DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::pushSurfel ( const Surfel aSurf,
const double  aDistance 
)
inline

Add the geometrical embedding of a surfel to the point list and update the normal spherical hough voting.

Parameters
aSurfa surfel to add
aDistancedistance of aSurf to the neighborhood boundary (NOT USED HERE)

Definition at line 138 of file SphericalHoughNormalVectorEstimator.h.

References DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myEmbedder, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myH, and DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myPoints.

140  {
141  BOOST_VERIFY(aDistance == aDistance);
142  RealPoint p = myH * ( myEmbedder->operator()(aSurf) );
143  myPoints.push_back(p);
144  }
const SCellEmbedder * myEmbedder
Alias of the geometrical embedder.
std::vector< RealPoint > myPoints
vector of embedded surfels
template<typename TSurfel , typename TEmbedder >
Matrix DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::randomRotation ( ) const
inlineprivate
Returns
a random rotation matrix.

Definition at line 214 of file SphericalHoughNormalVectorEstimator.h.

References DGtal::SimpleMatrix< TComponent, TM, TN >::setComponent().

Referenced by DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::SphericalHoughNormalVectorEstimator().

215  {
216  const double theta = (rand()+0.f)/RAND_MAX * 2* M_PI;
217  const double phi = (rand()+0.f)/RAND_MAX * 2* M_PI;
218  const double psi = (rand()+0.f)/RAND_MAX * 2* M_PI;
219  Matrix Rt;
220  Rt.setComponent(0,0,1);
221  Rt.setComponent(1,0,0);
222  Rt.setComponent(2,0,0);
223  Rt.setComponent(0,1,0);
224  Rt.setComponent(1,1,cos(theta));
225  Rt.setComponent(2,1,-sin(theta));
226  Rt.setComponent(0,2,0);
227  Rt.setComponent(1,2,sin(theta));
228  Rt.setComponent(2,2,cos(theta));
229 
230  Matrix Rph;
231  Rph.setComponent(0,0,cos(phi));
232  Rph.setComponent(1,0,0);
233  Rph.setComponent(2,0,sin(phi));
234  Rph.setComponent(0,1,0);
235  Rph.setComponent(1,1,1);
236  Rph.setComponent(2,1,0);
237  Rph.setComponent(0,2,-sin(phi));
238  Rph.setComponent(1,2,0);
239  Rph.setComponent(2,2,cos(phi));
240 
241  Matrix Rps;
242  Rps.setComponent(0,0,cos(psi));
243  Rps.setComponent(1,0,-sin(psi));
244  Rps.setComponent(2,0,0);
245  Rps.setComponent(0,1,sin(psi));
246  Rps.setComponent(1,1,cos(psi));
247  Rps.setComponent(2,1,0);
248  Rps.setComponent(0,2,0);
249  Rps.setComponent(1,2,0);
250  Rps.setComponent(2,2,1);
251 
252  return Rt*Rph*Rps;
253  }
void setComponent(const DGtal::Dimension i, const DGtal::Dimension j, const Component &aValue)
template<typename TSurfel , typename TEmbedder >
void DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::reset ( )
inline

Reset the point list.

Definition at line 201 of file SphericalHoughNormalVectorEstimator.h.

References DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myAccumulators, DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myNbAccumulators, and DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myPoints.

202  {
203  myPoints.clear();
204  //accumulators cleanup
205  for(auto i = 0u; i < myNbAccumulators; ++i)
206  myAccumulators[i].clear();
207  }
std::vector< SphericalAccumulator< RealPoint > > myAccumulators
Spherical Accumulators.
const unsigned int myNbAccumulators
Number of randomly shifted spherical accumulators to consider.
std::vector< RealPoint > myPoints
vector of embedded surfels

Field Documentation

template<typename TSurfel , typename TEmbedder >
std::vector< SphericalAccumulator<RealPoint> > DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myAccumulators
private
template<typename TSurfel , typename TEmbedder >
const double DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myAspectRatio
private

Minimal aspect ratio (norm of the cross-product) to consider a given triangle.

Definition at line 296 of file SphericalHoughNormalVectorEstimator.h.

Referenced by DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::eval().

template<typename TSurfel , typename TEmbedder >
const SCellEmbedder* DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myEmbedder
private
template<typename TSurfel , typename TEmbedder >
const double DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myH
private
template<typename TSurfel , typename TEmbedder >
std::vector< Matrix > DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myInverseRotations
private
template<typename TSurfel , typename TEmbedder >
const unsigned int DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myNbAccumulators
private
template<typename TSurfel , typename TEmbedder >
const unsigned int DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myNbTrials
private

Number of trials in the neignborhood.

Definition at line 299 of file SphericalHoughNormalVectorEstimator.h.

Referenced by DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::eval().

template<typename TSurfel , typename TEmbedder >
std::vector<RealPoint> DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myPoints
private
template<typename TSurfel , typename TEmbedder >
std::vector< Matrix > DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myRotations
private
template<typename TSurfel , typename TEmbedder >
const unsigned int DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::mySize
private

The documentation for this class was generated from the following file: