DGtal  1.5.beta
testVoronoiCovarianceMeasure.cpp
Go to the documentation of this file.
1 
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 
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" );
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 
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 // //
Aim: implements separable l_p metrics with exact predicates.
Iterator for HyperRectDomain.
const ConstIterator & end() const
const ConstIterator & begin() const
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Z3i this namespace gathers the standard of types for 3D imagery.
Space::Point Point
Definition: StdDefs.h:168
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Domain domain
bool testVoronoiCovarianceMeasure()
int main(int, char **)