DGtal 1.4.0
Loading...
Searching...
No Matches
testDistanceTransformationMetrics.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/geometry/volumes/distance/InexactPredicateLpSeparableMetric.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
Include dependency graph for testDistanceTransformationMetrics.cpp:

Go to the source code of this file.

Functions

template<typename Image >
void randomSeeds (Image &input, const unsigned int nb, const int value)
 
template<typename Image , typename Pred , typename Metric >
bool checkVoronoi (Image &result, Pred &pointPredicate, Metric &metric)
 
template<typename Space , int norm>
bool testCompareExactBruteForce (unsigned int size, unsigned int nb)
 
template<typename Space >
bool testCompareInexactBruteForce (double norm, unsigned int size, unsigned int nb)
 
int main (int argc, char **argv)
 

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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/12/30

Functions for testing class DistanceTransformation on several metrics.

This file is part of the DGtal library.

Definition in file testDistanceTransformationMetrics.cpp.

Function Documentation

◆ checkVoronoi()

template<typename Image , typename Pred , typename Metric >
bool checkVoronoi ( Image & result,
Pred & pointPredicate,
Metric & metric )

Definition at line 68 of file testDistanceTransformationMetrics.cpp.

69{
70 typedef typename Image::Domain Domain;
71
72 for(typename Domain::ConstIterator it = result.domain().begin(),
73 itend=result.domain().end();
74 it != itend; ++it)
75 {
76 typename Metric::Value dist = result(*it);
77
78 for(typename Domain::ConstIterator itbis = result.domain().begin(),
79 itendbis=result.domain().end();
80 itbis != itendbis; ++itbis)
81 {
82 if (!pointPredicate(*itbis) && (metric(*it, *itbis) < dist))
83 {
84 trace.error()<< "Error in Voronoi map at "<< *it<<" computed="<<dist<<" but find="<<metric(*it, *itbis) << std::endl;
85 return false;
86 }
87 }
88 }
89 return true;
90}
std::ostream & error()
Trace trace
Definition Common.h:153
HyperRectDomain< Space > Domain

References DGtal::Trace::error(), and DGtal::trace.

Referenced by testCompareExactBruteForce(), and testCompareInexactBruteForce().

◆ main()

int main ( int argc,
char ** argv )

Definition at line 178 of file testDistanceTransformationMetrics.cpp.

179{
180 trace.beginBlock ( "Testing class DistanceTransformationMetrics" );
181 trace.info() << "Args:";
182 for ( int i = 0; i < argc; ++i )
183 trace.info() << " " << argv[ i ];
184 trace.info() << endl;
185
195 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
196 trace.endBlock();
197 return res ? 0 : 1;
198}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
bool testCompareExactBruteForce(unsigned int size, unsigned int nb)
bool testCompareInexactBruteForce(double norm, unsigned int size, unsigned int nb)

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testCompareExactBruteForce(), testCompareInexactBruteForce(), and DGtal::trace.

◆ randomSeeds()

template<typename Image >
void randomSeeds ( Image & input,
const unsigned int nb,
const int value )

Definition at line 47 of file testDistanceTransformationMetrics.cpp.

48{
49 typename Image::Point p, low = input.domain().lowerBound(), up = input.domain().upperBound();
50 typename Image::Vector ext;
51
52 for (Dimension i = 0; i < Image::Domain::dimension; i++)
53 ext[i] = up[i] - low[i] + 1;
54
55
56 for (unsigned int k = 0 ; k < nb; k++)
57 {
58 for (unsigned int dim = 0; dim < Image::dimension; dim++)
59 {
60 p[dim] = rand() % (ext[dim]) + low[dim];
61 }
62 input.setValue(p, value);
63 }
64}
DGtal::uint32_t Dimension
Definition Common.h:136

References dim.

◆ testCompareExactBruteForce()

template<typename Space , int norm>
bool testCompareExactBruteForce ( unsigned int size,
unsigned int nb )

Definition at line 94 of file testDistanceTransformationMetrics.cpp.

95{
96 trace.beginBlock("Checking Exact/Inexct predicate metrics");
99 typedef typename Space::Point Point;
100 typedef DigitalSetBySTLSet<Domain> Set;
101 typedef functors::NotPointPredicate<Set> NegPredicate;
102
103 Point low=Point::diagonal(0),
104 up=Point::diagonal(size);
105
106 Domain domain(low,up);
107 Set set(domain);
108
109 for(unsigned int i = 0; i<nb; ++i)
110 {
111 Point p;
112 for(unsigned int dim=0; dim<Space::dimension;++dim)
113 p[dim] = rand() % size;
114 set.insert(p);
115 }
116
117 trace.info()<< "Testing metrics "<<MetricEx()<<std::endl;
118 trace.info()<< "Testing space dimension "<<Space::dimension<<std::endl;
119 trace.info()<< "Inserting "<<set.size() << " points."<<std::endl;
120
121 NegPredicate negPred(set);
122
124 MetricEx metricEx;
125 DTEx dtex(&domain, &negPred, &metricEx);
126
127 bool res=checkVoronoi(dtex, negPred, metricEx);
128
129 trace.endBlock();
130 return res;
131}
Aim: A container class for storing sets of digital points within some given domain.
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: implements separable l_p metrics with exact predicates.
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
static const Dimension dimension
static constants to store the dimension.
Definition SpaceND.h:132
Aim: The predicate returns true when the point predicate given at construction return false....
MyPointD Point
bool checkVoronoi(Image &result, Pred &pointPredicate, Metric &metric)
Domain domain

References DGtal::Trace::beginBlock(), checkVoronoi(), dim, DGtal::SpaceND< dim, TInteger >::dimension, domain, DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testCompareInexactBruteForce()

template<typename Space >
bool testCompareInexactBruteForce ( double norm,
unsigned int size,
unsigned int nb )

Definition at line 136 of file testDistanceTransformationMetrics.cpp.

137{
138 trace.beginBlock("Checking Exact/Inexct predicate metrics");
141 typedef typename Space::Point Point;
142 typedef DigitalSetBySTLSet<Domain> Set;
143 typedef functors::NotPointPredicate<Set> NegPredicate;
144
145 Point low=Point::diagonal(0),
146 up=Point::diagonal(size);
147
148 Domain domain(low,up);
149 Set set(domain);
150
151 for(unsigned int i = 0; i<nb; ++i)
152 {
153 Point p;
154 for(unsigned int dim=0; dim<Space::dimension;++dim)
155 p[dim] = rand() % size;
156 set.insert(p);
157 }
158
159 trace.info()<< "Testing metrics "<<MetricInex(norm)<<std::endl;
160 trace.info()<< "Testing space dimension "<<Space::dimension<<std::endl;
161 trace.info()<< "Inserting "<<set.size() << " points."<<std::endl;
162
163 NegPredicate negPred(set);
164
166 MetricInex metricInex(norm);
167 DTIn dtinex(&domain, &negPred, &metricInex);
168
169 bool res=checkVoronoi(dtinex, negPred, metricInex);
170
171 trace.endBlock();
172 return res;
173}
Aim: implements separable l_p metrics with approximated predicates.

References DGtal::Trace::beginBlock(), checkVoronoi(), dim, DGtal::SpaceND< dim, TInteger >::dimension, domain, DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().