VR-Forces 4.1.1 Class Documentation
DtOsgIntersector.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2012 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
14 #include <vrvCore/DtIntersector.h>
15 #include <vrvCore/DtDe.h>
16 #include <vrvOsg/DtOsgRenderer.h>
18 #include <osgUtil/IntersectVisitor>
19 
20 #include <osg/Node>
21 #include <osgUtil/LineSegmentIntersector>
22 
23 namespace osgUtil
24 {
25  class Hit;
26 }
27 
28 namespace osgViewer
29 {
30  class View;
31 }
32 
33 namespace makVrv
34 {
35  class DtOsgRenderer;
36 
42  {
43  public:
45 
46  DtOsgIntersectorResult( double x, double y, double z, double normalX,
47  double normalY, double normalZ, const DtUniqueID& id,
48  std::vector<osg::Vec3> triangle, osg::Matrixd localToWorld );
49 
51 
52  DtOsgIntersectorResult& operator=( const DtOsgIntersectorResult &orig );
53 
54  public:
55  // 3 points of the intersected triangle
56  std::vector<osg::Vec3> myHitTriangle;
57 
58  // matrix transform from world to triangle local coordinates
59  osg::Matrixd myLocalToWorld;
60  };
61 
67  {
68  public:
69 
70  // Abstract DtIntersector Implementation for OSG
71 
73  DtOsgIntersector( DtDe& de, int modelSet );
74 
76  virtual ~DtOsgIntersector();
77 
92  virtual bool findNearestIntersectionToPoint(double x, double y, double z,
93  double vx, double vy, double vz,
95  IntersectProperties properties=AllNodes,
96  std::vector<DtElementID>* ignoreList=0,
97  bool returnTriangle=false,
98  double maxIsectorLength=-1., bool useHighLod=false );
99 
107  virtual bool findAllIntersectionsThroughPoint( double x, double y, double z,
108  double vx, double vy, double vz, DtIntersections& intersections,
109  IntersectProperties properties=AllNodes,
110  std::vector<DtElementID>* ignoreList=0, bool sort=true, bool useHighLod=false );
111 
118  virtual bool findFirstIntersectWithLineSegment(
119  double x, double y, double z, double end_x, double end_y, double end_z,
120  DtIntersectorResult& intersection,
121  IntersectProperties properties=AllNodes,
122  std::vector<DtElementID>* ignoreList=0, bool useHighLod=false);
123 
130  virtual bool findAllIntersectWithLineSegment(
131  double x, double y, double z, double end_x, double end_y, double end_z,
132  DtIntersections& intersections,
133  IntersectProperties properties=AllNodes,
134  std::vector<DtElementID>* ignoreList=0, bool sort=true, bool useHighLod=false );
135 
141  virtual bool pick( DtChannel& channel, double mx, double my,
142  DtIntersectorResult& intersection,
143  IntersectProperties properties=AllNodes,
144  std::vector<DtElementID>* ignoreList=0);
145 
150  virtual bool pickAll( DtChannel* channel, double mx, double my,
151  DtIntersections& intersections, IntersectProperties properties=AllNodes,
152  std::vector<DtElementID>* ignoreList=0);
153 
154  public:
155 
156  // OSG-specific Interface
157 
158  typedef std::vector<DtOsgIntersectorResult> DtOsgIntersections;
159 
160 
180  bool findNearestIntersection(double x, double y, double z,
181  double vx, double vy, double vz, DtOsgIntersectorResult& intersection,
182  const DtOsgRenderer::RootList& intersectionRoots,
183  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
184  std::list<osg::Node*>* excludeNodeList=0, bool returnHitTriangle=false,
185  double maxIsectorLength=-1.0, bool useHighLod=false);
186 
200  bool findIntersectionsThroughPoint(double x, double y, double z,
201  double vx, double vy, double vz,
203  const DtOsgRenderer::RootList& intersectionRoots,
204  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
205  std::list<osg::Node*>* excludeNodeList=0, bool returnHitTriangle=false,
206  double maxIsectorLength=-1.0, bool sort=true, bool useHighLod=false );
207 
213  bool intersectLineSegmentWithScene( double x, double y, double z,
214  double end_x, double end_y, double end_z,
215  DtOsgIntersectorResult& intersection,
216  const DtOsgRenderer::RootList& intersectionRoots,
217  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
218  std::list<osg::Node*>* excludeNodeList=0,
219  bool returnHitTriangle=false, bool useHighLod=false );
220 
226  bool intersectLineSegmentWithScene( double x, double y, double z,
227  double end_x, double end_y, double end_z,
228  DtOsgIntersector::DtOsgIntersections& intersections,
229  const DtOsgRenderer::RootList& intersectionRoots,
230  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
231  std::list<osg::Node*>* excludeNodeList=0,
232  bool returnHitTriangle=false, bool sort=true, bool useHighLod=false );
233 
236  virtual bool pick( osgViewer::View& view, double mx, double my,
237  DtOsgIntersectorResult& intersection,
238  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
239  std::list<osg::Node*>* excludeNodeList=0,
240  bool returnHitTriangle=false );
241 
244  virtual bool pick( osgViewer::View& view, double mx, double my,
246  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
247  std::list<osg::Node*>* excludeNodeList=0,
248  bool returnHitTriangle=false );
249 
250  void getExcludeNodesFromIgnoreList( std::vector<DtUniqueID>* ignoreList,
251  std::list<osg::Node*>& excludeNodes );
252 
253  public:
254 
255  static osg::Node::NodeMask nodeMaskFromIntersectProperties(
256  IntersectProperties properties );
257 
258  static bool anyNodeInNodePath(std::list<osg::Node*>* n,
259  osg::NodePath const& path);
260 
261  protected:
262 
265  osg::Vec3d worldIntersectPoint( const osgUtil::Hit& hit );
266 
267  osg::Vec3d worldIntersectPoint(
268  const osgUtil::LineSegmentIntersector::Intersection& hit );
269 
270  osg::Vec3d localToWorld( const osg::Vec3& local, const osg::Matrix& localToWorld );
271 
272  bool findIdFromNodePath( const osg::NodePath& nodePath, DtUniqueID& id );
273 
275  bool fillResultFromHit(DtOsgIntersectorResult& result, const osgUtil::Hit& hit,
276  bool returnHitTriangle ) ;
277 
279  bool fillResultFromHit(DtOsgIntersectorResult& result,
280  const osgUtil::LineSegmentIntersector::Intersection& hit,
281  bool returnHitTriangle ) ;
282 
285  osgUtil::IntersectVisitor::HitList& getLineSegmentIntersection(
286  osgUtil::IntersectVisitor& collisionVisitor, double x, double y, double z,
287  double end_x, double end_y, double end_z,
288  const DtOsgRenderer::RootList& intersectionRoots, osg::Node::NodeMask mask);
289 
291  bool processLineSegmentIntersection(
292  osgUtil::IntersectVisitor::HitList& hitList,
293  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
294  DtOsgIntersectorResult& intersection );
295 
297  bool processLineSegmentIntersection( const osg::Vec3d& testPoint,
298  osgUtil::IntersectVisitor::HitList& hitList,
299  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
300  DtOsgIntersectorResult& intersection );
301 
303  bool processLineSegmentIntersection( const osg::Vec3d& testPoint,
304  osgUtil::IntersectVisitor::HitList& hitList,
305  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
306  DtOsgIntersector::DtOsgIntersections& intersections, bool sort );
307 
309  bool processPickIntersection(
310  osgUtil::LineSegmentIntersector::Intersections& hitList,
311  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
312  DtOsgIntersectorResult& intersection );
313 
315  bool processPickIntersection(
316  osgUtil::LineSegmentIntersector::Intersections& hitList,
317  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
318  DtOsgIntersector::DtOsgIntersections& intersections );
319 
320  protected:
322  };
323 
328  {
329  public:
330  DtOsgIntersectorSorter( const osg::Vec3d& reference )
331  : myReference( reference ) {}
332 
333  inline bool operator() ( const DtOsgIntersectorResult& a,
334  const DtOsgIntersectorResult& b )
335  {
336  osg::Vec3d diffA = osg::Vec3d(a.x, a.y, a.z) - myReference;
337  osg::Vec3d diffB = osg::Vec3d(b.x, b.y, b.z) - myReference;
338  return diffA.length2() > diffB.length2();
339  }
340  protected:
341  osg::Vec3d myReference;
342  };
343 
347  {
348  public:
350  virtual DtIntersector* create(DtDe& de, int modelSet );
351  };
352 }

Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)