VR-Forces 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) 2023 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 
54  {
55  public:
56  std::list<DtUniqueID> myExcludeIds;
57  std::list<osg::Node*> myExcludeNodes;
58  };
59 
60 
61 
67  {
68  public:
69 
70  // Abstract DtIntersector Implementation for OSG
71 
73  DtOsgIntersector( DtDe& de, DtModelSetId modelSet );
74 
76  virtual ~DtOsgIntersector();
77 
79  DtOsgIntersector() = delete;
81  DtOsgIntersector( const DtOsgIntersector& rhs ) = delete;
83  DtOsgIntersector& operator=( const DtOsgIntersector& rhs ) = delete;
84 
85  public:
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 ) const 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 ) const 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) const 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 ) const 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 ) const;
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 ) const;
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 ) const;
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 ) const;
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) const;
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 ) const;
304 
307  osg::Vec3d worldIntersectPoint( const osgUtil::Hit& hit ) const;
308 
309  osg::Vec3d worldIntersectPoint(
310  const osgUtil::LineSegmentIntersector::Intersection& hit ) const;
311 
312  osg::Vec3d localToWorld( const osg::Vec3& local, const osg::Matrix& localToWorld ) const;
313 
314  bool findIdFromNodePath( const osg::NodePath& nodePath, DtUniqueID& id ) const;
315 
318  void updateInstanceIntersectElementId(DtOsgIntersectorResult &result) const;
319 
321  bool fillResultFromHit(DtOsgIntersectorResult& result,
322  const osgUtil::LineSegmentIntersector::Intersection& hit,
323  bool returnHitTriangle ) const;
324 
327  void doLineSegmentIntersections(
328  osgUtil::IntersectionVisitor& collisionVisitor,
329  const DtSceneRootList& intersectionRoots, osg::Node::NodeMask mask) const;
330 
332  bool processLineSegmentIntersection(
333  osgUtil::LineSegmentIntersector::Intersections& hitList,
334  DtOsgItersectorExclusions* excludeNodeList, bool returnHitTriangle,
335  DtOsgIntersectorResult& intersection ) const;
336 
338  bool processLineSegmentIntersection( const osg::Vec3d& testPoint,
339  osgUtil::LineSegmentIntersector::Intersections& hitList,
340  DtOsgItersectorExclusions* excludeNodeList, bool returnHitTriangle,
341  DtOsgIntersectorResult& intersection ) const;
342 
344  bool processLineSegmentIntersection( const osg::Vec3d& testPoint,
345  osgUtil::LineSegmentIntersector::Intersections& hitList,
346  DtOsgItersectorExclusions* excludeNodeList, bool returnHitTriangle,
347  DtOsgIntersector::DtOsgIntersections& intersections, bool sort ) const;
348 
350  bool processPickIntersection(
351  osgUtil::LineSegmentIntersector::Intersections& hitList,
352  DtOsgItersectorExclusions* excludeNodeList, bool returnHitTriangle,
353  DtOsgIntersectorResult& intersection ) const;
354 
356  bool processPickIntersection(
357  osgUtil::LineSegmentIntersector::Intersections& hitList,
358  DtOsgItersectorExclusions* excludeNodeList, bool returnHitTriangle,
359  DtOsgIntersector::DtOsgIntersections& intersections ) const;
360 
363  void setupCollisionVisitor( bool useHighLod, DtOsgIntersectionVisitor& visitor ) const;
364 
367  bool shouldInstanceIntersect(osg::Node::NodeMask nodeMask) const;
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 ) const
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, DtModelSetId 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:135
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
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:66
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
bool operator()(const DtOsgIntersectorResult &a, const DtOsgIntersectorResult &b) const
Definition: DtOsgIntersector.h:379
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:53
unsigned long long DtUniqueID
Definition: DtUniqueID.h:19
std::list< DtUniqueID > myExcludeIds
Definition: DtOsgIntersector.h:56
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...
DT_DLL_VRVCORE double length(const makVrv::DtCoordinateSystem &, const std::vector< DtVector > &vertices)
Returns the total distance of a segmented line defined by the provided vector of vertices. Coordinates are in local database coordinates. The coordinate system is used to convert between the local database coordinates and geocentric. All distance is in 2D – the Z value is ignored.
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:72
Abstract creator base class.
Definition: DtIntersectorCreator.h:24
DtModelSetId
Definition: DtModelSetEnums.h:19
Contains makVrv::DtOsgRenderer class.
std::list< osg::Node * > myExcludeNodes
Definition: DtOsgIntersector.h:57
DtOsgIntersectorSorter provides an operator for comparing the the distances between 2 osg::vectors an...
Definition: DtOsgIntersector.h:373

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)