Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder > Class Template Reference

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

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

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
 Alias of the geometrical embedder.
const double myH
 Grid step.
const double myAspectRatio
 Minimal aspect ratio (norm of the cross-product) to consider a given triangle.
const unsigned int myNbTrials
 Number of trials in the neignborhood.
const unsigned int mySize
 Size of the accumulator.
const unsigned int myNbAccumulators
 Number of randomly shifted spherical accumulators to consider.
std::vector< RealPointmyPoints
 vector of embedded surfels
std::vector< SphericalAccumulator< RealPoint > > myAccumulators
 Spherical Accumulators.
std::vector< MatrixmyRotations
 Random rotations.
std::vector< MatrixmyInverseRotations
 Random inverse rotations.

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 [16] algorithm:

  • we first collect the surfels using the pushSurfel method;
  • we select random triples of surfels and estimate the normal vectors of the associated triangles;
  • each normal vector is added to a spherical accumulator (see SphericalAccumulator);
  • the estimated normal vector is computed from normal vectors of the bin of the accumulator with maximal vote.

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

◆ Matrix

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

Definition at line 92 of file SphericalHoughNormalVectorEstimator.h.

◆ Quantity

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

Definition at line 91 of file SphericalHoughNormalVectorEstimator.h.

◆ RealPoint

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

Definition at line 90 of file SphericalHoughNormalVectorEstimator.h.

◆ SCellEmbedder

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

Definition at line 89 of file SphericalHoughNormalVectorEstimator.h.

◆ Surfel

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

Definition at line 88 of file SphericalHoughNormalVectorEstimator.h.

Constructor & Destructor Documentation

◆ SphericalHoughNormalVectorEstimator() [1/2]

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.

109 :
112 {
114
115 //We precompute the random rotations and accumulators
116 for(auto i = 0u; i < myNbAccumulators; ++i)
117 {
119 myAccumulators.push_back( accum );
120 myRotations.push_back( m );
121 myInverseRotations.push_back( m.inverse() );
122 }
123 }
Aim: This functor estimates normal vector for a collection of surfels using spherical accumulator bas...
std::vector< SphericalAccumulator< RealPoint > > myAccumulators
Spherical Accumulators.
std::vector< Matrix > myInverseRotations
Random inverse rotations.
const SCellEmbedder * myEmbedder
Alias of the geometrical embedder.
const unsigned int myNbAccumulators
Number of randomly shifted spherical accumulators to consider.
const unsigned int myNbTrials
Number of trials in the neignborhood.
const double myAspectRatio
Minimal aspect ratio (norm of the cross-product) to consider a given triangle.

References DGtal::SimpleMatrix< TComponent, TM, TN >::inverse(), myAccumulators, myAspectRatio, myEmbedder, myH, myInverseRotations, myNbAccumulators, myNbTrials, myRotations, mySize, and randomRotation().

◆ SphericalHoughNormalVectorEstimator() [2/2]

template<typename TSurfel, typename TEmbedder>
DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::SphericalHoughNormalVectorEstimator ( )
delete

Disable default constructor.

Member Function Documentation

◆ eval()

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.

153 {
156 static_cast<int>(myPoints.size()) - 1 );
157 double aspect;
158
159 for(auto t = 0u; t < myNbTrials ; ++t)
160 {
161 unsigned int i,j,k;
162
163 //We pick 3 distinct point indices.
166 while ( (j = distribution(generator)) == i);
167 while (( (k = distribution(generator)) == i) || (k == j) );
168
170 if ((vector.norm() > 0.00001) && (aspect > myAspectRatio))
171 {
172 //we have an admissible triangle, we push both normal vectors
173 for(auto acc = 0u; acc < myNbAccumulators; ++acc)
174 {
176 myAccumulators[acc].addDirection( shifted );
177 myAccumulators[acc].addDirection( -shifted );
178 }
179 }
180 }
181 //We return the max bin orientation summing up all accumulators vote
184 for(auto acc = 0u; acc < myNbAccumulators; ++acc)
185 {
186 myAccumulators[acc].maxCountBin(posPhi, posTheta);
187 RealPoint dir = myInverseRotations[acc]*myAccumulators[acc].representativeDirection(posPhi, posTheta).getNormalized() ;
188
189 //We only consider z-oriented normals (since we pushed vector and -vector)
190 if ( dir.dot(RealPoint(0,0,1)) > 0.0 )
191 vote += dir;
192 else
193 vote += -dir;
194 }
195 return vote.getNormalized();
196 }
std::vector< RealPoint > myPoints
vector of embedded surfels
Quantity getNormal(const unsigned int i, const unsigned int j, const unsigned int k, double &aspect) const

References getNormal(), myAccumulators, myAspectRatio, myInverseRotations, myNbAccumulators, myNbTrials, myPoints, and myRotations.

◆ getNormal()

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 268 of file SphericalHoughNormalVectorEstimator.h.

272 {
273 ASSERT( i < myPoints.size());
274 ASSERT( j < myPoints.size());
275 ASSERT( k < myPoints.size());
276
277 const RealPoint v = myPoints[i] - myPoints[j];
278 const RealPoint u = myPoints[i] - myPoints[k];
279 const RealPoint w = myPoints[j] - myPoints[k];
280
281 //aspect ratio
282 const double a = u.norm() , b = v.norm();
283 const double c = w.norm();
284 const double s = (a+b+c)/2.0;
285 double denom = (8.0*(s-a)*(s-b)*(s-c));
286 if ( std::abs( denom ) <= std::abs( denom ) * 1e-6 )
287 aspect = 0.;
288 else
289 aspect = a*b*c / denom;
290
291 return v.crossProduct(u);
292 }

References myPoints.

Referenced by eval().

◆ pushSurfel()

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.

140 {
142 RealPoint p = myH * ( myEmbedder->operator()(aSurf) );
143 myPoints.push_back(p);
144 }

References myEmbedder, myH, and myPoints.

◆ randomRotation()

template<typename TSurfel, typename TEmbedder>
Matrix DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::randomRotation ( ) const
inlineprivate
Returns
a random rotation matrix.

Definition at line 215 of file SphericalHoughNormalVectorEstimator.h.

216 {
217 const double theta = (rand()+0.f)/RAND_MAX * 2* M_PI;
218 const double phi = (rand()+0.f)/RAND_MAX * 2* M_PI;
219 const double psi = (rand()+0.f)/RAND_MAX * 2* M_PI;
220 Matrix Rt;
221 Rt.setComponent(0,0,1);
222 Rt.setComponent(1,0,0);
223 Rt.setComponent(2,0,0);
224 Rt.setComponent(0,1,0);
225 Rt.setComponent(1,1,cos(theta));
226 Rt.setComponent(2,1,-sin(theta));
227 Rt.setComponent(0,2,0);
228 Rt.setComponent(1,2,sin(theta));
229 Rt.setComponent(2,2,cos(theta));
230
231 Matrix Rph;
232 Rph.setComponent(0,0,cos(phi));
233 Rph.setComponent(1,0,0);
234 Rph.setComponent(2,0,sin(phi));
235 Rph.setComponent(0,1,0);
236 Rph.setComponent(1,1,1);
237 Rph.setComponent(2,1,0);
238 Rph.setComponent(0,2,-sin(phi));
239 Rph.setComponent(1,2,0);
240 Rph.setComponent(2,2,cos(phi));
241
242 Matrix Rps;
243 Rps.setComponent(0,0,cos(psi));
244 Rps.setComponent(1,0,-sin(psi));
245 Rps.setComponent(2,0,0);
246 Rps.setComponent(0,1,sin(psi));
247 Rps.setComponent(1,1,cos(psi));
248 Rps.setComponent(2,1,0);
249 Rps.setComponent(0,2,0);
250 Rps.setComponent(1,2,0);
251 Rps.setComponent(2,2,1);
252
253 return Rt*Rph*Rps;
254 }

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

Referenced by SphericalHoughNormalVectorEstimator().

◆ reset()

template<typename TSurfel, typename TEmbedder>
void DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::reset ( )
inline

Reset the point list.

Definition at line 202 of file SphericalHoughNormalVectorEstimator.h.

203 {
204 myPoints.clear();
205 //accumulators cleanup
206 for(auto i = 0u; i < myNbAccumulators; ++i)
208 }

References myAccumulators, myNbAccumulators, and myPoints.

Field Documentation

◆ myAccumulators

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

Spherical Accumulators.

Definition at line 316 of file SphericalHoughNormalVectorEstimator.h.

Referenced by eval(), reset(), and SphericalHoughNormalVectorEstimator().

◆ myAspectRatio

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 301 of file SphericalHoughNormalVectorEstimator.h.

Referenced by eval(), and SphericalHoughNormalVectorEstimator().

◆ myEmbedder

template<typename TSurfel, typename TEmbedder>
const SCellEmbedder* DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myEmbedder
private

Alias of the geometrical embedder.

Definition at line 295 of file SphericalHoughNormalVectorEstimator.h.

Referenced by pushSurfel(), and SphericalHoughNormalVectorEstimator().

◆ myH

template<typename TSurfel, typename TEmbedder>
const double DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myH
private

Grid step.

Definition at line 298 of file SphericalHoughNormalVectorEstimator.h.

Referenced by pushSurfel(), and SphericalHoughNormalVectorEstimator().

◆ myInverseRotations

template<typename TSurfel, typename TEmbedder>
std::vector< Matrix > DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myInverseRotations
private

Random inverse rotations.

Definition at line 322 of file SphericalHoughNormalVectorEstimator.h.

Referenced by eval(), and SphericalHoughNormalVectorEstimator().

◆ myNbAccumulators

template<typename TSurfel, typename TEmbedder>
const unsigned int DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myNbAccumulators
private

Number of randomly shifted spherical accumulators to consider.

Definition at line 310 of file SphericalHoughNormalVectorEstimator.h.

Referenced by eval(), reset(), and SphericalHoughNormalVectorEstimator().

◆ myNbTrials

template<typename TSurfel, typename TEmbedder>
const unsigned int DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myNbTrials
private

Number of trials in the neignborhood.

Definition at line 304 of file SphericalHoughNormalVectorEstimator.h.

Referenced by eval(), and SphericalHoughNormalVectorEstimator().

◆ myPoints

template<typename TSurfel, typename TEmbedder>
std::vector<RealPoint> DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myPoints
private

vector of embedded surfels

Definition at line 313 of file SphericalHoughNormalVectorEstimator.h.

Referenced by eval(), getNormal(), pushSurfel(), and reset().

◆ myRotations

template<typename TSurfel, typename TEmbedder>
std::vector< Matrix > DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::myRotations
private

Random rotations.

Definition at line 319 of file SphericalHoughNormalVectorEstimator.h.

Referenced by eval(), and SphericalHoughNormalVectorEstimator().

◆ mySize

template<typename TSurfel, typename TEmbedder>
const unsigned int DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::mySize
private

Size of the accumulator.

Definition at line 307 of file SphericalHoughNormalVectorEstimator.h.

Referenced by SphericalHoughNormalVectorEstimator().


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