openscenegraph
Terrain
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSGTerrain
15#define OSGTerrain 1
16
17#include <osg/CoordinateSystemNode>
18#include <OpenThreads/ReentrantMutex>
19
20#include <osgTerrain/TerrainTile>
21#include <osgTerrain/GeometryPool>
22
23namespace osgTerrain {
24
25/** Terrain provides a framework for loosely coupling height field data with height rendering algorithms.
26 * This allows TerrainTechniques to be plugged in at runtime.*/
27class OSGTERRAIN_EXPORT Terrain : public osg::CoordinateSystemNode
28{
29 public:
30
31 Terrain();
32
33 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
34 Terrain(const Terrain&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
35
36 META_Node(osgTerrain, Terrain);
37
38 virtual void traverse(osg::NodeVisitor& nv);
39
40 virtual osgTerrain::Terrain* asTerrain() { return this; }
41 virtual const osgTerrain::Terrain* asTerrain() const { return this; }
42
43
44 /** Set the sample ratio hint that TerrainTile should use when building geometry.
45 * Defaults to 1.0, which means use all original sample points.*/
46 void setSampleRatio(float ratio);
47
48 /** Get the sample ratio hint.*/
49 float getSampleRatio() const { return _sampleRatio; }
50
51
52 /** Set the vertical scale hint.*/
53 void setVerticalScale(float scale);
54
55 /** Get the vertical scale hint.*/
56 float getVerticalScale() const { return _verticalScale; }
57
58
59 /** Set the default policy to use when deciding whether to enable/disable blending and use of transparent bin.
60 * Note, the Terrain::BlendingPolicy value only sets the value for the TerrainTiles it encloses for the
61 * TerrainTile's that have their policy set to INHERIT. INHERIT is the default BlendingPolicy for both
62 * Terrain and TerrainTile, and if both are left to INERHIT then the policy used is ENABLE_BLENDING_WHEN_ALPHA_PRESENT. */
63 void setBlendingPolicy(TerrainTile::BlendingPolicy policy);
64
65 /** Get the default policy to use when deciding whether to enable/disable blending and use of transparent bin.*/
66 TerrainTile::BlendingPolicy getBlendingPolicy() const { return _blendingPolicy; }
67
68 /** If set to true the boundaries between adjacent tiles should be equalized.
69 * Note, it is only possible to equalizae boundaries when the TerrainTile's contain properly assigned TileID's,
70 * databases built with VirtualPlanetBuilder-0.9.11 and older do not set the TileID, so databases must be
71 * built with later versions of VirtualPlanetBuilder to take advantage of boundary equalization. */
72 void setEqualizeBoundaries(bool equalizeBoundaries);
73
74 /** If true the boundaries between adjacent tiles will be equalized. */
75 bool getEqualizeBoundaries() const { return _equalizeBoundaries; }
76
77
78 /** Set a custom GeometryPool to be used by TerrainTechniques that share geometry.*/
79 void setGeometryPool(GeometryPool* gp) { _geometryPool = gp; }
80
81 /** Get the GeometryPool.*/
82 GeometryPool* getGeometryPool() { return _geometryPool.get(); }
83
84 /** Get the const GeometryPool.*/
85 const GeometryPool* getGeometryPool() const { return _geometryPool.get(); }
86
87
88
89 /** Get the TerrainTile for a given TileID.*/
90 TerrainTile* getTile(const TileID& tileID);
91
92 /** Get the const TerrainTile for a given TileID.*/
93 const TerrainTile* getTile(const TileID& tileID) const;
94
95 /** Set the TerrainTechnique prototype from which TerrainTiles can clone the techniques from.*/
96 void setTerrainTechniquePrototype(TerrainTechnique* technique) { _terrainTechnique = technique; }
97
98 /** Get the TerrainTechnique prototype */
99 TerrainTechnique* getTerrainTechniquePrototype() { return _terrainTechnique.get(); }
100
101 /** Get the const TerrainTechnique protype*/
102 const TerrainTechnique* getTerrainTechniquePrototype() const { return _terrainTechnique.get(); }
103
104 /** Tell the Terrain node to call the terrainTile's TerrainTechnique on the next update traversal.*/
105 void updateTerrainTileOnNextFrame(TerrainTile* terrainTile);
106
107 protected:
108
109 virtual ~Terrain();
110
111 friend class TerrainTile;
112
113 void dirtyRegisteredTiles(int dirtyMask = TerrainTile::ALL_DIRTY);
114
115 void registerTerrainTile(TerrainTile* tile);
116 void unregisterTerrainTile(TerrainTile* tile);
117
118 typedef std::map< TileID, TerrainTile* > TerrainTileMap;
119 typedef std::set< TerrainTile* > TerrainTileSet;
120
121 float _sampleRatio;
122 float _verticalScale;
123 TerrainTile::BlendingPolicy _blendingPolicy;
124 bool _equalizeBoundaries;
125 osg::ref_ptr<GeometryPool> _geometryPool;
126
127 mutable OpenThreads::ReentrantMutex _mutex;
128 TerrainTileSet _terrainTileSet;
129 TerrainTileMap _terrainTileMap;
130 TerrainTileSet _updateTerrainTileSet;
131
132 osg::ref_ptr<TerrainTechnique> _terrainTechnique;
133};
134
135}
136
137#endif