From b97d8c0fe06a274ba9cd2f88eeb7a63e35770f9f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 13 May 2007 09:54:51 +0000 Subject: [PATCH] Added TerrainNode::init() and s/getTreatBoundariesToValidDataAsDefaultValue flag. --- examples/osgterrain/osgterrain.cpp | 5 +++++ include/osgTerrain/TerrainNode | 12 +++++++++++- include/osgTerrain/TerrainTechnique | 5 ++++- src/osgTerrain/GeometryTechnique.cpp | 2 ++ src/osgTerrain/TerrainNode.cpp | 15 +++++++++++++-- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index a4aff48b9..7a1bb52d7 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -104,6 +104,11 @@ int main(int argc, char** argv) readParameter = true; } + else if (arguments.read(pos, "-b")) + { + terrain->setTreatBoundariesToValidDataAsDefaultValue(true); + } + else if (arguments.read(pos, "-e",x,y,w,h)) { // define the extents. diff --git a/include/osgTerrain/TerrainNode b/include/osgTerrain/TerrainNode index d72f71f6b..ba59756c6 100644 --- a/include/osgTerrain/TerrainNode +++ b/include/osgTerrain/TerrainNode @@ -39,6 +39,8 @@ class OSGTERRAIN_EXPORT TerrainNode : public osg::Group virtual void traverse(osg::NodeVisitor& nv); + /** Call init on any attached TerrainTechnique.*/ + void init(); /** Set the TerrainTechnique*/ void setTerrainTechnique(osgTerrain::TerrainTechnique* TerrainTechnique); @@ -105,13 +107,20 @@ class OSGTERRAIN_EXPORT TerrainNode : public osg::Group unsigned int getNumColorLayers() const { return _colorLayers.size(); } - /** Set whether the TerrainTechnique should create per vertex normals for lighting purposes.*/ + /** Set hint to whether the TerrainTechnique should create per vertex normals for lighting purposes.*/ void setRequiresNormals(bool flag) { _requiresNormals = flag; } /** Get whether the TerrainTechnique should create per vertex normals for lighting purposes.*/ bool getRequiresNormals() const { return _requiresNormals; } + /** Set the hint to whether the TerrainTechnique should treat the invalid Layer entries that at are neigbours to valid entries with the default value.*/ + void setTreatBoundariesToValidDataAsDefaultValue(bool flag) { _treatBoundariesToValidDataAsDefaultValue = flag; } + + /** Get whether the TeatBoundariesToValidDataAsDefaultValue hint.*/ + bool getTreatBoundariesToValidDataAsDefaultValue() const { return _treatBoundariesToValidDataAsDefaultValue; } + + /** Compute the bounding volume of the terrain by computing the union of the bounding volumes of all layers.*/ virtual osg::BoundingSphere computeBound() const; @@ -152,6 +161,7 @@ class OSGTERRAIN_EXPORT TerrainNode : public osg::Group Layers _colorLayers; bool _requiresNormals; + bool _treatBoundariesToValidDataAsDefaultValue; }; } diff --git a/include/osgTerrain/TerrainTechnique b/include/osgTerrain/TerrainTechnique index 4b3a709b5..654c25f97 100644 --- a/include/osgTerrain/TerrainTechnique +++ b/include/osgTerrain/TerrainTechnique @@ -51,9 +51,12 @@ class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object /** Traverse the terain subgraph.*/ virtual void traverse(osg::NodeVisitor& nv); - /** Dirty so that cached data structurese are updated.*/ + /** Dirty so that cached data structurese will be updated on next use.*/ virtual void dirty(); + /** Return true if cached data structurese need updating.*/ + virtual bool isDirty() const { return _dirty; } + protected: virtual ~TerrainTechnique(); diff --git a/src/osgTerrain/GeometryTechnique.cpp b/src/osgTerrain/GeometryTechnique.cpp index f261c4006..913747918 100644 --- a/src/osgTerrain/GeometryTechnique.cpp +++ b/src/osgTerrain/GeometryTechnique.cpp @@ -138,6 +138,8 @@ void GeometryTechnique::init() numRows = elevationLayer->getNumRows(); } + bool treatBoundariesToValidDataAsDefaultValue = _terrainNode->getTreatBoundariesToValidDataAsDefaultValue(); + osg::notify(osg::NOTICE)<<"TreatBoundariesToValidDataAsDefaultValue="<isDirty()) + { + _terrainTechnique->init(); + } +} + + void TerrainNode::setTerrainTechnique(osgTerrain::TerrainTechnique* terrainTechnique) { if (_terrainTechnique == terrainTechnique) return;