DGtal  0.9.2
DiscreteExteriorCalculus.h
1 
17 #pragma once
18 
31 #if defined(DiscreteExteriorCalculus_RECURSES)
32 #error Recursive header files inclusion detected in DiscreteExteriorCalculus.h
33 #else // defined(DiscreteExteriorCalculus_RECURSES)
34 
35 #define DiscreteExteriorCalculus_RECURSES
36 
37 #if !defined DiscreteExteriorCalculus_h
38 
39 #define DiscreteExteriorCalculus_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <vector>
45 #include <map>
46 #include <list>
47 #include <boost/array.hpp>
48 #include <boost/unordered_map.hpp>
49 #include "DGtal/kernel/SpaceND.h"
50 #include "DGtal/kernel/domains/HyperRectDomain.h"
51 #include "DGtal/base/Common.h"
52 #include "DGtal/topology/KhalimskySpaceND.h"
53 #include "DGtal/dec/Duality.h"
54 #include "DGtal/dec/KForm.h"
55 #include "DGtal/dec/LinearOperator.h"
56 #include "DGtal/dec/VectorField.h"
57 #include "DGtal/base/ConstAlias.h"
58 
59 #include <DGtal/kernel/sets/CDigitalSet.h>
60 #include <DGtal/math/linalg/CDynamicMatrix.h>
61 #include <DGtal/math/linalg/CDynamicVector.h>
62 #include <DGtal/math/linalg/CLinearAlgebra.h>
64 
65 namespace DGtal
66 {
67  // forward factory declaration
68  template <typename TLinearAlgebraBackend, typename TInteger>
70 
76  template <Dimension dim, typename TInteger>
77  size_t
79 
81  // template class DiscreteExteriorCalculus
95  template <Dimension dimEmbedded, Dimension dimAmbient, typename TLinearAlgebraBackend, typename TInteger = DGtal::int32_t>
97  {
98  // ----------------------- Standard services ------------------------------
99  public:
100 
101  friend class DiscreteExteriorCalculusFactory<TLinearAlgebraBackend, TInteger>;
102 
104 
105  typedef TLinearAlgebraBackend LinearAlgebraBackend;
106  typedef typename LinearAlgebraBackend::DenseVector::Index Index;
107  typedef typename LinearAlgebraBackend::DenseVector::Scalar Scalar;
108  typedef typename LinearAlgebraBackend::DenseVector DenseVector;
109  typedef typename LinearAlgebraBackend::DenseMatrix DenseMatrix;
110  typedef typename LinearAlgebraBackend::SparseMatrix SparseMatrix;
111 
113 
119 
120  BOOST_STATIC_ASSERT(( boost::is_same<Dimension, Order>::value ));
121 
125  BOOST_STATIC_ASSERT(( dimAmbient >= dimEmbedded ));
126 
127  BOOST_STATIC_CONSTANT( Dimension, dimensionEmbedded = dimEmbedded );
128  BOOST_STATIC_CONSTANT( Dimension, dimensionAmbient = dimAmbient );
129 
131  typedef typename KSpace::Cell Cell;
132  typedef typename KSpace::SCell SCell;
133  typedef typename KSpace::Point Point;
134 
151  struct Property
152  {
153  Scalar primal_size;
154  Scalar dual_size;
155  Index index;
156  bool flipped;
157  };
158 
162  typedef boost::unordered_map<Cell, Property> Properties;
163 
167  typedef std::vector<SCell> SCells;
168  typedef boost::array<SCells, dimEmbedded+1> IndexedSCells;
169 
175 
187 
197 
207 
211  typedef LinearOperator<Self, 0, PRIMAL, dimEmbedded-0, DUAL> PrimalHodge0;
212  typedef LinearOperator<Self, 1, PRIMAL, dimEmbedded-1, DUAL> PrimalHodge1;
213  typedef LinearOperator<Self, 2, PRIMAL, dimEmbedded-2, DUAL> PrimalHodge2;
214  typedef LinearOperator<Self, 3, PRIMAL, dimEmbedded-3, DUAL> PrimalHodge3;
215  typedef LinearOperator<Self, 0, DUAL, dimEmbedded-0, PRIMAL> DualHodge0;
216  typedef LinearOperator<Self, 1, DUAL, dimEmbedded-1, PRIMAL> DualHodge1;
217  typedef LinearOperator<Self, 2, DUAL, dimEmbedded-2, PRIMAL> DualHodge2;
218  typedef LinearOperator<Self, 3, DUAL, dimEmbedded-3, PRIMAL> DualHodge3;
219 
231 
237 
243  template <typename TDomain>
244  void
246 
247  // ----------------------- Iterators on property map -----------------------
248 
252  typedef typename Properties::const_iterator ConstIterator;
253 
257  ConstIterator begin() const;
258 
262  ConstIterator end() const;
263 
267  typedef typename Properties::iterator Iterator;
268 
272  Iterator begin();
273 
277  Iterator end();
278 
279  // ----------------------- Interface --------------------------------------
280  public:
281 
285  KSpace myKSpace;
286 
291  void selfDisplay(std::ostream& out) const;
292 
296  std::string className() const;
297 
305  bool
306  insertSCell(const SCell& signed_cell);
307 
317  bool
318  insertSCell(const SCell& signed_cell, const Scalar& primal_size, const Scalar& dual_size);
319 
326  bool
327  eraseCell(const Cell& cell);
328 
333  void
334  updateIndexes();
335 
340  const Properties&
341  getProperties() const;
342 
349  template <Order order, Duality duality>
350  const SCells&
351  getIndexedSCells() const;
352 
361  template <Order order, Duality duality, typename TConstIterator>
363  reorder(const TConstIterator& begin_range, const TConstIterator& end_range) const;
364 
371  template <Order order, Duality duality>
373  identity() const;
374 
381  template <Order order, Duality duality>
383  derivative() const;
384 
391  template <Order order, Duality duality>
392  LinearOperator<Self, order, duality, order-1, duality>
393  antiderivative() const;
394 
399  template <Duality duality>
401  laplace() const;
402 
409  template <Order order, Duality duality>
410  LinearOperator<Self, order, duality, dimEmbedded-order, OppositeDuality<duality>::duality>
411  hodge() const;
412 
419  template <Duality duality>
421  flat(const VectorField<Self, duality>& vector_field) const;
422 
430  template <Duality duality>
432  flatDirectional(const Dimension& dir) const;
433 
440  template <Duality duality>
442  sharp(const KForm<Self, 1, duality>& one_form) const;
443 
451  template <Duality duality>
453  sharpDirectional(const Dimension& dir) const;
454 
462  SCell
463  getSCell(const Order& order, const Duality& duality, const Index& index) const;
464 
469  bool
470  isCellFlipped(const Cell& cell) const;
471 
476  bool
477  containsCell(const Cell& cell) const;
478 
484  Index
485  getCellIndex(const Cell& cell) const;
486 
492  Index
493  kFormLength(const Order& order, const Duality& duality) const;
494 
502  Order
503  actualOrder(const Order& order, const Duality& duality) const;
504 
511  Scalar
512  hodgeSign(const Cell& cell, const Duality& duality) const;
513 
519  Dimension
520  edgeDirection(const Cell& cell, const Duality& duality) const;
521 
525  void
526  resetSizes();
527 
532  bool
533  isValid() const;
534 
535  // ------------------------- Private Datas --------------------------------
536  private:
537 
541  Properties myCellProperties;
542 
547  IndexedSCells myIndexSignedCells;
548 
552  boost::array<boost::array<SparseMatrix, dimAmbient>, 2> myFlatOperatorMatrixes;
553 
557  boost::array<boost::array<SparseMatrix, dimAmbient>, 2> mySharpOperatorMatrixes;
558 
563 
568 
569 
570  // ------------------------- Hidden services ------------------------------
571  protected:
572 
573  // ------------------------- Internals ------------------------------------
574  private:
575 
579  void
581 
586  template <Duality duality>
587  void
589 
594  template <Duality duality>
595  void
597 
598  }; // end of class DiscreteExteriorCalculus
599 
600 
607  template <Dimension dimEmbedded, Dimension dimAmbient, typename TLinearAlgebraBackend, typename TInteger>
608  std::ostream&
609  operator<<(std::ostream& out, const DiscreteExteriorCalculus<dimEmbedded, dimAmbient, TLinearAlgebraBackend, TInteger>& object);
610 
611 } // namespace DGtal
612 
613 
615 // Includes inline functions.
616 #include "DGtal/dec/DiscreteExteriorCalculus.ih"
617 
618 // //
620 
621 #endif // !defined DiscreteExteriorCalculus_h
622 
623 #undef DiscreteExteriorCalculus_RECURSES
624 #endif // else defined(DiscreteExteriorCalculus_RECURSES)
boost::array< SCells, dimEmbedded+1 > IndexedSCells
ConstIterator end() const
LinearOperator< Self, 3, DUAL, 2, DUAL > DualAntiderivative3
Aim: DiscreteExteriorCalculus represents a calculus in the dec package. This is the main structure in...
LinearOperator< Self, 3, DUAL, 3, DUAL > DualIdentity3
VectorField< Self, DUAL > DualVectorField
LinearOperator< Self, 2, PRIMAL, 3, PRIMAL > PrimalDerivative2
LinearAlgebraBackend::DenseVector::Scalar Scalar
void selfDisplay(std::ostream &out) const
LinearOperator< Self, 0, DUAL, 1, DUAL > DualDerivative0
const SCells & getIndexedSCells() const
VectorField< Self, duality > sharp(const KForm< Self, 1, duality > &one_form) const
LinearOperator< Self, 1, DUAL, dimEmbedded-1, PRIMAL > DualHodge1
LinearOperator< Self, 1, DUAL, 2, DUAL > DualDerivative1
BOOST_STATIC_ASSERT((boost::is_same< Dimension, Order >::value))
LinearOperator< Self, 3, DUAL, dimEmbedded-3, PRIMAL > DualHodge3
LinearAlgebraBackend::SparseMatrix SparseMatrix
Aim: Represent any dynamic sized matrix having sparse or dense representation.
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
DGtal::uint32_t Dimension
Definition: Common.h:113
DGtal::KhalimskySpaceND< dimAmbient, TInteger > KSpace
Index getCellIndex(const Cell &cell) const
boost::array< boost::array< SparseMatrix, dimAmbient >, 2 > mySharpOperatorMatrixes
LinearOperator< Self, 0, PRIMAL, 1, PRIMAL > PrimalDerivative0
Aim: KForm represents discrete kforms in the dec package.
Definition: KForm.h:65
BOOST_CONCEPT_ASSERT((concepts::CInteger< TInteger >))
LinearOperator< Self, 1, duality, 0, duality > sharpDirectional(const Dimension &dir) const
Aim: Check right multiplication between matrix and vector and internal matrix multiplication. Matrix and vector scalar types should be the same.
boost::unordered_map< Cell, Property > Properties
LinearOperator< Self, order, duality, order, duality > identity() const
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
LinearOperator< Self, order, duality, order+1, duality > derivative() const
Order actualOrder(const Order &order, const Duality &duality) const
LinearOperator< Self, 1, PRIMAL, 1, PRIMAL > PrimalIdentity1
SCell getSCell(const Order &order, const Duality &duality, const Index &index) const
LinearOperator< Self, order, duality, order-1, duality > antiderivative() const
LinearOperator< Self, 2, DUAL, 1, DUAL > DualAntiderivative2
LinearOperator< Self, 0, PRIMAL, 0, PRIMAL > PrimalIdentity0
ConstIterator begin() const
bool eraseCell(const Cell &cell)
Aim: This class provides static members to create DEC structures from various other DGtal structures...
size_t hash_value(const KhalimskyCell< dim, TInteger > &cell)
LinearOperator< Self, 1, PRIMAL, 2, PRIMAL > PrimalDerivative1
bool containsCell(const Cell &cell) const
LinearOperator< Self, 2, DUAL, 3, DUAL > DualDerivative2
LinearOperator< Self, 0, DUAL, dimEmbedded-0, PRIMAL > DualHodge0
LinearOperator< Self, 1, PRIMAL, 0, PRIMAL > PrimalAntiderivative1
KForm< Self, 1, duality > flat(const VectorField< Self, duality > &vector_field) const
VectorField< Self, PRIMAL > PrimalVectorField
LinearOperator< Self, 2, DUAL, dimEmbedded-2, PRIMAL > DualHodge2
Aim: LinearOperator represents discrete linear operator between discrete kforms in the DEC package...
std::string className() const
Holds size 'primal_size', 'dual_size', 'index' and 'flipped' for each cell of the DEC object...
DGtal is the top-level namespace which contains all DGtal functions and types.
LinearOperator< Self, 1, DUAL, 0, DUAL > DualAntiderivative1
Scalar hodgeSign(const Cell &cell, const Duality &duality) const
LinearOperator< Self, 2, DUAL, 2, DUAL > DualIdentity2
Aim: Represent any dynamic sized column vector having sparse or dense representation.
LinearAlgebraBackend::DenseVector DenseVector
unsigned int Order
Aim: Order is used as template parameter for DEC classes.
Definition: Duality.h:87
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
LinearOperator< Self, 3, PRIMAL, 2, PRIMAL > PrimalAntiderivative3
bool isCellFlipped(const Cell &cell) const
void initKSpace(ConstAlias< TDomain > domain)
LinearOperator< Self, 1, PRIMAL, dimEmbedded-1, DUAL > PrimalHodge1
LinearOperator< Self, order, duality, dimEmbedded-order, OppositeDuality< duality >::duality > hodge() const
LinearOperator< Self, 2, PRIMAL, 2, PRIMAL > PrimalIdentity2
LinearOperator< Self, 3, PRIMAL, dimEmbedded-3, DUAL > PrimalHodge3
LinearOperator< Self, 0, DUAL, 0, DUAL > DualIdentity0
LinearOperator< Self, 2, PRIMAL, dimEmbedded-2, DUAL > PrimalHodge2
LinearOperator< Self, 2, PRIMAL, 1, PRIMAL > PrimalAntiderivative2
LinearOperator< Self, 0, PRIMAL, dimEmbedded-0, DUAL > PrimalHodge0
bool insertSCell(const SCell &signed_cell)
Properties::const_iterator ConstIterator
boost::array< boost::array< SparseMatrix, dimAmbient >, 2 > myFlatOperatorMatrixes
Duality
Aim: Duality enumerator tells if templated object lives in primal or dual space. Used as template par...
Definition: Duality.h:57
LinearOperator< Self, 0, duality, 0, duality > laplace() const
DiscreteExteriorCalculus< dimEmbedded, dimAmbient, TLinearAlgebraBackend, TInteger > Self
Dimension edgeDirection(const Cell &cell, const Duality &duality) const
LinearAlgebraBackend::DenseMatrix DenseMatrix
Represents an (unsigned) cell in a cellular grid space by its Khalimsky coordinates.
Aim: VectorField represents a discrete vector field in the dec package. Vector field values are attac...
Definition: VectorField.h:66
Index kFormLength(const Order &order, const Duality &duality) const
LinearOperator< Self, 1, DUAL, 1, DUAL > DualIdentity1
LinearOperator< Self, 3, PRIMAL, 3, PRIMAL > PrimalIdentity3
const Properties & getProperties() const
LinearOperator< Self, order, duality, order, duality > reorder(const TConstIterator &begin_range, const TConstIterator &end_range) const
LinearOperator< Self, 0, duality, 1, duality > flatDirectional(const Dimension &dir) const
BOOST_STATIC_CONSTANT(Dimension, dimensionEmbedded=dimEmbedded)
LinearAlgebraBackend::DenseVector::Index Index