openscenegraph
LineSegmentIntersector
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUTIL_LINESEGMENTINTERSECTOR
15#define OSGUTIL_LINESEGMENTINTERSECTOR 1
16
18
19namespace osgUtil
20{
21
25{
26 public:
27
29 LineSegmentIntersector(const osg::Vec3d& start, const osg::Vec3d& end);
30
34
39 LineSegmentIntersector(CoordinateFrame cf, double x, double y);
40
42 {
44 ratio(-1.0),
45 primitiveIndex(0) {}
46
47 bool operator < (const Intersection& rhs) const { return ratio < rhs.ratio; }
48
49 typedef std::vector<unsigned int> IndexList;
50 typedef std::vector<double> RatioList;
51
52 double ratio;
60 unsigned int primitiveIndex;
61
62 const osg::Vec3d& getLocalIntersectPoint() const { return localIntersectionPoint; }
63 osg::Vec3d getWorldIntersectPoint() const { return matrix.valid() ? localIntersectionPoint * (*matrix) : localIntersectionPoint; }
64
65 const osg::Vec3& getLocalIntersectNormal() const { return localIntersectionNormal; }
66 osg::Vec3 getWorldIntersectNormal() const { return matrix.valid() ? osg::Matrix::transform3x3(osg::Matrix::inverse(*matrix),localIntersectionNormal) : localIntersectionNormal; }
67
71
72 };
73
74 typedef std::multiset<Intersection> Intersections;
75
76 inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
77
78 inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
79
80 inline Intersection getFirstIntersection() { Intersections& intersections = getIntersections(); return intersections.empty() ? Intersection() : *(intersections.begin()); }
81
82 inline void setStart(const osg::Vec3d& start) { _start = start; }
83 inline const osg::Vec3d& getStart() const { return _start; }
84
85 inline void setEnd(const osg::Vec3d& end) { _end = end; }
86 inline const osg::Vec3d& getEnd() const { return _end; }
87
88 public:
89
91
92 virtual bool enter(const osg::Node& node);
93
94 virtual void leave();
95
97
99 const osg::Vec3d& s, const osg::Vec3d& e);
100
101 virtual void reset();
102
103 virtual bool containsIntersections() { return !getIntersections().empty(); }
104
109
110protected:
111
114
116
119
121
122};
123
124}
125
126#endif
127
Definition IntersectionVisitor:152
Definition IntersectionVisitor:34
IntersectionLimit
Definition IntersectionVisitor:46
@ NO_LIMIT
Definition IntersectionVisitor:47
CoordinateFrame
Definition IntersectionVisitor:38
Definition LineSegmentIntersector:25
Intersections _intersections
Definition LineSegmentIntersector:120
LineSegmentIntersector * _parent
Definition LineSegmentIntersector:115
std::multiset< Intersection > Intersections
Definition LineSegmentIntersector:74
const osg::Vec3d & getStart() const
Definition LineSegmentIntersector:83
void setStart(const osg::Vec3d &start)
Definition LineSegmentIntersector:82
virtual void intersect(osgUtil::IntersectionVisitor &iv, osg::Drawable *drawable)
LineSegmentIntersector(CoordinateFrame cf, const osg::Vec3d &start, const osg::Vec3d &end, LineSegmentIntersector *parent=NULL, osgUtil::Intersector::IntersectionLimit intersectionLimit=osgUtil::Intersector::NO_LIMIT)
Intersection getFirstIntersection()
Definition LineSegmentIntersector:80
void insertIntersection(const Intersection &intersection)
Definition LineSegmentIntersector:76
bool intersects(const osg::BoundingSphere &bs)
virtual bool containsIntersections()
Definition LineSegmentIntersector:103
LineSegmentIntersector(CoordinateFrame cf, double x, double y)
virtual Intersector * clone(osgUtil::IntersectionVisitor &iv)
void setEnd(const osg::Vec3d &end)
Definition LineSegmentIntersector:85
osg::Vec3d _start
Definition LineSegmentIntersector:117
Intersections & getIntersections()
Definition LineSegmentIntersector:78
LineSegmentIntersector(const osg::Vec3d &start, const osg::Vec3d &end)
static osg::Matrix getTransformation(osgUtil::IntersectionVisitor &iv, CoordinateFrame cf)
const osg::Vec3d & getEnd() const
Definition LineSegmentIntersector:86
virtual void intersect(osgUtil::IntersectionVisitor &iv, osg::Drawable *drawable, const osg::Vec3d &s, const osg::Vec3d &e)
virtual bool enter(const osg::Node &node)
bool intersectAndClip(osg::Vec3d &s, osg::Vec3d &e, const osg::BoundingBox &bb)
osg::Vec3d _end
Definition LineSegmentIntersector:118
Definition BoundingBox:34
Definition BoundingSphere:35
Definition Drawable:89
Definition Matrixd:27
static Vec3f transform3x3(const Vec3f &v, const Matrixd &m)
Definition Matrixd:665
static Matrixd inverse(const Matrixd &matrix)
Definition Matrixd:536
Definition Node:72
Definition Texture:422
Definition Vec3d:30
Definition Vec3f:29
Definition ref_ptr:32
bool valid() const
Definition ref_ptr:120
Shader generator framework.
Definition NodeVisitor:25
std::vector< Node * > NodePath
Definition Node:47
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
#define NULL
Definition osg/Export:55
Definition LineSegmentIntersector:42
osg::Texture * getTextureLookUp(osg::Vec3 &tc) const
osg::Vec3 getWorldIntersectNormal() const
Definition LineSegmentIntersector:66
osg::ref_ptr< osg::RefMatrix > matrix
Definition LineSegmentIntersector:55
const osg::Vec3 & getLocalIntersectNormal() const
Definition LineSegmentIntersector:65
osg::Vec3d localIntersectionPoint
Definition LineSegmentIntersector:56
IndexList indexList
Definition LineSegmentIntersector:58
osg::Vec3d getWorldIntersectPoint() const
Definition LineSegmentIntersector:63
osg::ref_ptr< osg::Drawable > drawable
Definition LineSegmentIntersector:54
RatioList ratioList
Definition LineSegmentIntersector:59
unsigned int primitiveIndex
Definition LineSegmentIntersector:60
double ratio
Definition LineSegmentIntersector:52
osg::Vec3 localIntersectionNormal
Definition LineSegmentIntersector:57
const osg::Vec3d & getLocalIntersectPoint() const
Definition LineSegmentIntersector:62
Intersection()
Definition LineSegmentIntersector:43
std::vector< double > RatioList
Definition LineSegmentIntersector:50
std::vector< unsigned int > IndexList
Definition LineSegmentIntersector:49
osg::NodePath nodePath
Definition LineSegmentIntersector:53