PNTreeLightNode.h 2.53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
/***************************************
	Auteur : Pierre Aubert
	Mail : aubertp7@gmail.com
	Licence : CeCILL-C
****************************************/

#ifndef __PNTREE_LIGHT_NODE_H__
#define __PNTREE_LIGHT_NODE_H__

#include <iostream>
#include <fstream>

template<typename T, typename U, unsigned char N>
class PNTreeLightNode;

///@brief Describe a Quad tree
/**	T : Type of the positions
 * 	U : type of the data pointors to be stored
 * 	N : number of dimensions of the N Tree
*/
template<typename T, typename U, unsigned char N>
class PNTreeLightNode{
	public:
		PNTreeLightNode();
		virtual ~PNTreeLightNode();
		
		bool addElement(T * posData, U * data, const T pos[N], const T size[N], const T sizeLimit);
		void clear();
		
		bool saveGnuplotData(const std::string & fileName, T pos[N], T size[N]);
		bool saveGnuplotData(std::ofstream & fs, T height, T pos[N], T size[N]);
		
		const U * getData() const;
		U * getData();
		
		const T * getDataPos() const;
		T * getDataPos();
		
		const U * getLastData(const T * posData, const T pos[N], const T size[N]) const;
		bool getCloserData(U*& closerData, T & distFromCloserData, bool * tabIsNeighbourChecked, unsigned int nbNeighbour,
					const T * posData, const T pos[N], const T size[N]) const;
		
		const PNTreeLightNode<T, U, N> * getChildFromPos(T childPos[N], const T * posData, const T pos[N], const T size[N]) const;
		PNTreeLightNode<T, U, N> * getChildFromPos(T childPos[N], const T * posData, const T pos[N], const T size[N]);
		void getIndexOfChildFromPos(unsigned char index[N], const T posData[N], const T pos[N], const T size[N]) const;
		void getIndexOfChildFromPos(unsigned char index[N], T posData[N], T pos[N], T size[N]);
		unsigned char getFullIndexChild(unsigned char index[N]) const;
		
		const PNTreeLightNode<T, U, N> * getTabChildren() const;
		PNTreeLightNode<T, U, N> * getTabChildren();
		
		const PNTreeLightNode<T, U, N> * getChild(unsigned char childId) const;
		PNTreeLightNode<T, U, N> * getChild(unsigned char childId);
		
	protected:
		void copyPNTreeLightNode(const PNTreeLightNode<T, U, N> & other);
		
	private:
		PNTreeLightNode(const PNTreeLightNode<T, U, N> & other);
		bool split(const T pos[N], const T size[N], T sizeLimit);
		void initialisationPNTreeLightNode();
		
		///Position of the data in the cell
		T * p_posData;
		///Data of the node
		U * p_data;
		///Position of the data in the hyper cube
		PNTreeLightNode<T,U,N> * p_tableChildren;
};

bool isNeighbourSearchFinised(const bool * tabIsNeighbourChecked, unsigned int nbNeighbour);

#include "PNTreeLightNode_impl.h"


#endif