#ifndef __HV_KDTREE_HPP #define __HV_KDTREE_HPP #include #include "config.hpp" namespace CosmoTool { template struct NGBDef { typedef float CoordType; typedef float NGBCoordinates[N]; static const int NumCubes = 1 << (N); }; template struct NGBCell { bool active; ValType val; typename NGBDef::NGBCoordinates coord; }; class NotEnoughCells: public Exception { public: NotEnoughCells() : Exception() {} ~NotEnoughCells() throw () {} }; template struct NGBTreeNode { NGBCell *value; NGBTreeNode *children[2]; typename NGBDef::NGBCoordinates minBound, maxBound; }; template class RecursionInfoCells { public: typename NGBDef::NGBCoordinates x; typename NGBDef::CoordType r, r2; NGBCell **cells; uint32_t currentRank; uint32_t numCells; }; template class NGBTree { public: static const int NumCubes = NGBDef::NumCubes; public: typedef typename NGBDef::CoordType CoordType; typedef typename NGBDef::NGBCoordinates coords; typedef typename CosmoQueue*> NGBQueue; NGBTree(NGBCell *cells, uint32_t Ncells); ~NGBTree(); uint32_t getIntersection(const coords& x, CoordType r, NGBCell **cells, uint32_t numCells) throw (NotEnoughCells); NGBCell *getNearestNeighbour(const coords& x); void getNearestNeighbours(const coords& x, uint32_t N, NGBCell **cells); NGBTreeNode *getRoot() { return root; } void optimize(); NGBTreeNode *getAllNodes() { return nodes; } uint32_t getNumNodes() const { return lastNode; } uint32_t countActives() const; protected: NGBTreeNode *nodes; uint32_t numNodes; uint32_t lastNode; NGBTreeNode *root; NGBCell **sortingHelper; NGBTreeNode *buildTree(NGBCell **cell0, uint32_t N, uint32_t depth, coords minBound, coords maxBound); void recursiveIntersectionCells(RecursionInfoCells& info, NGBTreeNode *node, int level) throw (NotEnoughCells); CoordType computeDistance(NGBCell *cell, const coords& x); void recursiveNearest(NGBTreeNode *node, int level, const coords& x, CoordType& R2, NGBCell*& cell); void recursiveMultiNearest(NGBTreeNode *node, int level, const coords& x, NGBQueue& q); }; template uint32_t gatherActiveCells(NGBCell **cells, uint32_t numCells); }; #include "mykdtree.tcc" #endif