Initial work on adding KdTree support for PolytopeIntersector.
This commit is contained in:
@@ -158,6 +158,32 @@ class OSG_EXPORT KdTree : public osg::Shape
|
||||
TriangleList& getTriangles() { return _triangles; }
|
||||
const TriangleList& getTriangles() const { return _triangles; }
|
||||
|
||||
template<class IntersectFunctor>
|
||||
void intersect(IntersectFunctor& functor, const KdNode& node) const
|
||||
{
|
||||
if (node.first<0)
|
||||
{
|
||||
// treat as a leaf
|
||||
int istart = -node.first-1;
|
||||
int iend = istart + node.second;
|
||||
|
||||
for(int i=istart; i<iend; ++i)
|
||||
{
|
||||
const KdTree::Triangle& tri = _triangles[i];
|
||||
|
||||
// OSG_NOTICE<<" tri("<<tri.p1<<","<<tri.p2<<","<<tri.p3<<")"<<std::endl;
|
||||
|
||||
functor.intersect(_vertices.get(), i, tri.p0, tri.p1, tri.p2);
|
||||
}
|
||||
}
|
||||
else if (functor.intersect(node.bb))
|
||||
{
|
||||
if (node.first>0) intersect(functor, _kdNodes[node.first]);
|
||||
if (node.second>0) intersect(functor, _kdNodes[node.second]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -358,6 +358,9 @@ class OSG_EXPORT Polytope
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Check whether any part of a triangle is contained within the polytope.*/
|
||||
bool contains(const osg::Vec3f& v0, const osg::Vec3f& v1, const osg::Vec3f& v2) const;
|
||||
|
||||
|
||||
/** Transform the clipping set by matrix. Note, this operations carries out
|
||||
* the calculation of the inverse of the matrix since a plane must
|
||||
|
||||
@@ -44,6 +44,13 @@ class OSGUTIL_EXPORT PolytopeIntersector : public Intersector
|
||||
* In VIEW and MODEL coordinates (clip space cube) creates a five sided polytope box that has a front face at 0.0 and sides around box xMin, yMin, xMax, yMax.*/
|
||||
PolytopeIntersector(CoordinateFrame cf, double xMin, double yMin, double xMax, double yMax);
|
||||
|
||||
/** Get the Polytope used by the intersector.*/
|
||||
osg::Polytope& getPolytope() { return _polytope;}
|
||||
|
||||
/** Get the const Polytope used by the intersector.*/
|
||||
const osg::Polytope& getPolytope() const { return _polytope;}
|
||||
|
||||
|
||||
typedef osg::Plane::Vec3_type Vec3_type;
|
||||
|
||||
struct Intersection
|
||||
|
||||
Reference in New Issue
Block a user