OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PlaneIntersector.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_PLANEINTERSECTOR
15 #define OSGUTIL_PLANEINTERSECTOR 1
16 
17 #include <osgUtil/IntersectionVisitor>
18 
19 #include <osg/CoordinateSystemNode>
20 
21 namespace osgUtil
22 {
23 
27 {
28  public:
29 
31  PlaneIntersector(const osg::Plane& plane, const osg::Polytope& boundingPolytope=osg::Polytope());
32 
34  PlaneIntersector(CoordinateFrame cf, const osg::Plane& plane, const osg::Polytope& boundingPolytope=osg::Polytope());
35 
36  struct Intersection
37  {
39 
40  bool operator < (const Intersection& rhs) const
41  {
42  if (polyline < rhs.polyline) return true;
43  if (rhs.polyline < polyline) return false;
44 
45  if (nodePath < rhs.nodePath) return true;
46  if (rhs.nodePath < nodePath ) return false;
47 
48  return (drawable < rhs.drawable);
49  }
50 
51  typedef std::vector<osg::Vec3d> Polyline;
52  typedef std::vector<double> Attributes;
53 
57  Polyline polyline;
58  Attributes attributes;
59 
60  };
61 
62  typedef std::vector<Intersection> Intersections;
63 
64  inline void insertIntersection(const Intersection& intersection) { getIntersections().push_back(intersection); }
65 
66  inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
67 
68 
69  void setRecordHeightsAsAttributes(bool flag) { _recordHeightsAsAttributes = flag; }
70 
71  bool getRecordHeightsAsAttributes() const { return _recordHeightsAsAttributes; }
72 
73  void setEllipsoidModel(osg::EllipsoidModel* em) { _em = em; }
74 
75  const osg::EllipsoidModel* getEllipsoidModel() const { return _em.get(); }
76 
77  public:
78 
80 
81  virtual bool enter(const osg::Node& node);
82 
83  virtual void leave();
84 
85  virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
86 
87  virtual void reset();
88 
89  virtual bool containsIntersections() { return !getIntersections().empty(); }
90 
91  protected:
92 
94 
97 
100 
101  Intersections _intersections;
102 
103 };
104 
105 }
106 
107 #endif
108 
osg::ref_ptr< osg::Drawable > drawable
PlaneIntersector * _parent
osg::ref_ptr< osg::RefMatrix > matrix
osg::ref_ptr< osg::EllipsoidModel > _em
void setEllipsoidModel(osg::EllipsoidModel *em)
T * clone(const T *t, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Object.h:242
const osg::EllipsoidModel * getEllipsoidModel() const
std::vector< Intersection > Intersections
bool getRecordHeightsAsAttributes() const
void insertIntersection(const Intersection &intersection)
A plane class. It can be used to represent an infinite plane.
Definition: Plane.h:33
Definition: Node.h:71
#define OSGUTIL_EXPORT
Definition: Export.h:40
virtual bool containsIntersections()
void setRecordHeightsAsAttributes(bool flag)
Intersections & getIntersections()
std::vector< Node * > NodePath
Definition: Node.h:44
Shader generator framework.
Definition: RenderInfo.h:20