source: osgVisual/trunk/include/util/terrainQuery.h @ 305

Last change on this file since 305 was 305, checked in by Torben Dannhauer, 13 years ago
File size: 6.2 KB
Line 
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 osgVisual_HEIGHTABOVETERRAIN
18#define osgVisual_HEIGHTABOVETERRAIN 1
19
20#include <osgUtil/IntersectionVisitor>
21
22// include so we can get access to the DatabaseCacheReadCallback
23#include <osgSim/LineOfSight>
24
25namespace osgVisual {
26
27/** Helper class for setting up and acquiring height above terrain intersections with terrain.
28  * By default assigns a osgVisual::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.*/
35class terrainQuery
36{
37    public :
38
39                enum DataSource
40                {
41                        LOADED_SCENE,
42                        PAGE_HIGHEST_LOD
43                       
44                };
45   
46        terrainQuery();
47       
48   
49        /** Clear the internal HAT List so it contains no height above terrain tests.*/
50        void clear();
51       
52        /** Add a height above terrain test point in the CoordinateFrame.*/
53        unsigned int addPoint(const osg::Vec3d& point);
54
55        /** Get the number of height above terrain tests.*/
56        unsigned int getNumPoints() const { return _HATList.size(); }
57       
58        /** Set the source point of single height above terrain test.*/
59        void setPoint(unsigned int i, const osg::Vec3d& point) { _HATList[i]._point = point; }
60
61        /** Get the source point of single height above terrain test.*/
62        const osg::Vec3d& getPoint(unsigned int i) const { return _HATList[i]._point; }
63
64        /** Get the intersection height for a single height above terrain test.
65          * Note, you must call computeIntersections(..) before you can query the HeightAboveTerrain.
66          * If no intersections are found then height returned will be the height above mean sea level. */
67        double getHeightAboveTerrain(unsigned int i) const  { return _HATList[i]._hat; }
68
69                /** Get the intersection height for a single height of terrain test.
70          * Note, you must call computeIntersections(..) before you can query the HeightOfTerrain.
71          * If no intersections are found then height returned will be the height of mean sea level. */
72        double getHeightOfTerrain(unsigned int i) const  { return _HATList[i]._hot; }
73
74        /** Set the lowest height that the should be tested for.
75          * Defaults to -1000, i.e. 1000m below mean sea level. */
76        void setLowestHeight(double lowestHeight) { _lowestHeight = lowestHeight; }
77
78        /** Get the lowest height that the should be tested for.*/
79        double getLowestHeight() const { return _lowestHeight; }
80       
81        /** Compute the HAT intersections with the specified scene graph.
82          * The results are all stored in the form of a single height above terrain value per HAT test.
83          * Note, if the topmost node is a CoordinateSystemNode then the input points are assumed to be geocentric,
84          * with the up vector defined by the EllipsoidModel attached to the CoordinateSystemNode.
85          * If the topmost node is not a CoordinateSystemNode then a local coordinates frame is assumed, with a local up vector. */
86        void computeIntersections(osg::Node* scene, osg::Node::NodeMask traversalMask=0xffffffff);
87
88        /** Compute the vertical distance between the specified scene graph and a single HAT point. */
89        static double computeHeightAboveTerrain(osg::Node* scene, const osg::Vec3d& point, DataSource pagingBehaviour, osg::Node::NodeMask traversalMask=0xffffffff);
90       
91                /** Compute the vertical position of the scene at a single HOT point. */
92        static double computeHeightOfTerrain(osg::Node* scene, const osg::Vec3d& point, DataSource pagingBehaviour, osg::Node::NodeMask traversalMask=0xffffffff);
93
94       
95        /** Clear the database cache.*/
96        void clearDatabaseCache() { if (_dcrc.valid()) _dcrc->clearDatabaseCache(); }
97
98        /** Set the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.
99          * Note, if you have multiple LineOfSight or HeightAboveTerrain objects in use at one time then you should share a single
100          * DatabaseCacheReadCallback between all of them. */
101                void setDatabaseCacheReadCallback(osgSim::DatabaseCacheReadCallback* dcrc);
102
103        /** Get the ReadCallback that does the reading of external PagedLOD models, and caching of loaded subgraphs.*/
104                osgSim::DatabaseCacheReadCallback* getDatabaseCacheReadCallback() { return _dcrc.get(); }
105       
106    protected :
107   
108        struct HAT
109        {
110            HAT(const osg::Vec3d& point):
111                _point(point),
112                _hat(0.0),
113                                _hot(0.0) {}
114               
115            osg::Vec3d      _point;
116            double          _hat;
117                        double          _hot;
118        };
119       
120        typedef std::vector<HAT> HATList;
121       
122
123        double                                  _lowestHeight;
124        HATList                                 _HATList;
125
126                osg::ref_ptr<osgSim::DatabaseCacheReadCallback> _dcrc;
127        osgUtil::IntersectionVisitor            _intersectionVisitor;
128
129
130};
131
132}
133
134#endif
Note: See TracBrowser for help on using the repository browser.