DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testVoronoiCovarianceMeasure.cpp File Reference
#include <iostream>
#include <vector>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/volumes/estimation/VoronoiCovarianceMeasure.h"
#include "DGtal/geometry/tools/SpatialCubicalSubdivision.h"

Go to the source code of this file.

Functions

bool testVoronoiCovarianceMeasure ()
 
int main (int, char **)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2014/02/09

Functions for testing class VoronoiCovarianceMeasure, and also IntegralInvariantEstimator.

This file is part of the DGtal library.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2014/02/09

Functions for testing class VoronoiCovarianceMeasure.

This file is part of the DGtal library.

Definition in file testVoronoiCovarianceMeasure.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 112 of file testVoronoiCovarianceMeasure.cpp.

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}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
bool testVoronoiCovarianceMeasure()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), and testVoronoiCovarianceMeasure().

◆ testVoronoiCovarianceMeasure()

bool testVoronoiCovarianceMeasure ( )

Example of a test. To be completed.

Definition at line 48 of file testVoronoiCovarianceMeasure.cpp.

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}
Aim: implements separable l_p metrics with exact predicates.
Iterator for HyperRectDomain.
const ConstIterator & begin() const
const ConstIterator & end() const
std::ostream & info()
Aim: This class precomputes the Voronoi Covariance Measure of a set of points. It can compute the cov...
Z3i this namespace gathers the standard of types for 3D imagery.
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
HyperRectDomain< Space > Domain

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), domain, DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::HyperRectDomain< TSpace >::size().

Referenced by main().