DGtal  1.3.beta
Functions
testDistanceTransformationND.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
Include dependency graph for testDistanceTransformationND.cpp:

Go to the source code of this file.

Functions

bool testDistanceTransformND ()
 
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
2010/12/24

Functions for testing class DistanceTransformND.

This file is part of the DGtal library.

Definition in file testDistanceTransformationND.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 122 of file testDistanceTransformationND.cpp.

123 {
124  trace.beginBlock ( "Testing class DistanceTransformND" );
125  trace.info() << "Args:";
126  for ( int i = 0; i < argc; ++i )
127  trace.info() << " " << argv[ i ];
128  trace.info() << endl;
129 
130  bool res = testDistanceTransformND(); // && ... other tests
131  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
132  trace.endBlock();
133  return res ? 0 : 1;
134 }

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

◆ testDistanceTransformND()

bool testDistanceTransformND ( )

Example of a test. To be completed.

Definition at line 56 of file testDistanceTransformationND.cpp.

57 {
58  unsigned int nbok = 0;
59  unsigned int nb = 0;
60 
61  trace.beginBlock ( "Testing dT dim=5 ..." );
62 
63  typedef SpaceND<5> TSpace;
64  typedef TSpace::Point Point;
66  TSpace::Integer t[5] = {0,0,0,0,0};
67  Point a ( t );
68  TSpace::Integer t2[5] = {15,15,15,15,15};
69  Point b ( t2 );
70  TSpace::Integer t3[5] = {3,3,3,3,3};
71  Point c ( t3 );
72  Point d;
73 
75  Domain domain(a,b);
77 
78  //We create an object image with a signle background point (set to 0)
79  for (Image::Iterator it=image.begin(),itend=image.end(); it!=itend; ++it)
80  *it = 128;
81  image.setValue( c , 0 );
82 
84  Predicate aPredicate(image,0);
85 
87  L2Metric l2;
89 
90  //We check the result
91  bool res=true;
92  for(Domain::ConstIterator itDom = domain.begin(), itDomend = domain.end();
93  itDom != itDomend; ++itDom)
94  {
95  //distance from the point to the seed
96  d = (*itDom) - c;
97  L2Metric::RawValue norm2=0;
98  for(Point::Iterator itd=d.begin(), itdend=d.end(); itd!=itdend; ++itd)
99  norm2+= (*itd)*(*itd);
100 
101  if ( dt.metric()->rawDistance( (*itDom), dt.getVoronoiVector(*itDom) ) != norm2)
102  {
103  trace.error()<<"Error at "<<(*itDom)
104  << ": expected="<<norm2<<" and computed="
105  <<dt.metric()->rawDistance( (*itDom), dt.getVoronoiVector(*itDom) )
106  <<endl;
107  res=false;
108  }
109  }
110  nbok += res ? 1 : 0;
111  nb++;
112  trace.info() << "(" << nbok << "/" << nb << ") "
113  << "true == true" << std::endl;
114  trace.endBlock();
115 
116  return nbok == nb;
117 }

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

Referenced by main().

image
Image image(domain)
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition: HyperRectDomain.h:99
DGtal::Trace::endBlock
double endBlock()
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::Trace::error
std::ostream & error()
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::SpaceND
Definition: SpaceND.h:95
DGtal::Trace::info
std::ostream & info()
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
Domain
HyperRectDomain< Space > Domain
Definition: testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::ImageContainerBySTLVector< Domain, Value >::Iterator
std::vector< Value >::iterator Iterator
Definition: ImageContainerBySTLVector.h:264
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition: HyperRectDomain.h:201
DGtal::Z2i::L2Metric
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
Integer
Point::Coordinate Integer
Definition: examplePlaneProbingParallelepipedEstimator.cpp:44
testDistanceTransformND
bool testDistanceTransformND()
Definition: testDistanceTransformationND.cpp:56
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::HyperRectDomain_Iterator
Iterator for HyperRectDomain.
Definition: HyperRectDomain_Iterator.h:142
DGtal::ExactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with exact predicates.
Definition: ExactPredicateLpSeparableMetric.h:87
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition: DistanceTransformation.h:98
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition: HyperRectDomain.h:176
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::functors::SimpleThresholdForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
Definition: SimpleThresholdForegroundPredicate.h:65