OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LineSegmentIntersector.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_LINESEGMENTINTERSECTOR
15 #define OSGUTIL_LINESEGMENTINTERSECTOR 1
16 
17 #include <osgUtil/IntersectionVisitor>
18 
19 namespace osgUtil
20 {
21 
25 {
26  public:
27 
29  LineSegmentIntersector(const osg::Vec3d& start, const osg::Vec3d& end);
30 
34 
39  LineSegmentIntersector(CoordinateFrame cf, double x, double y);
40 
42  {
44  ratio(-1.0),
45  primitiveIndex(0) {}
46 
47  bool operator < (const Intersection& rhs) const { return ratio < rhs.ratio; }
48 
49  typedef std::vector<unsigned int> IndexList;
50  typedef std::vector<double> RatioList;
51 
52  double ratio;
58  IndexList indexList;
59  RatioList ratioList;
60  unsigned int primitiveIndex;
61 
62  const osg::Vec3d& getLocalIntersectPoint() const { return localIntersectionPoint; }
63  osg::Vec3d getWorldIntersectPoint() const { return matrix.valid() ? localIntersectionPoint * (*matrix) : localIntersectionPoint; }
64 
65  const osg::Vec3& getLocalIntersectNormal() const { return localIntersectionNormal; }
66  osg::Vec3 getWorldIntersectNormal() const { return matrix.valid() ? osg::Matrix::transform3x3(osg::Matrix::inverse(*matrix),localIntersectionNormal) : localIntersectionNormal; }
67 
70  osg::Texture* getTextureLookUp(osg::Vec3& tc) const;
71 
72  };
73 
74  typedef std::multiset<Intersection> Intersections;
75 
76  inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
77 
78  inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
79 
80  inline Intersection getFirstIntersection() { Intersections& intersections = getIntersections(); return intersections.empty() ? Intersection() : *(intersections.begin()); }
81 
82  inline void setStart(const osg::Vec3d& start) { _start = start; }
83  inline const osg::Vec3d& getStart() const { return _start; }
84 
85  inline void setEnd(const osg::Vec3d& end) { _end = end; }
86  inline const osg::Vec3d& getEnd() const { return _end; }
87 
88  public:
89 
91 
92  virtual bool enter(const osg::Node& node);
93 
94  virtual void leave();
95 
96  virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
97 
98  virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable,
99  const osg::Vec3d& s, const osg::Vec3d& e);
100 
101  virtual void reset();
102 
103  virtual bool containsIntersections() { return !getIntersections().empty(); }
104 
108  static osg::Matrix getTransformation(osgUtil::IntersectionVisitor& iv, CoordinateFrame cf);
109 
110 protected:
111 
112  bool intersects(const osg::BoundingSphere& bs);
113  bool intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const osg::BoundingBox& bb);
114 
116 
119 
120  Intersections _intersections;
121 
122 };
123 
124 }
125 
126 #endif
127 
const osg::Vec3d & getStart() const
#define NULL
Definition: Export.h:59
static Vec3f transform3x3(const Vec3f &v, const Matrixd &m)
Definition: Matrixd.h:659
bool valid() const
Definition: ref_ptr.h:95
void insertIntersection(const Intersection &intersection)
T * clone(const T *t, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Object.h:242
std::multiset< Intersection > Intersections
const osg::Vec3d & getEnd() const
static Matrixd inverse(const Matrixd &matrix)
Definition: Matrixd.h:530
Definition: Node.h:71
#define OSGUTIL_EXPORT
Definition: Export.h:40
void setEnd(const osg::Vec3d &end)
Matrixd CoordinateFrame
std::vector< Node * > NodePath
Definition: Node.h:44
Shader generator framework.
Definition: RenderInfo.h:20
void setStart(const osg::Vec3d &start)