DGtal  0.9.2
DigitalSurfaceConvolver.h
1 
17 #pragma once
18 
35 #if defined(DigitalSurfaceConvolver_RECURSES)
36 #error Recursive header files inclusion detected in DigitalSurfaceConvolver.h
37 #else // defined(DigitalSurfaceConvolver_RECURSES)
38 
39 #define DigitalSurfaceConvolver_RECURSES
40 
41 #if !defined DigitalSurfaceConvolver_h
42 
43 #define DigitalSurfaceConvolver_h
44 
46 // Inclusions
47 #include <iostream>
48 #include "DGtal/base/Common.h"
49 #include "DGtal/kernel/PointVector.h"
50 #include "DGtal/math/linalg/SimpleMatrix.h"
51 #include "DGtal/base/ConstAlias.h"
52 #include "DGtal/base/Alias.h"
53 #include "DGtal/base/Clone.h"
54 #include "DGtal/topology/CCellFunctor.h"
55 #include "DGtal/topology/CanonicSCellEmbedder.h"
56 #include "DGtal/topology/SCellsFunctors.h"
58 
59 namespace DGtal
60 {
61 
63 // template class DigitalSurfaceConvolver
75 template< typename TFunctor, typename TKernelFunctor, typename TKSpace, typename TDigitalKernel, Dimension dimension = TKSpace::dimension >
77 {
78 public:
79 
80  typedef TFunctor Functor;
81  typedef TKSpace KSpace;
82  typedef TKernelFunctor KernelFunctor;
83  typedef TDigitalKernel DigitalKernel;
84 
86 
87  typedef double Quantity;
91 
92  typedef typename KSpace::SCell Spel;
93  typedef typename KSpace::Point Point;
94  typedef typename KSpace::Space::RealPoint RealPoint;
96 
97  typedef std::pair< KernelConstIterator, KernelConstIterator > PairIterators;
99 
102 
103  // ----------------------- Standard services ------------------------------
104 
105 public:
106 
115 
121 
122 
127 
128  // ----------------------- Interface --------------------------------------
129 
130 public:
131 
147  void init ( const Point & pOrigin,
148  ConstAlias< PairIterators > fullKernel,
149  ConstAlias< std::vector< PairIterators > > masks );
150 
166  void init ( const Point & pOrigin,
167  ConstAlias< DigitalKernel > fullKernel,
168  ConstAlias< std::vector< PairIterators > > masks );
169 
179  template< typename SurfelIterator >
180  Quantity eval ( const SurfelIterator & it ) const;
181 
182 
194  template< typename SurfelIterator, typename EvalFunctor >
195  typename EvalFunctor::Value eval ( const SurfelIterator & it,
196  EvalFunctor functor ) const;
197 
198 
209  template< typename SurfelIterator, typename OutputIterator >
210  void eval ( const SurfelIterator & itbegin,
211  const SurfelIterator & itend,
212  OutputIterator & result ) const;
213 
226  template< typename SurfelIterator, typename OutputIterator, typename EvalFunctor >
227  void eval ( const SurfelIterator & itbegin,
228  const SurfelIterator & itend,
229  OutputIterator & result,
230  EvalFunctor functor ) const;
231 
232 
242  template< typename SurfelIterator >
243  CovarianceMatrix evalCovarianceMatrix ( const SurfelIterator & it ) const;
244 
256  template< typename SurfelIterator, typename EvalFunctor >
257  typename EvalFunctor::Value evalCovarianceMatrix ( const SurfelIterator & it,
258  EvalFunctor functor ) const;
259 
270  template< typename SurfelIterator, typename OutputIterator >
271  void evalCovarianceMatrix ( const SurfelIterator & itbegin,
272  const SurfelIterator & itend,
273  OutputIterator & result ) const;
274 
287  template< typename SurfelIterator, typename OutputIterator, typename EvalFunctor >
288  void evalCovarianceMatrix ( const SurfelIterator & itbegin,
289  const SurfelIterator & itend,
290  OutputIterator & result,
291  EvalFunctor functor ) const;
292 
293 
298  bool isValid () const;
299 
300 protected:
301 
312  void computeCovarianceMatrix( const Quantity * aMomentMatrix, CovarianceMatrix & aCovarianceMatrix ) const;
313 
325  void fillMoments( Quantity* aMomentMatrix, const Spel & aSpel, double direction ) const;
326 
327  static const int nbMoments;
328  static Spel defaultInnerSpel;
329  static Spel defaultOuterSpel;
330  static Quantity defaultInnerMoments[ 6 ];
331  static Quantity defaultOuterMoments[ 6 ];
332  static Quantity defaultInnerSum;
333  static Quantity defaultOuterSum;
334 
349  template< typename SurfelIterator >
350  bool core_eval ( const SurfelIterator & it,
351  Quantity & innerSum,
352  Quantity & outerSum,
353  bool useLastResults = false,
354  Spel & lastInnerSpel = defaultInnerSpel,
355  Spel & lastOuterSpel = defaultOuterSpel,
356  Quantity & lastInnerSum = defaultInnerSum,
357  Quantity & lastOuterSum = defaultOuterSum ) const;
358 
373  template< typename SurfelIterator >
374  bool core_evalCovarianceMatrix ( const SurfelIterator & it,
375  CovarianceMatrix & innerMatrix,
376  CovarianceMatrix & outerMatrix,
377  bool useLastResults = false,
378  Spel & lastInnerSpel = defaultInnerSpel,
379  Spel & lastOuterSpel = defaultOuterSpel,
380  Quantity * lastInnerMoments = defaultInnerMoments,
381  Quantity * lastOuterMoments = defaultOuterMoments ) const;
382 
383 
384 
385  // ------------------------- Private Datas --------------------------------
386 
387 private:
388 
389  const Functor & myFFunctor;
390 
391  const KernelFunctor & myGFunctor;
392 
393 
394  const KSpace & myKSpace;
395 
396  Embedder myEmbedder;
397 
399 
401 
402  const std::vector< PairIterators > * myMasks;
403 
404  const DigitalKernel * myKernel;
405  const PairIterators * myKernelMask;
406 
408 
409  // ------------------------- Hidden services ------------------------------
410 
411 protected:
417 
418 private:
419 
427 
428  // ------------------------- Internals ------------------------------------
429 
430 private:
431 
432 }; // end of class DigitalSurfaceConvolver
433 
434 template< typename TFunctor, typename TKernelFunctor, typename TKSpace, typename TDigitalKernel >
435 class DigitalSurfaceConvolver< TFunctor, TKernelFunctor, TKSpace, TDigitalKernel, 2 >
436 {
437  // ----------------------- Types ------------------------------------------
438 
439 public:
440 
441  typedef TFunctor Functor;
442  typedef TKSpace KSpace;
443  typedef TKernelFunctor KernelFunctor;
444  typedef TDigitalKernel DigitalKernel;
445 
447 
448  typedef double Quantity;
452 
453  typedef typename KSpace::SCell Spel;
454  typedef typename KSpace::Point Point;
455  typedef typename KSpace::Space::RealPoint RealPoint;
457 
458  typedef std::pair< KernelConstIterator, KernelConstIterator > PairIterators;
460 
463 
464  // ----------------------- Standard services ------------------------------
465 
466 public:
467 
476 
482 
487 
488  // ----------------------- Interface --------------------------------------
489 
490 public:
491 
507  void init ( const Point & pOrigin,
508  ConstAlias< PairIterators > fullKernel,
509  ConstAlias< std::vector< PairIterators > > masks );
510 
526  void init ( const Point & pOrigin,
527  ConstAlias< DigitalKernel > fullKernel,
528  ConstAlias< std::vector< PairIterators > > masks );
529 
539  template< typename SurfelIterator >
540  Quantity eval ( const SurfelIterator & it ) const;
541 
542 
554  template< typename SurfelIterator, typename EvalFunctor >
555  typename EvalFunctor::Value eval ( const SurfelIterator & it,
556  EvalFunctor functor ) const;
557 
558 
569  template< typename SurfelIterator, typename OutputIterator >
570  void eval ( const SurfelIterator & itbegin,
571  const SurfelIterator & itend,
572  OutputIterator & result ) const;
573 
586  template< typename SurfelIterator, typename OutputIterator, typename EvalFunctor >
587  void eval ( const SurfelIterator & itbegin,
588  const SurfelIterator & itend,
589  OutputIterator & result,
590  EvalFunctor functor ) const;
591 
592 
602  template< typename SurfelIterator >
603  CovarianceMatrix evalCovarianceMatrix ( const SurfelIterator & it ) const;
604 
616  template< typename SurfelIterator, typename EvalFunctor >
617  typename EvalFunctor::Value evalCovarianceMatrix ( const SurfelIterator & it,
618  EvalFunctor functor ) const;
619 
630  template< typename SurfelIterator, typename OutputIterator >
631  void evalCovarianceMatrix ( const SurfelIterator & itbegin,
632  const SurfelIterator & itend,
633  OutputIterator & result ) const;
634 
647  template< typename SurfelIterator, typename OutputIterator, typename EvalFunctor >
648  void evalCovarianceMatrix ( const SurfelIterator & itbegin,
649  const SurfelIterator & itend,
650  OutputIterator & result,
651  EvalFunctor functor ) const;
652 
653 
658  bool isValid () const;
659 
660 protected:
661 
672  void computeCovarianceMatrix( const Quantity * aMomentMatrix, CovarianceMatrix & aCovarianceMatrix ) const;
673 
685  void fillMoments( Quantity* aMomentMatrix, const Spel & aSpel, double direction ) const;
686 
687  static const int nbMoments;
688  static Spel defaultInnerSpel;
689  static Spel defaultOuterSpel;
690  static Quantity defaultInnerMoments[ 6 ];
691  static Quantity defaultOuterMoments[ 6 ];
692  static Quantity defaultInnerSum;
693  static Quantity defaultOuterSum;
694 
709  template< typename SurfelIterator >
710  bool core_eval ( const SurfelIterator & it,
711  Quantity & innerSum,
712  Quantity & outerSum,
713  bool useLastResults = false,
714  Spel & lastInnerSpel = defaultInnerSpel,
715  Spel & lastOuterSpel = defaultOuterSpel,
716  Quantity & lastInnerSum = defaultInnerSum,
717  Quantity & lastOuterSum = defaultOuterSum ) const;
718 
733  template< typename SurfelIterator >
734  bool core_evalCovarianceMatrix ( const SurfelIterator & it,
735  CovarianceMatrix & innerMatrix,
736  CovarianceMatrix & outerMatrix,
737  bool useLastResults = false,
738  Spel & lastInnerSpel = defaultInnerSpel,
739  Spel & lastOuterSpel = defaultOuterSpel,
740  Quantity * lastInnerMoments = defaultInnerMoments,
741  Quantity * lastOuterMoments = defaultOuterMoments ) const;
742 
743 
744 
745  // ------------------------- Private Datas --------------------------------
746 
747 private:
748 
750 
751  const Functor & myFFunctor;
752 
753  const KernelFunctor & myGFunctor;
754 
755 
756  const KSpace & myKSpace;
757 
758  Embedder myEmbedder;
759 
761 
763 
764  const std::vector< PairIterators > * myMasks;
765 
766  const DigitalKernel * myKernel;
767  const PairIterators * myKernelMask;
768 
770 
771  // ------------------------- Hidden services ------------------------------
772 
773 protected:
779 
780 private:
781 
789 
790  // ------------------------- Internals ------------------------------------
791 
792 private:
793 
794 }; // end of class DigitalSurfaceConvolver
795 
796 template< typename TFunctor, typename TKernelFunctor, typename TKSpace, typename TDigitalKernel >
797 class DigitalSurfaceConvolver< TFunctor, TKernelFunctor, TKSpace, TDigitalKernel, 3 >
798 {
799  // ----------------------- Types ------------------------------------------
800 
801 public:
802 
803  typedef TFunctor Functor;
804  typedef TKSpace KSpace;
805  typedef TKernelFunctor KernelFunctor;
806  typedef TDigitalKernel DigitalKernel;
807 
809 
810  typedef double Quantity;
814 
815  typedef typename KSpace::SCell Spel;
816  typedef typename KSpace::Point Point;
817  typedef typename KSpace::Space::RealPoint RealPoint;
819 
820 
821  typedef std::pair< KernelConstIterator, KernelConstIterator > PairIterators;
823 
826 
827  // ----------------------- Standard services ------------------------------
828 
829 public:
830 
840  ConstAlias< KSpace > space );
841 
847 
852 
853  // ----------------------- Interface --------------------------------------
854 
855 public:
856 
872  void init ( const Point & pOrigin,
873  ConstAlias< PairIterators > fullKernel,
874  ConstAlias< std::vector< PairIterators > > masks );
875 
891  void init ( const Point & pOrigin,
892  ConstAlias< DigitalKernel > fullKernel,
893  ConstAlias< std::vector< PairIterators > > masks );
894 
904  template< typename SurfelIterator >
905  Quantity eval ( const SurfelIterator & it ) const;
906 
907 
919  template< typename SurfelIterator, typename EvalFunctor >
920  typename EvalFunctor::Value eval ( const SurfelIterator & it,
921  EvalFunctor functor ) const;
922 
923 
934  template< typename SurfelIterator, typename OutputIterator >
935  void eval ( const SurfelIterator & itbegin,
936  const SurfelIterator & itend,
937  OutputIterator & result ) const;
938 
951  template< typename SurfelIterator, typename OutputIterator, typename EvalFunctor >
952  void eval ( const SurfelIterator & itbegin,
953  const SurfelIterator & itend,
954  OutputIterator & result,
955  EvalFunctor functor ) const;
956 
957 
967  template< typename SurfelIterator >
968  CovarianceMatrix evalCovarianceMatrix ( const SurfelIterator & it ) const;
969 
981  template< typename SurfelIterator, typename EvalFunctor >
982  typename EvalFunctor::Value evalCovarianceMatrix ( const SurfelIterator & it,
983  EvalFunctor functor ) const;
984 
995  template< typename SurfelIterator, typename OutputIterator >
996  void evalCovarianceMatrix ( const SurfelIterator & itbegin,
997  const SurfelIterator & itend,
998  OutputIterator & result ) const;
999 
1012  template< typename SurfelIterator, typename OutputIterator, typename EvalFunctor >
1013  void evalCovarianceMatrix ( const SurfelIterator & itbegin,
1014  const SurfelIterator & itend,
1015  OutputIterator & result,
1016  EvalFunctor functor ) const;
1017 
1022  bool isValid() const;
1023 
1024 protected:
1025 
1037  void computeCovarianceMatrix ( const Quantity * aMomentMatrix, CovarianceMatrix & aCovarianceMatrix ) const;
1038 
1051  void fillMoments ( Quantity * aMomentMatrix, const Spel & aSpel, double direction ) const;
1052 
1053  static const int nbMoments;
1054  static Spel defaultInnerSpel;
1055  static Spel defaultOuterSpel;
1056  static Quantity defaultInnerMoments[ 10 ];
1057  static Quantity defaultOuterMoments[ 10 ];
1058  static Quantity defaultInnerSum;
1059  static Quantity defaultOuterSum;
1060 
1075  template< typename SurfelIterator >
1076  bool core_eval ( const SurfelIterator & it,
1077  Quantity & innerSum,
1078  Quantity & outerSum,
1079  bool useLastResults = false,
1080  Spel & lastInnerSpel = defaultInnerSpel,
1081  Spel & lastOuterSpel = defaultOuterSpel,
1082  Quantity & lastInnerSum = defaultInnerSum,
1083  Quantity & lastOuterSum = defaultOuterSum ) const;
1084 
1099  template< typename SurfelIterator >
1100  bool core_evalCovarianceMatrix ( const SurfelIterator & it,
1101  CovarianceMatrix & innerMatrix,
1102  CovarianceMatrix & outerMatrix,
1103  bool useLastResults = false,
1104  Spel & lastInnerSpel = defaultInnerSpel,
1105  Spel & lastOuterSpel = defaultOuterSpel,
1106  Quantity * lastInnerMoments = defaultInnerMoments,
1107  Quantity * lastOuterMoments = defaultOuterMoments ) const;
1108 
1109 
1110  // ------------------------- Private Datas --------------------------------
1111 
1112 private:
1113 
1115 
1116  const Functor & myFFunctor;
1117 
1118  const KernelFunctor & myGFunctor;
1119 
1120 
1121  const KSpace & myKSpace;
1122 
1123  Embedder myEmbedder;
1124 
1126 
1128 
1129  const std::vector< PairIterators > * myMasks;
1130 
1131  const DigitalKernel * myKernel;
1132  const PairIterators * myKernelMask;
1133 
1135 
1136  // ------------------------- Hidden services ------------------------------
1137 
1138 protected:
1144 
1145 private:
1146 
1154 
1155  // ------------------------- Internals ------------------------------------
1156 
1157 private:
1158 
1159 }; // end of class DigitalSurfaceConvolver
1160 
1161 
1162 
1169 template< typename TF, typename TKF, typename TKS, typename TDK, Dimension dimension >
1170 std::ostream&
1171 operator<< ( std::ostream & out, const DGtal::DigitalSurfaceConvolver< TF, TKF, TKS, TDK, dimension > & object );
1172 
1173 template< typename TF, typename TKF, typename TKS, typename TDK >
1174 std::ostream&
1175 operator<< ( std::ostream & out, const DGtal::DigitalSurfaceConvolver< TF, TKF, TKS, TDK, 2 > & object );
1176 
1177 template< typename TF, typename TKF, typename TKS, typename TDK >
1178 std::ostream&
1179 operator<< ( std::ostream & out, const DGtal::DigitalSurfaceConvolver<TF, TKF, TKS, TDK, 3 > & object );
1180 
1181 
1182 } // namespace DGtal
1183 
1184 
1186 // Includes inline functions.
1187 #include "DGtal/geometry/surfaces/DigitalSurfaceConvolver.ih"
1188 
1189 
1190 // //
1192 
1193 #endif // !defined DigitalSurfaceConvolver_h
1194 
1195 #undef DigitalSurfaceConvolver_RECURSES
1196 #endif // else defined(DigitalSurfaceConvolver_RECURSES)
static const int nbMoments
the number of moments is dependent to the dimension. In 2D, they are 6 moments such that p+q <= 2...
static Spel defaultInnerSpel
default Spel, used as default parameter in core_eval and core_evalCovarianceMatrix functions ...
bool isInitFullMasks
If the user uses init with masks. See init() for more information.
CanonicSCellEmbedder< KSpace > Embedder
std::pair< KernelConstIterator, KernelConstIterator > PairIterators
const std::vector< PairIterators > * myMasks
Pointer of vector of iterators for kernel partial masks.
bool isInitFullMasks
If the user uses init with masks. See init() for more information.
static Quantity defaultOuterSum
default Quantity, used as default parameter in core_eval function
const DigitalKernel * myKernel
Two choice to iterate over the full kernel. See init() for more information.
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
static Spel defaultOuterSpel
default Spel, used as default parameter in core_eval and core_evalCovarianceMatrix functions ...
DGtal::uint32_t Dimension
Definition: Common.h:113
Aim: Defines a functor on cells.
Definition: CCellFunctor.h:89
const DigitalKernel * myKernel
Two choice to iterate over the full kernel. See init() for more information.
static Quantity defaultOuterMoments[6]
default array of Quantity, used as default parameter in core_evalCovarianceMatrix function ...
void init(const Point &pOrigin, ConstAlias< PairIterators > fullKernel, ConstAlias< std::vector< PairIterators > > masks)
const DigitalKernel * myKernel
Two choice to iterate over the full kernel. See init() for more information.
SimpleMatrix< Quantity, dimension, dimension > MatrixQuantity
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
bool isInitKernelAndMasks
If the user uses init with masks and digital (full) kernel. See init() for more information.
bool core_eval(const SurfelIterator &it, Quantity &innerSum, Quantity &outerSum, bool useLastResults=false, Spel &lastInnerSpel=defaultInnerSpel, Spel &lastOuterSpel=defaultOuterSpel, Quantity &lastInnerSum=defaultInnerSum, Quantity &lastOuterSum=defaultOuterSum) const
core_eval method used ( in intern by eval() ) to compute the Quantity on a given surfel (*it) ...
static Spel defaultInnerSpel
default Spel, used as default parameter in core_eval and core_evalCovarianceMatrix functions ...
Aim: implements basic MxN Matrix services (M,N>=1).
Definition: SimpleMatrix.h:75
static Quantity defaultInnerSum
default Quantity, used as default parameter in core_eval function
PointVector< dimension, Quantity > VectorQuantity
const PairIterators * myKernelMask
Two choice to iterate over the full kernel. See init() for more information.
SimpleMatrix< double, dimension, dimension > CovarianceMatrix
static const int nbMoments
the number of moments is dependent to the dimension. In 2D, they are 6 moments such that p+q <= 2 (se...
static Quantity defaultInnerSum
default Quantity, used as default parameter in core_eval function
static Quantity defaultOuterSum
default Quantity, used as default parameter in core_eval function
const std::vector< PairIterators > * myMasks
Pointer of vector of iterators for kernel partial masks.
Z2i::DigitalSet::ConstIterator KernelConstIterator
static const int nbMoments
the number of moments is dependent to the dimension. In 3D, they are 10 moments such that p+q+s <= 2 ...
Quantity eval(const SurfelIterator &it) const
bool core_evalCovarianceMatrix(const SurfelIterator &it, CovarianceMatrix &innerMatrix, CovarianceMatrix &outerMatrix, bool useLastResults=false, Spel &lastInnerSpel=defaultInnerSpel, Spel &lastOuterSpel=defaultOuterSpel, Quantity *lastInnerMoments=defaultInnerMoments, Quantity *lastOuterMoments=defaultOuterMoments) const
core_evalCovarianceMatrix method used ( in intern by evalCovarianceMatrix() ) to compute the covarian...
const KSpace & myKSpace
Const ref of the shape Kspace.
BOOST_CONCEPT_ASSERT((concepts::CCellFunctor< Functor >))
DigitalSurfaceConvolver & operator=(const DigitalSurfaceConvolver &other)
KSpace::Space::RealPoint RealPoint
const Functor & myFFunctor
Const ref of the shape functor.
const std::vector< PairIterators > * myMasks
Pointer of vector of iterators for kernel partial masks.
static Quantity defaultInnerSum
default Quantity, used as default parameter in core_eval function
static Quantity defaultInnerMoments[6]
default array of Quantity, used as default parameter in core_evalCovarianceMatrix function ...
void fillMoments(Quantity *aMomentMatrix, const Spel &aSpel, double direction) const
fillMoments fill the matrix of moments with a given spel.
DGtal is the top-level namespace which contains all DGtal functions and types.
Embedder myEmbedder
Converter Digital point -> Euclidean point.
static Spel defaultOuterSpel
default Spel, used as default parameter in core_eval and core_evalCovarianceMatrix functions ...
static Quantity defaultOuterSum
default Quantity, used as default parameter in core_eval function
bool isInitFullMasks
If the user uses init with masks. See init() for more information.
const KernelFunctor & myGFunctor
Const ref of the kernel functor.
void computeCovarianceMatrix(const Quantity *aMomentMatrix, CovarianceMatrix &aCovarianceMatrix) const
computeCovarianceMatrix compute the covariance matrix from matrix of moments.
const PairIterators * myKernelMask
Two choice to iterate over the full kernel. See init() for more information.
CovarianceMatrix evalCovarianceMatrix(const SurfelIterator &it) const
Container::const_iterator ConstIterator
ConstIterator type of the container;.
bool isInitKernelAndMasks
If the user uses init with masks and digital (full) kernel. See init() for more information.
static Spel defaultInnerSpel
default Spel, used as default parameter in core_eval and core_evalCovarianceMatrix functions ...
bool isInitKernelAndMasks
If the user uses init with masks and digital (full) kernel. See init() for more information.
Spel myKernelSpelOrigin
Copy of the origin cell of the kernel.
static Spel defaultOuterSpel
default Spel, used as default parameter in core_eval and core_evalCovarianceMatrix functions ...
const PairIterators * myKernelMask
Two choice to iterate over the full kernel. See init() for more information.