LineSegmentIntersector
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGUTIL_LINESEGMENTINTERSECTOR
#define OSGUTIL_LINESEGMENTINTERSECTOR 1
#include <osgUtil/IntersectionVisitor>
namespace osgUtil
{
class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector
{
public:
LineSegmentIntersector(const osg::Vec3d& start, const osg::Vec3d& end);
LineSegmentIntersector(CoordinateFrame cf, const osg::Vec3d& start, const osg::Vec3d& end, LineSegmentIntersector* parent = NULL,
osgUtil::Intersector::IntersectionLimit intersectionLimit = osgUtil::Intersector::NO_LIMIT);
LineSegmentIntersector(CoordinateFrame cf, double x, double y);
struct OSGUTIL_EXPORT Intersection
{
Intersection():
ratio(-1.0),
primitiveIndex(0) {}
bool operator < (const Intersection& rhs) const { return ratio < rhs.ratio; }
typedef std::vector<unsigned int> IndexList;
typedef std::vector<double> RatioList;
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;
RatioList ratioList;
unsigned int primitiveIndex;
const osg::Vec3d& getLocalIntersectPoint() const { return localIntersectionPoint; }
osg::Vec3d getWorldIntersectPoint() const { return matrix.valid() ? localIntersectionPoint * (*matrix) : localIntersectionPoint; }
const osg::Vec3& getLocalIntersectNormal() const { return localIntersectionNormal; }
osg::Vec3 getWorldIntersectNormal() const { return matrix.valid() ? osg::Matrix::transform3x3(osg::Matrix::inverse(*matrix),localIntersectionNormal) : localIntersectionNormal; }
osg::Texture* getTextureLookUp(osg::Vec3& tc) const;
};
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()); }
inline void setStart(const osg::Vec3d& start) { _start = start; }
inline const osg::Vec3d& getStart() const { return _start; }
inline void setEnd(const osg::Vec3d& end) { _end = end; }
inline const osg::Vec3d& getEnd() const { return _end; }
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 intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable,
const osg::Vec3d& s, const osg::Vec3d& e);
virtual void reset();
virtual bool containsIntersections() { return !getIntersections().empty(); }
static osg::Matrix getTransformation(osgUtil::IntersectionVisitor& iv, CoordinateFrame cf);
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;
};
}
#endif
IntersectionVisitor
osgUtil::IntersectionVisitor
Definition IntersectionVisitor:152
osgUtil::Intersector::IntersectionLimit
IntersectionLimit
Definition IntersectionVisitor:46
osgUtil::Intersector::NO_LIMIT
@ NO_LIMIT
Definition IntersectionVisitor:47
osgUtil::Intersector::CoordinateFrame
CoordinateFrame
Definition IntersectionVisitor:38
osgUtil::Intersector::Intersector
Intersector(CoordinateFrame cf=MODEL, IntersectionLimit il=NO_LIMIT)
Definition IntersectionVisitor:53
osgUtil::LineSegmentIntersector::_intersections
Intersections _intersections
Definition LineSegmentIntersector:120
osgUtil::LineSegmentIntersector::_parent
LineSegmentIntersector * _parent
Definition LineSegmentIntersector:115
osgUtil::LineSegmentIntersector::Intersections
std::multiset< Intersection > Intersections
Definition LineSegmentIntersector:74
osgUtil::LineSegmentIntersector::getStart
const osg::Vec3d & getStart() const
Definition LineSegmentIntersector:83
osgUtil::LineSegmentIntersector::setStart
void setStart(const osg::Vec3d &start)
Definition LineSegmentIntersector:82
osgUtil::LineSegmentIntersector::intersect
virtual void intersect(osgUtil::IntersectionVisitor &iv, osg::Drawable *drawable)
osgUtil::LineSegmentIntersector::LineSegmentIntersector
LineSegmentIntersector(CoordinateFrame cf, const osg::Vec3d &start, const osg::Vec3d &end, LineSegmentIntersector *parent=NULL, osgUtil::Intersector::IntersectionLimit intersectionLimit=osgUtil::Intersector::NO_LIMIT)
osgUtil::LineSegmentIntersector::getFirstIntersection
Intersection getFirstIntersection()
Definition LineSegmentIntersector:80
osgUtil::LineSegmentIntersector::insertIntersection
void insertIntersection(const Intersection &intersection)
Definition LineSegmentIntersector:76
osgUtil::LineSegmentIntersector::intersects
bool intersects(const osg::BoundingSphere &bs)
osgUtil::LineSegmentIntersector::containsIntersections
virtual bool containsIntersections()
Definition LineSegmentIntersector:103
osgUtil::LineSegmentIntersector::LineSegmentIntersector
LineSegmentIntersector(CoordinateFrame cf, double x, double y)
osgUtil::LineSegmentIntersector::clone
virtual Intersector * clone(osgUtil::IntersectionVisitor &iv)
osgUtil::LineSegmentIntersector::setEnd
void setEnd(const osg::Vec3d &end)
Definition LineSegmentIntersector:85
osgUtil::LineSegmentIntersector::_start
osg::Vec3d _start
Definition LineSegmentIntersector:117
osgUtil::LineSegmentIntersector::leave
virtual void leave()
osgUtil::LineSegmentIntersector::getIntersections
Intersections & getIntersections()
Definition LineSegmentIntersector:78
osgUtil::LineSegmentIntersector::reset
virtual void reset()
osgUtil::LineSegmentIntersector::LineSegmentIntersector
LineSegmentIntersector(const osg::Vec3d &start, const osg::Vec3d &end)
osgUtil::LineSegmentIntersector::getTransformation
static osg::Matrix getTransformation(osgUtil::IntersectionVisitor &iv, CoordinateFrame cf)
osgUtil::LineSegmentIntersector::getEnd
const osg::Vec3d & getEnd() const
Definition LineSegmentIntersector:86
osgUtil::LineSegmentIntersector::intersect
virtual void intersect(osgUtil::IntersectionVisitor &iv, osg::Drawable *drawable, const osg::Vec3d &s, const osg::Vec3d &e)
osgUtil::LineSegmentIntersector::enter
virtual bool enter(const osg::Node &node)
osgUtil::LineSegmentIntersector::intersectAndClip
bool intersectAndClip(osg::Vec3d &s, osg::Vec3d &e, const osg::BoundingBox &bb)
osgUtil::LineSegmentIntersector::_end
osg::Vec3d _end
Definition LineSegmentIntersector:118
osg::Drawable
Definition Drawable:89
osg::Matrixd::transform3x3
static Vec3f transform3x3(const Vec3f &v, const Matrixd &m)
Definition Matrixd:665
osg::Matrixd::inverse
static Matrixd inverse(const Matrixd &matrix)
Definition Matrixd:536
osg::Node
Definition Node:72
osg::Texture
Definition Texture:422
osg::Vec3d
Definition Vec3d:30
osg::ref_ptr
Definition ref_ptr:32
osgUtil
Definition NodeVisitor:25
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::BoundingBox
BoundingBoxd BoundingBox
Definition BoundingBox:257
osg::BoundingSphere
BoundingSphered BoundingSphere
Definition BoundingSphere:314
osg::Matrix
Matrixd Matrix
Definition Matrix:27
osg::NodePath
std::vector< Node * > NodePath
Definition Node:47
OSGUTIL_EXPORT
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
NULL
#define NULL
Definition osg/Export:55
osgUtil::LineSegmentIntersector::Intersection
Definition LineSegmentIntersector:42
osgUtil::LineSegmentIntersector::Intersection::getTextureLookUp
osg::Texture * getTextureLookUp(osg::Vec3 &tc) const
osgUtil::LineSegmentIntersector::Intersection::getWorldIntersectNormal
osg::Vec3 getWorldIntersectNormal() const
Definition LineSegmentIntersector:66
osgUtil::LineSegmentIntersector::Intersection::matrix
osg::ref_ptr< osg::RefMatrix > matrix
Definition LineSegmentIntersector:55
osgUtil::LineSegmentIntersector::Intersection::getLocalIntersectNormal
const osg::Vec3 & getLocalIntersectNormal() const
Definition LineSegmentIntersector:65
osgUtil::LineSegmentIntersector::Intersection::localIntersectionPoint
osg::Vec3d localIntersectionPoint
Definition LineSegmentIntersector:56
osgUtil::LineSegmentIntersector::Intersection::indexList
IndexList indexList
Definition LineSegmentIntersector:58
osgUtil::LineSegmentIntersector::Intersection::getWorldIntersectPoint
osg::Vec3d getWorldIntersectPoint() const
Definition LineSegmentIntersector:63
osgUtil::LineSegmentIntersector::Intersection::drawable
osg::ref_ptr< osg::Drawable > drawable
Definition LineSegmentIntersector:54
osgUtil::LineSegmentIntersector::Intersection::ratioList
RatioList ratioList
Definition LineSegmentIntersector:59
osgUtil::LineSegmentIntersector::Intersection::primitiveIndex
unsigned int primitiveIndex
Definition LineSegmentIntersector:60
osgUtil::LineSegmentIntersector::Intersection::ratio
double ratio
Definition LineSegmentIntersector:52
osgUtil::LineSegmentIntersector::Intersection::localIntersectionNormal
osg::Vec3 localIntersectionNormal
Definition LineSegmentIntersector:57
osgUtil::LineSegmentIntersector::Intersection::getLocalIntersectPoint
const osg::Vec3d & getLocalIntersectPoint() const
Definition LineSegmentIntersector:62
osgUtil::LineSegmentIntersector::Intersection::Intersection
Intersection()
Definition LineSegmentIntersector:43
osgUtil::LineSegmentIntersector::Intersection::RatioList
std::vector< double > RatioList
Definition LineSegmentIntersector:50
osgUtil::LineSegmentIntersector::Intersection::IndexList
std::vector< unsigned int > IndexList
Definition LineSegmentIntersector:49
osgUtil::LineSegmentIntersector::Intersection::nodePath
osg::NodePath nodePath
Definition LineSegmentIntersector:53