VR-Forces 4.3.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <vrvOsg/DtOsgRenderer.h>
16 
17 #include <vrvCore/DtIntersector.h>
18 #include <vrvCore/DtDe.h>
19 
20 #include <osgUtil/IntersectVisitor>
21 
22 #include <osg/Node>
23 #include <osgUtil/LineSegmentIntersector>
24 
25 namespace osgUtil
26 {
27  class Hit;
28 }
29 
30 namespace osgViewer
31 {
32  class View;
33 }
34 
35 class DtVector;
36 
37 namespace makVrv
38 {
39  class DtOsgRenderer;
40  class DtOsgIntersectVisitor;
41 
47  {
48  public:
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 
62 #if 0
63  class DtSceneObject;
65 
66  class DT_DLL_VRVOSG DtOsgDrawnIntersector : public DtDrawnIntersector
67  {
68  public:
69  DtOsgDrawnIntersector( DtDe& de );
70  virtual ~DtOsgDrawnIntersector();
71 
72  virtual void draw( const DtIntersector::DtIntersections& results );
73 
74  protected:
75  DtOsg3DSegmentedLineModel* myLineModel;
76  DtSceneObject* mySceneObject;
77  };
78 #endif
79 
85  {
86  public:
87 
88  // Abstract DtIntersector Implementation for OSG
89 
91  DtOsgIntersector( DtDe& de, int modelSet );
92 
94  virtual ~DtOsgIntersector();
95 
110  virtual bool findNearestIntersectionToPoint(double x, double y, double z,
111  double vx, double vy, double vz,
113  IntersectProperties properties=AllNodes,
114  std::vector<DtElementID>* ignoreList=0,
115  bool returnTriangle=false,
116  double maxIsectorLength=-1., bool useHighLod=false );
117 
125  virtual bool findAllIntersectionsThroughPoint( double x, double y, double z,
126  double vx, double vy, double vz, DtIntersections& intersections,
127  IntersectProperties properties=AllNodes,
128  std::vector<DtElementID>* ignoreList=0, bool sort=true, bool useHighLod=false );
129 
136  virtual bool findFirstIntersectWithLineSegment(
137  double x, double y, double z, double end_x, double end_y, double end_z,
138  DtIntersectorResult& intersection,
139  IntersectProperties properties=AllNodes,
140  std::vector<DtElementID>* ignoreList=0, bool useHighLod=false);
141 
148  virtual bool findAllIntersectWithLineSegment(
149  double x, double y, double z, double end_x, double end_y, double end_z,
150  DtIntersections& intersections,
151  IntersectProperties properties=AllNodes,
152  std::vector<DtElementID>* ignoreList=0, bool sort=true, bool useHighLod=false );
153 
159  virtual bool pick( DtChannel& channel, double mx, double my,
160  DtIntersectorResult& intersection,
161  IntersectProperties properties=AllNodes,
162  std::vector<DtElementID>* ignoreList=0);
163 
168  virtual bool pickAll( DtChannel* channel, double mx, double my,
169  DtIntersections& intersections, IntersectProperties properties=AllNodes,
170  std::vector<DtElementID>* ignoreList=0);
171 
172  public:
173 
174  // OSG-specific Interface
175 
176  typedef std::vector<DtOsgIntersectorResult> DtOsgIntersections;
177 
178 
198  virtual bool findNearestIntersection(double x, double y, double z,
199  double vx, double vy, double vz, DtOsgIntersectorResult& intersection,
200  const DtOsgRenderer::RootList& intersectionRoots,
201  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
202  std::list<osg::Node*>* excludeNodeList=0, bool returnHitTriangle=false,
203  double maxIsectorLength=-1.0, bool useHighLod=false );
204 
218  virtual bool findIntersectionsThroughPoint(double x, double y, double z,
219  double vx, double vy, double vz,
221  const DtOsgRenderer::RootList& intersectionRoots,
222  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
223  std::list<osg::Node*>* excludeNodeList=0, bool returnHitTriangle=false,
224  double maxIsectorLength=-1.0, bool sort=true, bool useHighLod=false );
225 
231  virtual bool intersectLineSegmentWithScene( double x, double y, double z,
232  double end_x, double end_y, double end_z,
233  DtOsgIntersectorResult& intersection,
234  const DtOsgRenderer::RootList& intersectionRoots,
235  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
236  std::list<osg::Node*>* excludeNodeList=0,
237  bool returnHitTriangle=false, bool useHighLod=false );
238 
244  virtual bool intersectLineSegmentWithScene( double x, double y, double z,
245  double end_x, double end_y, double end_z,
246  DtOsgIntersector::DtOsgIntersections& intersections,
247  const DtOsgRenderer::RootList& intersectionRoots,
248  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
249  std::list<osg::Node*>* excludeNodeList=0,
250  bool returnHitTriangle=false, bool sort=true, bool useHighLod=false );
251 
254  virtual bool pick( osgViewer::View& view, double mx, double my,
255  DtOsgIntersectorResult& intersection,
256  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
257  std::list<osg::Node*>* excludeNodeList=0,
258  bool returnHitTriangle=false );
259 
262  virtual bool pick( osgViewer::View& view, double mx, double my,
264  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
265  std::list<osg::Node*>* excludeNodeList=0,
266  bool returnHitTriangle=false );
267 
268  public:
269 
270  static osg::Node::NodeMask nodeMaskFromIntersectProperties(
271  IntersectProperties properties );
272 
273  static bool anyNodeInNodePath(std::list<osg::Node*>* n,
274  osg::NodePath const& path);
275 
276  protected:
277 
279  virtual float distanceToResult2(double x, double y, double z, DtOsgIntersectorResult& result);
280 
281  virtual bool calcEndpointsFromDirectionAndLength( double x, double y,
282  double z, double vx, double vy, double vz, double length,
283  const DtOsgRenderer::RootList& intersectionRoots, DtVector& startPoint,
284  DtVector& endPoint ) const;
285 
286  void getExcludeNodesFromIgnoreList( std::vector<DtUniqueID>* ignoreList,
287  std::list<osg::Node*>& excludeNodes );
288 
291  osg::Vec3d worldIntersectPoint( const osgUtil::Hit& hit );
292 
293  osg::Vec3d worldIntersectPoint(
294  const osgUtil::LineSegmentIntersector::Intersection& hit );
295 
296  osg::Vec3d localToWorld( const osg::Vec3& local, const osg::Matrix& localToWorld );
297 
298  bool findIdFromNodePath( const osg::NodePath& nodePath, DtUniqueID& id );
299 
302  osg::Camera * getActiveCamera(osgViewer::View& view);
303 
306  void updateInstanceIntersectElementId(DtOsgIntersectorResult &result);
307 
309  bool fillResultFromHit(DtOsgIntersectorResult& result, const osgUtil::Hit& hit,
310  bool returnHitTriangle ) ;
311 
313  bool fillResultFromHit(DtOsgIntersectorResult& result,
314  const osgUtil::LineSegmentIntersector::Intersection& hit,
315  bool returnHitTriangle ) ;
316 
319  osgUtil::IntersectVisitor::HitList& getLineSegmentIntersection(
320  osgUtil::IntersectVisitor& collisionVisitor, double x, double y, double z,
321  double end_x, double end_y, double end_z,
322  const DtOsgRenderer::RootList& intersectionRoots, osg::Node::NodeMask mask);
323 
325  bool processLineSegmentIntersection(
326  osgUtil::IntersectVisitor::HitList& hitList,
327  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
328  DtOsgIntersectorResult& intersection );
329 
331  bool processLineSegmentIntersection( const osg::Vec3d& testPoint,
332  osgUtil::IntersectVisitor::HitList& hitList,
333  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
334  DtOsgIntersectorResult& intersection );
335 
337  bool processLineSegmentIntersection( const osg::Vec3d& testPoint,
338  osgUtil::IntersectVisitor::HitList& hitList,
339  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
340  DtOsgIntersector::DtOsgIntersections& intersections, bool sort );
341 
343  bool processPickIntersection(
344  osgUtil::LineSegmentIntersector::Intersections& hitList,
345  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
346  DtOsgIntersectorResult& intersection );
347 
349  bool processPickIntersection(
350  osgUtil::LineSegmentIntersector::Intersections& hitList,
351  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
352  DtOsgIntersector::DtOsgIntersections& intersections );
353 
356  void setupCollisionVisitor( bool useHighLod, DtOsgIntersectVisitor& visitor );
357 
360  bool shouldInstanceIntersect(osg::Node::NodeMask nodeMask);
361 
362  protected:
364  };
365 
370  {
371  public:
372  DtOsgIntersectorSorter( const osg::Vec3d& reference )
373  : myReference( reference ) {}
374 
375  inline bool operator() ( const DtOsgIntersectorResult& a,
376  const DtOsgIntersectorResult& b )
377  {
378  osg::Vec3d diffA = osg::Vec3d(a.x, a.y, a.z) - myReference;
379  osg::Vec3d diffB = osg::Vec3d(b.x, b.y, b.z) - myReference;
380  return diffA.length2() < diffB.length2();
381  }
382  protected:
383  osg::Vec3d myReference;
384  };
385 
389  {
390  public:
392  virtual DtIntersector* create(DtDe& de, int modelSet );
393  };
394 }

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)