OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TerrainTile.h
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_TERRAINTILE
15 #define OSGTERRAIN_TERRAINTILE 1
16 
17 #include <osg/Group>
18 #include <osg/CoordinateSystemNode>
19 
20 #include <osgDB/ReaderWriter>
21 
22 #include <osgTerrain/TerrainTechnique>
23 #include <osgTerrain/Layer>
24 #include <osgTerrain/Locator>
25 
26 namespace osgTerrain {
27 
28 class Terrain;
29 
31 {
32  public:
33 
34  TileID();
35 
36  TileID(int in_level, int in_x, int in_y);
37 
38  bool operator == (const TileID& rhs) const
39  {
40  return (level==rhs.level) && (x==rhs.x) && (y==rhs.y);
41  }
42 
43  bool operator != (const TileID& rhs) const
44  {
45  return (level!=rhs.level) || (x!=rhs.x) || (y!=rhs.y);
46  }
47 
48  bool operator < (const TileID& rhs) const
49  {
50  if (level<rhs.level) return true;
51  if (level>rhs.level) return false;
52  if (x<rhs.x) return true;
53  if (x>rhs.x) return false;
54  return y<rhs.y;
55  }
56 
57  bool valid() const { return level>=0; }
58 
59  int level;
60  int x;
61  int y;
62 };
63 
64 
68 {
69  public:
70 
71  TerrainTile();
72 
75 
77 
78  virtual void traverse(osg::NodeVisitor& nv);
79 
81  void init(int dirtyMask, bool assumeMultiThreaded);
82 
84  void setTerrain(Terrain* ts);
85 
87  Terrain* getTerrain() { return _terrain; }
88 
90  const Terrain* getTerrain() const { return _terrain; }
91 
92 
96  void setTileID(const TileID& tileID);
97 
99  const TileID& getTileID() const { return _tileID; }
100 
101 
103  void setTerrainTechnique(TerrainTechnique* terrainTechnique);
104 
106  TerrainTechnique* getTerrainTechnique() { return _terrainTechnique.get(); }
107 
109  const TerrainTechnique* getTerrainTechnique() const { return _terrainTechnique.get(); }
110 
111 
114  void setLocator(Locator* locator) { _locator = locator; }
115 
117  Locator* getLocator() { return _locator.get(); }
118 
120  const Locator* getLocator() const { return _locator.get(); }
121 
123  void setElevationLayer(Layer* layer);
124 
126  Layer* getElevationLayer() { return _elevationLayer.get(); }
127 
129  const Layer* getElevationLayer() const { return _elevationLayer.get(); }
130 
131 
133  void setColorLayer(unsigned int i, Layer* layer);
134 
136  Layer* getColorLayer(unsigned int i) { return i<_colorLayers.size() ? _colorLayers[i].get() : 0; }
137 
139  const Layer* getColorLayer(unsigned int i) const { return i<_colorLayers.size() ? _colorLayers[i].get() : 0; }
140 
142  unsigned int getNumColorLayers() const { return static_cast<unsigned int>(_colorLayers.size()); }
143 
144 
146  void setRequiresNormals(bool flag) { _requiresNormals = flag; }
147 
149  bool getRequiresNormals() const { return _requiresNormals; }
150 
151 
153  void setTreatBoundariesToValidDataAsDefaultValue(bool flag) { _treatBoundariesToValidDataAsDefaultValue = flag; }
154 
156  bool getTreatBoundariesToValidDataAsDefaultValue() const { return _treatBoundariesToValidDataAsDefaultValue; }
157 
158 
160  {
164  ENABLE_BLENDING_WHEN_ALPHA_PRESENT
165  };
166 
168  void setBlendingPolicy(BlendingPolicy policy) { _blendingPolicy = policy; }
169 
171  BlendingPolicy getBlendingPolicy() const { return _blendingPolicy; }
172 
173 
175  {
176  NOT_DIRTY = 0,
177  IMAGERY_DIRTY = 1<<0,
178  ELEVATION_DIRTY = 1<<1,
179  LEFT_EDGE_DIRTY = 1<<2,
180  RIGHT_EDGE_DIRTY = 1<<3,
181  TOP_EDGE_DIRTY = 1<<4,
182  TOP_LEFT_CORNER_DIRTY = 1<<5,
183  TOP_RIGHT_CORNER_DIRTY = 1<<6,
184  BOTTOM_EDGE_DIRTY = 1<<7,
185  BOTTOM_LEFT_CORNER_DIRTY = 1<<8,
186  BOTTOM_RIGHT_CORNER_DIRTY = 1<<9,
187  EDGES_DIRTY = LEFT_EDGE_DIRTY | RIGHT_EDGE_DIRTY | TOP_EDGE_DIRTY | BOTTOM_EDGE_DIRTY |
188  TOP_LEFT_CORNER_DIRTY | TOP_RIGHT_CORNER_DIRTY | BOTTOM_LEFT_CORNER_DIRTY | BOTTOM_RIGHT_CORNER_DIRTY,
189  ALL_DIRTY = IMAGERY_DIRTY | ELEVATION_DIRTY | EDGES_DIRTY
190  };
191 
193  void setDirty(bool dirty) { setDirtyMask(dirty ? ALL_DIRTY : NOT_DIRTY); }
194 
196  int getDirty() const { return _dirtyMask!=NOT_DIRTY; }
197 
198 
200  void setDirtyMask(int dirtyMask);
201 
203  int getDirtyMask() const { return _dirtyMask; }
204 
205 
207  virtual osg::BoundingSphere computeBound() const;
208 
211  {
212  virtual bool deferExternalLayerLoading() const = 0;
213  virtual void loaded(osgTerrain::TerrainTile* tile, const osgDB::ReaderWriter::Options* options) const = 0;
214  };
215 
216  static void setTileLoadedCallback(TileLoadedCallback* lc);
217  static osg::ref_ptr<TileLoadedCallback>& getTileLoadedCallback();
218 
222  virtual void releaseGLObjects(osg::State* = 0) const;
223 
224 
225  protected:
226 
227  virtual ~TerrainTile();
228 
229  typedef std::vector< osg::ref_ptr<Layer> > Layers;
230 
231  friend class Terrain;
232 
234 
237 
239 
242 
244 
245  Layers _colorLayers;
246 
250 };
251 
256 {
257  public:
258 
260 
261  void allow(const std::string& setname) { _setWhiteList.insert(setname); }
262 
263  void setMinimumNumOfLayers(unsigned int numLayers) { _minumumNumberOfLayers = numLayers; }
264  unsigned int getMinimumNumOfLayers() const { return _minumumNumberOfLayers; }
265 
266  void setReplaceSwitchLayer(bool replaceSwitchLayer) { _replaceSwitchLayer = replaceSwitchLayer; }
267  bool getReplaceSwitchLayer() const { return _replaceSwitchLayer; }
268 
269  void setAllowAll(bool allowAll) { _allowAll = allowAll; }
270  bool getAllowAll() const { return _allowAll; }
271 
272  bool layerAcceptable(const std::string& setname) const;
273  bool readImageLayer(osgTerrain::ImageLayer* imageLayer, const osgDB::ReaderWriter::Options* options) const;
274 
275  virtual bool deferExternalLayerLoading() const;
276 
277  virtual void loaded(osgTerrain::TerrainTile* tile, const osgDB::ReaderWriter::Options* options) const;
278 
279  protected:
280 
281  virtual ~WhiteListTileLoadedCallback();
282 
283  typedef std::set<std::string> SetWhiteList;
284  SetWhiteList _setWhiteList;
287  bool _allowAll;
288 
289 };
290 
291 }
292 
293 #endif
bool getTreatBoundariesToValidDataAsDefaultValue() const
Definition: TerrainTile.h:156
bool valid() const
Definition: TerrainTile.h:57
Terrain * getTerrain()
Definition: TerrainTile.h:87
TerrainTechnique * getTerrainTechnique()
Definition: TerrainTile.h:106
Layer * getColorLayer(unsigned int i)
Definition: TerrainTile.h:136
std::vector< osg::ref_ptr< Layer > > Layers
Definition: TerrainTile.h:229
BlendingPolicy _blendingPolicy
Definition: TerrainTile.h:249
int getDirtyMask() const
Definition: TerrainTile.h:203
unsigned int getMinimumNumOfLayers() const
Definition: TerrainTile.h:264
#define META_Node(library, name)
Definition: Node.h:59
osg::ref_ptr< Layer > _elevationLayer
Definition: TerrainTile.h:243
const Layer * getElevationLayer() const
Definition: TerrainTile.h:129
std::set< std::string > SetWhiteList
Definition: TerrainTile.h:283
#define OSGTERRAIN_EXPORT
Definition: Export.h:39
void setDirty(bool dirty)
Definition: TerrainTile.h:193
const Layer * getColorLayer(unsigned int i) const
Definition: TerrainTile.h:139
osg::ref_ptr< Locator > _locator
Definition: TerrainTile.h:241
void setReplaceSwitchLayer(bool replaceSwitchLayer)
Definition: TerrainTile.h:266
void setLocator(Locator *locator)
Definition: TerrainTile.h:114
BlendingPolicy getBlendingPolicy() const
Definition: TerrainTile.h:171
bool getRequiresNormals() const
Definition: TerrainTile.h:149
osg::ref_ptr< TerrainTechnique > _terrainTechnique
Definition: TerrainTile.h:240
GLint level
Definition: GLU.h:71
const TerrainTechnique * getTerrainTechnique() const
Definition: TerrainTile.h:109
void allow(const std::string &setname)
Definition: TerrainTile.h:261
const Locator * getLocator() const
Definition: TerrainTile.h:120
unsigned int getNumColorLayers() const
Definition: TerrainTile.h:142
void setBlendingPolicy(BlendingPolicy policy)
Definition: TerrainTile.h:168
bool _treatBoundariesToValidDataAsDefaultValue
Definition: TerrainTile.h:248
void setMinimumNumOfLayers(unsigned int numLayers)
Definition: TerrainTile.h:263
void setTreatBoundariesToValidDataAsDefaultValue(bool flag)
Definition: TerrainTile.h:153
void setRequiresNormals(bool flag)
Definition: TerrainTile.h:146
const Terrain * getTerrain() const
Definition: TerrainTile.h:90
const TileID & getTileID() const
Definition: TerrainTile.h:99