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."
This commit is contained in:
Robert Osfield
2012-02-08 10:06:58 +00:00
parent ce4890fa7a
commit f537ece404
2 changed files with 9 additions and 12 deletions

View File

@@ -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<std::pair<PlaneMask,Vec3_type> > 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<PolytopeIntersection> 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<intersection._numPoints; ++i)
{
center += intersection._points[i];
}
center /= float(intersection._numPoints);
center /= PolytopeIntersectorUtils::value_type(intersection._numPoints);
hit.localIntersectionPoint = center;
hit.numIntersectionPoints = intersection._numPoints;