DGtal  1.0.0
IIGeometricFunctors.h
1
17 #pragma once
18
31 #if defined(IIGeometricFunctors_RECURSES)
32 #error Recursive header files inclusion detected in IIGeometricFunctors.h
33 #else // defined(IIGeometricFunctors_RECURSES)
34
35 #define IIGeometricFunctors_RECURSES
36
37 #if !defined IIGeometricFunctors_h
38
39 #define IIGeometricFunctors_h
40
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/math/linalg/EigenDecomposition.h"
47
48 // @since 0.8 In DGtal::functors
49 namespace DGtal {
50  namespace functors {
51
53  // template class IINormalDirectionFunctor
64  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
66  {
67  // ----------------------- Standard services ------------------------------
68  public:
70  typedef TSpace Space;
71  typedef typename Space::RealVector RealVector;
72  typedef typename RealVector::Component Component;
73  typedef TMatrix Matrix;
74  typedef Matrix Argument;
76  typedef Quantity Value;
77
78  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
80
84  IINormalDirectionFunctor( const Self& /* other */ ) {}
87  Self& operator=( const Self& /* other */ ) { return *this; }
96  Value operator()( const Argument& arg ) const
97  {
100
101  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
102 #ifdef DEBUG
103  for( Dimension i_dim = 1; i_dim < Space::dimension; ++i_dim )
104  {
105  ASSERT ( std::abs(eigenValues[i_dim - 1]) <= std::abs(eigenValues[i_dim]) );
106  }
107 #endif
108
109  return eigenVectors.column( 0 ); // normal vector is associated to smallest eigenvalue.
110  }
111
116  void init( Component /* h */, Component /* r */ ) {}
117
118  private:
123  }; // end of class IINormalDirectionFunctor
124
125
127  // template class IITangentDirectionFunctor
138  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
140  {
141  // ----------------------- Standard services ------------------------------
142  public:
144  typedef TSpace Space;
145  typedef typename Space::RealVector RealVector;
147  typedef TMatrix Matrix;
148  typedef Matrix Argument;
150  typedef Quantity Value;
151
152  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
155
159  IITangentDirectionFunctor( const Self& /* other */ ) {}
162  Self& operator=( const Self& /* other */ ) { return *this; }
171  Value operator()( const Argument& arg ) const
172  {
175
176  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
177 #ifdef DEBUG
178  for( Dimension i_dim = 1; i_dim < Space::dimension; ++i_dim )
179  {
180  ASSERT ( std::abs(eigenValues[i_dim - 1]) <= std::abs(eigenValues[i_dim]) );
181  }
182 #endif
183  return eigenVectors.column( 1 ); // tangent vector is associated to greatest eigenvalue.
184  }
185
190  void init( Component /* h */, Component /* r */ ) {}
191
192  private:
197  }; // end of class IITangentDirectionFunctor
198
199
201  // template class IIFirstPrincipalDirectionFunctor
216  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
218  {
219  // ----------------------- Standard services ------------------------------
220  public:
222  typedef TSpace Space;
223  typedef typename Space::RealVector RealVector;
225  typedef TMatrix Matrix;
226  typedef Matrix Argument;
228  typedef Quantity Value;
229
230  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
233
237  IIFirstPrincipalDirectionFunctor( const Self& /* other */ ) {}
240  Self& operator=( const Self& /* other */ ) { return *this; }
249  Value operator()( const Argument& arg ) const
250  {
253
254  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
255 #ifdef DEBUG
256  for( Dimension i_dim = 1; i_dim < Space::dimension; ++i_dim )
257  {
258  ASSERT ( std::abs(eigenValues[i_dim - 1]) <= std::abs(eigenValues[i_dim]) );
259  }
260 #endif
261
262  return eigenVectors.column( Space::dimension - 1 ); // first principal curvature direction is associated to greatest eigenvalue.
263  }
264
269  void init( Component /* h */, Component /* r */ ) {}
270
271  private:
276  }; // end of class IIFirstPrincipalDirectionFunctor
277
278
280  // template class IISecondPrincipalDirectionFunctor
295  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
297  {
298  // ----------------------- Standard services ------------------------------
299  public:
301  typedef TSpace Space;
302  typedef typename Space::RealVector RealVector;
304  typedef TMatrix Matrix;
305  typedef Matrix Argument;
307  typedef Quantity Value;
308
309  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
312
316  IISecondPrincipalDirectionFunctor( const Self& /* other */ ) {}
319  Self& operator=( const Self& /* other */ ) { return *this; }
328  Value operator()( const Argument& arg ) const
329  {
332
333  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
334 #ifdef DEBUG
335  for( Dimension i_dim = 1; i_dim < Space::dimension; ++i_dim )
336  {
337  ASSERT ( std::abs(eigenValues[i_dim - 1]) <= std::abs(eigenValues[i_dim]) );
338  }
339 #endif
340
341  return eigenVectors.column( Space::dimension - 2 ); // second principal curvature direction is associated to greatest eigenvalue.
342  }
343
348  void init( Component /* h */, Component /* r */ ) {}
349
350  private:
355  }; // end of class IISecondPrincipalDirectionFunctor
356
358  // template class IIPrincipalDirectionsFunctor
373  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
375  {
376  // ----------------------- Standard services ------------------------------
377  public:
379  typedef TSpace Space;
380  typedef typename Space::RealVector RealVector;
382  typedef TMatrix Matrix;
383  typedef Matrix Argument;
384  typedef std::pair<RealVector,RealVector> Quantity;
385  typedef Quantity Value;
386
387  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
390
394  IIPrincipalDirectionsFunctor( const Self& /* other */ ) {}
397  Self& operator=( const Self& /* other */ ) { return *this; }
406  Value operator()( const Argument& arg ) const
407  {
410
411  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
412 #ifdef DEBUG
413  for( Dimension i_dim = 1; i_dim < Space::dimension; ++i_dim )
414  {
415  ASSERT ( std::abs(eigenValues[i_dim - 1]) <= std::abs(eigenValues[i_dim]) );
416  }
417 #endif
418
419  return Value(
420  eigenVectors.column( Space::dimension - 1 ),
421  eigenVectors.column( Space::dimension - 2 )
422  );
423  }
424
429  void init( Component /* h */, Component /* r */ ) {}
430
431  private:
436  }; // end of class IIPrincipalDirectionsFunctor
437
439  // template class IICurvatureFunctor
450  template <typename TSpace>
452  {
453  // ----------------------- Standard services ------------------------------
454  public:
456  typedef TSpace Space;
457  typedef typename Space::RealVector RealVector;
461  typedef Quantity Value;
462
465
472  Value operator()( const Argument& arg ) const
473  {
474  Quantity cp_quantity = arg;
475  cp_quantity *= dh2;
476  return d3_r * ( dPI_2 - d1_r2 * cp_quantity );
477  }
478
485  void init( Component h, Component r )
486  {
487  d1_r2 = 1.0 / ( r * r );
488  dPI_2 = M_PI / 2.0;
489  d3_r = 3.0 / r;
490  dh2 = h * h;
491  }
492
493  private:
498  }; // end of class IICurvatureFunctor
499
500
502  // template class IIMeanCurvature3DFunctor
513  template <typename TSpace>
515  {
516  // ----------------------- Standard services ------------------------------
517  public:
519  typedef TSpace Space;
520  typedef typename Space::RealVector RealVector;
524  typedef Quantity Value;
525
528
535  Value operator()( const Argument& arg ) const
536  {
537  Quantity cp_quantity = arg;
538  cp_quantity *= dh3;
539  return d8_3r - d_4_PIr4 * cp_quantity;
540  }
541
548  void init( Component h, Component r )
549  {
550  d8_3r = 8.0 / ( 3.0 * r );
551  double r2 = r * r;
552  d_4_PIr4 = 4.0 / ( M_PI * r2 * r2 );
553  dh3 = h * h * h;
554  }
555
556  private:
560  }; // end of class IIMeanCurvature3DFunctor
561
563  // template class IIGaussianCurvature3DFunctor
577  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
579  {
580  // ----------------------- Standard services ------------------------------
581  public:
583  typedef TSpace Space;
584  typedef typename Space::RealVector RealVector;
586  typedef TMatrix Matrix;
587  typedef Matrix Argument;
589  typedef Quantity Value;
590
591  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
594
602  Value operator()( const Argument& arg ) const
603  {
604  Argument cp_arg = arg;
605  cp_arg *= dh5;
608
609  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
610  ASSERT ( (std::abs(eigenValues[0]) <= std::abs(eigenValues[1]))
611  && (std::abs(eigenValues[1]) <= std::abs(eigenValues[2])) );
612
613  Value k1 = d6_PIr6 * ( eigenValues[2] - ( 3.0 * eigenValues[1] )) + d8_5r;
614  Value k2 = d6_PIr6 * ( eigenValues[1] - ( 3.0 * eigenValues[2] )) + d8_5r;
615  return k1 * k2;
616  }
617
624  void init( Component h, Component r )
625  {
626  double r3 = r * r * r;
627  double r6 = r3 * r3;
628  d6_PIr6 = 6.0 / ( M_PI * r6 );
629  d8_5r = 8.0 / ( 5.0 * r );
630  double h2 = h * h;
631  dh5 = h2 * h2 * h;
632  }
633
634  private:
638
643  }; // end of class IIGaussianCurvature3DFunctor
644
646  // template class IIFirstPrincipalCurvature3DFunctor
660  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
662  {
663  // ----------------------- Standard services ------------------------------
664  public:
666  typedef TSpace Space;
667  typedef typename Space::RealVector RealVector;
669  typedef TMatrix Matrix;
670  typedef Matrix Argument;
672  typedef Quantity Value;
673
674  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
677
685  Value operator()( const Argument& arg ) const
686  {
687  Argument cp_arg = arg;
688  cp_arg *= dh5;
691
692  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
693  ASSERT ( (std::abs(eigenValues[0]) <= std::abs(eigenValues[1]))
694  && (std::abs(eigenValues[1]) <= std::abs(eigenValues[2])) );
695
696
697  return d6_PIr6 * ( eigenValues[2] - ( 3.0 * eigenValues[1] )) + d8_5r;
698  }
699
706  void init( Component h, Component r )
707  {
708  double r3 = r * r * r;
709  double r6 = r3 * r3;
710  d6_PIr6 = 6.0 / ( M_PI * r6 );
711  d8_5r = 8.0 / ( 5.0 * r );
712  double h2 = h * h;
713  dh5 = h2 * h2 * h;
714  }
715
716  private:
720
725  }; // end of class IIFirstPrincipalCurvature3DFunctor
726
728  // template class IISecondPrincipalCurvature3DFunctor
742  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
744  {
745  // ----------------------- Standard services ------------------------------
746  public:
748  typedef TSpace Space;
749  typedef typename Space::RealVector RealVector;
751  typedef TMatrix Matrix;
752  typedef Matrix Argument;
754  typedef Quantity Value;
755
756  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
759
767  Value operator()( const Argument& arg ) const
768  {
769  Argument cp_arg = arg;
770  cp_arg *= dh5;
773
774  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
775  ASSERT ( (std::abs(eigenValues[0]) <= std::abs(eigenValues[1]))
776  && (std::abs(eigenValues[1]) <= std::abs(eigenValues[2])) );
777
778  return d6_PIr6 * ( eigenValues[1] - ( 3.0 * eigenValues[2] )) + d8_5r;
779  }
780
787  void init( Component h, Component r )
788  {
789  double r3 = r * r * r;
790  double r6 = r3 * r3;
791  d6_PIr6 = 6.0 / ( M_PI * r6 );
792  d8_5r = 8.0 / ( 5.0 * r );
793  double h2 = h * h;
794  dh5 = h2 * h2 * h;
795  }
796
797  private:
801
806  }; // end of class IISecondPrincipalCurvature3DFunctor
807
808
810  // template class IIPrincipalCurvatures3DFunctor
823  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
825  {
826  // ----------------------- Standard services ------------------------------
827  public:
829  typedef TSpace Space;
830  typedef typename Space::RealVector RealVector;
832  typedef TMatrix Matrix;
833  typedef Matrix Argument;
834  typedef std::pair<Component, Component> Quantity;
835  typedef Quantity Value;
836
837  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
840
849  Value operator()( const Argument& arg ) const
850  {
851  Argument cp_arg = arg;
852  cp_arg *= dh5;
855
856  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
857  ASSERT ( (std::abs(eigenValues[0]) <= std::abs(eigenValues[1]))
858  && (std::abs(eigenValues[1]) <= std::abs(eigenValues[2])) );
859
860  return Value(
861  d6_PIr6 * ( eigenValues[2] - ( 3.0 * eigenValues[1] )) + d8_5r,
862  d6_PIr6 * ( eigenValues[1] - ( 3.0 * eigenValues[2] )) + d8_5r
863  );
864  }
865
872  void init( Component h, Component r )
873  {
874  double r3 = r * r * r;
875  double r6 = r3 * r3;
876  d6_PIr6 = 6.0 / ( M_PI * r6 );
877  d8_5r = 8.0 / ( 5.0 * r );
878  double h2 = h * h;
879  dh5 = h2 * h2 * h;
880  }
881
882  private:
883  double dh5;
884  double d6_PIr6;
885  double d8_5r;
886
891  }; // end of class IIPrincipalCurvatures3DFunctor
892
893 } // namespace functors
894
895 } // namespace DGtal
896
897
898 // //
900
901 #endif // !defined IIGeometricFunctors_h
902
903 #undef IIGeometricFunctors_RECURSES
904 #endif // else defined(IIGeometricFunctors_RECURSES)
IISecondPrincipalDirectionFunctor< TSpace > Self
IISecondPrincipalDirectionFunctor(const Self &)
Copy constructor. Nothing to do.
static const Dimension dimension
static constants to store the dimension.
Definition: SpaceND.h:132
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
IIFirstPrincipalCurvature3DFunctor< TSpace > Self
Matrix eigenVectors
A data member only used for temporary calculations.
IITangentDirectionFunctor(const Self &)
Copy constructor. Nothing to do.
Aim: A functor Matrix -> RealVector that returns the tangent direction by diagonalizing the given cov...
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
RealVector eigenValues
A data member only used for temporary calculations.
Matrix eigenVectors
A data member only used for temporary calculations.
RealVector eigenValues
A data member only used for temporary calculations.
DGtal::uint32_t Dimension
Definition: Common.h:127
Matrix eigenVectors
A data member only used for temporary calculations.
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Value operator()(const Argument &arg) const
Aim: A functor Matrix -> std::pair<RealVector,RealVector> that returns the first and the second princ...
IIMeanCurvature3DFunctor< TSpace > Self
RealVector eigenValues
A data member only used for temporary calculations.
BOOST_STATIC_ASSERT((Space::dimension==3))
Aim: A functor Matrix -> Real that returns the second principal curvature value by diagonalizing the ...
IISecondPrincipalCurvature3DFunctor< TSpace > Self
Matrix eigenVectors
A data member only used for temporary calculations.
Value operator()(const Argument &arg) const
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
IIGaussianCurvature3DFunctor< TSpace > Self
Aim: A functor Matrix -> RealVector that returns the first principal curvature direction by diagonali...
IIFirstPrincipalDirectionFunctor(const Self &)
Copy constructor. Nothing to do.
IIPrincipalDirectionsFunctor(const Self &)
Copy constructor. Nothing to do.
IIFirstPrincipalDirectionFunctor< TSpace > Self
Aim: A functor Matrix -> std::pair<Real,Real> that returns the first and the second principal curvatu...
IINormalDirectionFunctor< TSpace > Self
Matrix eigenVectors
A data member only used for temporary calculations.
Matrix eigenVectors
A data member only used for temporary calculations.
Aim: A functor Real -> Real that returns the 2d curvature by transforming the given volume....
std::pair< RealVector, RealVector > Quantity
Matrix eigenVectors
A data member only used for temporary calculations.
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Value operator()(const Argument &arg) const
RealVector eigenValues
A data member only used for temporary calculations.
Aim: A functor Matrix -> RealVector that returns the normal direction by diagonalizing the given cova...
BOOST_STATIC_ASSERT((Space::dimension==2))
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:105
IICurvatureFunctor< TSpace > Self
RealVector eigenValues
A data member only used for temporary calculations.
IIPrincipalCurvatures3DFunctor< TSpace > Self
DGtal is the top-level namespace which contains all DGtal functions and types.
RealVector eigenValues
A data member only used for temporary calculations.
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
RealVector eigenValues
A data member only used for temporary calculations.
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Aim: A functor Real -> Real that returns the 3d mean curvature by transforming the given volume....
Matrix eigenVectors
A data member only used for temporary calculations.
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Aim: A functor Matrix -> Real that returns the first principal curvature value by diagonalizing the g...
Matrix eigenVectors
A data member only used for temporary calculations.
IITangentDirectionFunctor< TSpace > Self
IINormalDirectionFunctor(const Self &)
Copy constructor. Nothing to do.
Value operator()(const Argument &arg) const
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
static void getEigenDecomposition(const Matrix &matrix, Matrix &eigenVectors, Vector &eigenValues)
Compute both eigen vectors and eigen values from an input matrix.
Value operator()(const Argument &arg) const
IIPrincipalDirectionsFunctor< TSpace > Self
BOOST_STATIC_ASSERT((Space::dimension==2))
RealVector eigenValues
A data member only used for temporary calculations.
Aim: A functor Matrix -> RealVector that returns the second principal curvature direction by diagonal...
void init(Component h, Component r)
Aim: A functor Matrix -> Real that returns the Gaussian curvature by diagonalizing the given covarian...
Value operator()(const Argument &arg) const
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
RealVector eigenValues
A data member only used for temporary calculations.
TEuclideanRing Component
Type for Vector elements.
Definition: PointVector.h:614
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))