ElevationSlice 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGSIM_ELEVATIONSLICE
  14. #define OSGSIM_ELEVATIONSLICE 1
  15. #include <osgUtil/IntersectionVisitor>
  16. // include so we can get access to the DatabaseCacheReadCallback
  17. #include <osgSim/LineOfSight>
  18. namespace osgSim {
  19. /** Helper class for setting up and acquiring height above terrain intersections with terrain.
  20. * By default assigns a osgSim::DatabaseCacheReadCallback that enables automatic loading
  21. * of external PagedLOD tiles to ensure that the highest level of detail is used in intersections.
  22. * This automatic loading of tiles is done by the intersection traversal that is done within
  23. * the computeIntersections(..) method, so can result in long intersection times when external
  24. * tiles have to be loaded.
  25. * The external loading of tiles can be disabled by removing the read callback, this is done by
  26. * calling the setDatabaseCacheReadCallback(DatabaseCacheReadCallback*) method with a value of 0.*/
  27. class OSGSIM_EXPORT ElevationSlice
  28. {
  29. public :
  30. ElevationSlice();
  31. /** Set the start point of the slice.*/
  32. void setStartPoint(const osg::Vec3d& startPoint) { _startPoint = startPoint; }
  33. /** Get the start point of the slice.*/
  34. const osg::Vec3d& getStartPoint() const { return _startPoint; }
  35. /** Set the end point of the slice.*/
  36. void setEndPoint(const osg::Vec3d& endPoint) { _endPoint = endPoint; }
  37. /** Get the end point of the slice.*/
  38. const osg::Vec3d& getEndPoint() const { return _endPoint; }
  39. typedef std::vector<osg::Vec3d> Vec3dList;
  40. /** Get the intersections in the form of a vector of Vec3d. */
  41. const Vec3dList& getIntersections() const { return _intersections; }
  42. typedef std::pair<double,double> DistanceHeight;
  43. typedef std::vector<DistanceHeight> DistanceHeightList;
  44. /** Get the intersections in the form a vector of pair<double,double> representing distance along the slice and height. */
  45. const DistanceHeightList& getDistanceHeightIntersections() const { return _distanceHeightIntersections; }
  46. /** Compute the intersections with the specified scene graph, the results are stored in vectors of Vec3d.
  47. * Note, if the topmost node is a CoordinateSystemNode then the input points are assumed to be geocentric,
  48. * with the up vector defined by the EllipsoidModel attached to the CoordinateSystemNode.
  49. * If the topmost node is not a CoordinateSystemNode then a local coordinates frame is assumed, with a local up vector. */
  50. void computeIntersections(osg::Node* scene, osg::Node::NodeMask traversalMask=0xffffffff);
  51. /** Compute the vertical distance between the specified scene graph and a single HAT point.*/
  52. static Vec3dList computeElevationSlice(osg::Node* scene, const osg::Vec3d& startPoint, const osg::Vec3d& endPoint, osg::Node::NodeMask traversalMask=0xffffffff);
  53. /** Clear the database cache.*/
  54. void clearDatabaseCache() { if (_dcrc.valid()) _dcrc->clearDatabaseCache(); }
  55. /** Set the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.
  56. * Note, if you have multiple LineOfSight or ElevationSlice objects in use at one time then you should share a single
  57. * DatabaseCacheReadCallback between all of them. */
  58. void setDatabaseCacheReadCallback(DatabaseCacheReadCallback* dcrc);
  59. /** Get the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.*/
  60. DatabaseCacheReadCallback* getDatabaseCacheReadCallback() { return _dcrc.get(); }
  61. protected :
  62. osg::Vec3d _startPoint;
  63. osg::Vec3d _endPoint;
  64. Vec3dList _intersections;
  65. DistanceHeightList _distanceHeightIntersections;
  66. osg::ref_ptr<DatabaseCacheReadCallback> _dcrc;
  67. osgUtil::IntersectionVisitor _intersectionVisitor;
  68. };
  69. }
  70. #endif