DGtal  1.4.beta
testMorton.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/PointVector.h"
#include "DGtal/images/Morton.h"
#include "DGtal/base/Bits.h"
Include dependency graph for testMorton.cpp:

Go to the source code of this file.

Functions

bool testMorton ()
 
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/10

Functions for testing class Morton.

This file is part of the DGtal library.

Definition in file testMorton.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 126 of file testMorton.cpp.

127 {
128  trace.beginBlock ( "Testing class Morton" );
129  trace.info() << "Args:";
130  for ( int i = 0; i < argc; ++i )
131  trace.info() << " " << argv[ i ];
132  trace.info() << endl;
133 
134  bool res = testMorton(); // && ... other tests
135  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
136  trace.endBlock();
137  return res ? 0 : 1;
138 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testMorton()
Definition: testMorton.cpp:49

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

◆ testMorton()

bool testMorton ( )

Example of a test. To be completed.

Definition at line 49 of file testMorton.cpp.

50 {
51  unsigned int nbok = 0;
52  unsigned int nb = 0;
53 
54  trace.beginBlock ( "Testing Morton codes ..." );
55 
57  typedef DGtal::uint64_t HashKey;
58 
59  Point p(0,0), pbis;
60  HashKey h, h2;
61  HashKey children[4];
62 
63  Morton<HashKey,Point> morton;
64 
65  trace.info() << endl;
66 
67  morton.interleaveBits( p , h );
68  trace.info() << p << h << " = "<< Bits::bitString( h )<<endl;
69  trace.info() << "Key (level2)= "<< Bits::bitString( h2=morton.keyFromCoordinates( 2, p ))<<endl;
70  nbok += (h == 0) ? 1 : 0;
71  nb++;
72 
73  morton.coordinatesFromKey( h2 , pbis);
74  trace.info() << "Point from code= "<<pbis<<endl;
75  nbok += (p == pbis) ? 1 : 0;
76  nb++;
77 
78  trace.info()<<endl;
79 
80  Point p2(2,3);
81  morton.interleaveBits( p2 , h );
82  trace.info() << p2<<" "<< h << " = "<< Bits::bitString( h )<<endl;
83  trace.info() << "Key (level2)= "<< Bits::bitString( h2 = morton.keyFromCoordinates( 2, p2 ))<<endl;
84  nbok += (h == 14) ? 1 : 0;
85  nb++;
86 
87  morton.coordinatesFromKey( h2 , pbis);
88  trace.info() << "Point from code= "<<pbis<<endl;
89  nbok += (p2 == pbis) ? 1 : 0;
90  nb++;
91 
92  trace.beginBlock("Testing children...");
93  h2 = morton.keyFromCoordinates( 2, p2);
94  morton.childrenKeys(h2, children);
95  for(unsigned int k=0; k<4;k++)
96  trace.info()<<"child["<<k<<"]= "<<children[k]<<" "<< Bits::bitString( children[k])<<endl;
97  trace.endBlock();
98 
99  trace.beginBlock("getKey Benchmark");
100 
101  Point p3(0,0);
102  DGtal::uint64_t sum=0;
103  for(unsigned int k=0; k < 1000000 ;k++)
104  {
105  p3[1] = k/1000;
106  p3[0] = k %1000;
107  sum += morton.keyFromCoordinates(32,p);
108  }
109  trace.endBlock();
110  if (sum == 345)
111  trace.info() << "Compiler trick"<<endl;
112 
113  trace.info() << "(" << nbok << "/" << nb << ") "
114  << "true == true" << std::endl;
115  trace.endBlock();
116 
117  trace.warning() << "Log2(64)=" <<LOG2<64>::VALUE<<endl;
118  trace.warning() << "Log2(1)=" <<LOG2<sizeof(int)>::VALUE<<endl;
119 
120  return nbok == nb;
121 }
Aim: Implements the binary Morton code construction in nD.
Definition: Morton.h:78
void interleaveBits(const Point &aPoint, HashKey &output) const
void childrenKeys(const HashKey key, HashKey *result) const
void coordinatesFromKey(const HashKey key, Point &coordinates) const
HashKey keyFromCoordinates(const std::size_t treeDepth, const Point &coordinates) const
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
std::ostream & warning()
boost::uint64_t uint64_t
unsigned 64-bit integer.
Definition: BasicTypes.h:65
MyPointD Point
Definition: testClone2.cpp:383

References DGtal::Trace::beginBlock(), DGtal::Morton< THashKey, TPoint >::childrenKeys(), DGtal::Morton< THashKey, TPoint >::coordinatesFromKey(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::Morton< THashKey, TPoint >::interleaveBits(), DGtal::Morton< THashKey, TPoint >::keyFromCoordinates(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().