OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PolytopeIntersector.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_POLYTOPEINTERSECTOR
15 #define OSGUTIL_POLYTOPEINTERSECTOR 1
16 
17 #include <osgUtil/IntersectionVisitor>
18 
19 namespace osgUtil
20 {
21 
25 {
26  public:
28  enum {
29  DimZero = (1<<0),
30  DimOne = (1<<1),
31  DimTwo = (1<<2),
32  AllDims = (DimZero | DimOne | DimTwo)
33  };
34 
36  PolytopeIntersector(const osg::Polytope& polytope);
37 
40 
45  PolytopeIntersector(CoordinateFrame cf, double xMin, double yMin, double xMax, double yMax);
46 
48 
49  struct Intersection
50  {
52  distance(0.0),
53  maxDistance(0.0),
54  numIntersectionPoints(0),
55  primitiveIndex(0) {}
56 
57  bool operator < (const Intersection& rhs) const
58  {
59  if (distance < rhs.distance) return true;
60  if (rhs.distance < distance) return false;
61  if (primitiveIndex < rhs.primitiveIndex) return true;
62  if (rhs.primitiveIndex < primitiveIndex) return false;
63  if (nodePath < rhs.nodePath) return true;
64  if (rhs.nodePath < nodePath ) return false;
65  return (drawable < rhs.drawable);
66  }
67 
68  enum { MaxNumIntesectionPoints=6 };
69 
70  double distance;
71  double maxDistance;
76  unsigned int numIntersectionPoints;
77  Vec3_type intersectionPoints[MaxNumIntesectionPoints];
78  unsigned int primitiveIndex;
79  };
80 
81  typedef std::set<Intersection> Intersections;
82 
83  inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
84 
85  inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
86 
87  inline Intersection getFirstIntersection() { Intersections& intersections = getIntersections(); return intersections.empty() ? Intersection() : *(intersections.begin()); }
88 
89  inline unsigned int getDimensionMask() const { return _dimensionMask; }
90 
95  inline void setDimensionMask(unsigned int dimensionMask) { _dimensionMask = dimensionMask; }
96 
97  inline const osg::Plane& getReferencePlane() const { return _referencePlane; }
98 
104  inline void setReferencePlane(const osg::Plane& plane) { _referencePlane = plane; }
105 
106  public:
107 
109 
110  virtual bool enter(const osg::Node& node);
111 
112  virtual void leave();
113 
114  virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
115 
116  virtual void reset();
117 
118  virtual bool containsIntersections() { return !getIntersections().empty(); }
119 
120  protected:
121 
123 
125 
126  unsigned int _dimensionMask;
128 
129  Intersections _intersections;
130 
131 };
132 
133 }
134 
135 #endif
136 
unsigned int _dimensionMask
mask which dimensions should be checked
osg::Plane _referencePlane
plane to use for sorting intersections
T * clone(const T *t, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Object.h:242
osg::Plane::Vec3_type Vec3_type
void setDimensionMask(unsigned int dimensionMask)
void insertIntersection(const Intersection &intersection)
std::set< Intersection > Intersections
Vec3_type localIntersectionPoint
center of all intersection points
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
double maxDistance
maximum distance of intersection points from reference plane
const osg::Plane & getReferencePlane() const
double distance
distance from reference plane
unsigned int getDimensionMask() const
unsigned int primitiveIndex
primitive index
Matrixd CoordinateFrame
std::vector< Node * > NodePath
Definition: Node.h:44
Shader generator framework.
Definition: RenderInfo.h:20
void setReferencePlane(const osg::Plane &plane)