7#ifndef __PNTREE_LIGHT_NODE_H_IMPL__
8#define __PNTREE_LIGHT_NODE_H_IMPL__
18template<
typename T,
typename U,
unsigned char N>
26template<
typename T,
typename U,
unsigned char N>
32template<
typename T,
typename U,
unsigned char N>
41template<
typename T,
unsigned char N>
43 for(
unsigned char i(0lu); i < N; ++i){
44 childSize[i] = parentSize[i]/2.f;
53template<
typename T,
unsigned char N>
55 for(
unsigned char i(0); i < N; ++i){
56 if(halfSizeChild[i] < sizeLimit)
return false;
69template<
typename T,
typename U,
unsigned char N>
80 if(!
split(pos, size, sizeLimit))
return false;
81 return addElement(posData, data, pos, size, sizeLimit);
91 return child->
addElement(posData, data, childPos, childSize, sizeLimit);
102template<
typename T,
typename U,
unsigned char N>
104 if(fileName ==
"")
return false;
107 if(!fs.is_open()){
return false;}
120template<
typename T,
typename U,
unsigned char N>
123 fs << pos[0] <<
"\t" << pos[1] <<
"\t" << height << std::endl;
124 fs << (pos[0] + size[0]) <<
"\t" << pos[1] <<
"\t" << height << std::endl;
125 fs << (pos[0] + size[0]) <<
"\t" << (pos[1] + size[1]) <<
"\t" << height << std::endl;
126 fs << pos[0] <<
"\t" << (pos[1] + size[1]) <<
"\t" << height << std::endl;
127 fs << pos[0] <<
"\t" << pos[1] <<
"\t" << height << std::endl;
129 T px0(pos[0]), px1(pos[0] + size[0]);
130 T py0(pos[1]), py1(pos[1] + size[1]);
131 T pz0(pos[2]), pz1(pos[2] + size[2]);
134 fs << px0 <<
"\t" << py0 <<
"\t" << pz0 << std::endl;
135 fs << px1 <<
"\t" << py0 <<
"\t" << pz0 << std::endl;
136 fs << px1 <<
"\t" << py1 <<
"\t" << pz0 << std::endl;
137 fs << px0 <<
"\t" << py1 <<
"\t" << pz0 << std::endl;
138 fs << px0 <<
"\t" << py0 <<
"\t" << pz0 << std::endl;
141 fs << px0 <<
"\t" << py0 <<
"\t" << pz1 << std::endl;
142 fs << px1 <<
"\t" << py0 <<
"\t" << pz1 << std::endl;
143 fs << px1 <<
"\t" << py1 <<
"\t" << pz1 << std::endl;
144 fs << px0 <<
"\t" << py1 <<
"\t" << pz1 << std::endl;
145 fs << px0 <<
"\t" << py0 <<
"\t" << pz1 << std::endl;
148 fs << px0 <<
"\t" << py0 <<
"\t" << pz0 << std::endl;
149 fs << px0 <<
"\t" << py0 <<
"\t" << pz1 << std::endl;
151 fs << px0 <<
"\t" << py1 <<
"\t" << pz0 << std::endl;
152 fs << px0 <<
"\t" << py1 <<
"\t" << pz1 << std::endl;
154 fs << px1 <<
"\t" << py1 <<
"\t" << pz0 << std::endl;
155 fs << px1 <<
"\t" << py1 <<
"\t" << pz1 << std::endl;
157 fs << px1 <<
"\t" << py0 <<
"\t" << pz0 << std::endl;
158 fs << px1 <<
"\t" << py0 <<
"\t" << pz1 << std::endl;
162 T childSize[N], posChild[N];
164 for(
unsigned char i(0); i < PPower<2, N>::Value; ++i){
165 for(
unsigned char k(0); k < N; ++k){
166 posChild[k] = pos[k] + ((i >> k) & 1)*childSize[k];
168 p_tableChildren[i].saveGnuplotData(fs, height + 1, posChild, childSize);
175template<
typename T,
typename U,
unsigned char N>
178 for(
unsigned char i(0); i < PPower<2, N>::Value; ++i){
194template<
typename T,
typename U,
unsigned char N>
197 if(
p_data == NULL)
return NULL;
202 if(child == NULL)
return NULL;
206 return child->
getLastData(posData, pos, childSize);
216template<
typename T,
unsigned char N>
219 for(
unsigned char i(0); i < N; ++i){
220 x = posA[i] - posB[i];
231template<
unsigned char N>
233 unsigned int index(0u), base(1u), tmp;
234 for(
unsigned char i(N); i < N; ++i){
236 if(indexChild[i] > currentChildIndex[i]){
238 }
else if(indexChild[i] == currentChildIndex[i]){
257template<
typename T,
typename U,
unsigned char N>
259 const T * posData,
const T pos[N],
const T size[N])
const
262 if(
p_data == NULL)
return false;
264 if(closerData == NULL){
270 if(dist < distFromCloserData){
271 distFromCloserData = dist;
280 if(child == NULL)
return false;
284 bool b = child->
getCloserData(closerData, distFromCloserData, tabIsNeighbourChecked, nbNeighbour, posData, childPos, childSize);
287 unsigned char indexChild[N], currentChildIndex[N];
288 T currentChildPos[N];
292 for(
unsigned char i(0); i < PPower<2, N>::Value; ++i){
293 if(i == fullIndexChild)
continue;
294 for(
unsigned char j(0); j < N; ++j){
295 currentChildIndex[j] = (i >> j) & 1;
296 currentChildPos[j] = pos[j] + ((T)currentChildIndex[j])*childSize[j];
300 if(tabIsNeighbourChecked[indexCurrentNeighbour])
continue;
302 tabIsNeighbourChecked[indexCurrentNeighbour] =
true;
303 if(child->
getCloserData(closerData, distFromCloserData, tabIsNeighbourChecked, nbNeighbour,
304 posData, currentChildPos, childSize))
323template<
typename T,
typename U,
unsigned char N>
326 unsigned char posChild(0), base(1);
328 for(
unsigned char j(0); j < N; ++j){
329 cond = ((posData[j] - pos[j]) > size[j]*0.5);
330 childPos[j] = pos[j] + cond*size[j]*0.5;
331 posChild += cond*base;
345template<
typename T,
typename U,
unsigned char N>
348 unsigned char posChild(0), base(1);
350 for(
unsigned char j(0); j < N; ++j){
351 cond = ((posData[j] - pos[j]) > size[j]*0.5);
352 childPos[j] = pos[j] + cond*size[j]*0.5;
353 posChild += cond*base;
369template<
typename T,
typename U,
unsigned char N>
371 if(p_tableChildren == NULL)
return;
372 for(
unsigned char j(0lu); j < N; ++j){
373 index[j] = ((posData[j] - pos[j]) > size[j]*0.5);
383template<
typename T,
typename U,
unsigned char N>
385 if(p_tableChildren == NULL)
return;
386 for(
unsigned char j(0); j < N; ++j){
387 index[j] = ((posData[j] - pos[j]) > size[j]*0.5);
395template<
typename T,
typename U,
unsigned char N>
397 unsigned char posChild(0), base(1);
398 for(
unsigned char j(0); j < N; ++j){
399 posChild += (index[j])*base;
408template<
typename T,
typename U,
unsigned char N>
414template<
typename T,
typename U,
unsigned char N>
420template<
typename T,
typename U,
unsigned char N>
426template<
typename T,
typename U,
unsigned char N>
433template<
typename T,
typename U,
unsigned char N>
443template<
typename T,
typename U,
unsigned char N>
452template<
typename T,
typename U,
unsigned char N>
463template<
typename T,
typename U,
unsigned char N>
466 std::cerr <<
"PNTreeLightNode<T, U, N>::split() : current node already split" << std::endl;
478 for(
unsigned char i(0); i < nbChildren; ++i){
488 if(child == NULL)
return false;
498template<
typename T,
typename U,
unsigned char N>
bool isNeighbourSearchFinised(const bool *tabIsNeighbourChecked, unsigned int nbNeighbour)
Says is the neighbours search is finised.
unsigned int getNeighbourCellIndex(unsigned char indexChild[N], unsigned char currentChildIndex[N])
Get the index of the check neighbours tab.
bool checkSizeLimitLight(const T halfSizeChild[N], T sizeLimit)
Check the size of the childs of a N Tree.
void makeHalfSize(T childSize[N], const T parentSize[N])
Get the size of the child.
T getDistanceFromData(const T posA[N], const T posB[N])
Get the distance between two points.
virtual ~PNTreeLightNode()
Destructeur of PNTreeLightNode.
void getIndexOfChildFromPos(unsigned char index[N], const T posData[N], const T pos[N], const T size[N]) const
void copyPNTreeLightNode(const PNTreeLightNode< T, U, N > &other)
Copy function of PNTreeLightNode.
PNTreeLightNode< T, U, N > * p_tableChildren
Position of the data in the hyper cube.
unsigned char getFullIndexChild(unsigned char index[N]) const
Get the full index position of a child.
PNTreeLightNode()
Default constructor of PNTreeLightNode.
const T * getDataPos() const
Returns the data position.
const PNTreeLightNode< T, U, N > * getChild(unsigned char childId) const
Returns the child of the PNTreeLightNode.
bool addElement(T *posData, U *data, const T pos[N], const T size[N], const T sizeLimit)
Add an element in the PNTreeLightNode.
bool split(const T pos[N], const T size[N], T sizeLimit)
Split the PNTreeLightNode.
void initialisationPNTreeLightNode()
Initialisation function of the class PNTreeLightNode.
void clear()
Clear the PNTreeLightNode content.
bool getCloserData(U *&closerData, T &distFromCloserData, bool *tabIsNeighbourChecked, unsigned int nbNeighbour, const T *posData, const T pos[N], const T size[N]) const
Get the closer data from the given position posData.
const PNTreeLightNode< T, U, N > * getTabChildren() const
Returns the table of children of the PNTreeLightNode.
U * p_data
Data of the node.
bool saveGnuplotData(const std::string &fileName, T pos[N], T size[N])
Saves the PNTreeLightNode into a txt file for gnuplot.
const U * getLastData(const T *posData, const T pos[N], const T size[N]) const
Get the data of the last node in the N tree.
T * p_posData
Position of the data in the cell.
const PNTreeLightNode< T, U, N > * getChildFromPos(T childPos[N], const T *posData, const T pos[N], const T size[N]) const
Get the child of the PNTreeLightNode with a position.