Moved osgUtil::PolytopeIntersector, osgUtil::PlaneIntersector and osgUtil::LineSegmentIntersector out from include/osgUtil/IntersecionVisitor into their own seperate files.

This commit is contained in:
Robert Osfield
2006-11-28 16:30:38 +00:00
parent 345810ef22
commit a2e79f6a38
15 changed files with 1065 additions and 906 deletions

View File

@@ -76,205 +76,6 @@ class Intersector : public osg::Referenced
};
/** Concrent class for implementing line intersections with the scene graph.
* To be used in conjunction with IntersectionVisitor. */
class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector
{
public:
/** Construct a LineSegmentIntersector the runs between the secified start and end points in MODEL coordinates. */
LineSegmentIntersector(const osg::Vec3d& start, const osg::Vec3d& end);
/** Construct a LineSegmentIntersector the runs between the secified start and end points in the specified coordinate frame. */
LineSegmentIntersector(CoordinateFrame cf, const osg::Vec3d& start, const osg::Vec3d& end);
/** Convinience constructor for supporting picking in WINDOW, or PROJECTION coorindates
* In WINDOW coordinates creates a start value of (x,y,0) and end value of (x,y,1).
* In PROJECTION coordinates (clip space cube) creates a start value of (x,y,1) and end value of (x,y,-1).
* In VIEW and MODEL coordinates creates a start value of (x,y,0) and end value of (x,y,1).*/
LineSegmentIntersector(CoordinateFrame cf, double x, double y);
struct Intersection
{
Intersection():
ratio(-1.0),
primitiveIndex(0) {}
bool operator < (const Intersection& rhs) const { return ratio < rhs.ratio; }
typedef std::vector<unsigned int> IndexList;
double ratio;
osg::NodePath nodePath;
osg::ref_ptr<osg::Drawable> drawable;
osg::ref_ptr<osg::RefMatrix> matrix;
osg::Vec3d localIntersectionPoint;
osg::Vec3 localIntersectionNormal;
IndexList indexList;
unsigned int primitiveIndex;
};
typedef std::multiset<Intersection> Intersections;
inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
inline Intersection getFirstIntersection() { Intersections& intersections = getIntersections(); return intersections.empty() ? Intersection() : *(intersections.begin()); }
public:
virtual Intersector* clone(osgUtil::IntersectionVisitor& iv);
virtual bool enter(const osg::Node& node);
virtual void leave();
virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
virtual void reset();
virtual bool containsIntersections() { return !_intersections.empty(); }
protected:
bool intersects(const osg::BoundingSphere& bs);
bool intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const osg::BoundingBox& bb);
LineSegmentIntersector* _parent;
osg::Vec3d _start;
osg::Vec3d _end;
Intersections _intersections;
};
/** Concrent class for implementing polytope intersections with the scene graph.
* To be used in conjunction with IntersectionVisitor. */
class OSGUTIL_EXPORT PolytopeIntersector : public Intersector
{
public:
/** Construct a PolytopeIntersector using speified polytope in MODEL coordinates.*/
PolytopeIntersector(const osg::Polytope& polytope);
/** Construct a PolytopeIntersector using speified polytope in specified coordinate frame.*/
PolytopeIntersector(CoordinateFrame cf, const osg::Polytope& polytope);
/** Convinience constructor for supporting picking in WINDOW, or PROJECTION coorindates
* In WINDOW 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.
* In PROJECTION coordinates (clip space cube) creates a five sided polytope box that has a front face at -1 and sides around box xMin, yMin, xMax, yMax.
* 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);
struct Intersection
{
Intersection() {}
bool operator < (const Intersection& rhs) const
{
if (nodePath < rhs.nodePath) return true;
if (rhs.nodePath < nodePath ) return false;
return (drawable < rhs.drawable);
}
osg::NodePath nodePath;
osg::ref_ptr<osg::Drawable> drawable;
};
typedef std::set<Intersection> Intersections;
inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
inline Intersection getFirstIntersection() { Intersections& intersections = getIntersections(); return intersections.empty() ? Intersection() : *(intersections.begin()); }
public:
virtual Intersector* clone(osgUtil::IntersectionVisitor& iv);
virtual bool enter(const osg::Node& node);
virtual void leave();
virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
virtual void reset();
virtual bool containsIntersections() { return !_intersections.empty(); }
protected:
PolytopeIntersector* _parent;
osg::Polytope _polytope;
Intersections _intersections;
};
/** Concrent class for implementing polytope intersections with the scene graph.
* To be used in conjunction with IntersectionVisitor. */
class OSGUTIL_EXPORT PlaneIntersector : public Intersector
{
public:
/** Construct a PolytopeIntersector using speified polytope in MODEL coordinates.*/
PlaneIntersector(const osg::Plane& plane, const osg::Polytope& boundingPolytope=osg::Polytope());
/** Construct a PolytopeIntersector using speified polytope in specified coordinate frame.*/
PlaneIntersector(CoordinateFrame cf, const osg::Plane& plane, const osg::Polytope& boundingPolytope=osg::Polytope());
struct Intersection
{
Intersection() {}
bool operator < (const Intersection& rhs) const
{
if (nodePath < rhs.nodePath) return true;
if (rhs.nodePath < nodePath ) return false;
return (drawable < rhs.drawable);
}
osg::NodePath nodePath;
osg::ref_ptr<osg::Drawable> drawable;
};
typedef std::set<Intersection> Intersections;
inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
inline Intersection getFirstIntersection() { Intersections& intersections = getIntersections(); return intersections.empty() ? Intersection() : *(intersections.begin()); }
public:
virtual Intersector* clone(osgUtil::IntersectionVisitor& iv);
virtual bool enter(const osg::Node& node);
virtual void leave();
virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
virtual void reset();
virtual bool containsIntersections() { return !_intersections.empty(); }
protected:
PlaneIntersector* _parent;
osg::Plane _plane;
osg::Polytope _polytope;
Intersections _intersections;
};
/** Concrent class for passing multiple intersectors through the scene graph.
* To be used in conjunction with IntersectionVisitor. */