OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IntersectionVisitor.h
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 
23 namespace osgUtil
24 {
25 
26 // forward declare to allow Intersector to reference it.
27 class IntersectionVisitor;
28 
34 {
35  public:
36 
38  {
43  };
44 
46  {
51  };
52 
54  _coordinateFrame(cf),
56  _disabledCount(0),
58 
59 
61 
63 
65 
67 
69 
70  virtual bool enter(const osg::Node& node) = 0;
71 
72  virtual void leave() = 0;
73 
74  virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable) = 0;
75 
76  virtual void reset() { _disabledCount = 0; }
77 
78  virtual bool containsIntersections() = 0;
79 
80  inline bool disabled() const { return _disabledCount!=0; }
81 
83 
85 
87 
90  {
93  };
94 
97 
100 
101 protected:
102 
105  unsigned int _disabledCount;
107 };
108 
109 
113 {
114  public:
115 
117 
119  void addIntersector(Intersector* intersector);
120 
121  typedef std::vector< osg::ref_ptr<Intersector> > Intersectors;
122 
124  Intersectors& getIntersectors() { return _intersectors; }
125 
127  void clear();
128 
129  public:
130 
132 
133  virtual bool enter(const osg::Node& node);
134 
135  virtual void leave();
136 
137  virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
138 
139  virtual void reset();
140 
141  virtual bool containsIntersections();
142 
143  protected:
144 
145  Intersectors _intersectors;
146 
147 };
148 
153 {
154  public:
155 
162  {
163  virtual osg::Node* readNodeFile(const std::string& filename) = 0;
164  };
165 
166 
167  IntersectionVisitor(Intersector* intersector=0, ReadCallback* readCallback=0);
168 
170 
171  virtual void reset();
172 
173 
175  void setIntersector(Intersector* intersector);
176 
178  Intersector* getIntersector() { return _intersectorStack.empty() ? 0 : _intersectorStack.front().get(); }
179 
181  const Intersector* getIntersector() const { return _intersectorStack.empty() ? 0 : _intersectorStack.front().get(); }
182 
183 
185  void setUseKdTreeWhenAvailable(bool useKdTrees) { _useKdTreesWhenAvailable = useKdTrees; }
186 
188  bool getUseKdTreeWhenAvailable() const { return _useKdTreesWhenAvailable; }
189 
190  void setDoDummyTraversal(bool dummy) { _dummyTraversal = dummy; }
191  bool getDoDummyTraversal() const { return _dummyTraversal; }
192 
193 
195  void setReadCallback(ReadCallback* rc) { _readCallback = rc; }
196 
198  ReadCallback* getReadCallback() { return _readCallback.get(); }
199 
201  const ReadCallback* getReadCallback() const { return _readCallback.get(); }
202 
203 
204  void pushWindowMatrix(osg::RefMatrix* matrix) { _windowStack.push_back(matrix); _eyePointDirty = true; }
205  void pushWindowMatrix(osg::Viewport* viewport) { _windowStack.push_back(new osg::RefMatrix( viewport->computeWindowMatrix()) ); _eyePointDirty = true; }
206  void popWindowMatrix() { _windowStack.pop_back(); _eyePointDirty = true; }
207  osg::RefMatrix* getWindowMatrix() { return _windowStack.empty() ? 0 : _windowStack.back().get(); }
208  const osg::RefMatrix* getWindowMatrix() const { return _windowStack.empty() ? 0 : _windowStack.back().get(); }
209 
210  void pushProjectionMatrix(osg::RefMatrix* matrix) { _projectionStack.push_back(matrix); _eyePointDirty = true; }
211  void popProjectionMatrix() { _projectionStack.pop_back(); _eyePointDirty = true; }
212  osg::RefMatrix* getProjectionMatrix() { return _projectionStack.empty() ? 0 : _projectionStack.back().get(); }
213  const osg::RefMatrix* getProjectionMatrix() const { return _projectionStack.empty() ? 0 : _projectionStack.back().get(); }
214 
215  void pushViewMatrix(osg::RefMatrix* matrix) { _viewStack.push_back(matrix); _eyePointDirty = true; }
216  void popViewMatrix() { _viewStack.pop_back(); _eyePointDirty = true; }
217  osg::RefMatrix* getViewMatrix() { return _viewStack.empty() ? 0 : _viewStack.back().get(); }
218  const osg::RefMatrix* getViewMatrix() const { return _viewStack.empty() ? 0 : _viewStack.back().get(); }
219 
220  void pushModelMatrix(osg::RefMatrix* matrix) { _modelStack.push_back(matrix); _eyePointDirty = true; }
221  void popModelMatrix() { _modelStack.pop_back(); _eyePointDirty = true; }
222  osg::RefMatrix* getModelMatrix() { return _modelStack.empty() ? 0 : _modelStack.back().get(); }
223  const osg::RefMatrix* getModelMatrix() const { return _modelStack.empty() ? 0 : _modelStack.back().get(); }
224 
225 
227  void setReferenceEyePoint(const osg::Vec3& ep) { _referenceEyePoint = ep; _eyePointDirty = true; }
228 
230  const osg::Vec3& getReferenceEyePoint() const { return _referenceEyePoint; }
231 
233  void setReferenceEyePointCoordinateFrame(Intersector::CoordinateFrame cf) { _referenceEyePointCoordinateFrame = cf; }
234 
236  Intersector::CoordinateFrame getReferenceEyePointCoordinateFrame() const { return _referenceEyePointCoordinateFrame; }
237 
238 
240  virtual osg::Vec3 getEyePoint() const;
241 
243  {
245  USE_EYE_POINT_FOR_LOD_LEVEL_SELECTION
246  };
247 
249  void setLODSelectionMode(LODSelectionMode mode) { _lodSelectionMode = mode; }
250 
252  LODSelectionMode getLODSelectionMode() const { return _lodSelectionMode; }
253 
256  virtual float getDistanceToEyePoint(const osg::Vec3& pos, bool withLODScale) const;
257 
258  public:
259 
260  virtual void apply(osg::Node& node);
261  virtual void apply(osg::Drawable& drawable);
262  virtual void apply(osg::Geode& geode);
263  virtual void apply(osg::Billboard& geode);
264  virtual void apply(osg::Group& group);
265  virtual void apply(osg::LOD& lod);
266  virtual void apply(osg::PagedLOD& lod);
267  virtual void apply(osg::Transform& transform);
268  virtual void apply(osg::Projection& projection);
269  virtual void apply(osg::Camera& camera);
270 
271  protected:
272 
273  inline bool enter(const osg::Node& node) { return _intersectorStack.empty() ? false : _intersectorStack.back()->enter(node); }
274  inline void leave() { _intersectorStack.back()->leave(); }
275  inline void intersect(osg::Drawable* drawable) { _intersectorStack.back()->intersect(*this, drawable); }
276  inline void push_clone() { _intersectorStack.push_back ( _intersectorStack.front()->clone(*this) ); }
277  inline void pop_clone() { if (_intersectorStack.size()>=2) _intersectorStack.pop_back(); }
278 
279  typedef std::list< osg::ref_ptr<Intersector> > IntersectorStack;
280  IntersectorStack _intersectorStack;
281 
284 
286 
287  typedef std::list< osg::ref_ptr<osg::RefMatrix> > MatrixStack;
288  MatrixStack _windowStack;
289  MatrixStack _projectionStack;
290  MatrixStack _viewStack;
291  MatrixStack _modelStack;
292 
296 
297  mutable bool _eyePointDirty;
299 };
300 
301 }
302 
303 #endif
304 
CoordinateFrame _coordinateFrame
Intersector::CoordinateFrame _referenceEyePointCoordinateFrame
void pushModelMatrix(osg::RefMatrix *matrix)
void setPrecisionHint(PrecisionHint hint)
LODSelectionMode getLODSelectionMode() const
void intersect(osg::Drawable *drawable)
std::vector< osg::ref_ptr< Intersector > > Intersectors
virtual Intersector * clone(osgUtil::IntersectionVisitor &iv)=0
PrecisionHint getPrecisionHint() const
osg::RefMatrix * getProjectionMatrix()
const osg::Matrix computeWindowMatrix() const
Definition: Viewport.h:129
const ReadCallback * getReadCallback() const
Intersector(CoordinateFrame cf=MODEL, IntersectionLimit il=NO_LIMIT)
const osg::RefMatrix * getViewMatrix() const
Intersector::CoordinateFrame getReferenceEyePointCoordinateFrame() const
virtual bool containsIntersections()=0
virtual bool enter(const osg::Node &node)=0
T * clone(const T *t, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Object.h:242
virtual void intersect(osgUtil::IntersectionVisitor &iv, osg::Drawable *drawable)=0
void setReferenceEyePointCoordinateFrame(Intersector::CoordinateFrame cf)
void pushViewMatrix(osg::RefMatrix *matrix)
Definition: LOD.h:35
const osg::Vec3 & getReferenceEyePoint() const
const osg::RefMatrix * getProjectionMatrix() const
void pushWindowMatrix(osg::RefMatrix *matrix)
void setUseKdTreeWhenAvailable(bool useKdTrees)
void pushProjectionMatrix(osg::RefMatrix *matrix)
#define META_NodeVisitor(library, name)
Definition: NodeVisitor.h:49
std::list< osg::ref_ptr< Intersector > > IntersectorStack
IntersectionLimit getIntersectionLimit() const
void pushWindowMatrix(osg::Viewport *viewport)
const Intersector * getIntersector() const
const osg::RefMatrix * getWindowMatrix() const
bool enter(const osg::Node &node)
std::list< osg::ref_ptr< osg::RefMatrix > > MatrixStack
Definition: Node.h:71
const osg::RefMatrix * getModelMatrix() const
void setCoordinateFrame(CoordinateFrame cf)
void setReferenceEyePoint(const osg::Vec3 &ep)
#define OSGUTIL_EXPORT
Definition: Export.h:40
OSGDB_EXPORT osg::Node * readNodeFile(const std::string &filename, const Options *options)
osg::ref_ptr< ReadCallback > _readCallback
CoordinateFrame getCoordinateFrame() const
void setReadCallback(ReadCallback *rc)
IntersectionLimit _intersectionLimit
void setIntersectionLimit(IntersectionLimit limit)
void setLODSelectionMode(LODSelectionMode mode)
virtual void leave()=0
Shader generator framework.
Definition: RenderInfo.h:20