openscenegraph
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
123 Intersectors& getIntersectors() { return _intersectors; }
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
169
170
172 virtual osgUtil::IntersectionVisitor* asIntersectionVisitor() { return this; }
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
195 bool getUseKdTreeWhenAvailable() const { return _useKdTreesWhenAvailable; }
196
197 void setDoDummyTraversal(bool dummy) { _dummyTraversal = dummy; }
198 bool getDoDummyTraversal() const { return _dummyTraversal; }
199
200
202 void setReadCallback(ReadCallback* rc) { _readCallback = rc; }
203
205 ReadCallback* getReadCallback() { return _readCallback.get(); }
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; }
218 void popProjectionMatrix() { _projectionStack.pop_back(); _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
234 void setReferenceEyePoint(const osg::Vec3& ep) { _referenceEyePoint = ep; _eyePointDirty = true; }
235
237 const osg::Vec3& getReferenceEyePoint() const { return _referenceEyePoint; }
238
240 void setReferenceEyePointCoordinateFrame(Intersector::CoordinateFrame cf) { _referenceEyePointCoordinateFrame = cf; }
241
243 Intersector::CoordinateFrame getReferenceEyePointCoordinateFrame() const { return _referenceEyePointCoordinateFrame; }
244
245
247 virtual osg::Vec3 getEyePoint() const;
248
250 {
252 USE_EYE_POINT_FOR_LOD_LEVEL_SELECTION
253 };
254
256 void setLODSelectionMode(LODSelectionMode mode) { _lodSelectionMode = mode; }
257
259 LODSelectionMode getLODSelectionMode() const { return _lodSelectionMode; }
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
Definition IntersectionVisitor:152
osg::Vec3 _referenceEyePoint
Definition IntersectionVisitor:300
void setReadCallback(ReadCallback *rc)
Definition IntersectionVisitor:202
virtual void apply(osg::Projection &projection)
LODSelectionMode getLODSelectionMode() const
Definition IntersectionVisitor:259
MatrixStack _modelStack
Definition IntersectionVisitor:298
void popWindowMatrix()
Definition IntersectionVisitor:213
void setLODSelectionMode(LODSelectionMode mode)
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
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
Definition IntersectionVisitor:243
virtual void apply(osg::PagedLOD &lod)
bool _useKdTreesWhenAvailable
Definition IntersectionVisitor:289
Intersector * getIntersector()
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
osg::RefMatrix * getModelMatrix()
Definition IntersectionVisitor:229
void pushProjectionMatrix(osg::RefMatrix *matrix)
Definition IntersectionVisitor:217
ReadCallback * getReadCallback()
Definition IntersectionVisitor:205
virtual void apply(osg::Group &group)
bool getUseKdTreeWhenAvailable() const
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)
Definition IntersectionVisitor:192
osg::ref_ptr< ReadCallback > _readCallback
Definition IntersectionVisitor:292
const osg::Vec3 & getReferenceEyePoint() const
Definition IntersectionVisitor:237
const Intersector * getIntersector() const
Definition IntersectionVisitor:188
const osg::RefMatrix * getWindowMatrix() const
Definition IntersectionVisitor:215
void setIntersector(Intersector *intersector)
const osg::RefMatrix * getProjectionMatrix() const
Definition IntersectionVisitor:220
META_NodeVisitor(osgUtil, IntersectionVisitor) virtual osgUtil
Definition IntersectionVisitor:168
virtual void apply(osg::Drawable &drawable)
MatrixStack _projectionStack
Definition IntersectionVisitor:296
bool _dummyTraversal
Definition IntersectionVisitor:290
const ReadCallback * getReadCallback() const
Definition IntersectionVisitor:208
void setReferenceEyePointCoordinateFrame(Intersector::CoordinateFrame cf)
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
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)
Definition IntersectionVisitor:234
virtual const osgUtil::IntersectionVisitor * asIntersectionVisitor() const
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
Definition IntersectionVisitor:112
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()
Definition IntersectionVisitor:123
void addIntersector(Intersector *intersector)
virtual bool containsIntersections()
virtual bool enter(const osg::Node &node)
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
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
Definition IntersectionVisitor:98
IntersectionLimit getIntersectionLimit() const
Definition IntersectionVisitor:65
void setPrecisionHint(PrecisionHint hint)
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
Definition Billboard:27
Definition Camera:45
Definition Drawable:89
Definition Geode:29
Definition Group:29
Definition LOD:36
Definition NodeVisitor:82
Definition Node:72
Definition PagedLOD:24
Definition Projection:25
Definition Matrixd:412
Definition Referenced:44
Definition Transform:75
Definition Vec3f:29
Definition Viewport:24
const osg::Matrix computeWindowMatrix() const
Definition Viewport:129
Definition ref_ptr:32
Shader generator framework.
Definition NodeVisitor:25
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
Definition IntersectionVisitor:161
virtual osg::ref_ptr< osg::Node > readNodeFile(const std::string &filename)=0