DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testMorton.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "DGtal/kernel/PointVector.h"
34
#include "DGtal/images/Morton.h"
35
#include "DGtal/base/Bits.h"
36
38
39
using namespace
std
;
40
using namespace
DGtal
;
41
43
// Functions for testing class Morton.
45
49
bool
testMorton
()
50
{
51
unsigned
int
nbok = 0;
52
unsigned
int
nb = 0;
53
54
trace
.
beginBlock
(
"Testing Morton codes ..."
);
55
56
typedef
PointVector<2,DGtal::int32_t>
Point
;
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
}
122
124
// Standard services - public :
125
126
int
main
(
int
argc,
char
** argv )
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
}
139
// //
DGtal::LOG2
Definition
ExpressionTemplates.h:71
DGtal::LOG2::VALUE
@ VALUE
Definition
ExpressionTemplates.h:72
DGtal::Morton
Aim: Implements the binary Morton code construction in nD.
Definition
Morton.h:78
DGtal::Morton::interleaveBits
void interleaveBits(const Point &aPoint, HashKey &output) const
DGtal::Morton::childrenKeys
void childrenKeys(const HashKey key, HashKey *result) const
DGtal::Morton::coordinatesFromKey
void coordinatesFromKey(const HashKey key, Point &coordinates) const
DGtal::Morton::keyFromCoordinates
HashKey keyFromCoordinates(const std::size_t treeDepth, const Point &coordinates) const
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition
PointVector.h:593
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::warning
std::ostream & warning()
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::uint64_t
std::uint64_t uint64_t
unsigned 64-bit integer.
Definition
BasicTypes.h:64
DGtal::trace
Trace trace
std
STL namespace.
DGtal::Bits::bitString
static std::string bitString(T value, unsigned nbBits=0)
Bits Structs grouping all the functions of this tiny library for bitwise calculation.
Definition
Bits.h:56
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testMorton
bool testMorton()
Definition
testMorton.cpp:49
tests
images
testMorton.cpp
Generated on
for DGtal by
1.18.0