dtTerrain::TerrainDataReader Class Reference

This is mostly an interface class to the data reader functionality of Delta3D terrains. More...

#include <terraindatareader.h>

Inheritance diagram for dtTerrain::TerrainDataReader:

dtCore::Base dtTerrain::DTEDTerrainReader

List of all members.

Public Member Functions

 TerrainDataReader (const std::string &name="TerrainDataReader")
 Constructs the terrain data reader.
virtual bool OnLoadTerrainTile (PagedTerrainTile &tile)=0
 This method is called when the parent terrain needs to load a tile.
virtual void OnUnloadTerrainTile (PagedTerrainTile &tile)
 This method is called when the parent terrain wishes to unload a terrain tile from its list of resident tiles.
virtual const TerrainDataTypeGetDataType () const =0
 Gets the type of data this reader supports.
virtual const std::string GenerateTerrainTileCachePath (const PagedTerrainTile &tile)=0
 This method is used by the terrain reader to generate a unique path name for a terrain tile's cached data.
void SetResizePolicy (const HeightFieldResizePolicy &policy)
 Sets the heightfield resize policy for this reader.
const HeightFieldResizePolicyGetResizePolicy () const
 Gets the current heightfield resize policy.
TerrainGetParentTerrain ()
 Gets the terrain object that currently owns this reader.
const TerrainGetParentTerrain () const
 Gets a read-only terrain object that currently owns this reader.

Protected Member Functions

virtual ~TerrainDataReader ()
 Empty destructor...
HeightFieldConvertHeightField (osg::HeightField *hf)
 Converts an OpenSceneGraph floating point heightfield to an internal 16-bit heightfield.
dtCore::RefPtr< osg::HeightField > ScaleOSGHeightField (osg::HeightField *hf)
 Scales an OpenSceneGraph heightfield according to the current resize policy.
float GetInterpolatedHeight (const osg::HeightField *hf, float x, float y)
 Performs a bi-linear interpolation at the specified coordinate to sample a height value.

Friends

class Terrain
 Allow the terrain to have access to this class.


Detailed Description

This is mostly an interface class to the data reader functionality of Delta3D terrains.

This allows the terrain to support an arbitrary number of terrain formats as long as the reader can parse the data and convert it to a terrain tile. TerrainDataReaders are primarily in charge of loading heightfield data, however, some may load more than that depending on a specific applications needs.


Constructor & Destructor Documentation

dtTerrain::TerrainDataReader::TerrainDataReader ( const std::string &  name = "TerrainDataReader"  )  [inline]

Constructs the terrain data reader.

Sets the default resize policy to NEAREST_POWER_OF_TWO_PLUS_ONE since this is a fairly common size requirement for terrain rendering architectures.

virtual dtTerrain::TerrainDataReader::~TerrainDataReader (  )  [inline, protected, virtual]

Empty destructor...


Member Function Documentation

virtual bool dtTerrain::TerrainDataReader::OnLoadTerrainTile ( PagedTerrainTile tile  )  [pure virtual]

This method is called when the parent terrain needs to load a tile.

Parameters:
tile The new tile. The loader should populate the fields of the tile as appropriate.
Note:
Should throw an exception if any errors occur.

At this point, the terrain tiles have had a chance to load data from their cache. Therefore, readers implementing this method may want to check the status of a tile's data before loading since it may have been retrieved from the cache.

Resources may be looked up using the parent terrain's resource path list. In most cases, the terrain will be made aware of any resource locations its readers may need.

See also:
Terrain

PagedTerrainTile

Implemented in dtTerrain::DTEDTerrainReader.

virtual void dtTerrain::TerrainDataReader::OnUnloadTerrainTile ( PagedTerrainTile tile  )  [inline, virtual]

This method is called when the parent terrain wishes to unload a terrain tile from its list of resident tiles.

Parameters:
tile The tile being unloaded.
Note:
Should throw an exception if any errors occur.

The default implementation does nothing as most renderers will probably only process data and have no need to respond to this method, however, it is available if needed. Also note, that the tile itself is responsible for caching its data, however, any data a renderer wishes to control may be cached in this method.

See also:
Terrain

PagedTerrainTile

virtual const TerrainDataType& dtTerrain::TerrainDataReader::GetDataType (  )  const [pure virtual]

Gets the type of data this reader supports.

Returns:
TerrainDataType The data type for this reader.

Implemented in dtTerrain::DTEDTerrainReader.

virtual const std::string dtTerrain::TerrainDataReader::GenerateTerrainTileCachePath ( const PagedTerrainTile tile  )  [pure virtual]

This method is used by the terrain reader to generate a unique path name for a terrain tile's cached data.

This path is a subdirectory under the parent terrain's cache path and should be unique on a per tile basis. This id should also be consistent across application invocations.

Parameters:
tile The tile with which to generate the path for.
Returns:
The tile specific cache path.
Note:
As an example, the DTEDTerrainReader generates this path by concatenating the latitude, longitude, and DTED level.

On a side note, I would have perferred that the parent terrain generate this cache path, however, I was unable to come up with a generic mechanism for this to occur so I thought the reader would be the next most likely candidate.

Implemented in dtTerrain::DTEDTerrainReader.

void dtTerrain::TerrainDataReader::SetResizePolicy ( const HeightFieldResizePolicy policy  )  [inline]

Sets the heightfield resize policy for this reader.

This is used when loading a new tile. If the policy is not set to NONE, the loaded heightfield will be resized according to the current policy.

Parameters:
policy The new policy.
Note:
This is useful as many renderers require their heightfield data to have certain dimensions in order for their refinement and or data hierarchy to work. By default, the policy is set to POWER_OF_TWO_PLUS_ONE.

const HeightFieldResizePolicy& dtTerrain::TerrainDataReader::GetResizePolicy (  )  const [inline]

Gets the current heightfield resize policy.

Returns:
The current policy.

Terrain* dtTerrain::TerrainDataReader::GetParentTerrain (  )  [inline]

Gets the terrain object that currently owns this reader.

Returns:
A pointer to the parent terrain.

const Terrain* dtTerrain::TerrainDataReader::GetParentTerrain (  )  const [inline]

Gets a read-only terrain object that currently owns this reader.

Returns:
A const pointer to the parent terrain.

HeightField * dtTerrain::TerrainDataReader::ConvertHeightField ( osg::HeightField *  hf  )  [protected]

Converts an OpenSceneGraph floating point heightfield to an internal 16-bit heightfield.

Parameters:
hf The OSG heightfield.
Returns:
A 16-bit heightfield.
See also:
HeightField

dtCore::RefPtr< osg::HeightField > dtTerrain::TerrainDataReader::ScaleOSGHeightField ( osg::HeightField *  hf  )  [protected]

Scales an OpenSceneGraph heightfield according to the current resize policy.

Parameters:
hf The OSG heightfield to resize.
Returns:
The resized heightfield. If the heightfield to resize meets the current resize criteria or the current policy is NONE, this will be a pointer to the same data that was passed as a parameter.

float dtTerrain::TerrainDataReader::GetInterpolatedHeight ( const osg::HeightField *  hf,
float  x,
float  y 
) [protected]

Performs a bi-linear interpolation at the specified coordinate to sample a height value.

Parameters:
hf The heightfield to query.
x The x coordinate to sample from.
y The y coordinate to sample from.


Friends And Related Function Documentation

friend class Terrain [friend]

Allow the terrain to have access to this class.


http://www.delta3d.org
2.0.0 generated 14 Feb 2008