DGtal  1.5.beta
DGtal::GeodesicsInHeat< TPolygonalCalculus > Class Template Reference

This class implements [41] on polygonal surfaces (using Discrete differential calculus on polygonal surfaces). More...

#include <DGtal/dec/GeodesicsInHeat.h>

Public Types

typedef TPolygonalCalculus PolygonalCalculus
 
typedef PolygonalCalculus::SparseMatrix SparseMatrix
 
typedef PolygonalCalculus::DenseMatrix DenseMatrix
 
typedef PolygonalCalculus::Solver Solver
 
typedef PolygonalCalculus::Vector Vector
 
typedef PolygonalCalculus::Vertex Vertex
 
typedef PolygonalCalculus::LinAlg LinAlgBackend
 
typedef DirichletConditions< LinAlgBackendConditions
 
typedef Conditions::IntegerVector IntegerVector
 

Public Member Functions

 GeodesicsInHeat ()=delete
 
 GeodesicsInHeat (ConstAlias< PolygonalCalculus > calculus)
 
 ~GeodesicsInHeat ()=default
 
 GeodesicsInHeat (const GeodesicsInHeat &other)=delete
 
 GeodesicsInHeat (GeodesicsInHeat &&other)=delete
 
GeodesicsInHeatoperator= (const GeodesicsInHeat &other)=delete
 
GeodesicsInHeatoperator= (GeodesicsInHeat &&other)=delete
 
void init (double dt, double lambda=1.0, bool boundary_with_mixed_solution=false)
 
void addSource (const Vertex aV)
 
void clearSource ()
 
Vector source () const
 
Vector compute () const
 
bool isValid () const
 

Private Attributes

const PolygonalCalculusmyCalculus
 The underlying PolygonalCalculus instance. More...
 
SparseMatrix myHeatOpe
 The operator for heat diffusion. More...
 
Solver myPoissonSolver
 Poisson solver. More...
 
Solver myHeatSolver
 Heat solver. More...
 
Vector mySource
 Source vector. More...
 
Vertex myLastSourceIndex
 Vertex index to the last source point (to shift the distances) More...
 
bool myIsInit
 Validitate flag. More...
 
double myLambda
 Lambda parameter. More...
 
bool myManageBoundary
 
IntegerVector myBoundary
 The boundary characteristic vector. More...
 
Solver myHeatDirichletSolver
 Heat solver with Dirichlet boundary conditions. More...
 

Detailed Description

template<typename TPolygonalCalculus>
class DGtal::GeodesicsInHeat< TPolygonalCalculus >

This class implements [41] on polygonal surfaces (using Discrete differential calculus on polygonal surfaces).

Description of template class 'GeodesicsInHeat'

see Geodesics In Heat using discrete polygonal calculus for details and examples.

Template Parameters
amodel of PolygonalCalculus.

Definition at line 62 of file GeodesicsInHeat.h.

Member Typedef Documentation

◆ Conditions

template<typename TPolygonalCalculus >
typedef DirichletConditions< LinAlgBackend > DGtal::GeodesicsInHeat< TPolygonalCalculus >::Conditions

Definition at line 74 of file GeodesicsInHeat.h.

◆ DenseMatrix

template<typename TPolygonalCalculus >
typedef PolygonalCalculus::DenseMatrix DGtal::GeodesicsInHeat< TPolygonalCalculus >::DenseMatrix

Definition at line 69 of file GeodesicsInHeat.h.

◆ IntegerVector

template<typename TPolygonalCalculus >
typedef Conditions::IntegerVector DGtal::GeodesicsInHeat< TPolygonalCalculus >::IntegerVector

Definition at line 75 of file GeodesicsInHeat.h.

◆ LinAlgBackend

template<typename TPolygonalCalculus >
typedef PolygonalCalculus::LinAlg DGtal::GeodesicsInHeat< TPolygonalCalculus >::LinAlgBackend

Definition at line 73 of file GeodesicsInHeat.h.

◆ PolygonalCalculus

template<typename TPolygonalCalculus >
typedef TPolygonalCalculus DGtal::GeodesicsInHeat< TPolygonalCalculus >::PolygonalCalculus

Definition at line 67 of file GeodesicsInHeat.h.

◆ Solver

template<typename TPolygonalCalculus >
typedef PolygonalCalculus::Solver DGtal::GeodesicsInHeat< TPolygonalCalculus >::Solver

Definition at line 70 of file GeodesicsInHeat.h.

◆ SparseMatrix

template<typename TPolygonalCalculus >
typedef PolygonalCalculus::SparseMatrix DGtal::GeodesicsInHeat< TPolygonalCalculus >::SparseMatrix

Definition at line 68 of file GeodesicsInHeat.h.

◆ Vector

template<typename TPolygonalCalculus >
typedef PolygonalCalculus::Vector DGtal::GeodesicsInHeat< TPolygonalCalculus >::Vector

Definition at line 71 of file GeodesicsInHeat.h.

◆ Vertex

template<typename TPolygonalCalculus >
typedef PolygonalCalculus::Vertex DGtal::GeodesicsInHeat< TPolygonalCalculus >::Vertex

Definition at line 72 of file GeodesicsInHeat.h.

Constructor & Destructor Documentation

◆ GeodesicsInHeat() [1/4]

template<typename TPolygonalCalculus >
DGtal::GeodesicsInHeat< TPolygonalCalculus >::GeodesicsInHeat ( )
delete

Default constructor.

◆ GeodesicsInHeat() [2/4]

template<typename TPolygonalCalculus >
DGtal::GeodesicsInHeat< TPolygonalCalculus >::GeodesicsInHeat ( ConstAlias< PolygonalCalculus calculus)
inline

Constructor from an existing polygonal calculus. T

Parameters
calculusa instance of PolygonalCalculus

Definition at line 84 of file GeodesicsInHeat.h.

85  {
86  myIsInit=false;
87  }
const PolygonalCalculus * myCalculus
The underlying PolygonalCalculus instance.
bool myIsInit
Validitate flag.
PolyCalculus * calculus

References DGtal::GeodesicsInHeat< TPolygonalCalculus >::myIsInit.

◆ ~GeodesicsInHeat()

template<typename TPolygonalCalculus >
DGtal::GeodesicsInHeat< TPolygonalCalculus >::~GeodesicsInHeat ( )
default

Destructor.

◆ GeodesicsInHeat() [3/4]

template<typename TPolygonalCalculus >
DGtal::GeodesicsInHeat< TPolygonalCalculus >::GeodesicsInHeat ( const GeodesicsInHeat< TPolygonalCalculus > &  other)
delete

Copy constructor.

Parameters
otherthe object to clone.

◆ GeodesicsInHeat() [4/4]

template<typename TPolygonalCalculus >
DGtal::GeodesicsInHeat< TPolygonalCalculus >::GeodesicsInHeat ( GeodesicsInHeat< TPolygonalCalculus > &&  other)
delete

Move constructor.

Parameters
otherthe object to move.

Member Function Documentation

◆ addSource()

template<typename TPolygonalCalculus >
void DGtal::GeodesicsInHeat< TPolygonalCalculus >::addSource ( const Vertex  aV)
inline

Adds a source point at a vertex aV

Parameters
aVthe Vertex

Definition at line 183 of file GeodesicsInHeat.h.

184  {
185  ASSERT_MSG(aV < myCalculus->nbVertices(), "Vertex is not in the surface mesh vertex range");
186  myLastSourceIndex = aV;
187  mySource( aV ) = 1.0;
188  }
Vertex myLastSourceIndex
Vertex index to the last source point (to shift the distances)
Vector mySource
Source vector.

References DGtal::GeodesicsInHeat< TPolygonalCalculus >::myLastSourceIndex, and DGtal::GeodesicsInHeat< TPolygonalCalculus >::mySource.

◆ clearSource()

template<typename TPolygonalCalculus >
void DGtal::GeodesicsInHeat< TPolygonalCalculus >::clearSource ( )
inline

Removes all source Diracs.

Definition at line 192 of file GeodesicsInHeat.h.

193  {
194  mySource = Vector::Zero(myCalculus->nbVertices());
195  }

References DGtal::GeodesicsInHeat< TPolygonalCalculus >::myCalculus, and DGtal::GeodesicsInHeat< TPolygonalCalculus >::mySource.

◆ compute()

template<typename TPolygonalCalculus >
Vector DGtal::GeodesicsInHeat< TPolygonalCalculus >::compute ( ) const
inline

Main computation of the Geodesic In Heat

Returns
the estimated geodesic distances from the sources.

Definition at line 209 of file GeodesicsInHeat.h.

210  {
211  FATAL_ERROR_MSG(myIsInit, "init() method must be called first");
212  //Heat diffusion
213  Vector heatDiffusion = myHeatSolver.solve(mySource);
214  ASSERT(myHeatSolver.info()==Eigen::Success);
215 
216  // Take care of boundaries
217  if ( myManageBoundary )
218  {
219  Vector bValues = Vector::Zero( myCalculus->nbVertices() );
221  myBoundary, bValues );
222  Vector bSol = myHeatDirichletSolver.solve( bSources );
223  Vector heatDiffusionDirichlet
224  = Conditions::dirichletSolution( bSol, myBoundary, bValues );
225  heatDiffusion = 0.5 * ( heatDiffusion + heatDiffusionDirichlet );
226  }
227  Vector divergence = Vector::Zero(myCalculus->nbVertices());
228  auto cpt=0;
229  auto surfmesh = myCalculus->getSurfaceMeshPtr();
230 
231  // Heat, normalization and divergence per face
232  for(typename PolygonalCalculus::MySurfaceMesh::Index f=0; f< myCalculus->nbFaces(); ++f)
233  {
234  Vector faceHeat( myCalculus->degree(f));
235  cpt=0;
236  auto vertices = surfmesh->incidentVertices(f);
237  for(auto v: vertices)
238  {
239  faceHeat(cpt) = heatDiffusion( v );
240  ++cpt;
241  }
242  // ∇heat / ∣∣∇heat∣∣
243  Vector grad = -myCalculus->gradient(f) * faceHeat;
244  grad.normalize();
245 
246  // div
247  DenseMatrix oneForm = myCalculus->flat(f)*grad;
248  Vector divergenceFace = myCalculus->divergence( f ) * oneForm;
249  cpt=0;
250  for(auto v: vertices)
251  {
252  divergence(v) += divergenceFace(cpt);
253  ++cpt;
254  }
255  }
256 
257  // Last Poisson solve
258  Vector distVec = myPoissonSolver.solve(divergence);
259  ASSERT(myPoissonSolver.info()==Eigen::Success);
260 
261  //Source val
262  auto sourceval = distVec(myLastSourceIndex);
263  //shifting the distances to get 0 at sources
264  return distVec - sourceval*Vector::Ones(myCalculus->nbVertices());
265  }
static DenseVector dirichletVector(const SparseMatrix &A, const DenseVector &b, const IntegerVector &p, const DenseVector &u)
static DenseVector dirichletSolution(const DenseVector &xd, const IntegerVector &p, const DenseVector &u)
Solver myHeatSolver
Heat solver.
SparseMatrix myHeatOpe
The operator for heat diffusion.
IntegerVector myBoundary
The boundary characteristic vector.
Solver myPoissonSolver
Poisson solver.
Solver myHeatDirichletSolver
Heat solver with Dirichlet boundary conditions.
SurfMesh surfmesh
DigitalPlane::Point Vector
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
std::size_t Index
The type used for numbering vertices and faces.
Definition: SurfaceMesh.h:105
EigenLinearAlgebraBackend::DenseMatrix DenseMatrix

References DGtal::DirichletConditions< TLinearAlgebraBackend >::dirichletSolution(), DGtal::DirichletConditions< TLinearAlgebraBackend >::dirichletVector(), DGtal::GeodesicsInHeat< TPolygonalCalculus >::myBoundary, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myCalculus, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myHeatDirichletSolver, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myHeatOpe, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myHeatSolver, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myIsInit, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myLastSourceIndex, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myManageBoundary, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myPoissonSolver, DGtal::GeodesicsInHeat< TPolygonalCalculus >::mySource, and surfmesh.

◆ init()

template<typename TPolygonalCalculus >
void DGtal::GeodesicsInHeat< TPolygonalCalculus >::init ( double  dt,
double  lambda = 1.0,
bool  boundary_with_mixed_solution = false 
)
inline

Initialize the solvers with dt as timestep for the heat diffusion and lambda parameter for the polygonal calculus, which guarantee definiteness for positive lambda.

Parameters
dtthe timestep
lambdatimestep
boundary_with_mixed_solutionwhen 'true' and when the surface has boundaries, mix two solutions of the heat diffusion operation (Neumann and Dirichlet null conditions on boundary).

Definition at line 135 of file GeodesicsInHeat.h.

137  {
138  myIsInit = true;
139  myLambda = lambda;
140 
141  SparseMatrix laplacian = myCalculus->globalLaplaceBeltrami( lambda );
142  SparseMatrix mass = myCalculus->globalLumpedMassMatrix();
143  myHeatOpe = mass - dt*laplacian;
144 
145  // from https://geometry-central.net
146  // NOTE: In theory, it should not be necessary to shift the Laplacian: the Polydec Laplace is always PSD. However, when the
147  // matrix is only positive SEMIdefinite, some solvers may not work (ie Eigen's Cholesky solver doesn't work, but
148  // Suitesparse does).
149  SparseMatrix Id = SparseMatrix(myCalculus->nbVertices(),myCalculus->nbVertices());
150  Id.setIdentity();
151  laplacian += 1e-6 * Id;
152 
153  //Prefactorizing
154  myPoissonSolver.compute( laplacian );
155  myHeatSolver.compute ( myHeatOpe );
156 
157  //empty source
158  mySource = Vector::Zero(myCalculus->nbVertices());
159 
160  // Manage boundaries
161  myManageBoundary = false;
162  if ( ! boundary_with_mixed_solution ) return;
163  myBoundary = IntegerVector::Zero(myCalculus->nbVertices());
164  const auto surfmesh = myCalculus->getSurfaceMeshPtr();
165  const auto edges = surfmesh->computeManifoldBoundaryEdges();
166  for ( auto e : edges )
167  {
168  const auto vtcs = surfmesh->edgeVertices( e );
169  myBoundary[ vtcs.first ] = 1;
170  myBoundary[ vtcs.second ] = 1;
171  }
172  myManageBoundary = ! edges.empty();
173  if ( ! myManageBoundary ) return;
174  // Prepare solver for a problem with Dirichlet conditions.
176  // Prefactoring
177  myHeatDirichletSolver.compute( heatOpe_d );
178  }
static SparseMatrix dirichletOperator(const SparseMatrix &A, const IntegerVector &p)
double myLambda
Lambda parameter.
PolygonalCalculus::SparseMatrix SparseMatrix
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator > edges(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
void laplacian(Shape &shape, const Options &options, std::function< double(const RealPoint3D &)> input_function, std::function< double(const RealPoint3D &)> target_function, int argc, char **argv)
EigenLinearAlgebraBackend::SparseMatrix SparseMatrix

References DGtal::DirichletConditions< TLinearAlgebraBackend >::dirichletOperator(), dt, laplacian(), DGtal::GeodesicsInHeat< TPolygonalCalculus >::myBoundary, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myCalculus, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myHeatDirichletSolver, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myHeatOpe, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myHeatSolver, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myIsInit, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myLambda, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myManageBoundary, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myPoissonSolver, DGtal::GeodesicsInHeat< TPolygonalCalculus >::mySource, and surfmesh.

◆ isValid()

template<typename TPolygonalCalculus >
bool DGtal::GeodesicsInHeat< TPolygonalCalculus >::isValid ( ) const
inline
Returns
true if the calculus is valid.

Definition at line 269 of file GeodesicsInHeat.h.

270  {
271  return myIsInit && myCalculus->isValid();
272  }

References DGtal::GeodesicsInHeat< TPolygonalCalculus >::myCalculus, and DGtal::GeodesicsInHeat< TPolygonalCalculus >::myIsInit.

◆ operator=() [1/2]

template<typename TPolygonalCalculus >
GeodesicsInHeat& DGtal::GeodesicsInHeat< TPolygonalCalculus >::operator= ( const GeodesicsInHeat< TPolygonalCalculus > &  other)
delete

Copy assignment operator.

Parameters
otherthe object to copy.
Returns
a reference on 'this'.

◆ operator=() [2/2]

template<typename TPolygonalCalculus >
GeodesicsInHeat& DGtal::GeodesicsInHeat< TPolygonalCalculus >::operator= ( GeodesicsInHeat< TPolygonalCalculus > &&  other)
delete

Move assignment operator.

Parameters
otherthe object to move.
Returns
a reference on 'this'.

◆ source()

template<typename TPolygonalCalculus >
Vector DGtal::GeodesicsInHeat< TPolygonalCalculus >::source ( ) const
inline
Returns
the source point vector.

Definition at line 200 of file GeodesicsInHeat.h.

201  {
202  FATAL_ERROR_MSG(myIsInit, "init() method must be called first");
203  return mySource;
204  }

References DGtal::GeodesicsInHeat< TPolygonalCalculus >::myIsInit, and DGtal::GeodesicsInHeat< TPolygonalCalculus >::mySource.

Field Documentation

◆ myBoundary

template<typename TPolygonalCalculus >
IntegerVector DGtal::GeodesicsInHeat< TPolygonalCalculus >::myBoundary
private

The boundary characteristic vector.

Definition at line 307 of file GeodesicsInHeat.h.

Referenced by DGtal::GeodesicsInHeat< TPolygonalCalculus >::compute(), and DGtal::GeodesicsInHeat< TPolygonalCalculus >::init().

◆ myCalculus

◆ myHeatDirichletSolver

template<typename TPolygonalCalculus >
Solver DGtal::GeodesicsInHeat< TPolygonalCalculus >::myHeatDirichletSolver
private

Heat solver with Dirichlet boundary conditions.

Definition at line 310 of file GeodesicsInHeat.h.

Referenced by DGtal::GeodesicsInHeat< TPolygonalCalculus >::compute(), and DGtal::GeodesicsInHeat< TPolygonalCalculus >::init().

◆ myHeatOpe

template<typename TPolygonalCalculus >
SparseMatrix DGtal::GeodesicsInHeat< TPolygonalCalculus >::myHeatOpe
private

The operator for heat diffusion.

Definition at line 282 of file GeodesicsInHeat.h.

Referenced by DGtal::GeodesicsInHeat< TPolygonalCalculus >::compute(), and DGtal::GeodesicsInHeat< TPolygonalCalculus >::init().

◆ myHeatSolver

template<typename TPolygonalCalculus >
Solver DGtal::GeodesicsInHeat< TPolygonalCalculus >::myHeatSolver
private

◆ myIsInit

◆ myLambda

template<typename TPolygonalCalculus >
double DGtal::GeodesicsInHeat< TPolygonalCalculus >::myLambda
private

Lambda parameter.

Definition at line 300 of file GeodesicsInHeat.h.

Referenced by DGtal::GeodesicsInHeat< TPolygonalCalculus >::init().

◆ myLastSourceIndex

template<typename TPolygonalCalculus >
Vertex DGtal::GeodesicsInHeat< TPolygonalCalculus >::myLastSourceIndex
private

Vertex index to the last source point (to shift the distances)

Definition at line 294 of file GeodesicsInHeat.h.

Referenced by DGtal::GeodesicsInHeat< TPolygonalCalculus >::addSource(), and DGtal::GeodesicsInHeat< TPolygonalCalculus >::compute().

◆ myManageBoundary

template<typename TPolygonalCalculus >
bool DGtal::GeodesicsInHeat< TPolygonalCalculus >::myManageBoundary
private

When 'true', manage boundaries with a mixed solution of Neumann and Dirichlet conditions.

Definition at line 304 of file GeodesicsInHeat.h.

Referenced by DGtal::GeodesicsInHeat< TPolygonalCalculus >::compute(), and DGtal::GeodesicsInHeat< TPolygonalCalculus >::init().

◆ myPoissonSolver

template<typename TPolygonalCalculus >
Solver DGtal::GeodesicsInHeat< TPolygonalCalculus >::myPoissonSolver
private

◆ mySource


The documentation for this class was generated from the following file: