DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testVoronoiCovarianceMeasure.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include <vector>
33
#include "DGtal/base/Common.h"
34
#include "DGtal/helpers/StdDefs.h"
35
#include "DGtal/geometry/volumes/estimation/VoronoiCovarianceMeasure.h"
36
#include "DGtal/geometry/tools/SpatialCubicalSubdivision.h"
37
39
41
// Functions for testing class VoronoiCovarianceMeasure
43
48
bool
testVoronoiCovarianceMeasure
()
49
{
50
unsigned
int
nbok = 0;
51
unsigned
int
nb = 0;
52
53
using namespace
DGtal
;
54
using namespace
DGtal::Z3i
;
// gets Space, Point, Domain
55
trace
.
beginBlock
(
"testVoronoiCovarianceMeasure"
);
56
typedef
ExactPredicateLpSeparableMetric<Space,2>
Metric;
57
typedef
VoronoiCovarianceMeasure<Space, Metric>
VCM;
58
typedef
VCM::MatrixNN Matrix;
59
60
Point
a(0,0);
61
Point
c(32,32,32);
62
Domain
domain
(a,c);
63
std::vector<Point> pts;
64
pts.push_back(
Point
( 10,10,10 ) );
65
pts.push_back(
Point
( 10,10,11 ) );
66
pts.push_back(
Point
( 10,11,11 ) );
67
pts.push_back(
Point
( 11,11,12 ) );
68
pts.push_back(
Point
( 11,12,12 ) );
69
pts.push_back(
Point
( 11,12,12 ) );
70
pts.push_back(
Point
( 12,12,12 ) );
71
pts.push_back(
Point
( 20,20,15 ) );
72
pts.push_back(
Point
( 30,10,25 ) );
73
pts.push_back(
Point
( 25,25,20 ) );
74
Metric l2;
75
VCM vcm( 5.0, 4.0, l2,
true
);
76
vcm.init( pts.begin(), pts.end() );
77
Domain
d = vcm.domain();
78
double
sum_dist = 0.0;
79
std::map<Point,int> sizeCells;
80
for
(
Domain::ConstIterator
it = d.begin(), itE = d.end(); it != itE; ++it )
81
{
82
sum_dist += l2( *it, vcm.voronoiMap()( *it ) );
83
sizeCells[ vcm.voronoiMap()( *it ) ] += 1;
84
}
85
double
avg_dist = ( sum_dist / d.size() );
86
trace
.
info
() <<
"Average distance is "
<< avg_dist << std::endl;
87
nbok += ( 9 <= avg_dist && avg_dist <= 11 ) ? 1 : 0;
88
nb++;
89
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
90
<<
"9 <= "
<< avg_dist <<
" <= 11 "
<< std::endl;
91
for
( std::map<Point,int>::const_iterator it = sizeCells.begin(), itE = sizeCells.end();
92
it != itE; ++it )
93
trace
.
info
() <<
"Nb("
<< it->first <<
")="
<< it->second << std::endl;
94
nbok += sizeCells.size() == 9 ? 1 : 0;
95
nb++;
96
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
97
<<
"sizeCells.size() == 10"
<< std::endl;
98
99
functors::HatPointFunction< Point, double >
chi_r( 1.0, 4.0 );
100
Matrix vcm_r = vcm.measure( chi_r,
Point
( 10,10,10 ) );
101
trace
.
info
() <<
"- vcm_r.row(0) = "
<< vcm_r.row( 0 ) << std::endl;
102
trace
.
info
() <<
"- vcm_r.row(1) = "
<< vcm_r.row( 1 ) << std::endl;
103
trace
.
info
() <<
"- vcm_r.row(2) = "
<< vcm_r.row( 2 ) << std::endl;
104
trace
.
endBlock
();
105
106
return
nbok == nb;
107
}
108
110
// Standard services - public :
111
112
int
main
(
int
/* argc */
,
char
**
/* argv */
)
113
{
114
using namespace
std
;
115
using namespace
DGtal
;
116
trace
.
beginBlock
(
"Testing VoronoiCovarianceMeasure ..."
);
117
bool
res =
testVoronoiCovarianceMeasure
();
118
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
119
trace
.
endBlock
();
120
return
res ? 0 : 1;
121
}
122
// //
DGtal::ExactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with exact predicates.
Definition
ExactPredicateLpSeparableMetric.h:88
DGtal::HyperRectDomain< Space >::ConstIterator
Iterator ConstIterator
Definition
HyperRectDomain.h:125
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal::VoronoiCovarianceMeasure
Aim: This class precomputes the Voronoi Covariance Measure of a set of points. It can compute the cov...
Definition
VoronoiCovarianceMeasure.h:80
DGtal::Z3i
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::functors::HatPointFunction
Definition
Point2ScalarFunctors.h:55
Point
MyPointD Point
Definition
testClone2.cpp:381
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
Domain
HyperRectDomain< Space > Domain
Definition
testSimpleRandomAccessRangeFromPoint.cpp:44
testVoronoiCovarianceMeasure
bool testVoronoiCovarianceMeasure()
Definition
testVoronoiCovarianceMeasure.cpp:48
tests
geometry
volumes
estimation
testVoronoiCovarianceMeasure.cpp
Generated on
for DGtal by
1.18.0