VR-Forces 5.0.1 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgIntersector.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2022 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
15 #include <vrvOsg/DtOsgRenderer.h>
16 
17 #include <vrvCore/DtIntersector.h>
19 
20 #include <osgUtil/LineSegmentIntersector>
21 #include <osgUtil/IntersectVisitor>
22 
23 #include <osg/Node>
24 
25 #include <matrix/vlVector.h>
26 
27 #include <vector>
28 
29 namespace osgUtil
30 {
31  class Hit;
32 }
33 
34 namespace osgViewer
35 {
36  class View;
37 }
38 
39 namespace makVrv
40 {
41  class DtOsgRenderer;
42  class DtOsgIntersectionVisitor;
43  class DtIntersectorManager;
44 
55  {
56  public:
57  std::list<DtUniqueID> myExcludeIds;
58  std::list<osg::Node*> myExcludeNodes;
59  };
60 
61 
62 
68  {
69  public:
70 
71  // Abstract DtIntersector Implementation for OSG
72 
74  DtOsgIntersector( DtDe& de, int modelSet );
75 
77  virtual ~DtOsgIntersector();
78 
80  DtOsgIntersector() = delete;
82  DtOsgIntersector( const DtOsgIntersector& rhs ) = delete;
84  DtOsgIntersector& operator=( const DtOsgIntersector& rhs ) = delete;
85 
100  virtual bool findNearestIntersectionToPoint(double x, double y, double z,
101  double vx, double vy, double vz,
103  IntersectProperties properties=AllNodes,
104  std::vector<DtElementID>* ignoreList=0,
105  bool returnTriangle=false,
106  double maxIsectorLength=-1., bool useHighLod=false ) override;
107 
115  virtual bool findAllIntersectionsThroughPoint( double x, double y, double z,
116  double vx, double vy, double vz, DtIntersections& intersections,
117  IntersectProperties properties=AllNodes,
118  std::vector<DtElementID>* ignoreList=0, bool sort=true, bool useHighLod=false ) override;
119 
126  virtual bool findFirstIntersectWithLineSegment(
127  double x, double y, double z, double end_x, double end_y, double end_z,
128  DtIntersectorResult& intersection,
129  IntersectProperties properties=AllNodes,
130  std::vector<DtElementID>* ignoreList=0, bool useHighLod=false) override;
131 
138  virtual bool findAllIntersectWithLineSegment(
139  double x, double y, double z, double end_x, double end_y, double end_z,
140  DtIntersections& intersections,
141  IntersectProperties properties=AllNodes,
142  std::vector<DtElementID>* ignoreList=0, bool sort=true, bool useHighLod=false ) override;
143 
149  virtual bool pick( DtChannel& channel, double mx, double my,
150  DtIntersectorResult& intersection,
151  IntersectProperties properties=AllNodes,
152  std::vector<DtElementID>* ignoreList=0) override;
153 
158  virtual bool pickAll( DtChannel* channel, double mx, double my,
159  DtIntersections& intersections, IntersectProperties properties=AllNodes,
160  std::vector<DtElementID>* ignoreList=0) override;
161 
162  public:
163 
164  // OSG-specific Interface
165 
179 
180 
181  typedef std::vector<DtOsgIntersectorResult> DtOsgIntersections;
182 
183 
203 
204  virtual bool findNearestIntersection(double x, double y, double z,
205  double vx, double vy, double vz, DtOsgIntersectorResult& intersection,
206  const DtSceneRootList& intersectionRoots,
207  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
208  DtOsgItersectorExclusions* excludeNodeList=0, bool returnHitTriangle=false,
209  double maxIsectorLength=-1.0, bool useHighLod=false );
210 
224  virtual bool findIntersectionsThroughPoint(double x, double y, double z,
225  double vx, double vy, double vz,
227  const DtSceneRootList& intersectionRoots,
228  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
229  DtOsgItersectorExclusions* exclusions=0, bool returnHitTriangle=false,
230  double maxIsectorLength=-1.0, bool sort=true, bool useHighLod=false );
231 
237  virtual bool intersectLineSegmentWithScene( double x, double y, double z,
238  double end_x, double end_y, double end_z,
239  DtOsgIntersectorResult& intersection,
240  const DtSceneRootList& intersectionRoots,
241  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
242  DtOsgItersectorExclusions* excludeNodeList=0,
243  bool returnHitTriangle=false, bool useHighLod=false );
244 
250  virtual bool intersectLineSegmentWithScene( double x, double y, double z,
251  double end_x, double end_y, double end_z,
252  DtOsgIntersector::DtOsgIntersections& intersections,
253  const DtSceneRootList& intersectionRoots,
254  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
255  DtOsgItersectorExclusions* excludeNodeList=0,
256  bool returnHitTriangle=false, bool sort=true, bool useHighLod=false );
257 
260  virtual bool pick(const osgViewer::View& view, double mx, double my,
261  DtOsgIntersectorResult& intersection,
262  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
263  DtOsgItersectorExclusions* excludeNodeList=0,
264  bool returnHitTriangle=false );
265 
268  virtual bool pick(const osgViewer::View& view, double mx, double my,
270  osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn,
271  DtOsgItersectorExclusions* excludeNodeList=0,
272  bool returnHitTriangle=false );
273 
274  public:
275 
276  static osg::Node::NodeMask nodeMaskFromIntersectProperties(
277  IntersectProperties properties );
278 
279  static bool anyNodeInNodePath(std::list<osg::Node*>* n,
280  osg::NodePath const& path);
281 
282  protected:
283 
285  virtual float distanceToResult2(double x, double y, double z, DtOsgIntersectorResult& result);
286 
287  virtual bool calcEndpointsFromDirectionAndLength( double x, double y,
288  double z, double vx, double vy, double vz, double length,
289  const DtSceneRootList& intersectionRoots, DtVector& startPoint,
290  DtVector& endPoint ) const;
291 
292  virtual void calculateStartEnd(DtVector& start, DtVector& end
293  , const osgViewer::View& view, double mx, double my) const;
294 
295  virtual void calculateStartEnd(DtVector& start, DtVector& end
296  , const osg::Camera* osgCamera, double mx, double my) const;
297 
300  virtual const osg::Camera * getActiveCamera(const osgViewer::View& view) const;
301 
302  void getExcludeNodesFromIgnoreList( std::vector<DtUniqueID>* ignoreList,
303  DtOsgItersectorExclusions& exclusions );
304 
307  osg::Vec3d worldIntersectPoint( const osgUtil::Hit& hit );
308 
309  osg::Vec3d worldIntersectPoint(
310  const osgUtil::LineSegmentIntersector::Intersection& hit );
311 
312  osg::Vec3d localToWorld( const osg::Vec3& local, const osg::Matrix& localToWorld );
313 
314  bool findIdFromNodePath( const osg::NodePath& nodePath, DtUniqueID& id );
315 
318  void updateInstanceIntersectElementId(DtOsgIntersectorResult &result);
319 
321  bool fillResultFromHit(DtOsgIntersectorResult& result,
322  const osgUtil::LineSegmentIntersector::Intersection& hit,
323  bool returnHitTriangle ) ;
324 
327  void doLineSegmentIntersections(
328  osgUtil::IntersectionVisitor& collisionVisitor,
329  const DtSceneRootList& intersectionRoots, osg::Node::NodeMask mask);
330 
332  bool processLineSegmentIntersection(
333  osgUtil::LineSegmentIntersector::Intersections& hitList,
334  DtOsgItersectorExclusions* excludeNodeList, bool returnHitTriangle,
335  DtOsgIntersectorResult& intersection );
336 
338  bool processLineSegmentIntersection( const osg::Vec3d& testPoint,
339  osgUtil::LineSegmentIntersector::Intersections& hitList,
340  DtOsgItersectorExclusions* excludeNodeList, bool returnHitTriangle,
341  DtOsgIntersectorResult& intersection );
342 
344  bool processLineSegmentIntersection( const osg::Vec3d& testPoint,
345  osgUtil::LineSegmentIntersector::Intersections& hitList,
346  DtOsgItersectorExclusions* excludeNodeList, bool returnHitTriangle,
347  DtOsgIntersector::DtOsgIntersections& intersections, bool sort );
348 
350  bool processPickIntersection(
351  osgUtil::LineSegmentIntersector::Intersections& hitList,
352  DtOsgItersectorExclusions* excludeNodeList, bool returnHitTriangle,
353  DtOsgIntersectorResult& intersection );
354 
356  bool processPickIntersection(
357  osgUtil::LineSegmentIntersector::Intersections& hitList,
358  DtOsgItersectorExclusions* excludeNodeList, bool returnHitTriangle,
359  DtOsgIntersector::DtOsgIntersections& intersections );
360 
363  void setupCollisionVisitor( bool useHighLod, DtOsgIntersectionVisitor& visitor );
364 
367  bool shouldInstanceIntersect(osg::Node::NodeMask nodeMask);
368  };
369 
374  {
375  public:
376  DtOsgIntersectorSorter( const osg::Vec3d& reference )
377  : myReference( reference ) {}
378 
379  inline bool operator() ( const DtOsgIntersectorResult& a,
380  const DtOsgIntersectorResult& b )
381  {
382  osg::Vec3d diffA = osg::Vec3d(a.x, a.y, a.z) - myReference;
383  osg::Vec3d diffB = osg::Vec3d(b.x, b.y, b.z) - myReference;
384  return diffA.length2() < diffB.length2();
385  }
386  protected:
387  osg::Vec3d myReference;
388  };
389 
393  {
394  public:
396  virtual DtIntersector* create(DtDe& de, int modelSet );
397  };
398 }
IntersectProperties
The IntersectProperties enum is a flag set that indicates the types of nodes to be considered for int...
Definition: DtIntersector.h:31
DtOsgIntersectorSorter(const osg::Vec3d &reference)
Definition: DtOsgIntersector.h:376
std::vector< DtSceneRoot > DtSceneRootList
A list of DtOsgRenderer::SceneRoots.
Definition: DtSceneRoot.h:133
DtOsgIntersectVisitor checks to see if it is visiting a a DtTerrainPatchGroup and if so...
Definition: DtOsgIntersectionVisitor.h:24
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
bool operator()(const DtOsgIntersectorResult &a, const DtOsgIntersectorResult &b)
Definition: DtOsgIntersector.h:379
DtIntersector is an abstract class that provides the interface for requesting intersections with the ...
Definition: DtIntersector.h:25
Contains makVrv:DtOsgNodeTraversalFlags class.
DtOsgIntersector is the OSG-specific implementation of the DtIntersector class. It provides a variety...
Definition: DtOsgIntersector.h:67
DtOsgIntersectorResult is the OSG-specific implementation of DtIntersectorResult; it is a container c...
Definition: DtOsgIntersectorResult.h:25
osg::Vec3d myReference
Definition: DtOsgIntersector.h:387
Descriptor for a single intersection result.
Definition: DtIntersectorResult.h:21
std::vector< DtOsgIntersectorResult > DtOsgIntersections
Note that even with intersection debug drawing enabled, these OSG-specific functions do not result in...
Definition: DtOsgIntersector.h:181
std::vector< DtIntersectorResult > DtIntersections
A vector of DtIntersectionRecords.
Definition: DtIntersector.h:50
Contains makVrv::DtIntersectorCreator class.
double y
y coordinate, in database coordinates of the intersection
Definition: DtIntersectorResult.h:57
static const unsigned int FlagAllOn
Nodemask bitflag definitions.
Definition: DtOsgNodeTraversalFlags.h:19
The abstract Channel Class.
Definition: DtChannel.h:35
Contains makVrv:DtIntersector class.
double z
z coordinate, in database coordinates of the intersection
Definition: DtIntersectorResult.h:60
DtOsgItersectorExclusions is a list of osg nodes from the scene graph and a list of element IDs to ex...
Definition: DtOsgIntersector.h:54
std::list< DtUniqueID > myExcludeIds
Definition: DtOsgIntersector.h:57
DT_DLL_vrfutil bool intersection(const DtRailSegment *currentSegment, const DtRailSegment *nextSegment)
Given two segments, determine if where they meet is an intersection or just a bend in the road...
Abstract creator base class.
Definition: DtOsgIntersector.h:392
double x
x coordinate, in database coordinates of the intersection
Definition: DtIntersectorResult.h:54
Contains DLL export macros.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:70
Abstract creator base class.
Definition: DtIntersectorCreator.h:23
Contains makVrv::DtOsgRenderer class.
std::list< osg::Node * > myExcludeNodes
Definition: DtOsgIntersector.h:58
DtOsgIntersectorSorter provides an operator for comparing the the distances between 2 osg::vectors an...
Definition: DtOsgIntersector.h:373

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)