DGtal  1.4.beta
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 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testDistanceTransformND()

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.getVoronoiSite(*itDom) ) != norm2)
102  {
103  trace.error()<<"Error at "<<(*itDom)
104  << ": expected="<<norm2<<" and computed="
105  <<dt.metric()->rawDistance( (*itDom), dt.getVoronoiSite(*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 }
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: implements separable l_p metrics with exact predicates.
Iterator for HyperRectDomain.
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
const ConstIterator & end() const
const ConstIterator & begin() const
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
std::ostream & error()
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
Image image(domain)
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain

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().