DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
area-estimation-with-indexed-digital-surface.cpp
Go to the documentation of this file.
1
16
29
61
62
64
#include <cstdlib>
65
#include <iostream>
66
#include <map>
67
#include "DGtal/base/Common.h"
68
#include "DGtal/base/CountedPtr.h"
69
#include "DGtal/helpers/StdDefs.h"
70
#include "DGtal/kernel/PointVector.h"
71
#include "DGtal/graph/CUndirectedSimpleGraph.h"
72
#include "DGtal/graph/BreadthFirstVisitor.h"
73
#include "DGtal/topology/DigitalSetBoundary.h"
74
#include "DGtal/topology/IndexedDigitalSurface.h"
75
#include "DGtal/shapes/Shapes.h"
76
78
79
using namespace
std
;
80
using namespace
DGtal
;
81
using namespace
DGtal::Z3i
;
82
83
int
main
(
int
argc,
char
** argv )
84
{
85
const
double
R = argc >= 2 ? atof( argv[ 1 ] ) : 13.0;
// radius of ball
86
const
unsigned
int
KN = argc >= 3 ? atoi( argv[ 2 ] ) : 6;
// size of neighborhood
87
const
int
M = (int) ceil( R + 2.0 );
88
trace
.
beginBlock
(
"Creating surface"
);
89
trace
.
info
() <<
"Sphere of radius "
<< R
90
<<
", "
<< KN <<
"-ring neighborhood"
<< std::endl;
91
typedef
DigitalSetBoundary < KSpace, DigitalSet > DigitalSurfaceContainer;
92
typedef
IndexedDigitalSurface< DigitalSurfaceContainer >
DigSurface;
93
typedef
BreadthFirstVisitor < DigSurface > BFSVisitor;
94
Point
p1( -M, -M, -M );
95
Point
p2( M, M, M );
96
KSpace
K
;
97
K
.
init
( p1, p2,
true
);
98
DigitalSet
aSet(
Domain
( p1, p2 ) );
99
Shapes<Domain>::addNorm2Ball
( aSet,
Point
( 0, 0, 0 ), R );
100
auto
dsc =
CountedPtr< DigitalSurfaceContainer >
(
new
DigitalSurfaceContainer(
K
, aSet ) );
101
DigSurface dsurf( dsc );
102
trace
.
info
() <<
"[OK]"
103
<<
" Sphere has "
<< dsurf.size() <<
" vertices/surfels"
104
<<
" with euler "
<< dsurf.Euler() << std::endl;
105
trace
.
endBlock
();
106
107
trace
.
beginBlock
(
"Estimating normals"
);
108
auto
v2n = dsurf.makeVertexMap(
RealPoint
() );
109
for
(
auto
v : dsurf )
110
{
111
int
nbv = 0;
112
RealPoint
normal =
RealPoint::zero
;
113
BFSVisitor bfv( dsurf, v );
114
while
( ! bfv.finished() )
115
{
// Vertex are colored according to the distance to initial seed.
116
auto
node = bfv.current();
117
if
( KN < node.second )
break
;
118
auto
surfel = dsurf.surfel( node.first );
119
RealPoint
nv =
RealPoint::zero
;
120
Dimension
k =
K
.
sOrthDir
( surfel );
121
nv[ k ] =
K
.
sDirect
( surfel, k ) ? 1.0 : -1.0;
122
normal += nv;
123
nbv += 1;
124
bfv.expand();
125
}
126
normal /= nbv;
127
v2n[ v ] = normal.
getNormalized
();
128
}
129
trace
.
endBlock
();
130
131
trace
.
beginBlock
(
"Estimating area"
);
132
const
double
area_true = 4.0 * M_PI * R * R;
133
double
area_averaged = 0.0;
134
double
area_corrected = 0.0;
135
for
(
auto
v : dsurf )
136
{
137
auto
surfel = dsurf.surfel( v );
138
Dimension
k =
K
.
sOrthDir
( surfel );
139
area_corrected += fabs( v2n[ v ][ k ] );
140
area_averaged += 1.0 / v2n[ v ].norm(
RealPoint::L_1
);
141
}
142
trace
.
info
() <<
"- true area = "
<< area_true << std::endl;
143
trace
.
info
() <<
"- corrected area = "
<< area_corrected << std::endl;
144
trace
.
info
() <<
"- averaged area = "
<< area_averaged << std::endl;
145
trace
.
endBlock
();
146
147
return
0;
148
}
149
DGtal::CountedPtr< DigitalSurfaceContainer >
DGtal::HyperRectDomain< Space >::Domain
HyperRectDomain< Space > Domain
Definition
HyperRectDomain.h:112
DGtal::IndexedDigitalSurface
Aim: Represents a digital surface with the topology of its dual surface. Its aim is to mimic the stan...
Definition
IndexedDigitalSurface.h:97
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::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::KhalimskySpaceND::sDirect
bool sDirect(const SCell &p, Dimension k) const
Return 'true' if the direct orientation of [p] along [k] is in the positive coordinate direction.
DGtal::PointVector::getNormalized
PointVector< dim, double, std::array< double, dim > > getNormalized() const
DGtal::PointVector< 3, double >::zero
static Self zero
Definition
PointVector.h:1595
DGtal::PointVector< 3, double >::L_1
@ L_1
Definition
PointVector.h:1493
DGtal::Shapes::addNorm2Ball
static void addNorm2Ball(TDigitalSet &aSet, const Point &aCenter, UnsignedInteger aRadius)
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal::Z3i
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal::Z3i::KSpace
KhalimskySpaceND< 3, Integer > KSpace
Definition
StdDefs.h:146
DGtal::Z3i::RealPoint
Space::RealPoint RealPoint
Definition
StdDefs.h:170
DGtal::Z3i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition
StdDefs.h:173
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::Dimension
DGtal::uint32_t Dimension
Definition
Common.h:119
DGtal::trace
Trace trace
std
STL namespace.
K
KSpace K
Definition
testCubicalComplex.cpp:62
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
examples
topology
area-estimation-with-indexed-digital-surface.cpp
Generated on
for DGtal by
1.18.0