1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSGSIM_HEIGHTABOVETERRAIN
15#define OSGSIM_HEIGHTABOVETERRAIN 1
17#include <osgUtil/IntersectionVisitor>
19// include so we can get access to the DatabaseCacheReadCallback
20#include <osgSim/LineOfSight>
24/** Helper class for setting up and acquiring height above terrain intersections with terrain.
25 * By default assigns a osgSim::DatabaseCacheReadCallback that enables automatic loading
26 * of external PagedLOD tiles to ensure that the highest level of detail is used in intersections.
27 * This automatic loading of tiles is done by the intersection traversal that is done within
28 * the computeIntersections(..) method, so can result in long intersection times when external
29 * tiles have to be loaded.
30 * The external loading of tiles can be disabled by removing the read callback, this is done by
31 * calling the setDatabaseCacheReadCallback(DatabaseCacheReadCallback*) method with a value of 0.*/
32class OSGSIM_EXPORT HeightAboveTerrain
40 /** Clear the internal HAT List so it contains no height above terrain tests.*/
43 /** Add a height above terrain test point in the CoordinateFrame.*/
44 unsigned int addPoint(const osg::Vec3d& point);
46 /** Get the number of height above terrain tests.*/
47 unsigned int getNumPoints() const { return _HATList.size(); }
49 /** Set the source point of single height above terrain test.*/
50 void setPoint(unsigned int i, const osg::Vec3d& point) { _HATList[i]._point = point; }
52 /** Get the source point of single height above terrain test.*/
53 const osg::Vec3d& getPoint(unsigned int i) const { return _HATList[i]._point; }
55 /** Get the intersection height for a single height above terrain test.
56 * Note, you must call computeIntersections(..) before you can query the HeightAboveTerrain.
57 * If no intersections are found then height returned will be the height above mean sea level. */
58 double getHeightAboveTerrain(unsigned int i) const { return _HATList[i]._hat; }
60 /** Set the lowest height that the should be tested for.
61 * Defaults to -1000, i.e. 1000m below mean sea level. */
62 void setLowestHeight(double lowestHeight) { _lowestHeight = lowestHeight; }
64 /** Get the lowest height that the should be tested for.*/
65 double getLowestHeight() const { return _lowestHeight; }
67 /** Compute the HAT intersections with the specified scene graph.
68 * The results are all stored in the form of a single height above terrain value per HAT test.
69 * Note, if the topmost node is a CoordinateSystemNode then the input points are assumed to be geocentric,
70 * with the up vector defined by the EllipsoidModel attached to the CoordinateSystemNode.
71 * If the topmost node is not a CoordinateSystemNode then a local coordinates frame is assumed, with a local up vector. */
72 void computeIntersections(osg::Node* scene, osg::Node::NodeMask traversalMask=0xffffffff);
74 /** Compute the vertical distance between the specified scene graph and a single HAT point. */
75 static double computeHeightAboveTerrain(osg::Node* scene, const osg::Vec3d& point, osg::Node::NodeMask traversalMask=0xffffffff);
78 /** Clear the database cache.*/
79 void clearDatabaseCache() { if (_dcrc.valid()) _dcrc->clearDatabaseCache(); }
81 /** Set the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.
82 * Note, if you have multiple LineOfSight or HeightAboveTerrain objects in use at one time then you should share a single
83 * DatabaseCacheReadCallback between all of them. */
84 void setDatabaseCacheReadCallback(DatabaseCacheReadCallback* dcrc);
86 /** Get the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.*/
87 DatabaseCacheReadCallback* getDatabaseCacheReadCallback() { return _dcrc.get(); }
93 HAT(const osg::Vec3d& point):
101 typedef std::vector<HAT> HATList;
104 double _lowestHeight;
108 osg::ref_ptr<DatabaseCacheReadCallback> _dcrc;
109 osgUtil::IntersectionVisitor _intersectionVisitor;