DGtal  1.5.beta
DGtal::dec_helper Namespace Reference

Namespace for functions useful to Discrete Exterior Calculus package. More...

## Functions

template<typename Calculus , DGtal::Dimension dim, DGtal::Duality duality>
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > diagonal (const DGtal::KForm< Calculus, dim, duality > &kform)

template<typename Calculus >
DGtal::LinearOperator< Calculus, 0, DGtal::PRIMAL, 1, DGtal::PRIMALaverageOperator01 (const Calculus &calculus)

template<typename Calculus >
DGtal::LinearOperator< Calculus, 1, DGtal::PRIMAL, 2, DGtal::PRIMALaverageOperator01 (const Calculus &calculus)

template<typename Calculus >
DGtal::LinearOperator< Calculus, 2, DGtal::PRIMAL, 0, DGtal::PRIMALaverageOperator20 (const Calculus &calculus)

## Detailed Description

Namespace for functions useful to Discrete Exterior Calculus package.

## ◆ averageOperator01() [1/2]

template<typename Calculus >
 DGtal::LinearOperator DGtal::dec_helper::averageOperator01 ( const Calculus & calculus )

Builds the linear operator that brings a primal 0-form to a primal 1-form by averaging (vertex to edge operator)

Parameters
 calculus any discrete calculus

Definition at line 82 of file DECHelpers.h.

83  {
84  auto M01 = calculus.template derivative<0,DGtal::PRIMAL>();
85  M01.myContainer = 0.5 * M01.myContainer.cwiseAbs();
86  return M01;
87  }
PolyCalculus * calculus

References calculus.

## ◆ averageOperator01() [2/2]

template<typename Calculus >
 DGtal::LinearOperator DGtal::dec_helper::averageOperator01 ( const Calculus & calculus )

Builds the linear operator that brings a primal 1-form to a primal 2-form by averaging (edge to face operator)

Parameters
 calculus any discrete calculus

Definition at line 95 of file DECHelpers.h.

96  {
97  auto M12 = calculus.template derivative<1,DGtal::PRIMAL>();
98  M12.myContainer = 0.25 * M12.myContainer.cwiseAbs();
99  return M12;
100  }

References calculus.

## ◆ averageOperator20()

template<typename Calculus >
 DGtal::LinearOperator DGtal::dec_helper::averageOperator20 ( const Calculus & calculus )

Builds the linear operator that brings a primal 2-form to a primal 0-form by averaging (face to vertex operator)

Parameters
 calculus a discrete calculus over a 2D digital surface in 3D.

Definition at line 108 of file DECHelpers.h.

109  {
110  BOOST_STATIC_ASSERT( Calculus::dimensionEmbedded == 2 );
111  BOOST_STATIC_ASSERT( Calculus::dimensionAmbient == 3 );
112  using DGtal::PRIMAL;
113  using DGtal::DUAL;
114
116  typedef typename Calculus::LinearAlgebraBackend::Triplet Triplet;
117  typedef typename Calculus::KSpace KSpace;
118  typedef typename Calculus::Index Index;
119  typedef typename Calculus::Cell Cell;
120  typedef typename Calculus::Scalar Scalar;
121  typedef typename Calculus::Point Point;
123  Operator;
124
125  const KSpace& kspace = calculus.myKSpace;
126
127  const std::vector<Point> deltas = {
128  Point(0,1,1), Point(0,-1,1), Point(0,-1,-1), Point(0,1,-1),
129  Point(1,0,1), Point(-1,0,1), Point(-1,0,-1), Point(1,0,-1),
130  Point(1,1,0), Point(-1,1,0), Point(-1,-1,0), Point(1,-1,0)
131  };
132
133  std::vector<Triplet> triplets;
134  for (Index index_point=0; index_point<calculus.kFormLength(0,PRIMAL); index_point++)
135  {
136  const Cell point = kspace.unsigns(calculus.getSCell(0, PRIMAL, index_point));
137  ASSERT( kspace.uDim(point) == 0 );
138
139  std::vector<Index> indexes_surfel;
140  for (const Point delta : deltas)
141  {
142  const Cell surfel = kspace.uCell((kspace.uKCoords(point)+delta));
143  ASSERT( kspace.uDim(surfel) == 2 );
144  if (calculus.containsCell(surfel))
145  indexes_surfel.push_back(calculus.getCellIndex(surfel));
146  }
147  ASSERT( indexes_surfel.size() > 2 );
148
149  const double weight = 1/static_cast<Scalar>(indexes_surfel.size());
150  for (const Index index_surfel : indexes_surfel)
151  triplets.emplace_back( index_point, index_surfel, weight );
152  }
153
154  SparseMatrix matrix( calculus.kFormLength(0, DGtal::PRIMAL),
155  calculus.kFormLength(2, DGtal::PRIMAL) );
156  matrix.setFromTriplets(triplets.begin(), triplets.end());
157
158  return Operator(calculus, matrix);
159  }
Aim: LinearOperator represents discrete linear operator between discrete kforms in the DEC package.
SMesh::Index Index
@ PRIMAL
Definition: Duality.h:61
@ DUAL
Definition: Duality.h:62
MyPointD Point
Definition: testClone2.cpp:383
KSpace::Cell Cell
EigenLinearAlgebraBackend::SparseMatrix SparseMatrix

## ◆ diagonal()

template<typename Calculus , DGtal::Dimension dim, DGtal::Duality duality>
 DGtal::LinearOperator DGtal::dec_helper::diagonal ( const DGtal::KForm< Calculus, dim, duality > & kform )

Builds a linear diagonal operator from a k-form. Corresponds to Diag(v) if v is a vector.

Parameters
 kform any k-dimensional form.
Returns
the corresponding diagonal linear operator.

Definition at line 60 of file DECHelpers.h.

61  {
63  typedef typename Calculus::LinearAlgebraBackend::Triplet Triplet;
64  typedef typename Calculus::Index Index;
65  typedef std::vector<Triplet> Triplets;
66
67  Triplets triplets;
68  for (Index index=0; index<kform.length(); index++)
69  triplets.emplace_back( index, index, kform.myContainer(index) );
70  Operator ope(kform.myCalculus);
71  ope.myContainer.setFromTriplets(triplets.begin(), triplets.end());
72
73  return ope;
74  }
const Calculus * myCalculus
Definition: KForm.h:136
Container myContainer
Definition: KForm.h:131
Index length() const