[osg-users] HeightField Performance

Teodor Hanchevici calin.hanchevici at gmail.com
Fri Nov 13 07:05:17 PST 2009


Hi,

I am trying to build a simple DEM editing tool, so I have to read the data myself from different file formats. I need not only to render the surface but also to interact and change its values.

I tried to duplicate the example in osgterrain and the performance was worse than before. 

This is the code I've used:

Code:

#define GRIDSIZE 2048
osgTerrain::TerrainTile* CreateLayer()
{
osgTerrain::TerrainTile* terrainTile = new osgTerrain::TerrainTile;
osg::HeightField* pGrid = new osg::HeightField();
osgTerrain::ValidDataOperator* validDataOperator = new osgTerrain::NoDataValue(0.0);
osgTerrain::Locator* locator = new osgTerrain::Locator;
pGrid->allocate(GRIDSIZE, GRIDSIZE);
pGrid->setXInterval(30.0f);
pGrid->setYInterval(30.0f);
osg::Texture::FilterMode filter = osg::Texture::LINEAR;
pci::rasterio::TiffIO* pTiff = new pci::rasterio::TiffIO();
pTiff->Open("F:/DEM/ASTGTM_N30W111_dem.tif");

unsigned char * pBuffer = new unsigned char[GRIDSIZE*GRIDSIZE*2];
short * pBufferInt = (short*) pBuffer;
memset(pBuffer, 0, GRIDSIZE*GRIDSIZE*2);
pTiff->ReadWindow(0,0,GRIDSIZE,GRIDSIZE, pBuffer);
for(unsigned int r = 0; r < GRIDSIZE ; ++r)
	for(unsigned int c = 0; c < GRIDSIZE; ++c)
		pGrid->setHeight(c,r,pBufferInt[c+GRIDSIZE*r]);
delete [] pBuffer;
osgTerrain::HeightFieldLayer* hfl = new osgTerrain::HeightFieldLayer;
hfl->setHeightField(pGrid);

locator->setCoordinateSystemType(osgTerrain::Locator::PROJECTED);
locator->setTransformAsExtents(0, 0, GRIDSIZE, GRIDSIZE);

hfl->setLocator(locator);
hfl->setValidDataOperator(validDataOperator);
hfl->setMagFilter(filter);
terrainTile->setElevationLayer(hfl);
return terrainTile;
}




Am I using the osgTerrain properly?

Thank you!

Cheers,
Teodor[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=19622#19622







More information about the osg-users mailing list