Fixed the computation of terrain bounding volume so that it properly accounts for

elevation layers
This commit is contained in:
Robert Osfield 2008-01-17 15:37:35 +00:00
parent ae33e4a459
commit efdc026114
4 changed files with 61 additions and 32 deletions

View File

@ -160,7 +160,7 @@ class OSGTERRAIN_EXPORT Layer : public osg::Object
/** Get modified count value. */
virtual unsigned int getModifiedCount() const { return 0; }
virtual osg::BoundingSphere computeBound() const;
virtual osg::BoundingSphere computeBound(bool treatAsElevationLayer) const;
protected:
@ -333,7 +333,7 @@ class OSGTERRAIN_EXPORT ProxyLayer : public Layer
virtual void setModifiedCount(unsigned int value);
virtual unsigned int getModifiedCount() const;
virtual osg::BoundingSphere computeBound() const;
virtual osg::BoundingSphere computeBound(bool treatAsElevationLayer) const;
protected:

View File

@ -34,32 +34,56 @@ Layer::~Layer()
{
}
osg::BoundingSphere Layer::computeBound() const
osg::BoundingSphere Layer::computeBound(bool treatAsElevationLayer) const
{
osg::BoundingSphere bs;
if (!getLocator()) return bs;
osg::Vec3d v;
if (getLocator()->convertLocalToModel(osg::Vec3d(0.0,0.0,0.0), v))
{
bs.expandBy(v);
}
if (getLocator()->convertLocalToModel(osg::Vec3d(1.0,0.0,0.0), v))
if (treatAsElevationLayer)
{
bs.expandBy(v);
}
osg::BoundingBox bb;
unsigned int numColumns = getNumColumns();
unsigned int numRows = getNumRows();
for(unsigned int r=0;r<numRows;++r)
{
for(unsigned int c=0;c<numColumns;++c)
{
float value = 0.0f;
bool validValue = getValidValue(c,r, value);
if (validValue)
{
osg::Vec3d ndc, v;
ndc.x() = ((double)c)/(double)(numColumns-1),
ndc.y() = ((double)r)/(double)(numRows-1);
ndc.z() = value;
if (getLocator()->convertLocalToModel(osg::Vec3d(1.0,1.0,0.0), v))
{
bs.expandBy(v);
if (getLocator()->convertLocalToModel(ndc, v))
{
bb.expandBy(v);
}
}
}
}
bs.expandBy(bb);
}
if (getLocator()->convertLocalToModel(osg::Vec3d(0.0,1.0,0.0), v))
else
{
bs.expandBy(v);
}
osg::Vec3d v;
if (getLocator()->convertLocalToModel(osg::Vec3d(0.5,0.5,0.0), v))
{
bs.center() = v;
}
if (getLocator()->convertLocalToModel(osg::Vec3d(0.0,0.0,0.0), v))
{
bs.expandBy(v);
bs.radius() = (bs.center() - v).length();
}
}
return bs;
}
@ -431,8 +455,8 @@ unsigned int ProxyLayer::getModifiedCount() const
}
osg::BoundingSphere ProxyLayer::computeBound() const
osg::BoundingSphere ProxyLayer::computeBound(bool treatAsElevationLayer) const
{
if (_implementation.valid()) return _implementation->computeBound();
if (_implementation.valid()) return _implementation->computeBound(treatAsElevationLayer);
}

View File

@ -104,14 +104,19 @@ osg::BoundingSphere Terrain::computeBound() const
{
osg::BoundingSphere bs;
if (_elevationLayer.valid()) bs.expandBy(_elevationLayer->computeBound());
for(Layers::const_iterator itr = _colorLayers.begin();
itr != _colorLayers.end();
++itr)
if (_elevationLayer.valid())
{
if (itr->layer.valid()) bs.expandBy(itr->layer->computeBound());
bs.expandBy(_elevationLayer->computeBound(true));
}
else
{
for(Layers::const_iterator itr = _colorLayers.begin();
itr != _colorLayers.end();
++itr)
{
if (itr->layer.valid()) bs.expandBy(itr->layer->computeBound(false));
}
}
return bs;
}

View File

@ -555,9 +555,9 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::Layer)
__unsigned_int__getModifiedCount,
"Get modified count value. ",
"");
I_Method0(osg::BoundingSphere, computeBound,
I_Method1(osg::BoundingSphere, computeBound, IN, bool, treatAsElevationLayer,
Properties::VIRTUAL,
__osg_BoundingSphere__computeBound,
__osg_BoundingSphere__computeBound__bool,
"",
"");
I_SimpleProperty(const osg::Vec4 &, DefaultValue,
@ -693,9 +693,9 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::ProxyLayer)
__unsigned_int__getModifiedCount,
"Get modified count value. ",
"");
I_Method0(osg::BoundingSphere, computeBound,
I_Method1(osg::BoundingSphere, computeBound, IN, bool, treatAsElevationLayer,
Properties::VIRTUAL,
__osg_BoundingSphere__computeBound,
__osg_BoundingSphere__computeBound__bool,
"",
"");
I_SimpleProperty(const std::string &, FileName,