Commit e0e2e222 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

Geometry/bsp: Added a few safeguards to the BSP tree.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14115 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c66f7f23
......@@ -60,6 +60,7 @@
//== CLASS DEFINITION =========================================================
#include <vector>
#include <stdexcept>
template <class BSPCore>
......@@ -70,6 +71,8 @@ nearest(const Point& _p) const
NearestNeighborData data;
data.ref = _p;
data.dist = FLT_MAX;
if (this->root_ == 0)
throw std::runtime_error("It seems like the BSP hasn't been built, yet. Did you call build(...)?");
_nearest(this->root_, data);
return NearestNeighbor(data.nearest, sqrt(data.dist));
}
......@@ -184,4 +187,4 @@ _raycollision(Node* _node, RayCollisionData& _data) const
}
//=============================================================================
\ No newline at end of file
//=============================================================================
......@@ -172,6 +172,14 @@ struct TreeNode
_object->add_face(face_vhandles);
}
}
private:
/*
* Noncopyable because of root_.
*/
TreeNode(const TreeNode &rhs);
TreeNode &operator=(const TreeNode &rhs);
};
//=============================================================================
......
......@@ -90,18 +90,32 @@ public: //---------------------------------------------------------------------
TriangleBSPCoreT(const BSPTraits& _traits) : traits_(_traits), root_(0), nodes(0) {}
/// Destructor
~TriangleBSPCoreT() { delete root_; }
~TriangleBSPCoreT() {
delete root_;
}
/// Reserve memory for _n entries
void reserve(unsigned int _n) { handles_.reserve(_n); }
/// Add a handle to the BSP
void push_back(Handle _h) { handles_.push_back(_h); }
/// Finally build the tree
/** Build the tree.
*
* @param _max_handles Maximum number of vertices per leaf.
* @param _max_depth Maximum depth.
*/
void build(unsigned int _max_handles, unsigned int _max_depth);
/// Create a PolyMesh object that visualizes the bounding boxes of the BSP tree
void visualizeTree(PolyMesh *_object, int _max_depth);
private:
/*
* Noncopyable because of root_.
*/
TriangleBSPCoreT(const TriangleBSPCoreT &rhs);
TriangleBSPCoreT &operator=(const TriangleBSPCoreT &rhs);
private: //---------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment