/*-------------------------------------------------------------------- * project ....: Darpa Urban Challenge 2007 * authors ....: Team AnnieWAY * organization: Transregional Collaborative Research Center 28 / * Cognitive Automobiles * creation ...: xx/xx/2007 * revisions ..: $Id:$ ---------------------------------------------------------------------*/ #ifndef AW_OCTREET_H #define AW_OCTREET_H //== INCLUDES ================================================================= #include #include #include #include #include namespace vlr { //== CLASS DEFINITION ========================================================= template class OctreeT { public: typedef T Scalar; typedef typename sla::Vec3 Point; typedef typename std::vector PointList; typedef typename PointList::iterator PointListIterator; typedef typename PointList::const_iterator PointListConstIterator; typedef typename std::vector IndexList; typedef typename IndexList::const_iterator IndexListConstIterator; OctreeT( int num_points, const Point* points, Scalar minRadius, int minPoints); OctreeT( int num_points, const Point* points, Point center, Scalar radius, Scalar minRadius, int minPoints); OctreeT( int num_points, const Point* points, Point center, Scalar radius, IndexList& indices, Scalar minRadius, int minPoints = 1, int parentIndex = 0, OctreeT* parentTree = NULL); ~OctreeT(void); bool searchNearest(const Point &p, int& nearestNeighbor, Scalar& distance); void refineTree(Scalar minRadius, int minPoints); void getCubes(PointList &points, std::vector &edges); void getCubeCenters(PointList ¢ers); void getPoints(PointList &points); void getIndices(IndexList& indices); void getLeaves(std::vector< OctreeT* >& leafes); Point center() { return m_center; } Scalar radius() { return m_radius; } bool isLeaf() { return m_isLeaf; } private: void initialize(IndexList& indices, Scalar& minRadius, int& minVertices); bool closerToPoint(const Point &p, const int& otherIndex, Scalar& distance); private: int m_num_points; const Point* m_points; Point m_center; Scalar m_radius; int m_parentIndex; OctreeT* m_parentTree; OctreeT* m_child[8]; bool m_isLeaf; std::vector m_indices; // point indices, groups of three }; //============================================================================= } // namespace vlr #if !defined(OCTREE_TEMPLATE) #include "aw_octree_template.h" #endif #endif // AW_OCTREET_H defined