DGtal  1.0.0
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 #include "DGtal/topology/CanonicSCellEmbedder.h"
59 
60 #include <DGtal/kernel/sets/CDigitalSet.h>
61 #include <DGtal/math/linalg/CDynamicMatrix.h>
62 #include <DGtal/math/linalg/CDynamicVector.h>
63 #include <DGtal/math/linalg/CLinearAlgebra.h>
65 
66 namespace DGtal
67 {
68  // forward factory declaration
69  template <typename TLinearAlgebraBackend, typename TInteger>
71 
77  template <Dimension dim, typename TInteger>
78  size_t
80 
82  // template class DiscreteExteriorCalculus
96  template <Dimension dimEmbedded, Dimension dimAmbient, typename TLinearAlgebraBackend, typename TInteger = DGtal::int32_t>
98  {
99  // ----------------------- Standard services ------------------------------
100  public:
101 
102  friend class DiscreteExteriorCalculusFactory<TLinearAlgebraBackend, TInteger>;
103 
105 
106  typedef TLinearAlgebraBackend LinearAlgebraBackend;
107  typedef typename LinearAlgebraBackend::DenseVector::Index Index;
108  typedef typename LinearAlgebraBackend::DenseVector::Scalar Scalar;
109  typedef typename LinearAlgebraBackend::DenseVector DenseVector;
112 
114 
120 
121  BOOST_STATIC_ASSERT(( boost::is_same<Dimension, Order>::value ));
122 
126  BOOST_STATIC_ASSERT(( dimAmbient >= dimEmbedded ));
127 
128  BOOST_STATIC_CONSTANT( Dimension, dimensionEmbedded = dimEmbedded );
129  BOOST_STATIC_CONSTANT( Dimension, dimensionAmbient = dimAmbient );
130 
132  typedef typename KSpace::Cell Cell;
133  typedef typename KSpace::SCell SCell;
134  typedef typename KSpace::Point Point;
135 
152  struct Property
153  {
157  bool flipped;
158  };
159 
163  typedef boost::unordered_map<Cell, Property> Properties;
164 
168  typedef std::vector<SCell> SCells;
169  typedef boost::array<SCells, dimEmbedded+1> IndexedSCells;
170 
176 
188 
198 
208 
212  typedef LinearOperator<Self, 0, PRIMAL, dimEmbedded-0, DUAL> PrimalHodge0;
213  typedef LinearOperator<Self, 1, PRIMAL, dimEmbedded-1, DUAL> PrimalHodge1;
214  typedef LinearOperator<Self, 2, PRIMAL, dimEmbedded-2, DUAL> PrimalHodge2;
215  typedef LinearOperator<Self, 3, PRIMAL, dimEmbedded-3, DUAL> PrimalHodge3;
216  typedef LinearOperator<Self, 0, DUAL, dimEmbedded-0, PRIMAL> DualHodge0;
217  typedef LinearOperator<Self, 1, DUAL, dimEmbedded-1, PRIMAL> DualHodge1;
218  typedef LinearOperator<Self, 2, DUAL, dimEmbedded-2, PRIMAL> DualHodge2;
219  typedef LinearOperator<Self, 3, DUAL, dimEmbedded-3, PRIMAL> DualHodge3;
220 
232 
238 
244  template <typename TDomain>
245  void
247 
248  // ----------------------- Iterators on property map -----------------------
249 
253  typedef typename Properties::const_iterator ConstIterator;
254 
258  ConstIterator begin() const;
259 
263  ConstIterator end() const;
264 
268  typedef typename Properties::iterator Iterator;
269 
273  Iterator begin();
274 
278  Iterator end();
279 
280  // ----------------------- Interface --------------------------------------
281  public:
282 
287 
292  void selfDisplay(std::ostream& out) const;
293 
297  std::string className() const;
298 
306  bool
307  insertSCell(const SCell& signed_cell);
308 
318  bool
319  insertSCell(const SCell& signed_cell, const Scalar& primal_size, const Scalar& dual_size);
320 
327  bool
328  eraseCell(const Cell& cell);
329 
334  void
335  updateIndexes();
336 
341  const Properties&
342  getProperties() const;
343 
350  template <Order order, Duality duality>
351  const SCells&
352  getIndexedSCells() const;
353 
362  template <Order order, Duality duality, typename TConstIterator>
364  reorder(const TConstIterator& begin_range, const TConstIterator& end_range) const;
365 
372  template <Order order, Duality duality>
374  identity() const;
375 
382  template <Order order, Duality duality>
384  derivative() const;
385 
392  template <Order order, Duality duality>
393  LinearOperator<Self, order, duality, order-1, duality>
394  antiderivative() const;
395 
400  template <Duality duality>
402  laplace() const;
403 
411  template <Duality duality>
413  heatLaplace(const typename DenseVector::Scalar& h, const typename DenseVector::Scalar& t, const typename DenseVector::Scalar& K) const;
414 
421  template <Order order, Duality duality>
422  LinearOperator<Self, order, duality, dimEmbedded-order, OppositeDuality<duality>::duality>
423  hodge() const;
424 
431  template <Duality duality>
433  flat(const VectorField<Self, duality>& vector_field) const;
434 
442  template <Duality duality>
444  flatDirectional(const Dimension& dir) const;
445 
452  template <Duality duality>
454  sharp(const KForm<Self, 1, duality>& one_form) const;
455 
463  template <Duality duality>
465  sharpDirectional(const Dimension& dir) const;
466 
474  SCell
475  getSCell(const Order& order, const Duality& duality, const Index& index) const;
476 
481  bool
482  isCellFlipped(const Cell& cell) const;
483 
488  bool
489  containsCell(const Cell& cell) const;
490 
496  Index
497  getCellIndex(const Cell& cell) const;
498 
504  Index
505  kFormLength(const Order& order, const Duality& duality) const;
506 
514  Order
515  actualOrder(const Order& order, const Duality& duality) const;
516 
523  Scalar
524  hodgeSign(const Cell& cell, const Duality& duality) const;
525 
531  Dimension
532  edgeDirection(const Cell& cell, const Duality& duality) const;
533 
537  void
538  resetSizes();
539 
544  bool
545  isValid() const;
546 
547  // ------------------------- Private Datas --------------------------------
548  private:
549 
554 
560 
564  boost::array<boost::array<SparseMatrix, dimAmbient>, 2> myFlatOperatorMatrixes;
565 
569  boost::array<boost::array<SparseMatrix, dimAmbient>, 2> mySharpOperatorMatrixes;
570 
575 
580 
581 
582  // ------------------------- Hidden services ------------------------------
583  protected:
584 
585  // ------------------------- Internals ------------------------------------
586  private:
587 
591  void
593 
598  template <Duality duality>
599  void
601 
606  template <Duality duality>
607  void
609 
610  }; // end of class DiscreteExteriorCalculus
611 
612 
619  template <Dimension dimEmbedded, Dimension dimAmbient, typename TLinearAlgebraBackend, typename TInteger>
620  std::ostream&
622 
623 } // namespace DGtal
624 
625 
627 // Includes inline functions.
628 #include "DGtal/dec/DiscreteExteriorCalculus.ih"
629 
630 // //
632 
633 #endif // !defined DiscreteExteriorCalculus_h
634 
635 #undef DiscreteExteriorCalculus_RECURSES
636 #endif // else defined(DiscreteExteriorCalculus_RECURSES)
boost::array< SCells, dimEmbedded+1 > IndexedSCells
LinearOperator< Self, 3, DUAL, 2, DUAL > DualAntiderivative3
Aim: DiscreteExteriorCalculus represents a calculus in the dec package. This is the main structure in...
ConstIterator end() const
LinearOperator< Self, 3, DUAL, 3, DUAL > DualIdentity3
Scalar hodgeSign(const Cell &cell, const Duality &duality) const
LinearOperator< Self, order, duality, order, duality > reorder(const TConstIterator &begin_range, const TConstIterator &end_range) const
VectorField< Self, DUAL > DualVectorField
LinearOperator< Self, 2, PRIMAL, 3, PRIMAL > PrimalDerivative2
LinearAlgebraBackend::DenseVector::Scalar Scalar
LinearOperator< Self, 0, DUAL, 1, DUAL > DualDerivative0
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
LinearOperator< Self, order, duality, dimEmbedded-order, OppositeDuality< duality >::duality > hodge() const
ConstIterator begin() const
Dimension edgeDirection(const Cell &cell, const Duality &duality) const
DGtal::uint32_t Dimension
Definition: Common.h:127
LinearOperator< Self, 0, duality, 1, duality > flatDirectional(const Dimension &dir) const
Index getCellIndex(const Cell &cell) const
DGtal::KhalimskySpaceND< dimAmbient, TInteger > KSpace
boost::array< boost::array< SparseMatrix, dimAmbient >, 2 > mySharpOperatorMatrixes
LinearOperator< Self, order, duality, order+1, duality > derivative() const
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 >))
const SCells & getIndexedSCells() const
LinearOperator< Self, order, duality, order, duality > identity() const
Aim: Check right multiplication between matrix and vector and internal matrix multiplication....
boost::unordered_map< Cell, Property > Properties
SCell getSCell(const Order &order, const Duality &duality, const Index &index) const
LinearOperator< Self, order, duality, order-1, duality > antiderivative() const
Domain domain
EigenLinearAlgebraBackend::DenseMatrix DenseMatrix
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
void selfDisplay(std::ostream &out) const
LinearOperator< Self, 1, PRIMAL, 1, PRIMAL > PrimalIdentity1
LinearOperator< Self, 2, DUAL, 1, DUAL > DualAntiderivative2
LinearOperator< Self, 0, PRIMAL, 0, PRIMAL > PrimalIdentity0
LinearOperator< Self, 0, duality, 0, duality > heatLaplace(const typename DenseVector::Scalar &h, const typename DenseVector::Scalar &t, const typename DenseVector::Scalar &K) 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
LinearOperator< Self, 2, DUAL, 3, DUAL > DualDerivative2
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
LinearOperator< Self, 0, DUAL, dimEmbedded-0, PRIMAL > DualHodge0
LinearOperator< Self, 0, duality, 0, duality > laplace() const
LinearOperator< Self, 1, PRIMAL, 0, PRIMAL > PrimalAntiderivative1
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.
bool containsCell(const Cell &cell) 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
EigenLinearAlgebraBackend::SparseMatrix SparseMatrix
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:89
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
LinearOperator< Self, 3, PRIMAL, 2, PRIMAL > PrimalAntiderivative3
Order actualOrder(const Order &order, const Duality &duality) const
void initKSpace(ConstAlias< TDomain > domain)
LinearOperator< Self, 1, PRIMAL, dimEmbedded-1, DUAL > PrimalHodge1
std::string className() const
LinearOperator< Self, 2, PRIMAL, 2, PRIMAL > PrimalIdentity2
LinearOperator< Self, 3, PRIMAL, dimEmbedded-3, DUAL > PrimalHodge3
KForm< Self, 1, duality > flat(const VectorField< Self, duality > &vector_field) const
LinearOperator< Self, 0, DUAL, 0, DUAL > DualIdentity0
const Properties & getProperties() const
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)
bool isCellFlipped(const Cell &cell) const
Properties::const_iterator ConstIterator
boost::array< boost::array< SparseMatrix, dimAmbient >, 2 > myFlatOperatorMatrixes
KSpace K
Duality
Aim: Duality enumerator tells if templated object lives in primal or dual space. Used as template par...
Definition: Duality.h:59
DiscreteExteriorCalculus< dimEmbedded, dimAmbient, TLinearAlgebraBackend, TInteger > Self
LinearOperator< Self, 1, duality, 0, duality > sharpDirectional(const Dimension &dir) 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:67
LinearOperator< Self, 1, DUAL, 1, DUAL > DualIdentity1
LinearOperator< Self, 3, PRIMAL, 3, PRIMAL > PrimalIdentity3
BOOST_STATIC_CONSTANT(Dimension, dimensionEmbedded=dimEmbedded)
Index kFormLength(const Order &order, const Duality &duality) const
LinearAlgebraBackend::DenseVector::Index Index