File: Terrain

package info (click to toggle)
openscenegraph 3.2.1-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,904 kB
  • ctags: 34,781
  • sloc: cpp: 370,251; ansic: 10,145; java: 1,020; yacc: 548; objc: 288; makefile: 282; xml: 155; lex: 151
file content (123 lines) | stat: -rw-r--r-- 5,292 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
*/

#ifndef OSGTerrain
#define OSGTerrain 1

#include <osg/CoordinateSystemNode>
#include <OpenThreads/ReentrantMutex>

#include <osgTerrain/TerrainTile>

namespace osgTerrain {

/** Terrain provides a framework for loosely coupling height field data with height rendering algorithms.
  * This allows TerrainTechniques to be plugged in at runtime.*/
class OSGTERRAIN_EXPORT Terrain : public osg::CoordinateSystemNode
{
    public:

        Terrain();

        /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
        Terrain(const Terrain&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);

        META_Node(osgTerrain, Terrain);

        virtual void traverse(osg::NodeVisitor& nv);

        virtual osgTerrain::Terrain* asTerrain() { return this; }
        virtual const osgTerrain::Terrain* asTerrain() const { return this; }


        /** Set the sample ratio hint that TerrainTile should use when building geometry.
          * Defaults to 1.0, which means use all original sample points.*/
        void setSampleRatio(float ratio);

        /** Get the sample ratio hint.*/
        float getSampleRatio() const { return _sampleRatio; }


        /** Set the vertical scale hint.*/
        void setVerticalScale(float scale);

        /** Get the vertical scale hint.*/
        float getVerticalScale() const { return _verticalScale; }

        /** If set to true the boundaries between adjacent tiles should be equalized.
          * Note, it is only possible to equalizae boundaries when the TerrainTile's contain properly assigned TileID's,
          * databases built with VirtualPlanetBuilder-0.9.11 and older do not set the TileID, so databases must be
          * built with later versions of VirtualPlanetBuilder to take advantage of boundary equalization. */
        void setEqualizeBoundaries(bool equalizeBoundaries);

        /** If true the boundaries between adjacent tiles will be equalized. */
        bool getEqualizeBoundaries() const { return _equalizeBoundaries; }

        /** Set the default policy to use when deciding whether to enable/disable blending and use of transparent bin.
          * Note, the Terrain::BlendingPolicy value only sets the value for the TerrainTiles it encloses for the
          * TerrainTile's that have their policy set to INHERIT.   INHERIT is the default BlendingPolicy for both
          * Terrain and TerrainTile, and if both are left to INERHIT then the policy used is ENABLE_BLENDING_WHEN_ALPHA_PRESENT. */
        void setBlendingPolicy(TerrainTile::BlendingPolicy policy);

        /** Get the default policy to use when deciding whether to enable/disable blending and use of transparent bin.*/
        TerrainTile::BlendingPolicy getBlendingPolicy() const { return _blendingPolicy; }


        /** Get the TerrainTile for a given TileID.*/
        TerrainTile* getTile(const TileID& tileID);

        /** Get the const TerrainTile for a given TileID.*/
        const TerrainTile* getTile(const TileID& tileID) const;

        /** Set the TerrainTechnique prototype from which TerrainTiles can clone the techniques from.*/
        void setTerrainTechniquePrototype(TerrainTechnique* technique) { _terrainTechnique = technique; }

        /** Get the TerrainTechnique prototype */
        TerrainTechnique* getTerrainTechniquePrototype() { return _terrainTechnique.get(); }

        /** Get the const TerrainTechnique protype*/
        const TerrainTechnique* getTerrainTechniquePrototype() const { return _terrainTechnique.get(); }

        /** Tell the Terrain node to call the terrainTile's TerrainTechnique on the next update traversal.*/
        void updateTerrainTileOnNextFrame(TerrainTile* terrainTile);

    protected:

        virtual ~Terrain();

        friend class TerrainTile;

        void dirtyRegisteredTiles(int dirtyMask = TerrainTile::ALL_DIRTY);

        void registerTerrainTile(TerrainTile* tile);
        void unregisterTerrainTile(TerrainTile* tile);

        typedef std::map< TileID, TerrainTile* >    TerrainTileMap;
        typedef std::set< TerrainTile* >            TerrainTileSet;

        float                               _sampleRatio;
        float                               _verticalScale;
        TerrainTile::BlendingPolicy         _blendingPolicy;
        bool                                _equalizeBoundaries;

        mutable OpenThreads::ReentrantMutex _mutex;
        TerrainTileSet                      _terrainTileSet;
        TerrainTileMap                      _terrainTileMap;
        TerrainTileSet                      _updateTerrainTileSet;

        osg::ref_ptr<TerrainTechnique>      _terrainTechnique;
};

}

#endif