1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#ifndef __PNTREELIGHT_H_IMPL__ |
8 |
|
|
#define __PNTREELIGHT_H_IMPL__ |
9 |
|
|
|
10 |
|
|
#include <string.h> |
11 |
|
|
|
12 |
|
|
#include "PNTreeLight.h" |
13 |
|
|
|
14 |
|
|
///Default constructeur of PNTreeLight |
15 |
|
|
template<typename T, typename U, unsigned char N> |
16 |
|
|
PNTreeLight<T,U,N>::PNTreeLight(){ |
17 |
|
|
p_sizeLimit = 1e-5; |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
///Default constructeur of PNTreeLight |
21 |
|
|
/** @param pos : position of the PNTreeLight |
22 |
|
|
* @param size : size of the PNTreeLight |
23 |
|
|
* @param sizeLimit : size limit of the cells |
24 |
|
|
*/ |
25 |
|
|
template<typename T, typename U, unsigned char N> |
26 |
|
4 |
PNTreeLight<T,U,N>::PNTreeLight(T pos[N], T size[N], T sizeLimit){ |
27 |
✓ |
4 |
initialisationPNTreeLight(pos, size, sizeLimit); |
28 |
|
4 |
} |
29 |
|
|
|
30 |
|
|
///Copy constructor of PNTreeLight |
31 |
|
|
/** @param other : class to copy |
32 |
|
|
*/ |
33 |
|
|
template<typename T, typename U, unsigned char N> |
34 |
|
|
PNTreeLight<T,U,N>::PNTreeLight(const PNTreeLight<T,U,N> & other){ |
35 |
|
|
copyPNTreeLight(other); |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
///Destructeur of PNTreeLight |
39 |
|
|
template<typename T, typename U, unsigned char N> |
40 |
|
4 |
PNTreeLight<T,U,N>::~PNTreeLight(){ |
41 |
|
4 |
p_node.clear(); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
///Saves the PNTreeLight into a txt file for gnuplot |
45 |
|
|
/** @param fileName : name of the text file we want to write |
46 |
|
|
* @return true on success, false otherwise |
47 |
|
|
*/ |
48 |
|
|
template<typename T, typename U, unsigned char N> |
49 |
|
4 |
bool PNTreeLight<T, U, N>::saveGnuplotData(const std::string & fileName){ |
50 |
|
4 |
return p_node.saveGnuplotData(fileName, p_pos, p_size); |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
///Saves the PNTreeLight into a txt file for gnuplot |
54 |
|
|
/** @param fs : text file we want to write |
55 |
|
|
* @param height : height of the quad to draw |
56 |
|
|
* @return true on success, false otherwise |
57 |
|
|
*/ |
58 |
|
|
template<typename T, typename U, unsigned char N> |
59 |
|
|
bool PNTreeLight<T, U, N>::saveGnuplotData(std::ofstream & fs, T height){ |
60 |
|
|
return p_node.saveGnuplotData(fs, height, p_pos, p_size); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
///Set the position of the PNTreeLight |
64 |
|
|
/** @param pos : position of the PNTreeLight |
65 |
|
|
*/ |
66 |
|
|
template<typename T, typename U, unsigned char N> |
67 |
|
4 |
void PNTreeLight<T, U, N>::setPosition(T pos[N]){ |
68 |
|
4 |
memcpy(p_pos, pos, N*sizeof(T)); |
69 |
|
4 |
} |
70 |
|
|
|
71 |
|
|
///Set the size of the PNTreeLight |
72 |
|
|
/** @param size : size of the PNTreeLight |
73 |
|
|
*/ |
74 |
|
|
template<typename T, typename U, unsigned char N> |
75 |
|
4 |
void PNTreeLight<T, U, N>::setSize(T size[N]){ |
76 |
|
4 |
memcpy(p_size, size, N*sizeof(T)); |
77 |
|
4 |
} |
78 |
|
|
|
79 |
|
|
///Set the limit size of the PNTreeLight cells |
80 |
|
|
/** @param limitSize : limit size of the PNTreeLight cells |
81 |
|
|
*/ |
82 |
|
|
template<typename T, typename U, unsigned char N> |
83 |
|
|
void PNTreeLight<T, U, N>::setLimitSize(T limitSize){ |
84 |
|
|
p_sizeLimit = limitSize; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
///Add an element in the PNTreeLightNode |
88 |
|
|
/** @param posData : position of the data |
89 |
|
|
* @param data : pointer to the data we want to sort |
90 |
|
|
* @return true on success, false otherwise |
91 |
|
|
*/ |
92 |
|
|
template<typename T, typename U, unsigned char N> |
93 |
|
1152 |
bool PNTreeLight<T, U, N>::addElement(T * posData, U * data){ |
94 |
|
1152 |
return p_node.addElement(posData, data, p_pos, p_size, p_sizeLimit); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
///Get the data of the last node in the N tree |
98 |
|
|
/** @param posData : position of the data |
99 |
|
|
* @return data of the last node in the N tree |
100 |
|
|
*/ |
101 |
|
|
template<typename T, typename U, unsigned char N> |
102 |
|
4 |
const U * PNTreeLight<T, U, N>::getLastData(T * posData) const{ |
103 |
|
4 |
return p_node.getLastData(posData, p_pos, p_size); |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
///Get the closer data from the given position |
107 |
|
|
/** @param posData : position we want the closer data |
108 |
|
|
* @return closer data from the given position |
109 |
|
|
*/ |
110 |
|
|
template<typename T, typename U, unsigned char N> |
111 |
|
|
const U * PNTreeLight<T, U, N>::getCloserData(T * posData) const{ |
112 |
|
|
unsigned int nbNeighbours(PPower<3, N>::Value); |
113 |
|
|
bool tabNeighbour[nbNeighbours]; |
114 |
|
|
for(unsigned int i(0u); i < nbNeighbours; ++i){ |
115 |
|
|
tabNeighbour[i] = false; |
116 |
|
|
} |
117 |
|
|
tabNeighbour[nbNeighbours/2] = true; //The cell of the current node |
118 |
|
|
U * closerData = NULL; |
119 |
|
|
T distFromCloserData = 0.0; |
120 |
|
|
p_node.getCloserData(closerData, distFromCloserData, tabNeighbour, nbNeighbours, posData, p_pos, p_size); |
121 |
|
|
return closerData; |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
///Get the closer data from the given position |
125 |
|
|
/** @param[out] distFromCloserData : distance from the closer data |
126 |
|
|
* @param posData : position we want the closer data |
127 |
|
|
* @return closer data from the given position |
128 |
|
|
*/ |
129 |
|
|
template<typename T, typename U, unsigned char N> |
130 |
|
|
const U * PNTreeLight<T, U, N>::getCloserDataDist(T & distFromCloserData, T * posData) const{ |
131 |
|
|
unsigned int nbNeighbours(PPower<3, N>::Value); |
132 |
|
|
bool tabNeighbour[nbNeighbours]; |
133 |
|
|
for(unsigned int i(0u); i < nbNeighbours; ++i){ |
134 |
|
|
tabNeighbour[i] = false; |
135 |
|
|
} |
136 |
|
|
tabNeighbour[nbNeighbours/2] = true; //The cell of the current node |
137 |
|
|
U * closerData = NULL; |
138 |
|
|
distFromCloserData = 0.0; |
139 |
|
|
p_node.getCloserData(closerData, distFromCloserData, tabNeighbour, nbNeighbours, posData, p_pos, p_size); |
140 |
|
|
return closerData; |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
///Definition of equal operator of PNTreeLight |
144 |
|
|
/** @param other : class to copy |
145 |
|
|
* @return copied class |
146 |
|
|
*/ |
147 |
|
|
template<typename T, typename U, unsigned char N> |
148 |
|
|
PNTreeLight<T,U,N> & PNTreeLight<T,U,N>::operator = (const PNTreeLight<T,U,N> & other){ |
149 |
|
|
copyPNTreeLight(other); |
150 |
|
|
return *this; |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
///Copy function of PNTreeLight |
154 |
|
|
/** @param other : class to copy |
155 |
|
|
*/ |
156 |
|
|
template<typename T, typename U, unsigned char N> |
157 |
|
|
void PNTreeLight<T,U,N>::copyPNTreeLight(const PNTreeLight<T,U,N> & other){ |
158 |
|
|
|
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
///Initialisation function of the class PNTreeLight |
162 |
|
|
/** @param pos : position of the PNTreeLight |
163 |
|
|
* @param size : size of the PNTreeLight |
164 |
|
|
* @param sizeLimit : limit of the cell size |
165 |
|
|
*/ |
166 |
|
|
template<typename T, typename U, unsigned char N> |
167 |
|
4 |
void PNTreeLight<T,U,N>::initialisationPNTreeLight(T pos[N], T size[N], T sizeLimit){ |
168 |
|
4 |
setPosition(pos); |
169 |
|
4 |
setSize(size); |
170 |
|
4 |
p_sizeLimit = sizeLimit; |
171 |
|
4 |
} |
172 |
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
#endif |
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|