TerrainTile
Go to the documentation of this file.
/* -*-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_TERRAINTILE
#define OSGTERRAIN_TERRAINTILE 1
#include <osg/Group>
#include <osg/CoordinateSystemNode>
#include <osgDB/ReaderWriter>
#include <osgTerrain/TerrainTechnique>
#include <osgTerrain/Layer>
#include <osgTerrain/Locator>
namespace osgTerrain {
class Terrain;
class OSGTERRAIN_EXPORT TileID
{
public:
TileID();
TileID(int in_level, int in_x, int in_y);
bool operator == (const TileID& rhs) const
{
return (level==rhs.level) && (x==rhs.x) && (y==rhs.y);
}
bool operator != (const TileID& rhs) const
{
return (level!=rhs.level) || (x!=rhs.x) || (y!=rhs.y);
}
bool operator < (const TileID& rhs) const
{
if (level<rhs.level) return true;
if (level>rhs.level) return false;
if (x<rhs.x) return true;
if (x>rhs.x) return false;
return y<rhs.y;
}
bool valid() const { return level>=0; }
int level;
int x;
int y;
};
class OSGTERRAIN_EXPORT TerrainTile : public osg::Group
{
public:
TerrainTile();
TerrainTile(const TerrainTile&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Node(osgTerrain, TerrainTile);
virtual void traverse(osg::NodeVisitor& nv);
void init(int dirtyMask, bool assumeMultiThreaded);
void setTerrain(Terrain* ts);
Terrain* getTerrain() { return _terrain; }
const Terrain* getTerrain() const { return _terrain; }
void setTileID(const TileID& tileID);
const TileID& getTileID() const { return _tileID; }
void setTerrainTechnique(TerrainTechnique* terrainTechnique);
template<class T> void setTerrainTechnique(const osg::ref_ptr<T>& terrainTechnique) { setTerrainTechnique(terrainTechnique.get()); }
TerrainTechnique* getTerrainTechnique() { return _terrainTechnique.get(); }
const TerrainTechnique* getTerrainTechnique() const { return _terrainTechnique.get(); }
void setLocator(Locator* locator) { _locator = locator; }
template<class T> void setLocator(const osg::ref_ptr<T>& locator) { setLocator(locator.get()); }
Locator* getLocator() { return _locator.get(); }
const Locator* getLocator() const { return _locator.get(); }
void setElevationLayer(Layer* layer);
template<class T> void setElevationLayer(const osg::ref_ptr<T>& layer) { setElevationLayer(layer.get()); }
Layer* getElevationLayer() { return _elevationLayer.get(); }
const Layer* getElevationLayer() const { return _elevationLayer.get(); }
void setColorLayer(unsigned int i, Layer* layer);
template<class T> void setColorLayer(unsigned int i, const osg::ref_ptr<T>& layer) { setColorLayer(i, layer.get()); }
Layer* getColorLayer(unsigned int i) { return i<_colorLayers.size() ? _colorLayers[i].get() : 0; }
const Layer* getColorLayer(unsigned int i) const { return i<_colorLayers.size() ? _colorLayers[i].get() : 0; }
unsigned int getNumColorLayers() const { return _colorLayers.size(); }
void setRequiresNormals(bool flag) { _requiresNormals = flag; }
bool getRequiresNormals() const { return _requiresNormals; }
void setTreatBoundariesToValidDataAsDefaultValue(bool flag) { _treatBoundariesToValidDataAsDefaultValue = flag; }
bool getTreatBoundariesToValidDataAsDefaultValue() const { return _treatBoundariesToValidDataAsDefaultValue; }
enum BlendingPolicy
{
INHERIT,
DO_NOT_SET_BLENDING,
ENABLE_BLENDING,
ENABLE_BLENDING_WHEN_ALPHA_PRESENT
};
void setBlendingPolicy(BlendingPolicy policy) { _blendingPolicy = policy; }
BlendingPolicy getBlendingPolicy() const { return _blendingPolicy; }
enum DirtyMask
{
NOT_DIRTY = 0,
IMAGERY_DIRTY = 1<<0,
ELEVATION_DIRTY = 1<<1,
LEFT_EDGE_DIRTY = 1<<2,
RIGHT_EDGE_DIRTY = 1<<3,
TOP_EDGE_DIRTY = 1<<4,
TOP_LEFT_CORNER_DIRTY = 1<<5,
TOP_RIGHT_CORNER_DIRTY = 1<<6,
BOTTOM_EDGE_DIRTY = 1<<7,
BOTTOM_LEFT_CORNER_DIRTY = 1<<8,
BOTTOM_RIGHT_CORNER_DIRTY = 1<<9,
EDGES_DIRTY = LEFT_EDGE_DIRTY | RIGHT_EDGE_DIRTY | TOP_EDGE_DIRTY | BOTTOM_EDGE_DIRTY |
TOP_LEFT_CORNER_DIRTY | TOP_RIGHT_CORNER_DIRTY | BOTTOM_LEFT_CORNER_DIRTY | BOTTOM_RIGHT_CORNER_DIRTY,
ALL_DIRTY = IMAGERY_DIRTY | ELEVATION_DIRTY | EDGES_DIRTY
};
void setDirty(bool dirty) { setDirtyMask(dirty ? ALL_DIRTY : NOT_DIRTY); }
int getDirty() const { return _dirtyMask!=NOT_DIRTY; }
void setDirtyMask(int dirtyMask);
int getDirtyMask() const { return _dirtyMask; }
virtual osg::BoundingSphere computeBound() const;
struct TileLoadedCallback : public osg::Referenced
{
virtual bool deferExternalLayerLoading() const = 0;
virtual void loaded(osgTerrain::TerrainTile* tile, const osgDB::ReaderWriter::Options* options) const = 0;
};
static void setTileLoadedCallback(TileLoadedCallback* lc);
static osg::ref_ptr<TileLoadedCallback>& getTileLoadedCallback();
virtual void releaseGLObjects(osg::State* = 0) const;
protected:
virtual ~TerrainTile();
typedef std::vector< osg::ref_ptr<Layer> > Layers;
friend class Terrain;
Terrain* _terrain;
int _dirtyMask;
bool _hasBeenTraversal;
TileID _tileID;
osg::ref_ptr<TerrainTechnique> _terrainTechnique;
osg::ref_ptr<Locator> _locator;
osg::ref_ptr<Layer> _elevationLayer;
Layers _colorLayers;
bool _requiresNormals;
bool _treatBoundariesToValidDataAsDefaultValue;
BlendingPolicy _blendingPolicy;
};
class OSGTERRAIN_EXPORT WhiteListTileLoadedCallback : public TerrainTile::TileLoadedCallback
{
public:
WhiteListTileLoadedCallback();
void allow(const std::string& setname) { _setWhiteList.insert(setname); }
void setMinimumNumOfLayers(unsigned int numLayers) { _minumumNumberOfLayers = numLayers; }
unsigned int getMinimumNumOfLayers() const { return _minumumNumberOfLayers; }
void setReplaceSwitchLayer(bool replaceSwitchLayer) { _replaceSwitchLayer = replaceSwitchLayer; }
bool getReplaceSwitchLayer() const { return _replaceSwitchLayer; }
void setAllowAll(bool allowAll) { _allowAll = allowAll; }
bool getAllowAll() const { return _allowAll; }
bool layerAcceptable(const std::string& setname) const;
bool readImageLayer(osgTerrain::ImageLayer* imageLayer, const osgDB::ReaderWriter::Options* options) const;
virtual bool deferExternalLayerLoading() const;
virtual void loaded(osgTerrain::TerrainTile* tile, const osgDB::ReaderWriter::Options* options) const;
protected:
virtual ~WhiteListTileLoadedCallback();
typedef std::set<std::string> SetWhiteList;
SetWhiteList _setWhiteList;
unsigned int _minumumNumberOfLayers;
bool _replaceSwitchLayer;
bool _allowAll;
};
}
#endif
CoordinateSystemNode
Group
ReaderWriter
TerrainTechnique
osgDB::ReaderWriter::Options
osgDB::Options Options
Definition ReaderWriter:227
osgTerrain::ImageLayer
Definition osgTerrain/Layer:303
osgTerrain::Layer
Definition osgTerrain/Layer:37
osgTerrain::Locator
Definition osgTerrain/Locator:26
osgTerrain::TerrainTechnique
Definition TerrainTechnique:53
osgTerrain::TerrainTile
Definition TerrainTile:68
osgTerrain::TerrainTile::setColorLayer
void setColorLayer(unsigned int i, Layer *layer)
osgTerrain::TerrainTile::getTileID
const TileID & getTileID() const
Definition TerrainTile:99
osgTerrain::TerrainTile::~TerrainTile
virtual ~TerrainTile()
osgTerrain::TerrainTile::setTileLoadedCallback
static void setTileLoadedCallback(TileLoadedCallback *lc)
osgTerrain::TerrainTile::setLocator
void setLocator(Locator *locator)
Definition TerrainTile:116
osgTerrain::TerrainTile::setLocator
void setLocator(const osg::ref_ptr< T > &locator)
Definition TerrainTile:118
osgTerrain::TerrainTile::init
void init(int dirtyMask, bool assumeMultiThreaded)
osgTerrain::TerrainTile::_terrainTechnique
osg::ref_ptr< TerrainTechnique > _terrainTechnique
Definition TerrainTile:248
osgTerrain::TerrainTile::_hasBeenTraversal
bool _hasBeenTraversal
Definition TerrainTile:244
osgTerrain::TerrainTile::setTerrain
void setTerrain(Terrain *ts)
osgTerrain::TerrainTile::getRequiresNormals
bool getRequiresNormals() const
Definition TerrainTile:157
osgTerrain::TerrainTile::getTerrain
Terrain * getTerrain()
Definition TerrainTile:87
osgTerrain::TerrainTile::TerrainTile
TerrainTile(const TerrainTile &, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgTerrain::TerrainTile::getTileLoadedCallback
static osg::ref_ptr< TileLoadedCallback > & getTileLoadedCallback()
osgTerrain::TerrainTile::DirtyMask
DirtyMask
Definition TerrainTile:183
osgTerrain::TerrainTile::ELEVATION_DIRTY
@ ELEVATION_DIRTY
Definition TerrainTile:186
osgTerrain::TerrainTile::BOTTOM_RIGHT_CORNER_DIRTY
@ BOTTOM_RIGHT_CORNER_DIRTY
Definition TerrainTile:194
osgTerrain::TerrainTile::EDGES_DIRTY
@ EDGES_DIRTY
Definition TerrainTile:195
osgTerrain::TerrainTile::TOP_EDGE_DIRTY
@ TOP_EDGE_DIRTY
Definition TerrainTile:189
osgTerrain::TerrainTile::TOP_LEFT_CORNER_DIRTY
@ TOP_LEFT_CORNER_DIRTY
Definition TerrainTile:190
osgTerrain::TerrainTile::RIGHT_EDGE_DIRTY
@ RIGHT_EDGE_DIRTY
Definition TerrainTile:188
osgTerrain::TerrainTile::TOP_RIGHT_CORNER_DIRTY
@ TOP_RIGHT_CORNER_DIRTY
Definition TerrainTile:191
osgTerrain::TerrainTile::IMAGERY_DIRTY
@ IMAGERY_DIRTY
Definition TerrainTile:185
osgTerrain::TerrainTile::ALL_DIRTY
@ ALL_DIRTY
Definition TerrainTile:197
osgTerrain::TerrainTile::NOT_DIRTY
@ NOT_DIRTY
Definition TerrainTile:184
osgTerrain::TerrainTile::BOTTOM_LEFT_CORNER_DIRTY
@ BOTTOM_LEFT_CORNER_DIRTY
Definition TerrainTile:193
osgTerrain::TerrainTile::BOTTOM_EDGE_DIRTY
@ BOTTOM_EDGE_DIRTY
Definition TerrainTile:192
osgTerrain::TerrainTile::LEFT_EDGE_DIRTY
@ LEFT_EDGE_DIRTY
Definition TerrainTile:187
osgTerrain::TerrainTile::setColorLayer
void setColorLayer(unsigned int i, const osg::ref_ptr< T > &layer)
Definition TerrainTile:141
osgTerrain::TerrainTile::META_Node
META_Node(osgTerrain, TerrainTile)
osgTerrain::TerrainTile::setElevationLayer
void setElevationLayer(Layer *layer)
osgTerrain::TerrainTile::getColorLayer
Layer * getColorLayer(unsigned int i)
Definition TerrainTile:144
osgTerrain::TerrainTile::computeBound
virtual osg::BoundingSphere computeBound() const
osgTerrain::TerrainTile::setTreatBoundariesToValidDataAsDefaultValue
void setTreatBoundariesToValidDataAsDefaultValue(bool flag)
Definition TerrainTile:161
osgTerrain::TerrainTile::getBlendingPolicy
BlendingPolicy getBlendingPolicy() const
Definition TerrainTile:179
osgTerrain::TerrainTile::BlendingPolicy
BlendingPolicy
Definition TerrainTile:168
osgTerrain::TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT
@ ENABLE_BLENDING_WHEN_ALPHA_PRESENT
Definition TerrainTile:172
osgTerrain::TerrainTile::ENABLE_BLENDING
@ ENABLE_BLENDING
Definition TerrainTile:171
osgTerrain::TerrainTile::INHERIT
@ INHERIT
Definition TerrainTile:169
osgTerrain::TerrainTile::DO_NOT_SET_BLENDING
@ DO_NOT_SET_BLENDING
Definition TerrainTile:170
osgTerrain::TerrainTile::_elevationLayer
osg::ref_ptr< Layer > _elevationLayer
Definition TerrainTile:251
osgTerrain::TerrainTile::getColorLayer
const Layer * getColorLayer(unsigned int i) const
Definition TerrainTile:147
osgTerrain::TerrainTile::TerrainTile
TerrainTile()
osgTerrain::TerrainTile::getElevationLayer
const Layer * getElevationLayer() const
Definition TerrainTile:135
osgTerrain::TerrainTile::releaseGLObjects
virtual void releaseGLObjects(osg::State *=0) const
osgTerrain::TerrainTile::setTerrainTechnique
void setTerrainTechnique(TerrainTechnique *terrainTechnique)
osgTerrain::TerrainTile::traverse
virtual void traverse(osg::NodeVisitor &nv)
osgTerrain::TerrainTile::setTerrainTechnique
void setTerrainTechnique(const osg::ref_ptr< T > &terrainTechnique)
Definition TerrainTile:105
osgTerrain::TerrainTile::Terrain
friend class Terrain
Definition TerrainTile:239
osgTerrain::TerrainTile::getLocator
const Locator * getLocator() const
Definition TerrainTile:124
osgTerrain::TerrainTile::_treatBoundariesToValidDataAsDefaultValue
bool _treatBoundariesToValidDataAsDefaultValue
Definition TerrainTile:256
osgTerrain::TerrainTile::getNumColorLayers
unsigned int getNumColorLayers() const
Definition TerrainTile:150
osgTerrain::TerrainTile::_locator
osg::ref_ptr< Locator > _locator
Definition TerrainTile:249
osgTerrain::TerrainTile::setTileID
void setTileID(const TileID &tileID)
osgTerrain::TerrainTile::getDirty
int getDirty() const
Definition TerrainTile:204
osgTerrain::TerrainTile::getTreatBoundariesToValidDataAsDefaultValue
bool getTreatBoundariesToValidDataAsDefaultValue() const
Definition TerrainTile:164
osgTerrain::TerrainTile::_colorLayers
Layers _colorLayers
Definition TerrainTile:253
osgTerrain::TerrainTile::_requiresNormals
bool _requiresNormals
Definition TerrainTile:255
osgTerrain::TerrainTile::setDirty
void setDirty(bool dirty)
Definition TerrainTile:201
osgTerrain::TerrainTile::setRequiresNormals
void setRequiresNormals(bool flag)
Definition TerrainTile:154
osgTerrain::TerrainTile::getTerrainTechnique
const TerrainTechnique * getTerrainTechnique() const
Definition TerrainTile:111
osgTerrain::TerrainTile::getDirtyMask
int getDirtyMask() const
Definition TerrainTile:211
osgTerrain::TerrainTile::_blendingPolicy
BlendingPolicy _blendingPolicy
Definition TerrainTile:257
osgTerrain::TerrainTile::setElevationLayer
void setElevationLayer(const osg::ref_ptr< T > &layer)
Definition TerrainTile:129
osgTerrain::TerrainTile::getLocator
Locator * getLocator()
Definition TerrainTile:121
osgTerrain::TerrainTile::_dirtyMask
int _dirtyMask
Definition TerrainTile:243
osgTerrain::TerrainTile::setDirtyMask
void setDirtyMask(int dirtyMask)
osgTerrain::TerrainTile::getTerrainTechnique
TerrainTechnique * getTerrainTechnique()
Definition TerrainTile:108
osgTerrain::TerrainTile::_terrain
Terrain * _terrain
Definition TerrainTile:241
osgTerrain::TerrainTile::getElevationLayer
Layer * getElevationLayer()
Definition TerrainTile:132
osgTerrain::TerrainTile::Layers
std::vector< osg::ref_ptr< Layer > > Layers
Definition TerrainTile:237
osgTerrain::TerrainTile::setBlendingPolicy
void setBlendingPolicy(BlendingPolicy policy)
Definition TerrainTile:176
osgTerrain::TerrainTile::_tileID
TileID _tileID
Definition TerrainTile:246
osgTerrain::TerrainTile::getTerrain
const Terrain * getTerrain() const
Definition TerrainTile:90
osgTerrain::TileID
Definition TerrainTile:31
osgTerrain::TileID::level
int level
Definition TerrainTile:59
osgTerrain::TileID::TileID
TileID()
osgTerrain::TileID::valid
bool valid() const
Definition TerrainTile:57
osgTerrain::TileID::TileID
TileID(int in_level, int in_x, int in_y)
osgTerrain::TileID::y
int y
Definition TerrainTile:61
osgTerrain::TileID::x
int x
Definition TerrainTile:60
osgTerrain::WhiteListTileLoadedCallback::loaded
virtual void loaded(osgTerrain::TerrainTile *tile, const osgDB::ReaderWriter::Options *options) const
osgTerrain::WhiteListTileLoadedCallback::SetWhiteList
std::set< std::string > SetWhiteList
Definition TerrainTile:291
osgTerrain::WhiteListTileLoadedCallback::getMinimumNumOfLayers
unsigned int getMinimumNumOfLayers() const
Definition TerrainTile:272
osgTerrain::WhiteListTileLoadedCallback::_replaceSwitchLayer
bool _replaceSwitchLayer
Definition TerrainTile:294
osgTerrain::WhiteListTileLoadedCallback::setMinimumNumOfLayers
void setMinimumNumOfLayers(unsigned int numLayers)
Definition TerrainTile:271
osgTerrain::WhiteListTileLoadedCallback::setReplaceSwitchLayer
void setReplaceSwitchLayer(bool replaceSwitchLayer)
Definition TerrainTile:274
osgTerrain::WhiteListTileLoadedCallback::~WhiteListTileLoadedCallback
virtual ~WhiteListTileLoadedCallback()
osgTerrain::WhiteListTileLoadedCallback::getAllowAll
bool getAllowAll() const
Definition TerrainTile:278
osgTerrain::WhiteListTileLoadedCallback::readImageLayer
bool readImageLayer(osgTerrain::ImageLayer *imageLayer, const osgDB::ReaderWriter::Options *options) const
osgTerrain::WhiteListTileLoadedCallback::_minumumNumberOfLayers
unsigned int _minumumNumberOfLayers
Definition TerrainTile:293
osgTerrain::WhiteListTileLoadedCallback::_setWhiteList
SetWhiteList _setWhiteList
Definition TerrainTile:292
osgTerrain::WhiteListTileLoadedCallback::layerAcceptable
bool layerAcceptable(const std::string &setname) const
osgTerrain::WhiteListTileLoadedCallback::allow
void allow(const std::string &setname)
Definition TerrainTile:269
osgTerrain::WhiteListTileLoadedCallback::setAllowAll
void setAllowAll(bool allowAll)
Definition TerrainTile:277
osgTerrain::WhiteListTileLoadedCallback::deferExternalLayerLoading
virtual bool deferExternalLayerLoading() const
osgTerrain::WhiteListTileLoadedCallback::_allowAll
bool _allowAll
Definition TerrainTile:295
osgTerrain::WhiteListTileLoadedCallback::WhiteListTileLoadedCallback
WhiteListTileLoadedCallback()
osgTerrain::WhiteListTileLoadedCallback::getReplaceSwitchLayer
bool getReplaceSwitchLayer() const
Definition TerrainTile:275
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Group
Definition Group:29
osg::NodeVisitor
Definition NodeVisitor:82
osg::Referenced
Definition Referenced:44
osg::State
Definition State:80
osg::ref_ptr
Definition ref_ptr:32
osg::ref_ptr::get
T * get() const
Definition ref_ptr:117
osgTerrain
Definition Node:29
osg::BoundingSphere
BoundingSphered BoundingSphere
Definition BoundingSphere:314
OSGTERRAIN_EXPORT
#define OSGTERRAIN_EXPORT
Definition osgTerrain/Export:39
Layer
Locator
osgTerrain::TerrainTile::TileLoadedCallback
Definition TerrainTile:219
osgTerrain::TerrainTile::TileLoadedCallback::loaded
virtual void loaded(osgTerrain::TerrainTile *tile, const osgDB::ReaderWriter::Options *options) const =0
osgTerrain::TerrainTile::TileLoadedCallback::deferExternalLayerLoading
virtual bool deferExternalLayerLoading() const =0