VR-Forces 4.3 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:
50 
51  DtOsgIntersectorResult( double x, double y, double z, double normalX,
52  double normalY, double normalZ, const DtUniqueID& id,
53  std::vector<osg::Vec3> triangle, osg::Matrixd localToWorld );
54 
56 
57  DtOsgIntersectorResult& operator=( const DtOsgIntersectorResult &orig );
58 
59  public:
60  // 3 points of the intersected triangle
61  std::vector<osg::Vec3> myHitTriangle;
62 
63  // matrix transform from world to triangle local coordinates
64  osg::Matrixd myLocalToWorld;
65  };
66 
72  {
73  public:
74 
75  // Abstract DtIntersector Implementation for OSG
76 
78  DtOsgIntersector( DtDe& de, int modelSet );
79 
81  virtual ~DtOsgIntersector();
82 
97  virtual bool findNearestIntersectionToPoint(double x, double y, double z,
98  double vx, double vy, double vz,
100  IntersectProperties properties=AllNodes,
101  std::vector<DtElementID>* ignoreList=0,
102  bool returnTriangle=false,
103  double maxIsectorLength=-1., bool useHighLod=false );
104 
112  virtual bool findAllIntersectionsThroughPoint( double x, double y, double z,
113  double vx, double vy, double vz, DtIntersections& intersections,
114  IntersectProperties properties=AllNodes,
115  std::vector<DtElementID>* ignoreList=0, bool sort=true, bool useHighLod=false );
116 
123  virtual bool findFirstIntersectWithLineSegment(
124  double x, double y, double z, double end_x, double end_y, double end_z,
125  DtIntersectorResult& intersection,
126  IntersectProperties properties=AllNodes,
127  std::vector<DtElementID>* ignoreList=0, bool useHighLod=false);
128 
135  virtual bool findAllIntersectWithLineSegment(
136  double x, double y, double z, double end_x, double end_y, double end_z,
137  DtIntersections& intersections,
138  IntersectProperties properties=AllNodes,
139  std::vector<DtElementID>* ignoreList=0, bool sort=true, bool useHighLod=false );
140 
146  virtual bool pick( DtChannel& channel, double mx, double my,
147  DtIntersectorResult& intersection,
148  IntersectProperties properties=AllNodes,
149  std::vector<DtElementID>* ignoreList=0);
150 
155  virtual bool pickAll( DtChannel* channel, double mx, double my,
156  DtIntersections& intersections, IntersectProperties properties=AllNodes,
157  std::vector<DtElementID>* ignoreList=0);
158 
159  public:
160 
161  // OSG-specific Interface
162 
163  typedef std::vector<DtOsgIntersectorResult> DtOsgIntersections;
164 
165 
185  virtual bool findNearestIntersection(double x, double y, double z,
186  double vx, double vy, double vz, DtOsgIntersectorResult& intersection,
187  const DtOsgRenderer::RootList& intersectionRoots,
188  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
189  std::list<osg::Node*>* excludeNodeList=0, bool returnHitTriangle=false,
190  double maxIsectorLength=-1.0, bool useHighLod=false );
191 
205  virtual bool findIntersectionsThroughPoint(double x, double y, double z,
206  double vx, double vy, double vz,
208  const DtOsgRenderer::RootList& intersectionRoots,
209  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
210  std::list<osg::Node*>* excludeNodeList=0, bool returnHitTriangle=false,
211  double maxIsectorLength=-1.0, bool sort=true, bool useHighLod=false );
212 
218  virtual bool intersectLineSegmentWithScene( double x, double y, double z,
219  double end_x, double end_y, double end_z,
220  DtOsgIntersectorResult& intersection,
221  const DtOsgRenderer::RootList& intersectionRoots,
222  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
223  std::list<osg::Node*>* excludeNodeList=0,
224  bool returnHitTriangle=false, 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  DtOsgIntersector::DtOsgIntersections& intersections,
234  const DtOsgRenderer::RootList& intersectionRoots,
235  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
236  std::list<osg::Node*>* excludeNodeList=0,
237  bool returnHitTriangle=false, bool sort=true, bool useHighLod=false );
238 
241  virtual bool pick( osgViewer::View& view, double mx, double my,
242  DtOsgIntersectorResult& intersection,
243  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
244  std::list<osg::Node*>* excludeNodeList=0,
245  bool returnHitTriangle=false );
246 
249  virtual bool pick( osgViewer::View& view, double mx, double my,
251  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
252  std::list<osg::Node*>* excludeNodeList=0,
253  bool returnHitTriangle=false );
254 
255  public:
256 
257  static osg::Node::NodeMask nodeMaskFromIntersectProperties(
258  IntersectProperties properties );
259 
260  static bool anyNodeInNodePath(std::list<osg::Node*>* n,
261  osg::NodePath const& path);
262 
263  protected:
264 
266  virtual float distanceToResult2(double x, double y, double z, DtOsgIntersectorResult& result);
267 
268  virtual bool calcEndpointsFromDirectionAndLength( double x, double y,
269  double z, double vx, double vy, double vz, double length,
270  const DtOsgRenderer::RootList& intersectionRoots, DtVector& startPoint,
271  DtVector& endPoint ) const;
272 
273  void getExcludeNodesFromIgnoreList( std::vector<DtUniqueID>* ignoreList,
274  std::list<osg::Node*>& excludeNodes );
275 
278  osg::Vec3d worldIntersectPoint( const osgUtil::Hit& hit );
279 
280  osg::Vec3d worldIntersectPoint(
281  const osgUtil::LineSegmentIntersector::Intersection& hit );
282 
283  osg::Vec3d localToWorld( const osg::Vec3& local, const osg::Matrix& localToWorld );
284 
285  bool findIdFromNodePath( const osg::NodePath& nodePath, DtUniqueID& id );
286 
289  osg::Camera * getActiveCamera(osgViewer::View& view);
290 
293  void updateInstanceIntersectElementId(DtOsgIntersectorResult &result);
294 
296  bool fillResultFromHit(DtOsgIntersectorResult& result, const osgUtil::Hit& hit,
297  bool returnHitTriangle ) ;
298 
300  bool fillResultFromHit(DtOsgIntersectorResult& result,
301  const osgUtil::LineSegmentIntersector::Intersection& hit,
302  bool returnHitTriangle ) ;
303 
306  osgUtil::IntersectVisitor::HitList& getLineSegmentIntersection(
307  osgUtil::IntersectVisitor& collisionVisitor, double x, double y, double z,
308  double end_x, double end_y, double end_z,
309  const DtOsgRenderer::RootList& intersectionRoots, osg::Node::NodeMask mask);
310 
312  bool processLineSegmentIntersection(
313  osgUtil::IntersectVisitor::HitList& hitList,
314  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
315  DtOsgIntersectorResult& intersection );
316 
318  bool processLineSegmentIntersection( const osg::Vec3d& testPoint,
319  osgUtil::IntersectVisitor::HitList& hitList,
320  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
321  DtOsgIntersectorResult& intersection );
322 
324  bool processLineSegmentIntersection( const osg::Vec3d& testPoint,
325  osgUtil::IntersectVisitor::HitList& hitList,
326  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
327  DtOsgIntersector::DtOsgIntersections& intersections, bool sort );
328 
330  bool processPickIntersection(
331  osgUtil::LineSegmentIntersector::Intersections& hitList,
332  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
333  DtOsgIntersectorResult& intersection );
334 
336  bool processPickIntersection(
337  osgUtil::LineSegmentIntersector::Intersections& hitList,
338  std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle,
339  DtOsgIntersector::DtOsgIntersections& intersections );
340 
343  void setupCollisionVisitor( bool useHighLod, DtOsgIntersectVisitor& visitor );
344 
347  bool shouldInstanceIntersect(osg::Node::NodeMask nodeMask);
348 
349  protected:
351  };
352 
357  {
358  public:
359  DtOsgIntersectorSorter( const osg::Vec3d& reference )
360  : myReference( reference ) {}
361 
362  inline bool operator() ( const DtOsgIntersectorResult& a,
363  const DtOsgIntersectorResult& b )
364  {
365  osg::Vec3d diffA = osg::Vec3d(a.x, a.y, a.z) - myReference;
366  osg::Vec3d diffB = osg::Vec3d(b.x, b.y, b.z) - myReference;
367  return diffA.length2() > diffB.length2();
368  }
369  protected:
370  osg::Vec3d myReference;
371  };
372 
376  {
377  public:
379  virtual DtIntersector* create(DtDe& de, int modelSet );
380  };
381 }

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)