Implemented HeightAboveTerrain and added usage into osgintersection

This commit is contained in:
Robert Osfield
2006-10-31 12:59:51 +00:00
parent e9b501002c
commit a253e17d3e
5 changed files with 215 additions and 14 deletions

View File

@@ -16,7 +16,8 @@
#include <osgUtil/IntersectionVisitor>
#include <osgSim/Export>
// include so we can get access to the DatabaseCacheReadCallback
#include <osgSim/LineOfSight>
namespace osgSim {
@@ -25,7 +26,85 @@ class OSGSIM_EXPORT HeightAboveTerrain
{
public :
HeightAboveTerrain();
/** Clear the internal HAT List so it contains no height above terrain tests.*/
void clear();
/** Add a height above terrain test point in the CoordinateFrame.*/
unsigned int addPoint(const osg::Vec3d& point);
/** Get the number of height above terrain tests.*/
unsigned int getNumPoints() const { return _HATList.size(); }
/** Set the source point of single height above terrain test.*/
void setPoint(unsigned int i, const osg::Vec3d& point) { _HATList[i]._point = point; }
/** Get the source point of single height above terrain test.*/
const osg::Vec3d& getPoint(unsigned int i) const { return _HATList[i]._point; }
/** Get the intersection height for a single height above terrain test.
* Note, you must call computeIntersections(..) before you can querry the HeightAboveTerrain.
* If no intersections are found then height returned will be the height above mean sea level. */
double getHeightAboveTerrain(unsigned int i) const { return _HATList[i]._hat; }
/** Set the lowest height that the should be tested for.
* Defaults to -1000, i.e. 1000m below mean sea level. */
void setLowestHeight(double lowestHeight) { _lowestHeight = lowestHeight; }
/** Get the lowest height that the should be tested for.*/
double getLowestHeight() const { return _lowestHeight; }
/** Compute the HAT intersections with the specified scene graph.
* The results are all stored in the form of a single height above terrain value per HAT test.
* Note, if the topmost node is a CoordinateSystemNode then the input points are assumed to be geocentric,
* with the up vector defined by the EllipsoidModel attached to the CoordinateSystemNode.
* If the topmost node is not a CoordinateSystemNode then a local coordinates frame is assumed, with a local up vector. */
void computeIntersections(osg::Node* scene);
/** Compute the vertical distance between the specified scene graph and a single HAT point. .*/
static double computeHeightAboveTerrain(osg::Node* scene, const osg::Vec3d& point);
/** Clear the database cache.*/
void clearDatabaseCache() { if (_dcrc.valid()) _dcrc->clearDatabaseCache(); }
/** Set the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.
* Note, if you have mulitple LineOfSight or HeightAboveTerrain objects in use at one time then you should share a single
* DatabaseCacheReadCallback between all of them. */
void setDatabaseCacheReadCallback(DatabaseCacheReadCallback* dcrc);
/** Get the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.*/
DatabaseCacheReadCallback* getDatabaseCacheReadCallback() { return _dcrc.get(); }
/** Get the IntersectionVistor that does the intersection traversal over the scene.
* Note, if you want to customized the traversal then you can use the IntersectionVisitor's method to alter its behavior. */
osgUtil::IntersectionVisitor& getIntersectionVisitor() { return _intersectionVisitor; }
protected :
struct HAT
{
HAT(const osg::Vec3d& point):
_point(point),
_hat(0.0) {}
osg::Vec3d _point;
double _hat;
};
typedef std::vector<HAT> HATList;
double _lowestHeight;
HATList _HATList;
osg::ref_ptr<DatabaseCacheReadCallback> _dcrc;
osgUtil::IntersectionVisitor _intersectionVisitor;
};

View File

@@ -52,7 +52,7 @@ class OSGSIM_EXPORT LineOfSight
LineOfSight();
/** Clear the internal LOS List so it contains no line of sight tests.*/
void clearLOS();
void clear();
/** Add a line of sight test, consisting of start and end point. Returns the index number of the newly adding LOS test.*/
unsigned int addLOS(const osg::Vec3d& start, const osg::Vec3d& end);
@@ -78,7 +78,7 @@ class OSGSIM_EXPORT LineOfSight
const Intersections& getIntersections(unsigned int i) const { return _LOSList[i]._intersections; }
/** Compute the LOS intersections with the specified scene graph.
* The results are all stored in the form of IntersectionList, one per LOS test.*/
* The results are all stored in the form of Intersections list, one per LOS test.*/
void computeIntersections(osg::Node* scene);
/** Compute the intersection between the specified scene graph and a single LOS start,end pair. Returns an IntersectionList, of all the points intersected.*/