Removed hardware down sampling hack from GeoemtryTechnique and replaced with Terrain::g/setSampleRatio()

usage.
This commit is contained in:
Robert Osfield 2008-04-22 11:39:47 +00:00
parent 37bea2727b
commit 234bfeb648
4 changed files with 22 additions and 7 deletions

View File

@ -259,6 +259,7 @@ int main( int argc, char **argv )
{ {
terrain = new osgTerrain::Terrain; terrain = new osgTerrain::Terrain;
terrain->addChild(rootnode); terrain->addChild(rootnode);
terrain->setSampleRatio(0.25f);
rootnode = terrain; rootnode = terrain;
} }

View File

@ -36,6 +36,14 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
virtual void traverse(osg::NodeVisitor& nv); virtual void traverse(osg::NodeVisitor& nv);
/** Set the sample ratio hint that TerrainTile should use when building geometry.
* Defaults to 1.0, which means use all original sample points.*/
void setSampleRatio(float ratio) { _sampleRatio = ratio; }
/** Get the sample ratio hint.*/
float getSampleRatio() const { return _sampleRatio; }
/** Get the TerrainTile for a given TileID.*/ /** Get the TerrainTile for a given TileID.*/
TerrainTile* getTile(const TileID& tileID); TerrainTile* getTile(const TileID& tileID);
@ -54,12 +62,13 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
typedef std::map< TileID, TerrainTile* > TerrainTileMap; typedef std::map< TileID, TerrainTile* > TerrainTileMap;
typedef std::set< TerrainTile* > TerrainTileSet; typedef std::set< TerrainTile* > TerrainTileSet;
float _sampleRatio;
mutable OpenThreads::Mutex _mutex; mutable OpenThreads::Mutex _mutex;
TerrainTileSet _terrainTileSet; TerrainTileSet _terrainTileSet;
TerrainTileMap _terrainTileMap; TerrainTileMap _terrainTileMap;
}; };
} }

View File

@ -13,6 +13,7 @@
#include <osgTerrain/GeometryTechnique> #include <osgTerrain/GeometryTechnique>
#include <osgTerrain/TerrainTile> #include <osgTerrain/TerrainTile>
#include <osgTerrain/Terrain>
#include <osgUtil/SmoothingVisitor> #include <osgUtil/SmoothingVisitor>
@ -228,24 +229,26 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3
numRows = elevationLayer->getNumRows(); numRows = elevationLayer->getNumRows();
} }
float sampleRatio = _terrainTile->getTerrain() ? _terrainTile->getTerrain()->getSampleRatio() : 1.0f;
double i_sampleFactor = 1.0; double i_sampleFactor = 1.0;
double j_sampleFactor = 1.0; double j_sampleFactor = 1.0;
unsigned int targetSize = 32; if (sampleRatio!=1.0f)
if (numColumns==64 && numColumns>targetSize)
{ {
unsigned int originalNumColumns = numColumns; unsigned int originalNumColumns = numColumns;
unsigned int originalNumRows = numRows; unsigned int originalNumRows = numRows;
numColumns = targetSize; numColumns = std::max((unsigned int) (float(originalNumColumns)*sqrtf(sampleRatio)), 4u);
numRows = targetSize; numRows = std::max((unsigned int) (float(originalNumRows)*sqrtf(sampleRatio)),4u);
i_sampleFactor = double(originalNumColumns-1)/double(numColumns-1); i_sampleFactor = double(originalNumColumns-1)/double(numColumns-1);
j_sampleFactor = double(originalNumRows-1)/double(numRows-1); j_sampleFactor = double(originalNumRows-1)/double(numRows-1);
} }
bool treatBoundariesToValidDataAsDefaultValue = _terrainTile->getTreatBoundariesToValidDataAsDefaultValue(); bool treatBoundariesToValidDataAsDefaultValue = _terrainTile->getTreatBoundariesToValidDataAsDefaultValue();
osg::notify(osg::INFO)<<"TreatBoundariesToValidDataAsDefaultValue="<<treatBoundariesToValidDataAsDefaultValue<<std::endl; osg::notify(osg::INFO)<<"TreatBoundariesToValidDataAsDefaultValue="<<treatBoundariesToValidDataAsDefaultValue<<std::endl;

View File

@ -17,12 +17,14 @@
using namespace osg; using namespace osg;
using namespace osgTerrain; using namespace osgTerrain;
Terrain::Terrain() Terrain::Terrain():
_sampleRatio(1.0)
{ {
} }
Terrain::Terrain(const Terrain& ts, const osg::CopyOp& copyop): Terrain::Terrain(const Terrain& ts, const osg::CopyOp& copyop):
osg::Group(ts,copyop) osg::Group(ts,copyop),
_sampleRatio(ts._sampleRatio)
{ {
} }