OpenSceneGraph 3.6.5
IntersectVisitor
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_INTERSECTVISITOR
15#define OSGUTIL_INTERSECTVISITOR 1
16
17#include <osg/NodeVisitor>
18#include <osg/LineSegment>
19#include <osg/Geode>
20#include <osg/Matrix>
21#include <osg/Transform>
22
23#include <osgUtil/Export>
24
25#include <map>
26#include <set>
27#include <vector>
28
29namespace osgUtil {
30
31
34{
35 public:
36
37 Hit();
38 Hit(const Hit& hit);
40
41 Hit& operator = (const Hit& hit);
42
43 typedef std::vector<int> VecIndexList;
44
45 bool operator < (const Hit& hit) const
46 {
47 if (_originalLineSegment<hit._originalLineSegment) return true;
48 if (hit._originalLineSegment<_originalLineSegment) return false;
49 return _ratio<hit._ratio;
50 }
51
52
55
56 const osg::Vec3 getWorldIntersectPoint() const { if (_matrix.valid()) return _intersectPoint*(*_matrix); else return _intersectPoint; }
58
59 float getRatio() const { return _ratio; }
63 const osg::NodePath& getNodePath() const { return _nodePath; }
64 osg::Geode* getGeode() { return _geode.get(); }
65 const osg::Geode* getGeode() const { return _geode.get(); }
66 osg::Drawable* getDrawable() { return _drawable.get(); }
67 const osg::Drawable* getDrawable() const { return _drawable.get(); }
68 const osg::RefMatrix* getMatrix() const { return _matrix.get(); }
69 const osg::RefMatrix* getInverseMatrix() const { return _inverse.get(); }
70 const VecIndexList& getVecIndexList() const { return _vecIndexList; }
71 int getPrimitiveIndex() const { return _primitiveIndex; }
72
73
74 float _ratio;
82
87
88
89};
90
91
94{
95 public:
96
99
101
102 void reset();
103
109
110 typedef std::vector<Hit> HitList;
111 typedef std::map<const osg::LineSegment*,HitList > LineSegmentHitListMap;
112
113 HitList& getHitList(const osg::LineSegment* seg) { return _segHitList[seg]; }
114
115 int getNumHits(const osg::LineSegment* seg) { return _segHitList[seg].size(); }
116
118
119 bool hits();
120
126
129
134 void setEyePoint(const osg::Vec3& eye) { _pseudoEyePoint = eye; }
135
136 virtual osg::Vec3 getEyePoint() const;
137
138
141 virtual float getDistanceToEyePoint(const osg::Vec3& pos, bool withLODScale) const;
142
143 virtual void apply(osg::Node&);
144 virtual void apply(osg::Drawable&);
145 virtual void apply(osg::Geode& node);
146 virtual void apply(osg::Billboard& node);
147
148 virtual void apply(osg::Group& node);
149 virtual void apply(osg::Transform& node);
150 virtual void apply(osg::Switch& node);
151 virtual void apply(osg::LOD& node);
152
153 protected:
154
184
186
188 void popMatrix();
189
190 bool enterNode(osg::Node& node);
191 void leaveNode();
192
193 typedef std::vector<osg::ref_ptr<IntersectState> > IntersectStateStack;
194
196
198
201};
202
205{
206 public:
207
208 PickVisitor(const osg::Viewport* viewport, const osg::Matrixd& proj, const osg::Matrixd& view, float mx, float my);
209
210 void runNestedPickVisitor(osg::Node& node, const osg::Viewport* viewport, const osg::Matrix& proj, const osg::Matrix& view, float mx, float my);
211
212 void apply(osg::Projection& projection);
213
214 void apply(osg::Camera& camera);
215
216 protected:
217
218 float _mx;
219 float _my;
220
224};
225
226}
227
228#endif
229
Vec3f Vec3
Definition Vec3:21
BoundingBoxd BoundingBox
Definition BoundingBox:257
BoundingSphered BoundingSphere
Definition BoundingSphere:308
Matrixd Matrix
Definition Matrix:27
std::vector< Node * > NodePath
A vector of Nodes pointers which is used to describe the path from a root node to a descendant.
Definition Node:47
RefMatrixd RefMatrix
Definition Matrix:28
The osgUtil library provides general purpose utility classes such as update, cull and draw traverses,...
Definition NodeVisitor:25
Billboard is a derived form of Geode that orients its osg::Drawable children to face the eye point.
Definition Billboard:27
Camera - is a subclass of Transform which represents encapsulates the settings of a Camera.
Definition Camera:45
Pure virtual base class for drawable geometry.
Definition Drawable:89
A Geode is a "geometry node", that is, a leaf node on the scene graph that can have "renderable thing...
Definition Geode:29
General group node which maintains a list of children.
Definition Group:29
LineSegment class for representing a line segment.
Definition LineSegment:25
LOD - Level Of Detail group node which allows switching between children depending on distance from e...
Definition LOD:36
Definition Matrixd:27
Base class for all internal nodes in the scene graph.
Definition Node:72
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
virtual void reset()
Method to call to reset visitor.
Definition NodeVisitor:167
Projection nodes set up the frustum/orthographic projection used when rendering the scene.
Definition Projection:25
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Base class for providing reference counted objects.
Definition Referenced:44
Switch is a Group node that allows switching between children.
Definition Switch:27
A Transform is a group node for which all children are transformed by a 4x4 matrix.
Definition Transform:75
ReferenceFrame
Definition Transform:98
Encapsulate OpenGL glViewport.
Definition Viewport:24
Hit(const Hit &hit)
osg::ref_ptr< osg::Geode > _geode
Definition IntersectVisitor:78
const VecIndexList & getVecIndexList() const
Definition IntersectVisitor:70
osg::ref_ptr< osg::LineSegment > _originalLineSegment
Definition IntersectVisitor:75
const osg::Drawable * getDrawable() const
Definition IntersectVisitor:67
int _primitiveIndex
Definition IntersectVisitor:84
osg::NodePath & getNodePath()
Definition IntersectVisitor:62
osg::ref_ptr< osg::Drawable > _drawable
Definition IntersectVisitor:79
const osg::Vec3 getWorldIntersectNormal() const
const osg::NodePath & getNodePath() const
Definition IntersectVisitor:63
int getPrimitiveIndex() const
Definition IntersectVisitor:71
osg::ref_ptr< osg::RefMatrix > _inverse
Definition IntersectVisitor:81
osg::Drawable * getDrawable()
Definition IntersectVisitor:66
float getRatio() const
Definition IntersectVisitor:59
const osg::RefMatrix * getMatrix() const
Definition IntersectVisitor:68
const osg::Vec3 & getLocalIntersectPoint() const
Definition IntersectVisitor:53
float _ratio
Definition IntersectVisitor:74
const osg::LineSegment * getLocalLineSegment() const
Definition IntersectVisitor:61
std::vector< int > VecIndexList
Definition IntersectVisitor:43
osg::Vec3 _intersectNormal
Definition IntersectVisitor:86
osg::ref_ptr< osg::RefMatrix > _matrix
Definition IntersectVisitor:80
const osg::LineSegment * getOriginalLineSegment() const
Definition IntersectVisitor:60
const osg::RefMatrix * getInverseMatrix() const
Definition IntersectVisitor:69
osg::ref_ptr< osg::LineSegment > _localLineSegment
Definition IntersectVisitor:76
VecIndexList _vecIndexList
Definition IntersectVisitor:83
osg::Geode * getGeode()
Definition IntersectVisitor:64
const osg::Vec3 getWorldIntersectPoint() const
Definition IntersectVisitor:56
osg::NodePath _nodePath
Definition IntersectVisitor:77
const osg::Geode * getGeode() const
Definition IntersectVisitor:65
osg::Vec3 _intersectPoint
Definition IntersectVisitor:85
const osg::Vec3 & getLocalIntersectNormal() const
Definition IntersectVisitor:54
Deprecated - use IntersectionVisitor instead.
Definition IntersectVisitor:94
virtual void apply(osg::Billboard &node)
void setEyePoint(const osg::Vec3 &eye)
Set the eye point in local coordinates.
Definition IntersectVisitor:134
META_NodeVisitor(osgUtil, IntersectVisitor) void reset()
virtual void apply(osg::LOD &node)
osg::Vec3 _pseudoEyePoint
Definition IntersectVisitor:200
std::vector< Hit > HitList
Definition IntersectVisitor:110
virtual void apply(osg::Node &)
virtual void apply(osg::Drawable &)
void pushMatrix(osg::RefMatrix *matrix, osg::Transform::ReferenceFrame rf)
LODSelectionMode getLODSelectionMode() const
Definition IntersectVisitor:128
std::vector< osg::ref_ptr< IntersectState > > IntersectStateStack
Definition IntersectVisitor:193
int getNumHits(const osg::LineSegment *seg)
Definition IntersectVisitor:115
bool intersect(osg::Drawable &gset)
virtual void apply(osg::Switch &node)
virtual osg::Vec3 getEyePoint() const
Get the eye point in local coordinates.
virtual void apply(osg::Geode &node)
LineSegmentHitListMap _segHitList
Definition IntersectVisitor:197
void addLineSegment(osg::LineSegment *seg)
Add a line segment to use for intersection testing during scene traversal.
LineSegmentHitListMap & getSegHitList()
Definition IntersectVisitor:117
LODSelectionMode _lodSelectionMode
Definition IntersectVisitor:199
virtual float getDistanceToEyePoint(const osg::Vec3 &pos, bool withLODScale) const
Get the distance from a point to the eye point, distance value in local coordinate system.
IntersectStateStack _intersectStateStack
Definition IntersectVisitor:195
void setLODSelectionMode(LODSelectionMode mode)
Definition IntersectVisitor:127
bool enterNode(osg::Node &node)
virtual void apply(osg::Transform &node)
LODSelectionMode
Definition IntersectVisitor:122
@ USE_HIGHEST_LEVEL_OF_DETAIL
Definition IntersectVisitor:123
@ USE_SEGMENT_START_POINT_AS_EYE_POINT_FOR_LOD_LEVEL_SELECTION
Definition IntersectVisitor:124
virtual void apply(osg::Group &node)
std::map< const osg::LineSegment *, HitList > LineSegmentHitListMap
Definition IntersectVisitor:111
HitList & getHitList(const osg::LineSegment *seg)
Definition IntersectVisitor:113
void addLineSegment(osg::LineSegment *seg)
osg::ref_ptr< osg::RefMatrix > _view_inverse
Definition IntersectVisitor:162
std::vector< LineSegmentPair > LineSegmentList
Definition IntersectVisitor:167
osg::ref_ptr< osg::RefMatrix > _model_inverse
Definition IntersectVisitor:164
unsigned int LineSegmentMask
Definition IntersectVisitor:170
LineSegmentList _segList
Definition IntersectVisitor:168
osg::ref_ptr< osg::RefMatrix > _view_matrix
Definition IntersectVisitor:161
osg::ref_ptr< osg::RefMatrix > _model_matrix
Definition IntersectVisitor:163
LineSegmentMaskStack _segmentMaskStack
Definition IntersectVisitor:172
std::pair< osg::ref_ptr< osg::LineSegment >, osg::ref_ptr< osg::LineSegment > > LineSegmentPair
Definition IntersectVisitor:166
bool isCulled(const osg::BoundingBox &bb, LineSegmentMask &segMaskOut)
std::vector< LineSegmentMask > LineSegmentMaskStack
Definition IntersectVisitor:171
bool isCulled(const osg::BoundingSphere &bs, LineSegmentMask &segMaskOut)
PickVisitor(const osg::Viewport *viewport, const osg::Matrixd &proj, const osg::Matrixd &view, float mx, float my)
osg::ref_ptr< const osg::Viewport > _lastViewport
Definition IntersectVisitor:221
osg::Matrixd _lastViewMatrix
Definition IntersectVisitor:223
float _my
Definition IntersectVisitor:219
void runNestedPickVisitor(osg::Node &node, const osg::Viewport *viewport, const osg::Matrix &proj, const osg::Matrix &view, float mx, float my)
float _mx
Definition IntersectVisitor:218
void apply(osg::Camera &camera)
osg::Matrixd _lastProjectionMatrix
Definition IntersectVisitor:222
void apply(osg::Projection &projection)
#define OSGUTIL_EXPORT
Definition Export:40

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.