From e03d9f84c6d66a7b13f1cb61453829dade3c2978 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 21 Apr 2017 11:09:26 +0100 Subject: [PATCH] Moved the Polytope::contains(..) triangle test into PolytopeIntersector to enable customization and optimization. --- src/osg/Polytope.cpp | 1 - src/osgUtil/PolytopeIntersector.cpp | 111 +++++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/src/osg/Polytope.cpp b/src/osg/Polytope.cpp index 69473caa7..e9df80520 100644 --- a/src/osg/Polytope.cpp +++ b/src/osg/Polytope.cpp @@ -59,7 +59,6 @@ bool Polytope::contains(const osg::Vec3f& v0, const osg::Vec3f& v1, const osg::V if (d_previous>=0.0) { dest.push_back(*v_previous); - } if (d_previous*d_current<0.0) diff --git a/src/osgUtil/PolytopeIntersector.cpp b/src/osgUtil/PolytopeIntersector.cpp index f50a810a7..7e45f87ba 100644 --- a/src/osgUtil/PolytopeIntersector.cpp +++ b/src/osgUtil/PolytopeIntersector.cpp @@ -614,6 +614,115 @@ struct IntersectFunctor _polytopeIntersector->getPolytope().popCurrentMask(); } +#if 1 + typedef std::vector Vertices; + Vertices src, dest; + + bool contains(const osg::Vec3f& v0, const osg::Vec3f& v1, const osg::Vec3f& v2) + { + const osg::Polytope& polytope = _polytopeIntersector->getPolytope(); + + osg::Polytope::ClippingMask resultMask = polytope.getCurrentMask(); + + if (!resultMask) return true; + + const osg::Polytope::PlaneList& planeList = polytope.getPlaneList(); + + // initialize the set of vertices to test. + src.reserve(4+planeList.size()); + dest.reserve(4+planeList.size()); + + src.clear(); + src.push_back(v0); + src.push_back(v1); + src.push_back(v2); + src.push_back(v0); + + osg::Polytope::ClippingMask selector_mask = 0x1; + + for(osg::Polytope::PlaneList::const_iterator pitr = planeList.begin(); + pitr != planeList.end(); + ++pitr) + { + if (resultMask&selector_mask) + { + //OSG_NOTICE<<"Polytope::contains() Plane testing"<=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()="<