Implemented Polytope::contains(..) for triangle vertices and added support for using the results mask.
This commit is contained in:
parent
265efb85a1
commit
8f5493e573
@ -176,10 +176,12 @@ class OSG_EXPORT KdTree : public osg::Shape
|
|||||||
functor.intersect(_vertices.get(), i, tri.p0, tri.p1, tri.p2);
|
functor.intersect(_vertices.get(), i, tri.p0, tri.p1, tri.p2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (functor.intersect(node.bb))
|
else if (functor.enter(node.bb))
|
||||||
{
|
{
|
||||||
if (node.first>0) intersect(functor, _kdNodes[node.first]);
|
if (node.first>0) intersect(functor, _kdNodes[node.first]);
|
||||||
if (node.second>0) intersect(functor, _kdNodes[node.second]);
|
if (node.second>0) intersect(functor, _kdNodes[node.second]);
|
||||||
|
|
||||||
|
functor.leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,8 +390,8 @@ class OSG_EXPORT Polytope
|
|||||||
if (_resultMask&selector_mask)
|
if (_resultMask&selector_mask)
|
||||||
{
|
{
|
||||||
itr->transformProvidingInverse(matrix);
|
itr->transformProvidingInverse(matrix);
|
||||||
selector_mask <<= 1;
|
|
||||||
}
|
}
|
||||||
|
selector_mask <<= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,9 +18,85 @@ using namespace osg;
|
|||||||
|
|
||||||
bool Polytope::contains(const osg::Vec3f& v0, const osg::Vec3f& v1, const osg::Vec3f& v2) const
|
bool Polytope::contains(const osg::Vec3f& v0, const osg::Vec3f& v1, const osg::Vec3f& v2) const
|
||||||
{
|
{
|
||||||
if (contains(v0)) return true;
|
if (!_maskStack.back()) return true;
|
||||||
if (contains(v1)) return true;
|
|
||||||
if (contains(v2)) return true;
|
|
||||||
|
|
||||||
return false;
|
// initialize the set of vertices to test.
|
||||||
|
typedef std::vector<osg::Vec3d> Vertices;
|
||||||
|
|
||||||
|
Vertices src, dest;
|
||||||
|
src.reserve(4+_planeList.size());
|
||||||
|
dest.reserve(4+_planeList.size());
|
||||||
|
|
||||||
|
src.push_back(v0);
|
||||||
|
src.push_back(v1);
|
||||||
|
src.push_back(v2);
|
||||||
|
src.push_back(v0);
|
||||||
|
|
||||||
|
ClippingMask resultMask = _maskStack.back();
|
||||||
|
ClippingMask selector_mask = 0x1;
|
||||||
|
|
||||||
|
for(PlaneList::const_iterator pitr = _planeList.begin();
|
||||||
|
pitr != _planeList.end();
|
||||||
|
++pitr)
|
||||||
|
{
|
||||||
|
if (resultMask&selector_mask)
|
||||||
|
{
|
||||||
|
//OSG_NOTICE<<"Polytope::contains() Plane testing"<<std::endl;
|
||||||
|
|
||||||
|
dest.clear();
|
||||||
|
|
||||||
|
const osg::Plane& plane = *pitr;
|
||||||
|
Vertices::iterator vitr = src.begin();
|
||||||
|
|
||||||
|
osg::Vec3d* v_previous = &(*(vitr++));
|
||||||
|
double d_previous = plane.distance(*v_previous);
|
||||||
|
|
||||||
|
for(; vitr != src.end(); ++vitr)
|
||||||
|
{
|
||||||
|
osg::Vec3d* v_current = &(*vitr);
|
||||||
|
double d_current = plane.distance(*v_current);
|
||||||
|
|
||||||
|
if (d_previous>=0.0)
|
||||||
|
{
|
||||||
|
dest.push_back(*v_previous);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d_previous*d_current<0.0)
|
||||||
|
{
|
||||||
|
// edge crosses plane so insert the vertex between them.
|
||||||
|
double distance = d_previous-d_current;
|
||||||
|
double r_current = d_previous/distance;
|
||||||
|
osg::Vec3d v_new = (*v_previous)*(1.0-r_current) + (*v_current)*r_current;
|
||||||
|
dest.push_back(v_new);
|
||||||
|
}
|
||||||
|
|
||||||
|
d_previous = d_current;
|
||||||
|
v_previous = v_current;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d_previous>=0.0)
|
||||||
|
{
|
||||||
|
dest.push_back(*v_previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dest.size()<=1)
|
||||||
|
{
|
||||||
|
// OSG_NOTICE<<"Polytope::contains() All points on triangle culled, dest.size()="<<dest.size()<<std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dest.swap(src);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// OSG_NOTICE<<"Polytope::contains() Plane disabled"<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
selector_mask <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//OSG_NOTICE<<"Polytope::contains() triangle within Polytope, src.size()="<<src.size()<<std::endl;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -596,9 +596,22 @@ struct IntersectFunctor
|
|||||||
|
|
||||||
typedef std::vector<Hit> Hits;
|
typedef std::vector<Hit> Hits;
|
||||||
|
|
||||||
bool intersect(const osg::BoundingBox& bb)
|
bool enter(const osg::BoundingBox& bb)
|
||||||
{
|
{
|
||||||
return _polytopeIntersector->getPolytope().contains(bb);
|
if (_polytopeIntersector->getPolytope().contains(bb))
|
||||||
|
{
|
||||||
|
_polytopeIntersector->getPolytope().pushCurrentMask();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void leave()
|
||||||
|
{
|
||||||
|
_polytopeIntersector->getPolytope().popCurrentMask();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool intersect(const osg::Vec3Array* vertices, int i, unsigned int p0, unsigned int p1, unsigned int p2)
|
bool intersect(const osg::Vec3Array* vertices, int i, unsigned int p0, unsigned int p1, unsigned int p2)
|
||||||
|
Loading…
Reference in New Issue
Block a user