From f537ece404054ae98871f7ada91d02c9f8edc557 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 8 Feb 2012 10:06:58 +0000 Subject: [PATCH] From Leandro Motto Barros, "I've made a few changes to osgUtil::PolytopeIntersector so that it actually uses double precision floating point numbers everywhere (as long as OSG_USE_FLOAT_PLANE is not defined). I needed double precision intersections in a project I am working on. These changes fixed the problems I was having -- this is all testing I have done. Notice that I have changed osgUtil::PolytopeIntersector::Intersection's members to use doubles (osg::Vec3d, instead of osg::Vec3). I could have added #ifdef's there too, but I think it is better to not change the types of stuff in the public interface depending on some preprocessor definition. The modified files are attached. A diff also follows, for those who like it." With the following changes from Robert Osfield: "I've just reviewed your changes and have just tweaked them a little to streamline them. What I have done in the PolytopeIntersector header is add: typedef osg::Plane::Vec3_type Vec3_type; And then use this typedef in the definition of the vertices rather then Vec3d as you did. Next changes were to PolytopeInteresector.cpp where to the PolytopeIntersectorUtils defintions of the Vec3_type, and value_type which now simply read: typedef osg::Plane::Vec3_type Vec3_type; typedef Vec3_type::value_type value_type; This way I was able to complete avoid any if def's and have essential the same implementation as you achieved. Changes now checked into svn/trunk." --- include/osgUtil/PolytopeIntersector | 6 ++++-- src/osgUtil/PolytopeIntersector.cpp | 15 +++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/osgUtil/PolytopeIntersector b/include/osgUtil/PolytopeIntersector index 4e2a0b4ef..e3c91ee0b 100644 --- a/include/osgUtil/PolytopeIntersector +++ b/include/osgUtil/PolytopeIntersector @@ -44,6 +44,8 @@ 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); + typedef osg::Plane::Vec3_type Vec3_type; + struct Intersection { Intersection(): @@ -70,9 +72,9 @@ class OSGUTIL_EXPORT PolytopeIntersector : public Intersector osg::NodePath nodePath; osg::ref_ptr drawable; osg::ref_ptr matrix; - osg::Vec3 localIntersectionPoint; ///< center of all intersection points + Vec3_type localIntersectionPoint; ///< center of all intersection points unsigned int numIntersectionPoints; - osg::Vec3 intersectionPoints[MaxNumIntesectionPoints]; + Vec3_type intersectionPoints[MaxNumIntesectionPoints]; unsigned int primitiveIndex; ///< primitive index }; diff --git a/src/osgUtil/PolytopeIntersector.cpp b/src/osgUtil/PolytopeIntersector.cpp index 2213da1a0..862c66ca2 100644 --- a/src/osgUtil/PolytopeIntersector.cpp +++ b/src/osgUtil/PolytopeIntersector.cpp @@ -24,13 +24,8 @@ using namespace osgUtil; namespace PolytopeIntersectorUtils { -#ifdef OSG_USE_FLOAT_PLANE - typedef float value_type; - typedef osg::Vec3f Vec3_type; -#else - typedef double value_type; - typedef osg::Vec3d Vec3_type; -#endif + typedef osg::Plane::Vec3_type Vec3_type; + typedef Vec3_type::value_type value_type; typedef osg::Polytope::ClippingMask PlaneMask; typedef std::vector > CandList_t; @@ -63,7 +58,7 @@ namespace PolytopeIntersectorUtils value_type _maxDistance; ///< maximum distance of intersection points from reference plane unsigned int _index; ///< primitive index unsigned int _numPoints; - osg::Vec3 _points[MaxNumIntesections]; + Vec3_type _points[MaxNumIntesections]; }; // class PolytopeIntersection typedef std::vector Intersections; @@ -590,12 +585,12 @@ void PolytopeIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Drawa hit.drawable = drawable; hit.matrix = iv.getModelMatrix(); - osg::Vec3 center; + PolytopeIntersectorUtils::Vec3_type center; for (unsigned int i=0; i