DGtal  1.4.beta
tutorial-examples/AreaSurfaceEstimation-final.cpp

Example of tutorial 4: Surface area estimation

See also
Tutorial: Surface area estimation
#include "DGtal/shapes/parametric/Ball3D.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/graph/DepthFirstVisitor.h"
#include "DGtal/graph/GraphVisitorRange.h"
#include "DGtal/geometry/surfaces/estimation/IIGeometricFunctors.h"
#include "DGtal/geometry/surfaces/estimation/IntegralInvariantCovarianceEstimator.h"
using namespace DGtal;
int main( int argc, char** argv )
{
const double h = 1;
const double radiusBall = 12.0;
const double radiusII = 6;
const double trueAreaSurface = 4.0*M_PI*radiusBall*radiusBall;
trace.beginBlock( "Make parametric shape..." );
Z3i::RealPoint center( 0.0, 0.0, 0.0 );
Shape ball( center, radiusBall );
trace.beginBlock( "Make digital shape..." );
DigitalShape digitalBall;
digitalBall.attach( ball );
digitalBall.init( ball.getLowerBound() - Z3i::RealPoint( 1.0, 1.0, 1.0 ),
ball.getUpperBound() + Z3i::RealPoint( 1.0, 1.0, 1.0 ),
h );
Domain domain = digitalBall.getDomain();
Z3i::KSpace kspace;
kspace.init( domain.lowerBound(), domain.upperBound(), true );
trace.beginBlock( "Make digital surface..." );
typedef GraphVisitorRange::ConstIterator SurfelConstIterator;
Surfel bel = Surfaces< Z3i::KSpace >::findABel( kspace, digitalBall, 500 );
LightDigitalSurface lightDigitalSurface( kspace, digitalBall, surfelAdjacency, bel );
DigitalSurface digitalSurface( lightDigitalSurface );
GraphVisitorRange graphVisitorRange( new DepthFirstVisitor( digitalSurface, *digitalSurface.begin() ) );
SurfelConstIterator sbegin = graphVisitorRange.begin();
SurfelConstIterator send = graphVisitorRange.end();
std::vector< Surfel > v_border;
while( sbegin != send )
{
v_border.push_back( *sbegin );
++sbegin;
}
trace.beginBlock( "Computation with normal estimation ..." );
typedef IIGeometricFunctors::IINormalDirectionFunctor< Z3i::Space > NormalFunctor;
NormalFunctor normalFunctor;
IINormalEstimator normalEstimator( normalFunctor );
normalEstimator.attach( kspace, digitalBall );
normalEstimator.setParams( radiusII / h );
normalEstimator.init( h, v_border.begin(), v_border.end() );
double areaSurfaceEstimated = 0.0;
for( unsigned int i_position = 0; i_position < v_border.size(); ++i_position )
{
Z3i::RealPoint normalEstimated = normalEstimator.eval( &(v_border[i_position]) );
Z3i::RealPoint normalSurfel = kspace.sKCoords( kspace.sDirectIncident( v_border[i_position], kspace.sOrthDir( v_border[i_position] ))) - kspace.sKCoords( v_border[i_position] );
normalEstimated = normalEstimated.getNormalized();
areaSurfaceEstimated += std::abs( normalEstimated.dot( normalSurfel )) * h * h;
}
trace.info() << "Area Surface estimated : " << areaSurfaceEstimated << std::endl;
trace.info() << "True areaSurface : " << trueAreaSurface << std::endl;
trace.info() << "Ratio : " << areaSurfaceEstimated / trueAreaSurface << std::endl;
return 0;
}
DGtal::GaussDigitizer
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Definition: GaussDigitizer.h:79
DGtal::GaussDigitizer::getDomain
Domain getDomain() const
DGtal::GraphVisitorRange::begin
ConstIterator begin() const
DGtal::Astroid2D< Space >
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::detail::center
Point center(const std::vector< Point > &points)
Definition: QuickHullKernels.h:66
DGtal::GraphVisitorRange
Aim: Transforms a graph visitor into a single pass input range.
Definition: GraphVisitorRange.h:71
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:139
DGtal::SurfelAdjacency
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Definition: SurfelAdjacency.h:65
DGtal::HyperRectDomain::upperBound
const Point & upperBound() const
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::Astroid2D::getLowerBound
RealPoint getLowerBound() const
Definition: Astroid2D.h:122
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::GaussDigitizer::attach
void attach(ConstAlias< EuclideanShape > shape)
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::IntegralInvariantCovarianceEstimator
Aim: This class implement an Integral Invariant estimator which computes for each surfel the covarian...
Definition: IntegralInvariantCovarianceEstimator.h:115
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::GaussDigitizer::init
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
DGtal::Trace::info
std::ostream & info()
Surfel
KSpace::SCell Surfel
Definition: testArithmeticalDSSComputerOnSurfels.cpp:50
DGtal::KhalimskySpaceND::sDirectIncident
SCell sDirectIncident(const SCell &p, Dimension k) const
Return the direct incident cell of [p] along [k] (the incident cell along [k])
DGtal::LightImplicitDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Definition: LightImplicitDigitalSurface.h:115
DGtal::DigitalSurface::begin
ConstIterator begin() const
DGtal::Surfaces::findABel
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Domain
HyperRectDomain< Space > Domain
Definition: testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::PointVector::getNormalized
PointVector< dim, double, std::array< double, dim > > getNormalized() const
DGtal::KhalimskySpaceND::sKCoords
const Point & sKCoords(const SCell &c) const
Return its Khalimsky coordinates.
Shape
Astroid2D< Space > Shape
Definition: testAstroid2D.cpp:48
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::KhalimskySpaceND::sOrthDir
Dimension sOrthDir(const SCell &s) const
Given a signed surfel [s], returns its orthogonal direction (ie, the coordinate where the surfel is c...
DGtal::GraphVisitorRange::GenericConstIterator
Definition: GraphVisitorRange.h:117
DGtal::PointVector::dot
auto dot(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::dotProduct(*this, v))
Dot product with a PointVector.
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
DGtal::DepthFirstVisitor
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Definition: DepthFirstVisitor.h:95
DGtal::Ball3D
Aim: Model of the concept StarShaped3D represents any Sphere in the space.
Definition: Ball3D.h:60
DGtal::Astroid2D::getUpperBound
RealPoint getUpperBound() const
Definition: Astroid2D.h:131
DGtal::HyperRectDomain::lowerBound
const Point & lowerBound() const
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64
DGtal::GraphVisitorRange::end
ConstIterator end() const