Added TerrainNode::init() and s/getTreatBoundariesToValidDataAsDefaultValue flag.

This commit is contained in:
Robert Osfield
2007-05-13 09:54:51 +00:00
parent 91ddcdf531
commit b97d8c0fe0
5 changed files with 35 additions and 4 deletions

View File

@@ -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.

View File

@@ -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;
};
}

View File

@@ -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();

View File

@@ -138,6 +138,8 @@ void GeometryTechnique::init()
numRows = elevationLayer->getNumRows();
}
bool treatBoundariesToValidDataAsDefaultValue = _terrainNode->getTreatBoundariesToValidDataAsDefaultValue();
osg::notify(osg::NOTICE)<<"TreatBoundariesToValidDataAsDefaultValue="<<treatBoundariesToValidDataAsDefaultValue<<std::endl;
unsigned int numVertices = numRows * numColumns;

View File

@@ -17,7 +17,8 @@ using namespace osg;
using namespace osgTerrain;
TerrainNode::TerrainNode():
_requiresNormals(true)
_requiresNormals(true),
_treatBoundariesToValidDataAsDefaultValue(false)
{
setNumChildrenRequiringUpdateTraversal(1);
}
@@ -26,7 +27,8 @@ TerrainNode::TerrainNode(const TerrainNode& terrain,const osg::CopyOp& copyop):
Group(terrain,copyop),
_elevationLayer(terrain._elevationLayer),
_colorLayers(terrain._colorLayers),
_requiresNormals(terrain._requiresNormals)
_requiresNormals(terrain._requiresNormals),
_treatBoundariesToValidDataAsDefaultValue(terrain._treatBoundariesToValidDataAsDefaultValue)
{
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
@@ -49,6 +51,15 @@ void TerrainNode::traverse(osg::NodeVisitor& nv)
}
}
void TerrainNode::init()
{
if (_terrainTechnique.valid() && _terrainTechnique->isDirty())
{
_terrainTechnique->init();
}
}
void TerrainNode::setTerrainTechnique(osgTerrain::TerrainTechnique* terrainTechnique)
{
if (_terrainTechnique == terrainTechnique) return;