1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSGUTIL_PLANEINTERSECTOR
15#define OSGUTIL_PLANEINTERSECTOR 1
17#include <osgUtil/IntersectionVisitor>
19#include <osg/CoordinateSystemNode>
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
30 /** Construct a PolytopeIntersector using speified polytope in MODEL coordinates.*/
31 PlaneIntersector(const osg::Plane& plane, const osg::Polytope& boundingPolytope=osg::Polytope());
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());
40 bool operator < (const Intersection& rhs) const
42 if (polyline < rhs.polyline) return true;
43 if (rhs.polyline < polyline) return false;
45 if (nodePath < rhs.nodePath) return true;
46 if (rhs.nodePath < nodePath ) return false;
48 return (drawable < rhs.drawable);
51 typedef std::vector<osg::Vec3d> Polyline;
52 typedef std::vector<double> Attributes;
54 osg::NodePath nodePath;
55 osg::ref_ptr<osg::RefMatrix> matrix;
56 osg::ref_ptr<osg::Drawable> drawable;
58 Attributes attributes;
62 typedef std::vector<Intersection> Intersections;
64 inline void insertIntersection(const Intersection& intersection) { getIntersections().push_back(intersection); }
66 inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
69 void setRecordHeightsAsAttributes(bool flag) { _recordHeightsAsAttributes = flag; }
71 bool getRecordHeightsAsAttributes() const { return _recordHeightsAsAttributes; }
73 void setEllipsoidModel(osg::EllipsoidModel* em) { _em = em; }
75 const osg::EllipsoidModel* getEllipsoidModel() const { return _em.get(); }
79 virtual Intersector* clone(osgUtil::IntersectionVisitor& iv);
81 virtual bool enter(const osg::Node& node);
85 virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
89 virtual bool containsIntersections() { return !getIntersections().empty(); }
93 PlaneIntersector* _parent;
95 bool _recordHeightsAsAttributes;
96 osg::ref_ptr<osg::EllipsoidModel> _em;
99 osg::Polytope _polytope;
101 Intersections _intersections;