openscenegraph
PlaneIntersector
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
21namespace osgUtil
22{
23
24/** Concrete class for implementing polytope intersections with the scene graph.
25 * To be used in conjunction with IntersectionVisitor. */
26class OSGUTIL_EXPORT PlaneIntersector : public Intersector
27{
28 public:
29
30 /** Construct a PolytopeIntersector using speified polytope in MODEL coordinates.*/
31 PlaneIntersector(const osg::Plane& plane, const osg::Polytope& boundingPolytope=osg::Polytope());
32
33 /** Construct a PolytopeIntersector using speified polytope in specified coordinate frame.*/
34 PlaneIntersector(CoordinateFrame cf, const osg::Plane& plane, const osg::Polytope& boundingPolytope=osg::Polytope());
35
36 struct Intersection
37 {
38 Intersection() {}
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
54 osg::NodePath nodePath;
55 osg::ref_ptr<osg::RefMatrix> matrix;
56 osg::ref_ptr<osg::Drawable> drawable;
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
79 virtual Intersector* clone(osgUtil::IntersectionVisitor& iv);
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
93 PlaneIntersector* _parent;
94
95 bool _recordHeightsAsAttributes;
96 osg::ref_ptr<osg::EllipsoidModel> _em;
97
98 osg::Plane _plane;
99 osg::Polytope _polytope;
100
101 Intersections _intersections;
102
103};
104
105}
106
107#endif
108