DGtal  1.5.beta
testReverseDT.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/geometry/volumes/distance/ReverseDistanceTransformation.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
Include dependency graph for testReverseDT.cpp:

Go to the source code of this file.

Functions

template<typename Image >
void randomSeeds (Image &input, const unsigned int nb, const int value)
 
bool testReverseDT ()
 
bool testReverseDTL1 ()
 
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
2011/03/03

Functions for testing class ReverseDT.

This file is part of the DGtal library.

Definition in file testReverseDT.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 271 of file testReverseDT.cpp.

272 {
273  trace.beginBlock ( "Testing class ReverseDT" );
274  trace.info() << "Args:";
275  for ( int i = 0; i < argc; ++i )
276  trace.info() << " " << argv[ i ];
277  trace.info() << endl;
278 
279  bool res = testReverseDT()
280  && testReverseDTL1(); // && ... other tests
281 
282  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
283  trace.endBlock();
284  return res ? 0 : 1;
285 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testReverseDTL1()
bool testReverseDT()

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

◆ randomSeeds()

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

Definition at line 51 of file testReverseDT.cpp.

52 {
53  typename Image::Point p, low = input.lowerBound();
54  typename Image::Vector ext;
55 
56  ext = input.extent();
57 
58  for (unsigned int k = 0 ; k < nb; k++)
59  {
60  for (unsigned int dim = 0; dim < Image::dimension; dim++)
61  {
62  p[dim] = rand() % (ext[dim]) + low[dim];
63  }
64  input.setValue(p, value);
65  }
66 }
unsigned int dim(const Vector &z)

References dim().

◆ testReverseDT()

bool testReverseDT ( )

Example of a test. To be completed.

Definition at line 77 of file testReverseDT.cpp.

78 {
79  unsigned int nbok = 0;
80  unsigned int nb = 0;
81 
82  trace.beginBlock ( "Testing Reverse DT in 2D ..." );
83 
84  Z2i::Point a (2, 2 );
85  Z2i::Point b ( 15, 15 );
86 
88  Image image (Z2i::Domain( a, b ));
89 
90  for ( unsigned k = 0; k < 49; k++ )
91  {
92  a[0] = ( k / 7 ) + 5;
93  a[1] = ( k % 7 ) + 5;
94  image.setValue ( a, 128 );
95  }
96 
97  a = Z2i::Point(2,2);
98 
100  Predicate aPredicate(image,0);
101 
103  Z2i::Domain dom(a,b);
104  L2Metric l2;
106 
107  trace.info() << dt<< std::endl;
108  //ReverseDT
109  trace.warning()<<"DT:"<<endl;
111  for (unsigned int y = 2; y < 16; y++)
112  {
113  for (unsigned int x = 2; x < 16; x++)
114  {
115  std::cout << (*it) << " ";
116  ++it;
117  }
118  std::cout << std::endl;
119  }
120 
122  Z2i::L2PowerMetric l2power;
123  RDT reverseDT(&dom,&dt,&l2power);
124 
125 
126  for(unsigned int j=2; j<16; j++)
127  {
128  for(unsigned int i=2; i<16; i++)
129  trace.info()<< reverseDT.getPowerVector(Z2i::Point(i,j))[0]<<","<<reverseDT.getPowerVector(Z2i::Point(i,j))[1]<<" ";
130  trace.info()<<std::endl;
131  }
132 
133  trace.warning()<<"REDT:"<<endl;
134  RDT::ConstRange::ConstIterator it2 = reverseDT.constRange().begin();
135  for (unsigned int y = 2; y < 16; y++)
136  {
137  for (unsigned int x = 2; x < 16; x++)
138  {
139  std::cout << (*it2) << " ";
140  ++it2;
141  }
142  std::cout << std::endl;
143  }
144 
145  //Checking
146  bool ok=true;
147  RDT::ConstRange::ConstIterator itrec = reverseDT.constRange().begin(), itend = reverseDT.constRange().end();
148  Image::ConstIterator itinit = image.begin();
149  for( ; itrec != itend; ++itrec,++itinit)
150  if ((*itrec) >= 0)
151  ok = ok & ((*itinit) == 0);
152 
153 
154  trace.info() << "vector (4,7)= "<< reverseDT.getPowerVector(Z2i::Point(4,7))<<std::endl;
155  nbok += (reverseDT.getPowerVector(Z2i::Point(4,7))==Z2i::Point(5,7)) ? 1 : 0;
156  nb++;
157  trace.info() << "(" << nbok << "/" << nb << ") "
158  << "ok" << std::endl;
159 
160  trace.info() << "dist (4,7)= "<< reverseDT.metricPtr()->exactDistanceRepresentation(Z2i::Point(4,7), Z2i::Point(5,7))<<std::endl;
161  nbok += (reverseDT.metricPtr()->exactDistanceRepresentation(Z2i::Point(4,7), Z2i::Point(5,7))==1) ? 1 : 0;
162  nb++;
163  trace.info() << "(" << nbok << "/" << nb << ") "
164  << "true == true" << std::endl;
165 
166  trace.info() << "power (4,7)= "<< reverseDT(Z2i::Point(4,7))<<std::endl;
167  nbok += (reverseDT(Z2i::Point(4,7))==0) ? 1 : 0;
168  nb++;
169  trace.info() << "(" << nbok << "/" << nb << ") "
170  << "true == true" << std::endl;
171 
172 
173 
174 
175  nbok += ok ? 1 : 0;
176  nb++;
177  trace.info() << "(" << nbok << "/" << nb << ") "
178  << "true == true" << std::endl;
179  trace.endBlock();
180 
181  return nbok == nb;
182 }
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: implements weighted separable l_p metrics with exact predicates.
Aim: implements separable l_p metrics with exact predicates.
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
Aim: Implementation of the linear in time reverse distance transformation for separable metrics.
std::ostream & warning()
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
MyDigitalSurface::ConstIterator ConstIterator
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
MyPointD Point
Definition: testClone2.cpp:383
Image image(domain)
ImageContainerBySTLVector< Domain, Value > Image

References DGtal::Trace::beginBlock(), dt, DGtal::Trace::endBlock(), image(), DGtal::Trace::info(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

◆ testReverseDTL1()

bool testReverseDTL1 ( )

Definition at line 184 of file testReverseDT.cpp.

185 {
186  unsigned int nbok = 0;
187  unsigned int nb = 0;
188 
189  trace.beginBlock ( "Testing Reverse DT in 2D with L1 metric ..." );
190 
191  Z2i::Point a (2, 2 );
192  Z2i::Point b ( 15, 15 );
193 
195  Image image ( Z2i::Domain( a, b ));
196 
197  for ( unsigned k = 0; k < 49; k++ )
198  {
199  a[0] = ( k / 7 ) + 5;
200  a[1] = ( k % 7 ) + 5;
201  image.setValue ( a, 128 );
202  }
203  a = Z2i::Point(2, 2 );
204 
205 
207  Predicate aPredicate(image,0);
208  Z2i::Domain dom= image.domain();
210  L1Metric l1;
212 
213 
214  //ReverseDT
215  trace.warning()<<"DT:"<<endl;
217  for (unsigned int y = 2; y < 16; y++)
218  {
219  for (unsigned int x = 2; x < 16; x++)
220  {
221  std::cout << (int)(*it) << " ";
222  ++it;
223  }
224  std::cout << std::endl;
225  }
226 
228  Z2i::L1PowerMetric l1power;
229  RDT reverseDT(&dom, &dt, &l1power);
230 
231 
232  trace.warning()<<"Power"<<std::endl;
233  for(unsigned int j=2; j<16; j++)
234  {
235  for(unsigned int i=2; i<16; i++)
236  trace.info()<< reverseDT.getPowerVector(Z2i::Point(i,j))[0]<<","<<reverseDT.getPowerVector(Z2i::Point(i,j))[1]<<" ";
237  trace.info()<<std::endl;
238  }
239 
240  trace.warning()<<"REDT:"<<endl;
241  RDT::ConstRange::ConstIterator it2 = reverseDT.constRange().begin();
242  for (unsigned int y = 2; y < 16; y++)
243  {
244  for (unsigned int x = 2; x < 16; x++)
245  {
246  std::cout << (int)(*it2) << " ";
247  ++it2;
248  }
249  std::cout << std::endl;
250  }
251 
252  //Checking
253  bool ok=true;
254  RDT::ConstRange::ConstIterator itrec = reverseDT.constRange().begin(), itend = reverseDT.constRange().end();
255  Image::ConstIterator itinit = image.begin();
256  for( ; itrec != itend; ++itrec,++itinit)
257  if ((*itrec) >= 0)
258  ok = ok & ((*itinit) == 0);
259 
260  nbok += ok ? 1 : 0;
261  nb++;
262  trace.info() << "(" << nbok << "/" << nb << ") "
263  << "true == true" << std::endl;
264  trace.endBlock();
265  return nbok == nb;
266 }
ExactPredicateLpSeparableMetric< Space, 1 > L1Metric
Definition: StdDefs.h:119

References DGtal::Trace::beginBlock(), dt, DGtal::Trace::endBlock(), image(), DGtal::Trace::info(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().