DGtal  0.9.2
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;
75  typedef RealVector Quantity;
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:
120  mutable Matrix eigenVectors;
122  mutable RealVector eigenValues;
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;
149  typedef RealVector Quantity;
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 
184  return eigenVectors.column( 1 ); // tangent vector is associated to greatest eigenvalue.
185  }
186 
187  private:
189  mutable Matrix eigenVectors;
191  mutable RealVector eigenValues;
192  }; // end of class IITangentDirectionFunctor
193 
194 
196  // template class IIFirstPrincipalDirectionFunctor
211  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
213  {
214  // ----------------------- Standard services ------------------------------
215  public:
217  typedef TSpace Space;
218  typedef typename Space::RealVector RealVector;
220  typedef TMatrix Matrix;
221  typedef Matrix Argument;
222  typedef RealVector Quantity;
223  typedef Quantity Value;
224 
225  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
228 
232  IIFirstPrincipalDirectionFunctor( const Self& /* other */ ) {}
235  Self& operator=( const Self& /* other */ ) { return *this; }
244  Value operator()( const Argument& arg ) const
245  {
248 
249  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
250 #ifdef DEBUG
251  for( Dimension i_dim = 1; i_dim < Space::dimension; ++i_dim )
252  {
253  ASSERT ( std::abs(eigenValues[i_dim - 1]) <= std::abs(eigenValues[i_dim]) );
254  }
255 #endif
256 
257  return eigenVectors.column( Space::dimension - 1 ); // first principal curvature direction is associated to greatest eigenvalue.
258  }
259 
264  void init( Component /* h */, Component /* r */ ) {}
265 
266  private:
268  mutable Matrix eigenVectors;
270  mutable RealVector eigenValues;
271  }; // end of class IIFirstPrincipalDirectionFunctor
272 
273 
275  // template class IISecondPrincipalDirectionFunctor
290  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
292  {
293  // ----------------------- Standard services ------------------------------
294  public:
296  typedef TSpace Space;
297  typedef typename Space::RealVector RealVector;
299  typedef TMatrix Matrix;
300  typedef Matrix Argument;
301  typedef RealVector Quantity;
302  typedef Quantity Value;
303 
304  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
307 
311  IISecondPrincipalDirectionFunctor( const Self& /* other */ ) {}
314  Self& operator=( const Self& /* other */ ) { return *this; }
323  Value operator()( const Argument& arg ) const
324  {
327 
328  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
329 #ifdef DEBUG
330  for( Dimension i_dim = 1; i_dim < Space::dimension; ++i_dim )
331  {
332  ASSERT ( std::abs(eigenValues[i_dim - 1]) <= std::abs(eigenValues[i_dim]) );
333  }
334 #endif
335 
336  return eigenVectors.column( Space::dimension - 2 ); // second principal curvature direction is associated to greatest eigenvalue.
337  }
338 
343  void init( Component /* h */, Component /* r */ ) {}
344 
345  private:
347  mutable Matrix eigenVectors;
349  mutable RealVector eigenValues;
350  }; // end of class IISecondPrincipalDirectionFunctor
351 
353  // template class IIPrincipalDirectionsFunctor
368  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
370  {
371  // ----------------------- Standard services ------------------------------
372  public:
374  typedef TSpace Space;
375  typedef typename Space::RealVector RealVector;
377  typedef TMatrix Matrix;
378  typedef Matrix Argument;
379  typedef std::pair<RealVector,RealVector> Quantity;
380  typedef Quantity Value;
381 
382  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
385 
389  IIPrincipalDirectionsFunctor( const Self& /* other */ ) {}
392  Self& operator=( const Self& /* other */ ) { return *this; }
401  Value operator()( const Argument& arg ) const
402  {
405 
406  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
407 #ifdef DEBUG
408  for( Dimension i_dim = 1; i_dim < Space::dimension; ++i_dim )
409  {
410  ASSERT ( std::abs(eigenValues[i_dim - 1]) <= std::abs(eigenValues[i_dim]) );
411  }
412 #endif
413 
414  return Value(
415  eigenVectors.column( Space::dimension - 1 ),
416  eigenVectors.column( Space::dimension - 2 )
417  );
418  }
419 
424  void init( Component /* h */, Component /* r */ ) {}
425 
426  private:
428  mutable Matrix eigenVectors;
430  mutable RealVector eigenValues;
431  }; // end of class IIPrincipalDirectionsFunctor
432 
434  // template class IICurvatureFunctor
445  template <typename TSpace>
447  {
448  // ----------------------- Standard services ------------------------------
449  public:
451  typedef TSpace Space;
452  typedef typename Space::RealVector RealVector;
454  typedef Component Argument;
455  typedef Component Quantity;
456  typedef Quantity Value;
457 
460 
467  Value operator()( const Argument& arg ) const
468  {
469  Quantity cp_quantity = arg;
470  cp_quantity *= dh2;
471  return d3_r * ( dPI_2 - d1_r2 * cp_quantity );
472  }
473 
480  void init( Component h, Component r )
481  {
482  d1_r2 = 1.0 / ( r * r );
483  dPI_2 = M_PI / 2.0;
484  d3_r = 3.0 / r;
485  dh2 = h * h;
486  }
487 
488  private:
489  Quantity dh2;
490  Quantity d3_r;
491  Quantity dPI_2;
492  Quantity d1_r2;
493  }; // end of class IICurvatureFunctor
494 
495 
497  // template class IIMeanCurvature3DFunctor
508  template <typename TSpace>
510  {
511  // ----------------------- Standard services ------------------------------
512  public:
514  typedef TSpace Space;
515  typedef typename Space::RealVector RealVector;
517  typedef Component Argument;
518  typedef Component Quantity;
519  typedef Quantity Value;
520 
523 
530  Value operator()( const Argument& arg ) const
531  {
532  Quantity cp_quantity = arg;
533  cp_quantity *= dh3;
534  return d8_3r - d_4_PIr4 * cp_quantity;
535  }
536 
543  void init( Component h, Component r )
544  {
545  d8_3r = 8.0 / ( 3.0 * r );
546  double r2 = r * r;
547  d_4_PIr4 = 4.0 / ( M_PI * r2 * r2 );
548  dh3 = h * h * h;
549  }
550 
551  private:
552  Quantity dh3;
553  Quantity d8_3r;
554  Quantity d_4_PIr4;
555  }; // end of class IIMeanCurvature3DFunctor
556 
558  // template class IIGaussianCurvature3DFunctor
572  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
574  {
575  // ----------------------- Standard services ------------------------------
576  public:
578  typedef TSpace Space;
579  typedef typename Space::RealVector RealVector;
581  typedef TMatrix Matrix;
582  typedef Matrix Argument;
583  typedef Component Quantity;
584  typedef Quantity Value;
585 
586  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
589 
597  Value operator()( const Argument& arg ) const
598  {
599  Argument cp_arg = arg;
600  cp_arg *= dh5;
603 
604  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
605  ASSERT ( (std::abs(eigenValues[0]) <= std::abs(eigenValues[1]))
606  && (std::abs(eigenValues[1]) <= std::abs(eigenValues[2])) );
607 
608  Value k1 = d6_PIr6 * ( eigenValues[2] - ( 3.0 * eigenValues[1] )) + d8_5r;
609  Value k2 = d6_PIr6 * ( eigenValues[1] - ( 3.0 * eigenValues[2] )) + d8_5r;
610  return k1 * k2;
611  }
612 
619  void init( Component h, Component r )
620  {
621  double r3 = r * r * r;
622  double r6 = r3 * r3;
623  d6_PIr6 = 6.0 / ( M_PI * r6 );
624  d8_5r = 8.0 / ( 5.0 * r );
625  double h2 = h * h;
626  dh5 = h2 * h2 * h;
627  }
628 
629  private:
630  Quantity dh5;
631  Quantity d6_PIr6;
632  Quantity d8_5r;
633 
635  mutable Matrix eigenVectors;
637  mutable RealVector eigenValues;
638  }; // end of class IIGaussianCurvature3DFunctor
639 
641  // template class IIFirstPrincipalCurvature3DFunctor
655  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
657  {
658  // ----------------------- Standard services ------------------------------
659  public:
661  typedef TSpace Space;
662  typedef typename Space::RealVector RealVector;
664  typedef TMatrix Matrix;
665  typedef Matrix Argument;
666  typedef Component Quantity;
667  typedef Quantity Value;
668 
669  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
672 
680  Value operator()( const Argument& arg ) const
681  {
682  Argument cp_arg = arg;
683  cp_arg *= dh5;
686 
687  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
688  ASSERT ( (std::abs(eigenValues[0]) <= std::abs(eigenValues[1]))
689  && (std::abs(eigenValues[1]) <= std::abs(eigenValues[2])) );
690 
691 
692  return d6_PIr6 * ( eigenValues[2] - ( 3.0 * eigenValues[1] )) + d8_5r;
693  }
694 
701  void init( Component h, Component r )
702  {
703  double r3 = r * r * r;
704  double r6 = r3 * r3;
705  d6_PIr6 = 6.0 / ( M_PI * r6 );
706  d8_5r = 8.0 / ( 5.0 * r );
707  double h2 = h * h;
708  dh5 = h2 * h2 * h;
709  }
710 
711  private:
712  Quantity dh5;
713  Quantity d6_PIr6;
714  Quantity d8_5r;
715 
717  mutable Matrix eigenVectors;
719  mutable RealVector eigenValues;
720  }; // end of class IIFirstPrincipalCurvature3DFunctor
721 
723  // template class IISecondPrincipalCurvature3DFunctor
737  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
739  {
740  // ----------------------- Standard services ------------------------------
741  public:
743  typedef TSpace Space;
744  typedef typename Space::RealVector RealVector;
746  typedef TMatrix Matrix;
747  typedef Matrix Argument;
748  typedef Component Quantity;
749  typedef Quantity Value;
750 
751  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
754 
762  Value operator()( const Argument& arg ) const
763  {
764  Argument cp_arg = arg;
765  cp_arg *= dh5;
768 
769  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
770  ASSERT ( (std::abs(eigenValues[0]) <= std::abs(eigenValues[1]))
771  && (std::abs(eigenValues[1]) <= std::abs(eigenValues[2])) );
772 
773  return d6_PIr6 * ( eigenValues[1] - ( 3.0 * eigenValues[2] )) + d8_5r;
774  }
775 
782  void init( Component h, Component r )
783  {
784  double r3 = r * r * r;
785  double r6 = r3 * r3;
786  d6_PIr6 = 6.0 / ( M_PI * r6 );
787  d8_5r = 8.0 / ( 5.0 * r );
788  double h2 = h * h;
789  dh5 = h2 * h2 * h;
790  }
791 
792  private:
793  Quantity dh5;
794  Quantity d6_PIr6;
795  Quantity d8_5r;
796 
798  mutable Matrix eigenVectors;
800  mutable RealVector eigenValues;
801  }; // end of class IISecondPrincipalCurvature3DFunctor
802 
803 
805  // template class IIPrincipalCurvatures3DFunctor
818  template <typename TSpace, typename TMatrix=SimpleMatrix< typename TSpace::RealVector::Component, TSpace::dimension, TSpace::dimension> >
820  {
821  // ----------------------- Standard services ------------------------------
822  public:
824  typedef TSpace Space;
825  typedef typename Space::RealVector RealVector;
827  typedef TMatrix Matrix;
828  typedef Matrix Argument;
829  typedef std::pair<Component, Component> Quantity;
830  typedef Quantity Value;
831 
832  // BOOST_CONCEPT_ASSERT(( CMatrix<TMatrix> ));
835 
844  Value operator()( const Argument& arg ) const
845  {
846  Argument cp_arg = arg;
847  cp_arg *= dh5;
850 
851  ASSERT ( !std::isnan(eigenValues[0]) ); // NaN
852  ASSERT ( (std::abs(eigenValues[0]) <= std::abs(eigenValues[1]))
853  && (std::abs(eigenValues[1]) <= std::abs(eigenValues[2])) );
854 
855  return Value(
856  d6_PIr6 * ( eigenValues[2] - ( 3.0 * eigenValues[1] )) + d8_5r,
857  d6_PIr6 * ( eigenValues[1] - ( 3.0 * eigenValues[2] )) + d8_5r
858  );
859  }
860 
867  void init( Component h, Component r )
868  {
869  double r3 = r * r * r;
870  double r6 = r3 * r3;
871  d6_PIr6 = 6.0 / ( M_PI * r6 );
872  d8_5r = 8.0 / ( 5.0 * r );
873  double h2 = h * h;
874  dh5 = h2 * h2 * h;
875  }
876 
877  private:
878  double dh5;
879  double d6_PIr6;
880  double d8_5r;
881 
883  mutable Matrix eigenVectors;
885  mutable RealVector eigenValues;
886  }; // end of class IIPrincipalCurvatures3DFunctor
887 
888 } // namespace functors
889 
890 } // namespace DGtal
891 
892 
893 // //
895 
896 #endif // !defined IIGeometricFunctors_h
897 
898 #undef IIGeometricFunctors_RECURSES
899 #endif // else defined(IIGeometricFunctors_RECURSES)
IISecondPrincipalDirectionFunctor< TSpace > Self
IISecondPrincipalDirectionFunctor(const Self &)
Copy constructor. Nothing to do.
Value operator()(const Argument &arg) const
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:113
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 that returns the first and the second princ...
Aim: This class provides methods to compute the eigen decomposition of a matrix. Its objective is to ...
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:141
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 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 >))
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.
Value operator()(const Argument &arg) const
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.
Value operator()(const Argument &arg) const
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.
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
IIPrincipalDirectionsFunctor< TSpace > Self
BOOST_STATIC_ASSERT((Space::dimension==2))
RealVector eigenValues
A data member only used for temporary calculations.
Value operator()(const Argument &arg) const
Value operator()(const Argument &arg) const
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...
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:155
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))