DGtal  1.0.0
testHeatLaplace.cpp
Go to the documentation of this file.
1 
29 #include "DGtal/helpers/StdDefs.h"
30 
31 #include "DGtal/math/linalg/EigenSupport.h"
32 
33 #include "DGtal/dec/DiscreteExteriorCalculus.h"
34 #include "DGtal/dec/DiscreteExteriorCalculusFactory.h"
35 
36 #include "DGtal/shapes/parametric/Ball3D.h"
37 #include "DGtal/shapes/GaussDigitizer.h"
38 
39 #include "DGtal/topology/DigitalSurface.h"
40 #include "DGtal/topology/ImplicitDigitalSurface.h"
41 
42 #include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
43 #include "DGtal/geometry/surfaces/estimation/IIGeometricFunctors.h"
44 #include "DGtal/geometry/surfaces/estimation/IntegralInvariantCovarianceEstimator.h"
45 
46 #include "DGtalCatch.h"
47 
48 using namespace DGtal;
49 
52 
53 bool test_operator( const DenseMatrix& M )
54 {
55  bool test = true;
56 
57  for( int i = 0; i < M.rows(); i++ )
58  {
59  for( int j = 0; j < M.cols(); j++ )
60  {
61  if( i == j && M(i, j) > 0 ) test = false;
62  if( i != j && M(i, j) < 0 ) test = false;
63  }
64 
65  if( M.row(i).sum() >= 1e-10 ) test = false;
66  }
67 
68  return test;
69 }
70 
71 bool laplace_sphere( const double& h )
72 {
73  typedef Z3i::Space Space;
74  typedef Z3i::KSpace KSpace;
75  typedef Z3i::Domain Domain;
76  typedef Z3i::Point Point;
77  typedef Z3i::Vector Vector;
78  typedef Ball3D<Space> Ball;
80  typedef ImplicitDigitalSurface<KSpace, GaussDigitizer> MyImplicitDigitalSurface;
82 
83  Ball ball( Point(0, 0, 0), 1.0 );
84 
85  GaussDigitizer digitizer;
86  digitizer.attach( ball );
87  digitizer.init( ball.getLowerBound() + Vector(-1, -1, -1), ball.getUpperBound() + Vector(1, 1, 1), h );
88 
89  Domain domain = digitizer.getDomain();
90 
91  KSpace kspace;
92  kspace.init( domain.lowerBound(), domain.upperBound(), true );
93 
95  KSpace::Surfel bel = Surfaces<KSpace>::findABel( kspace, digitizer, 10000 );
96  MyImplicitDigitalSurface ImpSurf( kspace, digitizer, SAdj, bel );
97  MyDigitalSurface digSurf( ImpSurf );
98 
99  typedef functors::IINormalDirectionFunctor<Space> MyIINormalFunctor;
101 
102  MyIINormalFunctor normalFunctor;
103  normalFunctor.init( h, 3.5 * pow( h, 1. / 3. ) );
104 
105  MyIINormalEstimator normalEstimator( normalFunctor );
106  normalEstimator.attach( kspace, digitizer );
107  normalEstimator.setParams( 3.5 * pow( h, 1. / 3. ) / h );
108  normalEstimator.init( h, digSurf.begin(), digSurf.end() );
109 
112 
113  const Calculus calculus = CalculusFactory::createFromNSCells<2>( digSurf.begin(), digSurf.end(), normalEstimator, h );
114 
115  const double t = 0.1 * pow( h, 2./3. );
116  const double cut_locus = 3.0;
117  const Calculus::PrimalIdentity0 laplace_primal = calculus.heatLaplace<PRIMAL>( h, t, cut_locus );
118  const Calculus::DualIdentity0 laplace_dual = calculus.heatLaplace<DUAL>( h, t, cut_locus );
119 
120  return test_operator( laplace_primal.myContainer ) && test_operator( laplace_dual.myContainer );
121 }
122 
123 TEST_CASE( "Operator Test" )
124 {
125  SECTION( "Test" )
126  {
127  REQUIRE( laplace_sphere( 1.0 ) );
128  REQUIRE( laplace_sphere( 0.5 ) );
129  REQUIRE( laplace_sphere( 0.2 ) );
130  }
131 }
Aim: DiscreteExteriorCalculus represents a calculus in the dec package. This is the main structure in...
HyperRectDomain< Space > Domain
void attach(ConstAlias< EuclideanShape > shape)
const Point & upperBound() const
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Domain domain
Aim: This class implement an Integral Invariant estimator which computes for each surfel the covarian...
ConstIterator begin() const
EigenLinearAlgebraBackend::DenseMatrix DenseMatrix
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
void init(const double _h, SurfelConstIterator itb, SurfelConstIterator ite)
REQUIRE(domain.isInside(aPoint))
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Aim: This class provides static members to create DEC structures from various other DGtal structures.
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
TEST_CASE("Operator Test")
Aim: A functor Matrix -> RealVector that returns the normal direction by diagonalizing the given cova...
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Z3i::KSpace KSpace
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
bool test_operator(const DenseMatrix &M)
EigenLinearAlgebraBackend::SparseMatrix SparseMatrix
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
FreemanChain< int >::Vector Vector
const Point & lowerBound() const
ConstIterator end() const
Domain getDomain() const
SECTION("Testing constant forward iterators")
Eigen::SparseMatrix< DenseVector::Scalar, Eigen::ColMajor, DenseVector::Index > SparseMatrix
Definition: EigenSupport.h:104
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool laplace_sphere(const double &h)
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: Model of the concept StarShaped3D represents any Sphere in the space.
Definition: Ball3D.h:60
bool test(const I &itb, const I &ite)