DGtal 1.3.0
Loading...
Searching...
No Matches
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)
 
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 [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 }
const PolygonalCalculus * myCalculus
The underlying PolygonalCalculus instance.
bool myIsInit
Validitate flag.

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");
179 mySource( aV ) = 1.0;
180 }
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 184 of file GeodesicsInHeat.h.

185 {
186 mySource = Vector::Zero(myCalculus->nbVertices());
187 }

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

202 {
203 FATAL_ERROR_MSG(myIsInit, "init() method must be called first");
204 //Heat diffusion
205 Vector heatDiffusion = myHeatSolver.solve(mySource);
206 // Take care of boundaries
207 if ( myManageBoundary )
208 {
209 Vector bValues = Vector::Zero( myCalculus->nbVertices() );
211 myBoundary, bValues );
212 Vector bSol = myHeatDirichletSolver.solve( bSources );
213 Vector heatDiffusionDirichlet
214 = Conditions::dirichletSolution( bSol, myBoundary, bValues );
215 heatDiffusion = 0.5 * ( heatDiffusion + heatDiffusionDirichlet );
216 }
217
218 Vector divergence = Vector::Zero(myCalculus->nbVertices());
219 auto cpt=0;
220 auto surfmesh = myCalculus->getSurfaceMeshPtr();
221
222 // Heat, normalization and divergence per face
223 for(auto f=0; f< myCalculus->nbFaces(); ++f)
224 {
225 Vector faceHeat( myCalculus->degree(f));
226 cpt=0;
227 auto vertices = surfmesh->incidentVertices(f);
228 for(auto v: vertices)
229 {
230 faceHeat(cpt) = heatDiffusion( v );
231 ++cpt;
232 }
233 // ∇heat / ∣∣∇heat∣∣
234 Vector grad = -myCalculus->gradient(f) * faceHeat;
235 grad.normalize();
236
237 // div
238 DenseMatrix oneForm = myCalculus->flat(f)*grad;
239 Vector divergenceFace = myCalculus->divergence( f, myLambda ) * oneForm;
240 cpt=0;
241 for(auto v: vertices)
242 {
243 divergence(v) += divergenceFace(cpt);
244 ++cpt;
245 }
246 }
247
248 // Last Poisson solve
249 Vector distVec = myPoissonSolver.solve(divergence);
250
251 //Source val
252 auto sourceval = distVec(myLastSourceIndex);
253
254 //shifting the distances to get 0 at sources
255 return distVec - sourceval*Vector::Ones(myCalculus->nbVertices());
256 }
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)
double myLambda
Lambda parameter.
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.
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
FreemanChain< int >::Vector Vector
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 >::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 }
static SparseMatrix dirichletOperator(const SparseMatrix &A, const IntegerVector &p)
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(), 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 260 of file GeodesicsInHeat.h.

261 {
262 return myIsInit && myCalculus->isValid();
263 }

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

193 {
194 FATAL_ERROR_MSG(myIsInit, "init() method must be called first");
195 return mySource;
196 }

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 298 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 301 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 273 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 285 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 295 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: