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:
@@ -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<osg::Drawable> drawable;
|
||||
osg::ref_ptr<osg::RefMatrix> 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
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user