1 |
|
|
|
2 |
|
|
/*************************************** |
3 |
|
|
Auteur : Pierre Aubert |
4 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
5 |
|
|
Licence : CeCILL-C |
6 |
|
|
****************************************/ |
7 |
|
|
|
8 |
|
|
#include <iostream> |
9 |
|
|
#include "Tree/PNTreeLight.h" |
10 |
|
|
|
11 |
|
|
#define NB_POINT 8lu |
12 |
|
|
#define NB_POINT_TOTAL (NB_POINT*NB_POINT) |
13 |
|
|
|
14 |
|
|
#define NB_POINT_3D 8lu |
15 |
|
|
#define NB_POINT_3D_TOTAL (NB_POINT_3D*NB_POINT_3D*NB_POINT_3D) |
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
///Tests the basis of the quadtree |
20 |
|
|
/** @return true on success, false otherwise |
21 |
|
|
*/ |
22 |
|
1 |
bool testBaseQuadTree(){ |
23 |
|
1 |
size_t nbPoint(NB_POINT); |
24 |
|
1 |
float dXY(5.0f); |
25 |
|
1 |
float shift(dXY/2.0f); |
26 |
|
|
|
27 |
|
1 |
float posXY(0.0f), sizeXY(((size_t)(2.0f*shift + ((float)(nbPoint - 1lu))*dXY))); |
28 |
|
1 |
float posTab[] = {posXY, posXY}; |
29 |
|
1 |
float sizeTab[] = {sizeXY, sizeXY}; |
30 |
✓ |
2 |
PNTreeLight<float, size_t, 2> quadTree(posTab, sizeTab, 1.0f); |
31 |
|
|
size_t tabId[NB_POINT_TOTAL], id; |
32 |
✓✓ |
65 |
for(size_t i(0lu); i < NB_POINT_TOTAL; ++i){tabId[i] = i;} |
33 |
|
|
float x, y; |
34 |
|
|
float tabPos[2*NB_POINT_TOTAL]; |
35 |
|
|
|
36 |
|
1 |
bool b(true); |
37 |
✓ |
2 |
std::ofstream fs; |
38 |
✓ |
1 |
fs.open("pointAddedInQuadTree.txt"); |
39 |
✓ |
1 |
b &= fs.is_open(); |
40 |
✓✓ |
9 |
for(size_t i(0lu); i < nbPoint; ++i){ |
41 |
|
8 |
y = shift + ((float)i)*dXY; |
42 |
✓✓ |
72 |
for(size_t j(0lu); j < nbPoint; ++j){ |
43 |
|
64 |
x = shift + ((float)j)*dXY; |
44 |
|
64 |
tabPos[(i*nbPoint + j)*2lu] = x; |
45 |
|
64 |
tabPos[(i*nbPoint + j)*2lu + 1lu] = y; |
46 |
|
64 |
id = i*nbPoint + j; |
47 |
✓✓✓✓ ✓✓✓ |
64 |
std::cerr << "Add point " << x << "," << y << "\t, id = " << id << std::endl; |
48 |
✓✓✓✓ ✓ |
64 |
fs << x << "\t" << y << "\t0" << std::endl; |
49 |
✓✗✓ |
64 |
if(!quadTree.addElement(&(tabPos[(i*nbPoint + j)*2lu]), tabId+id)){ |
50 |
|
|
std::cerr << "quadTree.addElement : can't add element : Stop" << std::endl; |
51 |
|
|
i = nbPoint; |
52 |
|
|
break; |
53 |
|
|
} |
54 |
|
|
} |
55 |
|
|
} |
56 |
✓ |
1 |
fs.close(); |
57 |
✓ |
1 |
std::string fileTxt("quadTree.txt"); |
58 |
✓ |
1 |
b &= quadTree.saveGnuplotData(fileTxt); |
59 |
|
1 |
float posLastData[] = {11.0f, 19.0f}; |
60 |
✓ |
1 |
const size_t * data = quadTree.getLastData(posLastData); |
61 |
|
1 |
b &= (data != NULL); |
62 |
✓✓✓ |
1 |
std::cout << "testBaseQuadTree : data (11.0, 19.0) = " << *data << std::endl; |
63 |
✓✓✓ |
1 |
std::cout << "testBaseQuadTree : b = " << b << std::endl; |
64 |
|
2 |
return b; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
///Tests the basis of the quadtree |
68 |
|
|
/** @return true on success, false otherwise |
69 |
|
|
*/ |
70 |
|
1 |
bool testBaseQuadTree3d(){ |
71 |
|
1 |
size_t nbPoint(NB_POINT_3D); |
72 |
|
1 |
float dXY(5.0f); |
73 |
|
1 |
float shift(dXY/2.0f); |
74 |
|
|
|
75 |
|
1 |
float posXY(0.0f), sizeXY(((size_t)(2.0f*shift + ((float)(nbPoint - 1lu))*dXY))); |
76 |
|
1 |
float posTab[] = {posXY, posXY, posXY}; |
77 |
|
1 |
float sizeTab[] = {sizeXY, sizeXY, sizeXY}; |
78 |
✓ |
2 |
PNTreeLight<float, size_t, 3> quadTree(posTab, sizeTab); |
79 |
|
|
size_t tabId[NB_POINT_3D_TOTAL], id; |
80 |
✓✓ |
513 |
for(size_t i(0lu); i < NB_POINT_3D_TOTAL; ++i){tabId[i] = i;} |
81 |
|
|
float tabPos[3*NB_POINT_3D_TOTAL]; |
82 |
|
|
float x,y,z; |
83 |
|
1 |
bool b(true); |
84 |
✓ |
2 |
std::ofstream fs; |
85 |
✓ |
1 |
fs.open("pointAddedInQuadTree3d.txt"); |
86 |
✓ |
1 |
b &= fs.is_open(); |
87 |
✓✓ |
9 |
for(size_t k(0lu); k < nbPoint; ++k){ |
88 |
|
8 |
z = shift + ((float)k)*dXY; |
89 |
✓✓ |
72 |
for(size_t i(0lu); i < nbPoint; ++i){ |
90 |
|
64 |
y = shift + ((float)i)*dXY; |
91 |
✓✓ |
576 |
for(size_t j(0lu); j < nbPoint; ++j){ |
92 |
|
512 |
x = shift + ((float)j)*dXY; |
93 |
|
512 |
id = k*nbPoint*nbPoint + i*nbPoint + j; |
94 |
|
|
// std::cerr << "Add point " << tabPos[0] << "," << tabPos[1] << "," << tabPos[2] << "\t, id = " << id << std::endl; |
95 |
|
512 |
tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu] = x; |
96 |
|
512 |
tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu + 1lu] = y; |
97 |
|
512 |
tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu + 2lu] = z; |
98 |
✓✓✓✓ ✓✓ |
512 |
fs << x << "\t" << y << "\t"<< z << std::endl; |
99 |
✓✗✓ |
512 |
if(!quadTree.addElement(&(tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu]), tabId+id)){ |
100 |
|
|
std::cerr << "quadTree.addElement : can't add element : Stop" << std::endl; |
101 |
|
|
i = nbPoint; |
102 |
|
|
break; |
103 |
|
|
} |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
} |
107 |
✓ |
1 |
fs.close(); |
108 |
✓ |
1 |
std::string fileTxt("quadTree3d.txt"); |
109 |
✓ |
1 |
b &= quadTree.saveGnuplotData(fileTxt); |
110 |
|
|
|
111 |
|
1 |
float posLastData[] = {11.0f, 19.0f, 10.0f}; |
112 |
✓ |
1 |
const size_t * data = quadTree.getLastData(posLastData); |
113 |
|
1 |
b &= (data != NULL); |
114 |
✓✓✓ |
1 |
std::cout << "testBaseQuadTree3d : data (11.0, 19.0) = " << *data << std::endl; |
115 |
✓✓✓ |
1 |
std::cout << "testBaseQuadTree3d : b = " << b << std::endl; |
116 |
|
2 |
return b; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
///Check the function isNeighbourSearchFinised |
120 |
|
|
/** @return true on success, false otherwise |
121 |
|
|
*/ |
122 |
|
1 |
bool checkIsNeigbourFinished(){ |
123 |
|
1 |
bool value(true); |
124 |
|
1 |
bool b(true); |
125 |
✓ |
1 |
b &= isNeighbourSearchFinised(&value, 1lu); |
126 |
|
1 |
value = false; |
127 |
✓ |
1 |
b &= !isNeighbourSearchFinised(&value, 1lu); |
128 |
✓✓✓ |
1 |
std::cout << "checkIsNeigbourFinished : b = " << b << std::endl; |
129 |
|
1 |
return b; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
1 |
int main(int argc, char** argv){ |
133 |
|
1 |
bool b(checkIsNeigbourFinished()); |
134 |
|
1 |
b &= testBaseQuadTree(); |
135 |
|
1 |
b &= testBaseQuadTree3d(); |
136 |
|
1 |
return b - 1; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|