DGtal  1.3.beta
Public Types | Public Member Functions | Private Attributes
DGtal::GeodesicsInHeat< TPolygonalCalculus > Class Template Reference

This class implements [39] 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)
 
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 [39] 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.

84  : myCalculus(&calculus)
85  {
86  myIsInit=false;
87  }

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 175 of file GeodesicsInHeat.h.

176  {
177  ASSERT_MSG(aV < myCalculus->nbVertices(), "Vertex is not in the surface mesh vertex range");
178  myLastSourceIndex = aV;
179  mySource( aV ) = 1.0;
180  }

References DGtal::GeodesicsInHeat< TPolygonalCalculus >::myLastSourceIndex, 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 194 of file GeodesicsInHeat.h.

195  {
196  FATAL_ERROR_MSG(myIsInit, "init() method must be called first");
197  //Heat diffusion
198  Vector heatDiffusion = myHeatSolver.solve(mySource);
199  // Take care of boundaries
200  if ( myManageBoundary )
201  {
202  Vector bValues = Vector::Zero( myCalculus->nbVertices() );
204  myBoundary, bValues );
205  Vector bSol = myHeatDirichletSolver.solve( bSources );
206  Vector heatDiffusionDirichlet
207  = Conditions::dirichletSolution( bSol, myBoundary, bValues );
208  heatDiffusion = 0.5 * ( heatDiffusion + heatDiffusionDirichlet );
209  }
210 
211  Vector divergence = Vector::Zero(myCalculus->nbVertices());
212  auto cpt=0;
213  auto surfmesh = myCalculus->getSurfaceMeshPtr();
214 
215  // Heat, normalization and divergence per face
216  for(auto f=0; f< myCalculus->nbFaces(); ++f)
217  {
218  Vector faceHeat( myCalculus->degree(f));
219  cpt=0;
220  auto vertices = surfmesh->incidentVertices(f);
221  for(auto v: vertices)
222  {
223  faceHeat(cpt) = heatDiffusion( v );
224  ++cpt;
225  }
226  // ∇heat / ∣∣∇heat∣∣
227  Vector grad = -myCalculus->gradient(f) * faceHeat;
228  grad.normalize();
229 
230  // div
231  DenseMatrix oneForm = myCalculus->flat(f)*grad;
232  Vector divergenceFace = myCalculus->divergence( f, myLambda ) * oneForm;
233  cpt=0;
234  for(auto v: vertices)
235  {
236  divergence(v) += divergenceFace(cpt);
237  ++cpt;
238  }
239  }
240 
241  // Last Poisson solve
242  Vector distVec = myPoissonSolver.solve(divergence);
243 
244  //Source val
245  auto sourceval = distVec(myLastSourceIndex);
246 
247  //shifting the distances to get 0 at sources
248  return distVec - sourceval*Vector::Ones(myCalculus->nbVertices());
249  }

References DGtal::DirichletConditions< TLinearAlgebraBackend >::dirichletSolution(), DGtal::DirichletConditions< TLinearAlgebraBackend >::dirichletVector(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::incidentVertices(), 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 >::myLastSourceIndex, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myManageBoundary, DGtal::GeodesicsInHeat< TPolygonalCalculus >::myPoissonSolver, and DGtal::GeodesicsInHeat< TPolygonalCalculus >::mySource.

◆ 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  //Prefactorizing
146  myPoissonSolver.compute( laplacian );
147  myHeatSolver.compute ( myHeatOpe );
148 
149  //empty source
150  mySource = Vector::Zero(myCalculus->nbVertices());
151 
152  // Manage boundaries
153  myManageBoundary = false;
154  if ( ! boundary_with_mixed_solution ) return;
155  myBoundary = IntegerVector::Zero(myCalculus->nbVertices());
156  const auto surfmesh = myCalculus->getSurfaceMeshPtr();
157  const auto edges = surfmesh->computeManifoldBoundaryEdges();
158  for ( auto e : edges )
159  {
160  const auto vtcs = surfmesh->edgeVertices( e );
161  myBoundary[ vtcs.first ] = 1;
162  myBoundary[ vtcs.second ] = 1;
163  }
164  myManageBoundary = ! edges.empty();
165  if ( ! myManageBoundary ) return;
166  // Prepare solver for a problem with Dirichlet conditions.
168  // Prefactoring
169  myHeatDirichletSolver.compute( heatOpe_d );
170  }

References DGtal::SurfaceMesh< TRealPoint, TRealVector >::computeManifoldBoundaryEdges(), DGtal::DirichletConditions< TLinearAlgebraBackend >::dirichletOperator(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::edgeVertices(), 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, and DGtal::GeodesicsInHeat< TPolygonalCalculus >::mySource.

◆ isValid()

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

Definition at line 253 of file GeodesicsInHeat.h.

254  {
255  return myIsInit && myCalculus->isValid();
256  }

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 185 of file GeodesicsInHeat.h.

186  {
187  FATAL_ERROR_MSG(myIsInit, "init() method must be called first");
188  return mySource;
189  }

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 291 of file GeodesicsInHeat.h.

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

◆ myCalculus

template<typename TPolygonalCalculus >
const PolygonalCalculus* DGtal::GeodesicsInHeat< TPolygonalCalculus >::myCalculus
private

◆ myHeatDirichletSolver

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

Heat solver with Dirichlet boundary conditions.

Definition at line 294 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 266 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

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

◆ myLambda

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

◆ myLastSourceIndex

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

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

Definition at line 278 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 288 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

template<typename TPolygonalCalculus >
Vector DGtal::GeodesicsInHeat< TPolygonalCalculus >::mySource
private

The documentation for this class was generated from the following file:
DGtal::GeodesicsInHeat::myBoundary
IntegerVector myBoundary
The boundary characteristic vector.
Definition: GeodesicsInHeat.h:291
DGtal::GeodesicsInHeat::myCalculus
const PolygonalCalculus * myCalculus
The underlying PolygonalCalculus instance.
Definition: GeodesicsInHeat.h:263
DGtal::DirichletConditions::dirichletVector
static DenseVector dirichletVector(const SparseMatrix &A, const DenseVector &b, const IntegerVector &p, const DenseVector &u)
Definition: DirichletConditions.h:170
boost::edges
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator > edges(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
Definition: DigitalSurfaceBoostGraphInterface.h:503
DGtal::SurfaceMesh::computeManifoldBoundaryEdges
Edges computeManifoldBoundaryEdges() const
DGtal::GeodesicsInHeat::myHeatOpe
SparseMatrix myHeatOpe
The operator for heat diffusion.
Definition: GeodesicsInHeat.h:266
DGtal::DirichletConditions::dirichletSolution
static DenseVector dirichletSolution(const DenseVector &xd, const IntegerVector &p, const DenseVector &u)
Definition: DirichletConditions.h:203
DGtal::DirichletConditions::dirichletOperator
static SparseMatrix dirichletOperator(const SparseMatrix &A, const IntegerVector &p)
Definition: DirichletConditions.h:130
boost::vertices
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
SparseMatrix
EigenLinearAlgebraBackend::SparseMatrix SparseMatrix
Definition: testHeatLaplace.cpp:50
DGtal::GeodesicsInHeat::mySource
Vector mySource
Source vector.
Definition: GeodesicsInHeat.h:275
laplacian
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)
Definition: sphereCotangentLaplaceOperator.cpp:89
DGtal::GeodesicsInHeat::myManageBoundary
bool myManageBoundary
Definition: GeodesicsInHeat.h:288
DGtal::SurfaceMesh::edgeVertices
const VertexPair & edgeVertices(Edge e) const
Definition: SurfaceMesh.h:329
DenseMatrix
EigenLinearAlgebraBackend::DenseMatrix DenseMatrix
Definition: testHeatLaplace.cpp:51
Vector
FreemanChain< int >::Vector Vector
Definition: testCombinDSS.cpp:60
DGtal::GeodesicsInHeat::myHeatDirichletSolver
Solver myHeatDirichletSolver
Heat solver with Dirichlet boundary conditions.
Definition: GeodesicsInHeat.h:294
DGtal::GeodesicsInHeat::myHeatSolver
Solver myHeatSolver
Heat solver.
Definition: GeodesicsInHeat.h:272
DGtal::GeodesicsInHeat::myLambda
double myLambda
Lambda parameter.
Definition: GeodesicsInHeat.h:284
DGtal::GeodesicsInHeat::myLastSourceIndex
Vertex myLastSourceIndex
Vertex index to the last source point (to shift the distances)
Definition: GeodesicsInHeat.h:278
DGtal::SurfaceMesh::incidentVertices
const Vertices & incidentVertices(Face f) const
Definition: SurfaceMesh.h:307
DGtal::GeodesicsInHeat::myIsInit
bool myIsInit
Validitate flag.
Definition: GeodesicsInHeat.h:281
DGtal::GeodesicsInHeat::myPoissonSolver
Solver myPoissonSolver
Poisson solver.
Definition: GeodesicsInHeat.h:269