DGtal  1.5.beta
testHashTree.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/colormaps/ColorBrightnessColorMap.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/ImageContainerByHashTree.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/helpers/StdDefs.h"
Include dependency graph for testHashTree.cpp:

Go to the source code of this file.

Functions

bool testHashTree ()
 
bool testHashTree2D ()
 
bool testGetSetVal ()
 
bool testBadKeySizes ()
 
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/09/02

Functions for testing class HashTree.

This file is part of the DGtal library.

Definition in file testHashTree.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 279 of file testHashTree.cpp.

280 {
281  trace.beginBlock ( "Testing class HashTree" );
282  trace.info() << "Args:";
283  for ( int i = 0; i < argc; ++i )
284  trace.info() << " " << argv[ i ];
285  trace.info() << std::endl;
286 
287  bool res = testHashTree() && testHashTree2D() && testGetSetVal() && testBadKeySizes(); // && ... other tests
288  trace.emphase() << ( res ? "Passed." : "Error." ) << std::endl;
289  trace.endBlock();
290  return res ? 0 : 1;
291 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testBadKeySizes()
bool testHashTree2D()
bool testHashTree()
bool testGetSetVal()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testBadKeySizes(), testGetSetVal(), testHashTree(), testHashTree2D(), and DGtal::trace.

◆ testBadKeySizes()

bool testBadKeySizes ( )

This should raise an ASSERT abort if uncommented

Definition at line 241 of file testHashTree.cpp.

242 {
243  typedef SpaceND<2> SpaceType;
244  typedef HyperRectDomain<SpaceType> TDomain;
245  typedef TDomain::Point Point;
246  Board2D board;
247  board.setUnit(Board2D::UCentimeter);
248 
249 
250  //Default image selector = STLVector
252  Point d(128,128);
253 
254  trace.beginBlock ( "Test maximal depth > number of bits of the HashKey type" );
255  Image myImage ( 3, 80, 0 );
256  trace.info() << myImage;
257  trace.endBlock();
258 
259  trace.beginBlock ( "Test morton hash size > number of bits of the HashKey type" );
261  // Image myImage2 ( 80, 8, 0 );
262  //trace.info() << myImage2;
263  trace.endBlock();
264 
265  //Default image selector = STLVector
267  trace.beginBlock ( "Changing the HashKey type" );
268  Image2 myImage3( 3, 80, 0 );
269  trace.info() << myImage3;
270  trace.endBlock();
271 
272 
273  return true;
274 }
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
Model of CImageContainer implementing the association key<->Value using a hash tree....
void setUnit(Unit unit)
Definition: Board.cpp:239
MyPointD Point
Definition: testClone2.cpp:383
ImageContainerBySTLVector< Domain, Value > Image

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), LibBoard::Board::setUnit(), DGtal::trace, and LibBoard::Board::UCentimeter.

Referenced by main().

◆ testGetSetVal()

bool testGetSetVal ( )

Example of a test. To be completed.

Domain characterized by points

Domain characterized by points

Definition at line 112 of file testHashTree.cpp.

113 {
114  unsigned int nbok = 0;
115  unsigned int nb = 0;
116 
117  typedef SpaceND<2> SpaceType;
118  typedef HyperRectDomain<SpaceType> TDomain;
119  typedef TDomain::Point Point;
120  Board2D board;
121  typedef HueShadeColorMap<unsigned char,2> HueTwice;
123 
124 
125  //Default image selector = STLVector
127  typedef ImageContainerBySTLVector<TDomain, int> ImageVector;
128 
129  Point a( 1,1 );
130  Point b ( 50,50 );
131  Point c(15,15);
132  Point d(128,128);
133 
134  Point l(0,0);
135  Point u(255,255);
136 
137  trace.beginBlock ( "Image init" );
139  Image myImage ( 3, 8, 0 );
140 
141  ImageVector myImageV(TDomain(l,u));
142 
143  trace.info() << myImage;
144  trace.endBlock();
145 
146 
147  trace.beginBlock("SetVal");
148  for( a[1] = 0; a[1] < 256; a[1]++)
149  for( a[0] = 0; a[0] < 256; a[0]++)
150  {
151  if ( pow((double)(a[0]-128),3.0) - pow((double)(a[1]-128),3.0) < pow(32.0,3.0))
152  {
153  myImage.setValue(a, 30);
154  myImageV.setValue(a,30);
155  }
156 
157  else
158  if ( pow((double)(a[0]-128),3.0) - pow((double)(a[1]-128),3.0) < pow(64.0,3.0))
159  {
160  myImage.setValue(a, 10);
161  myImageV.setValue(a,10);
162  }
163  }
164  trace.endBlock();
165 
166  bool result=true;
167 
168  trace.beginBlock("GetVal consistency test");
169  for( a[1] = 0; a[1] < 256; a[1]++)
170  for( a[0] = 0; a[0] < 256; a[0]++)
171  {
172  if ( pow((a[0]-128),3.0) - pow((a[1]-128),3.0) < pow(32,3.0))
173  result = result && (myImage(a) == 30);
174  else
175  if ( pow((a[0]-128),3.0) - pow((a[1]-128),3.0) < pow(64,3.0))
176  result = result && (myImage(a) == 10);
177  }
178  trace.endBlock();
179 
180  if (result)
181  trace.info() << "Get/Set test passed"<<std::endl;
182  else
183  trace.error() << "Get/Set test error"<<std::endl;
184  nbok += result ? 1 : 0;
185  nb++;
186 
187  trace.info() << myImage;
188  trace.info() << myImageV;
189 
190  Display2DFactory::drawImageHashTree<HueTwice>(board, myImage, 0, 255);
191  board.saveSVG( "hashtree.svg" );
192  board.clear();
193  Display2DFactory::drawImage<HueTwice>(board, myImageV, 0, 255);
194  board.saveSVG( "hashtree-vector.svg" );
195 
196 
198  Image myImage2 ( 5, 8, 0 );
199 
200  trace.beginBlock("SetVal (keysize=5)");
201  for( a[1] = 0; a[1] < 256; a[1]++)
202  for( a[0] = 0; a[0] < 256; a[0]++)
203  {
204  if ( pow((a[0]-128),3.0) - pow((a[1]-128),3.0) < pow(32,3.0))
205  myImage2.setValue(a, 30);
206  else
207  if ( pow((a[0]-128),3.0) - pow((a[1]-128),3.0) < pow(64,3.0))
208  myImage2.setValue(a, 10);
209  }
210  trace.endBlock();
211 
212  result=true;
213 
214  trace.beginBlock("GetVal consistency test (keysize=5)");
215  for( a[1] = 0; a[1] < 256; a[1]++)
216  for( a[0] = 0; a[0] < 256; a[0]++)
217  {
218  if ( pow((a[0]-128),3.0) - pow((a[1]-128),3.0) < pow(32,3.0))
219  result = result && (myImage2(a) == 30);
220  else
221  if ( pow((a[0]-128),3.0) - pow((a[1]-128),3.0) < pow(64,3.0))
222  result = result && (myImage2(a) == 10);
223  }
224  trace.endBlock();
225 
226  if (result)
227  trace.info() << "Get/Set test passed"<<std::endl;
228  else
229  trace.error() << "Get/Set test error"<<std::endl;
230  nbok += result ? 1 : 0;
231  nb++;
232 
233  trace.warning() << "(" << nbok << "/" << nb << ") "
234  << "true == true" << std::endl;
235 
236 
237  return nbok == nb;
238 }
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
std::ostream & error()
std::ostream & warning()
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:151
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1011

References DGtal::Trace::beginBlock(), LibBoard::Board::clear(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Trace::info(), LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), DGtal::Image< TImageContainer >::setValue(), DGtal::trace, LibBoard::Board::UCentimeter, and DGtal::Trace::warning().

Referenced by main().

◆ testHashTree()

bool testHashTree ( )

Example of a test. To be completed.

Image created from depth

Domain characterized by points a and b

Definition at line 58 of file testHashTree.cpp.

59 {
60  trace.beginBlock ( "Testing simple init ..." );
61 
62 
63  typedef SpaceND<4> Space4Type;
64  typedef HyperRectDomain<Space4Type> TDomain;
65  typedef TDomain::Point Point;
67 
68  //Default image selector = STLVector
70 
71  const Integer t[ ] = { 1, 2, 3 ,4};
72  const Integer t2[ ] = { 5, 5, 3 ,4};
73  Point a ( t );
74  Point b ( t2 );
75 
77  Image myImage ( 3, 3,0 );
78 
80  TDomain domain(a,b);
81  Image myImage2 ( domain );
82 
83  trace.info() << myImage;
84  trace.info() << myImage2;
85 
86  trace.endBlock();
87 
88  return true;
89 }
Domain domain

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

Referenced by main().

◆ testHashTree2D()

bool testHashTree2D ( )

Hashtree2D

Definition at line 95 of file testHashTree.cpp.

96 {
97  trace.beginBlock("Testing 2D");
98  Z2i::Domain domain(Z2i::Point(0,0), Z2i::Point(255,255));
100 
101  Image myImage(domain);
102  trace.info()<< myImage<<std::endl;
103  trace.endBlock();
104 
105  return true;
106 }

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

Referenced by main().