1 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer |
---|
2 | * |
---|
3 | * This library is based on OpenSceneGraph, 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 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
9 | * You have to aquire licenses for all used proprietary modules. |
---|
10 | * |
---|
11 | * This library is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * OpenSceneGraph Public License for more details. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef OSGSIM_HEIGHTABOVETERRAIN |
---|
18 | #define OSGSIM_HEIGHTABOVETERRAIN 1 |
---|
19 | |
---|
20 | #include <osgUtil/IntersectionVisitor> |
---|
21 | |
---|
22 | // include so we can get access to the DatabaseCacheReadCallback |
---|
23 | #include <osgSim/LineOfSight> |
---|
24 | |
---|
25 | namespace osgSim { |
---|
26 | |
---|
27 | /** Helper class for setting up and acquiring height above terrain intersections with terrain. |
---|
28 | * By default assigns a osgSim::DatabaseCacheReadCallback that enables automatic loading |
---|
29 | * of external PagedLOD tiles to ensure that the highest level of detail is used in intersections. |
---|
30 | * This automatic loading of tiles is done by the intersection traversal that is done within |
---|
31 | * the computeIntersections(..) method, so can result in long intersection times when external |
---|
32 | * tiles have to be loaded. |
---|
33 | * The external loading of tiles can be disabled by removing the read callback, this is done by |
---|
34 | * calling the setDatabaseCacheReadCallback(DatabaseCacheReadCallback*) method with a value of 0.*/ |
---|
35 | class OSGSIM_EXPORT HeightAboveTerrain |
---|
36 | { |
---|
37 | public : |
---|
38 | |
---|
39 | |
---|
40 | HeightAboveTerrain(bool loadHighestLOD = true); |
---|
41 | |
---|
42 | |
---|
43 | /** Clear the internal HAT List so it contains no height above terrain tests.*/ |
---|
44 | void clear(); |
---|
45 | |
---|
46 | /** Add a height above terrain test point in the CoordinateFrame.*/ |
---|
47 | unsigned int addPoint(const osg::Vec3d& point); |
---|
48 | |
---|
49 | /** Get the number of height above terrain tests.*/ |
---|
50 | unsigned int getNumPoints() const { return _HATList.size(); } |
---|
51 | |
---|
52 | /** Set the source point of single height above terrain test.*/ |
---|
53 | void setPoint(unsigned int i, const osg::Vec3d& point) { _HATList[i]._point = point; } |
---|
54 | |
---|
55 | /** Get the source point of single height above terrain test.*/ |
---|
56 | const osg::Vec3d& getPoint(unsigned int i) const { return _HATList[i]._point; } |
---|
57 | |
---|
58 | /** Get the intersection height for a single height above terrain test. |
---|
59 | * Note, you must call computeIntersections(..) before you can query the HeightAboveTerrain. |
---|
60 | * If no intersections are found then height returned will be the height above mean sea level. */ |
---|
61 | double getHeightAboveTerrain(unsigned int i) const { return _HATList[i]._hat; } |
---|
62 | |
---|
63 | /** Get the intersection height for a single height of terrain test. |
---|
64 | * Note, you must call computeIntersections(..) before you can query the HeightOfTerrain. |
---|
65 | * If no intersections are found then height returned will be the height of mean sea level. */ |
---|
66 | double getHeightOfTerrain(unsigned int i) const { return _HATList[i]._hot; } |
---|
67 | |
---|
68 | /** Set the lowest height that the should be tested for. |
---|
69 | * Defaults to -1000, i.e. 1000m below mean sea level. */ |
---|
70 | void setLowestHeight(double lowestHeight) { _lowestHeight = lowestHeight; } |
---|
71 | |
---|
72 | /** Get the lowest height that the should be tested for.*/ |
---|
73 | double getLowestHeight() const { return _lowestHeight; } |
---|
74 | |
---|
75 | /** Compute the HAT intersections with the specified scene graph. |
---|
76 | * The results are all stored in the form of a single height above terrain value per HAT test. |
---|
77 | * Note, if the topmost node is a CoordinateSystemNode then the input points are assumed to be geocentric, |
---|
78 | * with the up vector defined by the EllipsoidModel attached to the CoordinateSystemNode. |
---|
79 | * If the topmost node is not a CoordinateSystemNode then a local coordinates frame is assumed, with a local up vector. */ |
---|
80 | void computeIntersections(osg::Node* scene, osg::Node::NodeMask traversalMask=0xffffffff); |
---|
81 | |
---|
82 | /** Compute the vertical distance between the specified scene graph and a single HAT point. */ |
---|
83 | static double computeHeightAboveTerrain(osg::Node* scene, const osg::Vec3d& point, bool loadHighestLOD = true, osg::Node::NodeMask traversalMask=0xffffffff); |
---|
84 | |
---|
85 | /** Compute the vertical position of the scene at a single HOT point. */ |
---|
86 | static double computeHeightOfTerrain(osg::Node* scene, const osg::Vec3d& point, bool loadHighestLOD = true, osg::Node::NodeMask traversalMask=0xffffffff); |
---|
87 | |
---|
88 | |
---|
89 | /** Clear the database cache.*/ |
---|
90 | void clearDatabaseCache() { if (_dcrc.valid()) _dcrc->clearDatabaseCache(); } |
---|
91 | |
---|
92 | /** Set the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs. |
---|
93 | * Note, if you have multiple LineOfSight or HeightAboveTerrain objects in use at one time then you should share a single |
---|
94 | * DatabaseCacheReadCallback between all of them. */ |
---|
95 | void setDatabaseCacheReadCallback(DatabaseCacheReadCallback* dcrc); |
---|
96 | |
---|
97 | /** Get the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.*/ |
---|
98 | DatabaseCacheReadCallback* getDatabaseCacheReadCallback() { return _dcrc.get(); } |
---|
99 | |
---|
100 | protected : |
---|
101 | |
---|
102 | struct HAT |
---|
103 | { |
---|
104 | HAT(const osg::Vec3d& point): |
---|
105 | _point(point), |
---|
106 | _hat(0.0), |
---|
107 | _hot(0.0) {} |
---|
108 | |
---|
109 | osg::Vec3d _point; |
---|
110 | double _hat; |
---|
111 | double _hot; |
---|
112 | }; |
---|
113 | |
---|
114 | typedef std::vector<HAT> HATList; |
---|
115 | |
---|
116 | |
---|
117 | double _lowestHeight; |
---|
118 | HATList _HATList; |
---|
119 | |
---|
120 | |
---|
121 | osg::ref_ptr<DatabaseCacheReadCallback> _dcrc; |
---|
122 | osgUtil::IntersectionVisitor _intersectionVisitor; |
---|
123 | |
---|
124 | |
---|
125 | }; |
---|
126 | |
---|
127 | } |
---|
128 | |
---|
129 | #endif |
---|