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

Geometry/bsp: Improving BSP tree implementation.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14509 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 04517849
......@@ -61,7 +61,7 @@
//== CLASS DEFINITION =========================================================
#include <vector>
#include <stdexcept>
#include <limits>
template <class BSPCore>
typename BSPImplT<BSPCore>::NearestNeighbor
......@@ -70,7 +70,7 @@ nearest(const Point& _p) const
{
NearestNeighborData data;
data.ref = _p;
data.dist = FLT_MAX;
data.dist = std::numeric_limits<Scalar>::infinity();
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);
......
......@@ -61,7 +61,7 @@
//== CLASS DEFINITION =========================================================
#include <vector>
#include <ostream>
template <class BSPCore>
class BSPImplT : public BSPCore
......@@ -118,6 +118,11 @@ private: //---------------------------------------------------------------------
Point ref;
Scalar dist;
Handle nearest;
friend std::ostream &operator<< (std::ostream &stream, const NearestNeighborData &data) {
stream << "[NearestNeghborData instance. ref: " << data.ref << ", dist: " << data.dist << ", nearest: " << data.nearest.idx() << "]";
return stream;
}
};
/// Store ray collide information
......@@ -138,7 +143,6 @@ private: //---------------------------------------------------------------------
void _raycollision(Node* _node, RayCollisionData& _data) const;
};
//=============================================================================
#if defined(OM_INCLUDE_TEMPLATES) && !defined(BSPIMPLT_C)
# define BSPIMPLT_TEMPLATES
......
......@@ -57,6 +57,7 @@
#include <ACG/Geometry/Types/PlaneT.hh>
#include <ACG/Geometry/Algorithms.hh>
#include <ObjectTypes/PolyMesh/PolyMeshTypes.hh>
#include <ostream>
//== CLASS DEFINITION =========================================================
......@@ -96,6 +97,10 @@ struct TreeNode
return handles_.end();
}
size_t size() const {
return handles_.size();
}
Handles handles_;
TreeNode *parent_, *left_child_, *right_child_;
Plane plane_;
......@@ -182,6 +187,20 @@ struct TreeNode
};
template<class Mesh>
std::ostream &operator<< (std::ostream &stream, const TreeNode<Mesh> &node) {
stream << "[TreeNode instance. Handles: ";
for (typename std::vector<typename TreeNode<Mesh>::Handle>::const_iterator it = node.handles_.begin(), it_end = node.handles_.end();
it != it_end; ++it) {
stream << it->idx();
if (it < it_end-1) stream << ", ";
}
stream << ", parent: " << node.parent_ << ", left_child_: " << node.left_child_
<< ", right_child_: " << node.right_child_ << ", plane_: <not implemented>, bb_min: "
<< node.bb_min << ", bb_max: " << node.bb_max << ", size(): " << node.size() << "]";
return stream;
}
//=============================================================================
#endif // MB_BSPTREENODE_HH defined
//=============================================================================
......@@ -87,7 +87,7 @@ public: //---------------------------------------------------------------------
/** Constructor: need traits that define the types and
give us the points by traits_.point(PointHandle) */
TriangleBSPCoreT(const BSPTraits& _traits) : traits_(_traits), root_(0), nodes(0) {}
TriangleBSPCoreT(const BSPTraits& _traits) : traits_(_traits), root_(0), nodes(0), n_triangles(0) {}
/// Destructor
~TriangleBSPCoreT() {
......@@ -98,7 +98,17 @@ public: //---------------------------------------------------------------------
/// 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); }
void push_back(Handle _h) { handles_.push_back(_h); ++n_triangles; }
/**
* @return size() == 0
*/
bool empty() { return n_triangles == 0; }
/**
* @return The number of triangles contained in the tree.
*/
size_t size() { return n_triangles; }
/** Build the tree.
*
......@@ -134,7 +144,7 @@ protected: //-------------------------------------------------------------------
BSPTraits traits_;
Handles handles_;
Node* root_;
int nodes;
int nodes, n_triangles;
};
......
......@@ -115,8 +115,8 @@ public:
//determine splitting axis
HandleIter it_h;
Point p0, p1, p2, bb_min, bb_max;
bb_min.vectorize(FLT_MAX);
bb_max.vectorize(-FLT_MAX);
bb_min.vectorize(std::numeric_limits<typename Point::value_type>::infinity());
bb_max.vectorize(-std::numeric_limits<typename Point::value_type>::infinity());
std::list<Point> vertices;
......
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