OpenSceneGraph 3.6.5
IntersectionVisitor
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_INTERSECTIONVISITOR
15#define OSGUTIL_INTERSECTIONVISITOR 1
16
17#include <osg/NodeVisitor>
18#include <osg/Drawable>
19#include <osgUtil/Export>
20
21#include <list>
22
23namespace osgUtil
24{
25
26// forward declare to allow Intersector to reference it.
27class IntersectionVisitor;
28
34{
35 public:
36
44
52
58
60
62
64
66
68
69 virtual bool enter(const osg::Node& node) = 0;
70
71 virtual void leave() = 0;
72
73 virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable) = 0;
74
75 virtual void reset() { _disabledCount = 0; }
76
77 virtual bool containsIntersections() = 0;
78
79 inline bool disabled() const { return _disabledCount!=0; }
80
82
84
86
93
96
99
100protected:
101
104 unsigned int _disabledCount;
106};
107
108
112{
113 public:
114
116
118 void addIntersector(Intersector* intersector);
119
120 typedef std::vector< osg::ref_ptr<Intersector> > Intersectors;
121
124
126 void clear();
127
128 public:
129
131
132 virtual bool enter(const osg::Node& node);
133
134 virtual void leave();
135
137
138 virtual void reset();
139
140 virtual bool containsIntersections();
141
142 protected:
143
145
146};
147
152{
153 public:
154
161 {
162 virtual osg::ref_ptr<osg::Node> readNodeFile(const std::string& filename) = 0;
163 };
164
165
166 IntersectionVisitor(Intersector* intersector=0, ReadCallback* readCallback=0);
167
173
176 virtual const osgUtil::IntersectionVisitor* asIntersectionVisitor() const { return this; }
177
178
179 virtual void reset();
180
182 void setIntersector(Intersector* intersector);
183
185 Intersector* getIntersector() { return _intersectorStack.empty() ? 0 : _intersectorStack.front().get(); }
186
188 const Intersector* getIntersector() const { return _intersectorStack.empty() ? 0 : _intersectorStack.front().get(); }
189
190
192 void setUseKdTreeWhenAvailable(bool useKdTrees) { _useKdTreesWhenAvailable = useKdTrees; }
193
196
197 void setDoDummyTraversal(bool dummy) { _dummyTraversal = dummy; }
198 bool getDoDummyTraversal() const { return _dummyTraversal; }
199
200
203
206
208 const ReadCallback* getReadCallback() const { return _readCallback.get(); }
209
210
211 void pushWindowMatrix(osg::RefMatrix* matrix) { _windowStack.push_back(matrix); _eyePointDirty = true; }
212 void pushWindowMatrix(osg::Viewport* viewport) { _windowStack.push_back(new osg::RefMatrix( viewport->computeWindowMatrix()) ); _eyePointDirty = true; }
213 void popWindowMatrix() { _windowStack.pop_back(); _eyePointDirty = true; }
214 osg::RefMatrix* getWindowMatrix() { return _windowStack.empty() ? 0 : _windowStack.back().get(); }
215 const osg::RefMatrix* getWindowMatrix() const { return _windowStack.empty() ? 0 : _windowStack.back().get(); }
216
217 void pushProjectionMatrix(osg::RefMatrix* matrix) { _projectionStack.push_back(matrix); _eyePointDirty = true; }
219 osg::RefMatrix* getProjectionMatrix() { return _projectionStack.empty() ? 0 : _projectionStack.back().get(); }
220 const osg::RefMatrix* getProjectionMatrix() const { return _projectionStack.empty() ? 0 : _projectionStack.back().get(); }
221
222 void pushViewMatrix(osg::RefMatrix* matrix) { _viewStack.push_back(matrix); _eyePointDirty = true; }
223 void popViewMatrix() { _viewStack.pop_back(); _eyePointDirty = true; }
224 osg::RefMatrix* getViewMatrix() { return _viewStack.empty() ? 0 : _viewStack.back().get(); }
225 const osg::RefMatrix* getViewMatrix() const { return _viewStack.empty() ? 0 : _viewStack.back().get(); }
226
227 void pushModelMatrix(osg::RefMatrix* matrix) { _modelStack.push_back(matrix); _eyePointDirty = true; }
228 void popModelMatrix() { _modelStack.pop_back(); _eyePointDirty = true; }
229 osg::RefMatrix* getModelMatrix() { return _modelStack.empty() ? 0 : _modelStack.back().get(); }
230 const osg::RefMatrix* getModelMatrix() const { return _modelStack.empty() ? 0 : _modelStack.back().get(); }
231
232
235
238
241
244
245
247 virtual osg::Vec3 getEyePoint() const;
248
254
257
260
263 virtual float getDistanceToEyePoint(const osg::Vec3& pos, bool withLODScale) const;
264
265 public:
266
267 virtual void apply(osg::Node& node);
268 virtual void apply(osg::Drawable& drawable);
269 virtual void apply(osg::Geode& geode);
270 virtual void apply(osg::Billboard& geode);
271 virtual void apply(osg::Group& group);
272 virtual void apply(osg::LOD& lod);
273 virtual void apply(osg::PagedLOD& lod);
274 virtual void apply(osg::Transform& transform);
275 virtual void apply(osg::Projection& projection);
276 virtual void apply(osg::Camera& camera);
277
278 protected:
279
280 inline bool enter(const osg::Node& node) { return _intersectorStack.empty() ? false : _intersectorStack.back()->enter(node); }
281 inline void leave() { _intersectorStack.back()->leave(); }
282 inline void intersect(osg::Drawable* drawable) { _intersectorStack.back()->intersect(*this, drawable); }
283 inline void push_clone() { _intersectorStack.push_back ( _intersectorStack.front()->clone(*this) ); }
284 inline void pop_clone() { if (_intersectorStack.size()>=2) _intersectorStack.pop_back(); }
285
286 typedef std::list< osg::ref_ptr<Intersector> > IntersectorStack;
288
291
293
294 typedef std::list< osg::ref_ptr<osg::RefMatrix> > MatrixStack;
299
303
304 mutable bool _eyePointDirty;
306};
307
308}
309
310#endif
311
Vec3f Vec3
Definition Vec3:21
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
LOD - Level Of Detail group node which allows switching between children depending on distance from e...
Definition LOD:36
Base class for all internal nodes in the scene graph.
Definition Node:72
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
PagedLOD.
Definition PagedLOD:24
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
A Transform is a group node for which all children are transformed by a 4x4 matrix.
Definition Transform:75
Encapsulate OpenGL glViewport.
Definition Viewport:24
const osg::Matrix computeWindowMatrix() const
Compute the Window Matrix which takes projected coords into Window coordinates.
Definition Viewport:129
Pure virtual base class for implementing custom intersection technique.
Definition IntersectionVisitor:34
bool reachedLimit()
Definition IntersectionVisitor:85
virtual void leave()=0
virtual Intersector * clone(osgUtil::IntersectionVisitor &iv)=0
virtual void reset()
Definition IntersectionVisitor:75
CoordinateFrame _coordinateFrame
Definition IntersectionVisitor:102
virtual void intersect(osgUtil::IntersectionVisitor &iv, osg::Drawable *drawable)=0
void incrementDisabledCount()
Definition IntersectionVisitor:81
virtual bool containsIntersections()=0
IntersectionLimit
Definition IntersectionVisitor:46
@ NO_LIMIT
Definition IntersectionVisitor:47
@ LIMIT_ONE
Definition IntersectionVisitor:49
@ LIMIT_ONE_PER_DRAWABLE
Definition IntersectionVisitor:48
@ LIMIT_NEAREST
Definition IntersectionVisitor:50
unsigned int _disabledCount
Definition IntersectionVisitor:104
void setCoordinateFrame(CoordinateFrame cf)
Definition IntersectionVisitor:59
PrecisionHint
Hint to precision used in the internal intersections calculations.
Definition IntersectionVisitor:89
@ USE_FLOAT_CALCULATIONS
Definition IntersectionVisitor:91
@ USE_DOUBLE_CALCULATIONS
Definition IntersectionVisitor:90
bool disabled() const
Definition IntersectionVisitor:79
CoordinateFrame
Definition IntersectionVisitor:38
@ WINDOW
Definition IntersectionVisitor:39
@ MODEL
Definition IntersectionVisitor:42
@ VIEW
Definition IntersectionVisitor:41
@ PROJECTION
Definition IntersectionVisitor:40
void decrementDisabledCount()
Definition IntersectionVisitor:83
IntersectionLimit _intersectionLimit
Definition IntersectionVisitor:103
CoordinateFrame getCoordinateFrame() const
Definition IntersectionVisitor:61
virtual bool enter(const osg::Node &node)=0
PrecisionHint getPrecisionHint() const
Get the hint to what precision should be used in the intersections calculations.
Definition IntersectionVisitor:98
IntersectionLimit getIntersectionLimit() const
Definition IntersectionVisitor:65
void setPrecisionHint(PrecisionHint hint)
Set the hint to what precision to use in the intersections calculations.
Definition IntersectionVisitor:95
PrecisionHint _precisionHint
Definition IntersectionVisitor:105
void setIntersectionLimit(IntersectionLimit limit)
Definition IntersectionVisitor:63
Intersector(CoordinateFrame cf=MODEL, IntersectionLimit il=NO_LIMIT)
Definition IntersectionVisitor:53
virtual void intersect(osgUtil::IntersectionVisitor &iv, osg::Drawable *drawable)
virtual Intersector * clone(osgUtil::IntersectionVisitor &iv)
std::vector< osg::ref_ptr< Intersector > > Intersectors
Definition IntersectionVisitor:120
Intersectors _intersectors
Definition IntersectionVisitor:144
Intersectors & getIntersectors()
Get the list of intersector.
Definition IntersectionVisitor:123
void addIntersector(Intersector *intersector)
Add an Intersector.
virtual bool containsIntersections()
virtual bool enter(const osg::Node &node)
void clear()
Clear the list of intersectors.
IntersectionVisitor is used to testing for intersections with the scene, traversing the scene using g...
Definition IntersectionVisitor:152
osg::Vec3 _referenceEyePoint
Definition IntersectionVisitor:300
void setReadCallback(ReadCallback *rc)
Set the read callback.
Definition IntersectionVisitor:202
virtual void apply(osg::Projection &projection)
LODSelectionMode getLODSelectionMode() const
Get the LOD selection scheme.
Definition IntersectionVisitor:259
MatrixStack _modelStack
Definition IntersectionVisitor:298
void popWindowMatrix()
Definition IntersectionVisitor:213
void setLODSelectionMode(LODSelectionMode mode)
Set the LOD selection scheme.
Definition IntersectionVisitor:256
virtual void apply(osg::Node &node)
virtual void apply(osg::Transform &transform)
void popProjectionMatrix()
Definition IntersectionVisitor:218
virtual void apply(osg::Geode &geode)
void popModelMatrix()
Definition IntersectionVisitor:228
virtual void reset()
Method to call to reset visitor.
MatrixStack _viewStack
Definition IntersectionVisitor:297
bool getDoDummyTraversal() const
Definition IntersectionVisitor:198
osg::RefMatrix * getViewMatrix()
Definition IntersectionVisitor:224
virtual void apply(osg::Camera &camera)
void pushViewMatrix(osg::RefMatrix *matrix)
Definition IntersectionVisitor:222
LODSelectionMode _lodSelectionMode
Definition IntersectionVisitor:302
Intersector::CoordinateFrame getReferenceEyePointCoordinateFrame() const
Get the coordinate frame of the reference eye point.
Definition IntersectionVisitor:243
virtual void apply(osg::PagedLOD &lod)
bool _useKdTreesWhenAvailable
Definition IntersectionVisitor:289
Intersector * getIntersector()
Get the intersector that will be used to intersect with the scene, and to store any hits that occur.
Definition IntersectionVisitor:185
void push_clone()
Definition IntersectionVisitor:283
virtual void apply(osg::Billboard &geode)
MatrixStack _windowStack
Definition IntersectionVisitor:295
Intersector::CoordinateFrame _referenceEyePointCoordinateFrame
Definition IntersectionVisitor:301
void leave()
Definition IntersectionVisitor:281
osg::Vec3 _eyePoint
Definition IntersectionVisitor:305
bool _eyePointDirty
Definition IntersectionVisitor:304
std::list< osg::ref_ptr< osg::RefMatrix > > MatrixStack
Definition IntersectionVisitor:294
virtual osg::Vec3 getEyePoint() const
Get the eye point in the local coordinate frame a given traversal point.
osg::RefMatrix * getModelMatrix()
Definition IntersectionVisitor:229
void pushProjectionMatrix(osg::RefMatrix *matrix)
Definition IntersectionVisitor:217
ReadCallback * getReadCallback()
Get the read callback.
Definition IntersectionVisitor:205
virtual void apply(osg::Group &group)
bool getUseKdTreeWhenAvailable() const
Set whether the intersectors should use KdTrees.
Definition IntersectionVisitor:195
osg::RefMatrix * getProjectionMatrix()
Definition IntersectionVisitor:219
void pushWindowMatrix(osg::Viewport *viewport)
Definition IntersectionVisitor:212
virtual void apply(osg::LOD &lod)
void setUseKdTreeWhenAvailable(bool useKdTrees)
Set whether the intersectors should use KdTrees when they are found on the scene graph.
Definition IntersectionVisitor:192
osg::ref_ptr< ReadCallback > _readCallback
Definition IntersectionVisitor:292
const osg::Vec3 & getReferenceEyePoint() const
Get the reference eye point.
Definition IntersectionVisitor:237
const Intersector * getIntersector() const
Get the const intersector that will be used to intersect with the scene, and to store any hits that o...
Definition IntersectionVisitor:188
const osg::RefMatrix * getWindowMatrix() const
Definition IntersectionVisitor:215
void setIntersector(Intersector *intersector)
Set the intersector that will be used to intersect with the scene, and to store any hits that occur.
const osg::RefMatrix * getProjectionMatrix() const
Definition IntersectionVisitor:220
META_NodeVisitor(osgUtil, IntersectionVisitor) virtual osgUtil
Convert 'this' into a osgUtil::IntersectionVisitor pointer if Object is a IntersectionVisitor,...
Definition IntersectionVisitor:168
virtual void apply(osg::Drawable &drawable)
MatrixStack _projectionStack
Definition IntersectionVisitor:296
bool _dummyTraversal
Definition IntersectionVisitor:290
const ReadCallback * getReadCallback() const
Get the const read callback.
Definition IntersectionVisitor:208
void setReferenceEyePointCoordinateFrame(Intersector::CoordinateFrame cf)
Set the coordinate frame of the reference eye point.
Definition IntersectionVisitor:240
void pushWindowMatrix(osg::RefMatrix *matrix)
Definition IntersectionVisitor:211
void pushModelMatrix(osg::RefMatrix *matrix)
Definition IntersectionVisitor:227
const osg::RefMatrix * getViewMatrix() const
Definition IntersectionVisitor:225
void pop_clone()
Definition IntersectionVisitor:284
void setDoDummyTraversal(bool dummy)
Definition IntersectionVisitor:197
LODSelectionMode
Definition IntersectionVisitor:250
@ USE_HIGHEST_LEVEL_OF_DETAIL
Definition IntersectionVisitor:251
@ USE_EYE_POINT_FOR_LOD_LEVEL_SELECTION
Definition IntersectionVisitor:252
bool enter(const osg::Node &node)
Definition IntersectionVisitor:280
std::list< osg::ref_ptr< Intersector > > IntersectorStack
Definition IntersectionVisitor:286
IntersectionVisitor(Intersector *intersector=0, ReadCallback *readCallback=0)
osg::RefMatrix * getWindowMatrix()
Definition IntersectionVisitor:214
void intersect(osg::Drawable *drawable)
Definition IntersectionVisitor:282
void setReferenceEyePoint(const osg::Vec3 &ep)
Set the reference eye point that is used for nodes that require an eye point to position themselves,...
Definition IntersectionVisitor:234
virtual const osgUtil::IntersectionVisitor * asIntersectionVisitor() const
convert 'const this' into a const osgUtil::IntersectionVisitor pointer if Object is a IntersectionVis...
Definition IntersectionVisitor:176
void popViewMatrix()
Definition IntersectionVisitor:223
const osg::RefMatrix * getModelMatrix() const
Definition IntersectionVisitor:230
IntersectorStack _intersectorStack
Definition IntersectionVisitor:287
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.
Callback used to implement the reading of external files, allowing support for paged databases to be ...
Definition IntersectionVisitor:161
virtual osg::ref_ptr< osg::Node > readNodeFile(const std::string &filename)=0
#define OSGUTIL_EXPORT
Definition Export:40

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