Added support for multiple colour layers, and fixed handling of elevation

and colour layers having different locator
This commit is contained in:
Robert Osfield
2007-04-11 11:20:04 +00:00
parent e42daa775f
commit 557fdacba2
3 changed files with 66 additions and 22 deletions

View File

@@ -60,18 +60,43 @@ class OSGTERRAIN_EXPORT TerrainNode : public osg::Group
/** Get the coordinate frame locator of the terrain node.*/
const Locator* getLocator() const { return _locator.get(); }
/** Set the layer to use to define the elevations of the terrain.*/
void setElevationLayer(Layer* layer);
/** Get the layer to use to define the elevations of the terrain.*/
Layer* getElevationLayer() { return _elevationLayer.get(); }
/** Get the const layer to use to define the elevations of the terrain.*/
const Layer* getElevationLayer() const { return _elevationLayer.get(); }
/** Set a color layer with specified layer number.*/
void setColorLayer(unsigned int i, osgTerrain::Layer* layer);
/** Get color layer with specified layer number.*/
Layer* getColorLayer(unsigned int i) { return i<_colorLayers.size() ? _colorLayers[i].layer.get() : 0; }
/** Set const color layer with specified layer number.*/
const Layer* getColorLayer(unsigned int i) const { return i<_colorLayers.size() ? _colorLayers[i].layer.get() : 0; }
void setColorLayer(osgTerrain::Layer* layer);
Layer* getColorLayer() { return _colorLayer.get(); }
const Layer* getColorLayer() const { return _colorLayer.get(); }
void setColorTransferFunction(osg::TransferFunction* tf);
osg::TransferFunction* getColorTransferFunction() { return _colorTransferFunction.get(); }
const osg::TransferFunction* getColorTransferFunction() const { return _colorTransferFunction.get(); }
/** Set a color transfer function with specified layer number.*/
void setColorTransferFunction(unsigned int i, osg::TransferFunction* tf);
/** Get color transfer function with specified layer number.*/
osg::TransferFunction* getColorTransferFunction(unsigned int i) { return i<_colorLayers.size() ? _colorLayers[i].transferFunction.get() : 0; }
/** Get const color transfer function with specified layer number.*/
const osg::TransferFunction* getColorTransferFunction(unsigned int i) const { return i<_colorLayers.size() ? _colorLayers[i].transferFunction.get() : 0; }
unsigned int getNumColorLayers() const { return _colorLayers.size(); }
/** Set 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; }
/** Compute the bounding volume of the terrain by computing the union of the bounding volumes of all layers.*/
virtual osg::BoundingSphere computeBound() const;
@@ -80,13 +105,22 @@ class OSGTERRAIN_EXPORT TerrainNode : public osg::Group
virtual ~TerrainNode();
struct LayerData
{
osg::ref_ptr<Layer> layer;
osg::ref_ptr<osg::TransferFunction> transferFunction;
};
typedef std::vector<LayerData> Layers;
osg::ref_ptr<TerrainTechnique> _terrainTechnique;
osg::ref_ptr<Locator> _locator;
osg::ref_ptr<Layer> _elevationLayer;
osg::ref_ptr<Layer> _colorLayer;
osg::ref_ptr<osg::TransferFunction> _colorTransferFunction;
Layers _colorLayers;
bool _requiresNormals;
};
}

View File

@@ -47,8 +47,8 @@ void GeometryTechnique::init()
osgTerrain::Layer* elevationLayer = _terrainNode->getElevationLayer();
osgTerrain::Layer* colorLayer = _terrainNode->getColorLayer();
osg::TransferFunction* colorTF = _terrainNode->getColorTransferFunction();
osgTerrain::Layer* colorLayer = _terrainNode->getColorLayer(0);
osg::TransferFunction* colorTF = _terrainNode->getColorTransferFunction(0);
// if the elevationLayer and colorLayer are the same, and there is colorTF then
// simply assing as a texture coordinate.
@@ -182,7 +182,7 @@ void GeometryTechnique::init()
for(unsigned int i=0; i<numColumns; ++i)
{
unsigned int iv = j*numColumns + i;
osg::Vec3d ndc( (double)i/(double)(numColumns-1), (double)j/(double)(numColumns-1), 0.0);
osg::Vec3d ndc( ((double)i)/(double)(numColumns-1), ((double)j)/(double)(numRows-1), 0.0);
if (elevationLayer)
{
@@ -202,7 +202,7 @@ void GeometryTechnique::init()
if (colorLocator!= masterLocator)
{
osg::Vec3d color_ndc;
colorLocator->computeLocalBounds(*masterLocator, ndc, color_ndc);
Locator::convertLocalCoordBetween(*masterLocator, ndc, *colorLocator, color_ndc);
(*texcoords)[iv].set(color_ndc.x(), color_ndc.y());
}
else

View File

@@ -16,7 +16,8 @@
using namespace osg;
using namespace osgTerrain;
TerrainNode::TerrainNode()
TerrainNode::TerrainNode():
_requiresNormals(true)
{
setNumChildrenRequiringUpdateTraversal(1);
}
@@ -24,8 +25,8 @@ TerrainNode::TerrainNode()
TerrainNode::TerrainNode(const TerrainNode& terrain,const osg::CopyOp& copyop):
Group(terrain,copyop),
_elevationLayer(terrain._elevationLayer),
_colorLayer(terrain._colorLayer),
_colorTransferFunction(terrain._colorTransferFunction)
_colorLayers(terrain._colorLayers),
_requiresNormals(terrain._requiresNormals)
{
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
@@ -66,14 +67,18 @@ void TerrainNode::setElevationLayer(osgTerrain::Layer* layer)
_elevationLayer = layer;
}
void TerrainNode::setColorLayer(osgTerrain::Layer* layer)
void TerrainNode::setColorLayer(unsigned int i, osgTerrain::Layer* layer)
{
_colorLayer = layer;
if (_colorLayers.size() <= i) _colorLayers.resize(i+1);
_colorLayers[i].layer = layer;
}
void TerrainNode::setColorTransferFunction(osg::TransferFunction* tf)
void TerrainNode::setColorTransferFunction(unsigned int i, osg::TransferFunction* tf)
{
_colorTransferFunction = tf;
if (_colorLayers.size() <= i) _colorLayers.resize(i+1);
_colorLayers[i].transferFunction = tf;
}
osg::BoundingSphere TerrainNode::computeBound() const
@@ -82,7 +87,12 @@ osg::BoundingSphere TerrainNode::computeBound() const
if (_elevationLayer.valid()) bs.expandBy(_elevationLayer->computeBound());
if (_colorLayer.valid()) bs.expandBy(_colorLayer->computeBound());
for(Layers::const_iterator itr = _colorLayers.begin();
itr != _colorLayers.end();
++itr)
{
if (itr->layer.valid()) bs.expandBy(itr->layer->computeBound());
}
return bs;
}