vtlib library
Public Member Functions | Protected Member Functions | List of all members
vtTerrain Class Reference

Inherits CultureExtension.

Public Member Functions

void SetParamFile (const char *fname)
 
void SetParams (const TParams &Params)
 
TParamsGetParams ()
 
void SetLocalGrid (vtElevationGrid *pGrid, bool bPreserve)
 
void SetTin (vtTin3d *pTin)
 
bool GetGeoExtentsFromMetadata ()
 
bool CreateStep2 ()
 
bool CreateStep3 (vtTransform *pSunLight, vtLightSource *pLightSource)
 
bool CreateStep4 ()
 
bool CreateStep5 ()
 
void CreateStep6 ()
 
void SetTextureContours (float fInterval, float fSize)
 Sets the texture colors to be a set of black contour stripes. More...
 
void SetTextureColorMap (ColorMap *colors)
 Set the colors to be used in a derived texture. More...
 
bool IsCreated ()
 Return true if the terrain has been created.
 
void Enable (bool bVisible)
 Set the enabled state of the terrain (whether it is shown or not).
 
vtTransformLoadModel (const char *filename, bool bAllowCache=true)
 Load an external geometry file. More...
 
void addNode (osg::Node *pNode)
 Add a model (or any node) to the terrain. More...
 
void removeNode (osg::Node *pNode)
 Remove a node from the terrain's scene graph. More...
 
void PlantModel (vtTransform *model)
 Place a model on the terrain. More...
 
void PlantModelAtPoint (vtTransform *model, const DPoint2 &pos)
 Place a model on the terrain at a specific point. More...
 
bool PointIsInTerrain (const DPoint2 &p)
 Test whether a given point is within the current terrain. More...
 
LayerSetGetLayers ()
 Get at the container for all the layers.
 
vtVegLayerNewVegLayer ()
 
bool AddPlant (vtVegLayer *v_layer, const DPoint2 &pos, int iSpecies, float fSize)
 
int DeleteSelectedPlants (vtVegLayer *v_layer)
 
void SetSpeciesList (vtSpeciesList3d *pSpeciesList)
 
bool AddNodeToVegGrid (osg::Node *pNode)
 Get the plant array for this terrain. You can modify it directly. More...
 
vtStructureLayerGetStructureLayer () const
 
vtStructureLayerNewStructureLayer ()
 
int DeleteSelectedStructures (vtStructureLayer *st_layer)
 
bool AddNodeToStructGrid (osg::Node *pNode)
 
void RemoveNodeFromStructGrid (osg::Node *pNode)
 
virtual void OnCreateBehavior (vtStructure *s)
 
vtAbstractLayerNewAbstractLayer ()
 
vtAbstractLayerGetAbstractLayer ()
 
vtTransformGetScaledFeatures ()
 
vtImageLayerNewImageLayer ()
 
virtual void CreateCustomCulture ()
 
void AddEngine (vtEngine *pE)
 
FPoint3 GetCenter ()
 
float GetRadius ()
 
vtHeightField3dGetHeightField () const
 
vtHeightFieldGrid3dGetHeightFieldGrid3d ()
 
vtAnimContainer * GetAnimContainer ()
 Access the animation paths associated with this terrain.
 
void SetFog (bool fog)
 
void SetFogColor (const RGBf &color)
 
void SetFogDistance (float fMeters)
 
void SetShadows (bool shadows)
 
void SetShadowOptions (const vtShadowOptions &opt)
 
vtTime GetInitialTime ()
 
void TranslateToGMT (vtTime &time)
 
void TranslateFromGMT (vtTime &time)
 
void UpdateElevation ()
 
void RedrapeCulture (const DRECT &area)
 
void ReshadeTexture (vtTransform *pSunLight, bool progress_callback(int)=NULL)
 
osg::Image * GetTextureImage ()
 
void RecreateTexture (vtTransform *pSunLight, bool progress_callback(int)=NULL)
 

Protected Member Functions

void CreateWaterPlane ()
 

Detailed Description

The vtTerrain class represents a terrain, which is a part of the surface of the earth.

It is generally described by a set of parameters such as elevation, vegetation, and built structures. These terrain parameters are contained in the class TParams.

To create a new terrain, first construct a vtTerrain and set its parameters with SetParams() or SetParamFile(). You can also set many properties of the terrain directly, which is useful if you want to set them from memory instead of from disk. These include:

You can then build the terrain using the CreateStep methods, or add it to a vtTerrainScene and use vtTerrainScene::BuildTerrain.

Customizing your Terrain

To extend your terrain beyond what is possible with the terrain parameters, you can create a subclass of vtTerrain and implement the method CreateCustomCulture(). Here you can create anything you like, and add it to the terrain. Generally you should add your nodes with AddNode(), or AddNodeToStructGrid() if it is a structure that should be culled in the distance. You can also add your nodes with GetScaledFeatures()->addChild(), if they are 'flat' like GIS features or contour lines, which should be scaled up/down with the vertical exaggeration of the terrain.

How it works

The terrain is implemented with a scene graph with the following structure. When you call SetShadows() or SetFog(), a vtShadow or vtFog node (but not both) may be inserted between the container and the main terrain group.

dot_terrain_graph.png
Top of the Scenegraph per Terrain

Member Function Documentation

void vtTerrain::AddEngine ( vtEngine pE)

Add an engine to this terrain's group of engines. The engine will be enabled only when the terrain is visible.

void vtTerrain::addNode ( osg::Node *  pNode)

Adds a node to the terrain. The node will be added directly to this specific terrain, so it will be hidden whenever the terrain is not active.

See also
AddNodeToVegGrid, AddNodeToStructGrid
bool vtTerrain::AddNodeToStructGrid ( osg::Node *  pNode)

Adds a node to the terrain. The node will be added to the Structure LOD Grid of the terrain, so it will be culled when it is far from the viewer. This is usually desirable when the models are complicated or there are lot of them.

There is another form of this method which takes a vtGeode node instead.

See also
AddNode
bool vtTerrain::AddNodeToVegGrid ( osg::Node *  pNode)

Adds a node to the terrain. The node will be added to the Vegetation LOD Grid of the terrain, so it will be culled when it is far from the viewer. This method is used by the terrain vegetation methods, and you can also use it directly if you have your own vegetation nodes to add.

See also
AddNode
bool vtTerrain::AddPlant ( vtVegLayer v_layer,
const DPoint2 pos,
int  iSpecies,
float  fSize 
)

Create a new plant instance at a given location and add it to the terrain.

Parameters
v_layerThe vegetation layer to add to.
posThe 2D earth position of the new plant.
iSpeciesIndex of the species in the terrain's plant list. If you don't know the index, you can find it with vtSpeciesList::GetSpeciesIdByName or vtSpeciesList::GetSpeciesIdByCommonName.
fSizeHeight of the new plant (meters).
void vtTerrain::CreateCustomCulture ( )
virtual

The base CreateCustomCulture does nothing; this virtual method is meant to be overridden by your terrain subclass to add its own culture.

bool vtTerrain::CreateStep2 ( )

First step in terrain creation: load elevation. You can use these methods to build a terrain step by step, or simply use the method vtTerrainScene::BuildTerrain, which calls them all.

bool vtTerrain::CreateStep3 ( vtTransform pSunLight,
vtLightSource pLightSource 
)

Next step in terrain creation: create textures.

bool vtTerrain::CreateStep4 ( )

Next step in terrain creation: create 3D geometry for the terrain.

bool vtTerrain::CreateStep5 ( )

Next step in terrain creation: additional CLOD construction.

void vtTerrain::CreateStep6 ( )

Next step in terrain creation: create the culture and labels.

void vtTerrain::CreateWaterPlane ( )
protected

Create a horizontal water plane at sea level. It can be moved up and down with a transform.

int vtTerrain::DeleteSelectedPlants ( vtVegLayer v_layer)

Delete all the selected plants in the terrain's plant array.

int vtTerrain::DeleteSelectedStructures ( vtStructureLayer st_layer)

Delete all the selected structures in the terrain's active structure array.

Returns
the number of structures deleted.
vtAbstractLayer * vtTerrain::GetAbstractLayer ( )

Get the currently active abstract layer for this terrain.

FPoint3 vtTerrain::GetCenter ( )

Return the center of the bounding sphere that encloses the terrain's dynamic geometry.

bool vtTerrain::GetGeoExtentsFromMetadata ( )

For this terrain, look at its elevation source, and determine the extents of that data, in geographic coords. This is done without actually doing a full load of the data, to quickly describe the terrain's location on the earth.

vtHeightField3d * vtTerrain::GetHeightField ( ) const

Return the heightfield for this terrain. It may be a grid, or a TIN. If you know that your data is a grid, you can use GetHeightFieldGrid3d() to get that specifically.

vtHeightFieldGrid3d * vtTerrain::GetHeightFieldGrid3d ( )

Return the heightfield grid for this terrain. During the construction of the terain, this may be a source vtElevationGrid. Later, at runtime, it is likely to be one of the dynamic geometry (CLOD) grids.

vtTime vtTerrain::GetInitialTime ( )

Get the time at which a terrain is set to begin.

TParams & vtTerrain::GetParams ( )

Returns a direct reference to the parameters object for this terrain, so that you can get and set the parameters.

Example:
TParams &par = pTerrain->GetParams();
par.SetBoolValue(STR_SKY, false);
float vtTerrain::GetRadius ( )

Return the radius of the bounding sphere that encloses the terrain's dynamic geometry.

vtTransform* vtTerrain::GetScaledFeatures ( )
inline

You should add your nodes to this terrain's scaled features if they are 'flat' like GIS features or contour lines, which should be scaled up/down with the vertical exaggeration of the terrain.

vtStructureLayer * vtTerrain::GetStructureLayer ( ) const

Get the currently active structure layer for this terrain.

osg::Image * vtTerrain::GetTextureImage ( )

Get the texture image of the ground texture, if there is one. If the texture is more complicated (e.g. tileset) then NULL is returned.

vtTransform * vtTerrain::LoadModel ( const char *  filename,
bool  bAllowCache = true 
)

Loads an external 3D model as a movable node. The file will be looked for on the Terrain's data path, and wrapped with a vtTransform so that it can be moved.

To add the model to the Terrain's scene graph, use AddModel or AddModelToLodGrid. To plant the model on the terrain, use PlantModel or PlantModelAtPoint.

You should also make sure that your model is displayed at the correct scale. If the units are of the model are not meters, you should scale the correct factor so that it matches the units of the Terrain:

Example:
MyTerrain::CreateCustomCulture()
{
// model is in centimeters (cm)
vtTransform *pFountain = LoadModel("Culture/fountain.3ds");
pFountain->Scale(.01f);
PlantModelAtPoint(pFountain, DPoint2(217690, 4123475));
AddModel(pFountain);
}
vtAbstractLayer * vtTerrain::NewAbstractLayer ( )

Create a new abstract array for this terrain, and returns it.

vtImageLayer * vtTerrain::NewImageLayer ( )

Create a new image array for this terrain, and returns it.

vtStructureLayer * vtTerrain::NewStructureLayer ( )

Create a new structure array for this terrain, and return it.

vtVegLayer * vtTerrain::NewVegLayer ( )

Create a new veg array for this terrain, and returns it.

void vtTerrain::OnCreateBehavior ( vtStructure str)
virtual

Extend some structures with behavior. A developer can also subclass vtTerrain to implement their own behaviors.

void vtTerrain::PlantModel ( vtTransform model)

"Plants" a model on the ground. This is done by moving the model directly up or down such that its local origin is at the height of the terrain.

Note: this function does not add the model to the terrain's scene graph. Use AddNode for that operation.

void vtTerrain::PlantModelAtPoint ( vtTransform model,
const DPoint2 pos 
)

"Plants" a model on the ground. This is done by moving the node to the indicated earth coordinate, then moving it directly up or down such that its local origin is at the height of the terrain.

Parameters
modelThe model to be placed on the terrain.
posThe position (in earth coordinates) at which to place it. This position is assumed to be in the same coordinate system that the Terrain is using.

Note: this function does not add the model to the terrain's scene graph. Use AddNode for that operation.

bool vtTerrain::PointIsInTerrain ( const DPoint2 p)

Tests whether a given point (in Earth coordinates) is within the current extents of the terrain.

void vtTerrain::RecreateTexture ( vtTransform pSunLight,
bool   progress_callbackint = NULL 
)

Re-create the ground texture. It is completely made again (reloaded from disk, or regenerated from a colormap).

void vtTerrain::RedrapeCulture ( const DRECT area)

Drape all the culture on the terrain again, to keep them on the surface in the case when the elevation values have changed.

Parameters
areaYou can speed up this function by passing the area to re-drape in. Otherwise, simply pass an empty area, and all culture will be re-draped.
void vtTerrain::removeNode ( osg::Node *  pNode)

Removes a node from the terrain.

See also
RemoveNodeFromStructGrid
void vtTerrain::RemoveNodeFromStructGrid ( osg::Node *  pNode)

Removes a node from the terrain's structure LOD grid.

See also
RemoveNode
void vtTerrain::ReshadeTexture ( vtTransform pSunLight,
bool   progress_callbackint = NULL 
)

Re-shade the ground texture. This is useful if you have changed the time of day, and want to see the lighting/shading of the terrain updated.

void vtTerrain::SetFog ( bool  fog)

Turn on fog for this terrain. Mutually exclusive with shadow.

void vtTerrain::SetFogColor ( const RGBf color)

Set the color of the fog.

void vtTerrain::SetFogDistance ( float  fMeters)

Set the distance at which the fog is solid.

void vtTerrain::SetLocalGrid ( vtElevationGrid pGrid,
bool  bPreserve 
)

This method allows you to give the terrain a grid to use directly instead of loading the BT file specified in the TParams.

You must allocate this grid dynamically with 'new', since vtTerrain will 'delete' it after using it during initialization. If you don't want the memory to be deleted, pass 'true' for bPreserve.

Parameters
pGridThe grid object which the terrain should use.
bPreserveTrue if the terrain should not delete the grid object, otherwise false.
void vtTerrain::SetParamFile ( const char *  fname)

Tells the terrain what file contains the parameters to use.

Parameters
fnameThe name of a terrain parameters file, e.g. "Simple.xml".
void vtTerrain::SetParams ( const TParams Params)

Set all of the parameters for this terrain.

Parameters
ParamsAn object which contains all the parameters for the terrain.
Note that you can set individual parameters like this:
TParams &par = pTerrain->GetParams();
par.SetBoolValue(STR_SKY, false);
void vtTerrain::SetShadowOptions ( const vtShadowOptions opt)

Set shadow options (darkness, radius, etc.)

void vtTerrain::SetShadows ( bool  shadows)

Turn on shadows for this terrain. Mutually exclusive with fog.

void vtTerrain::SetSpeciesList ( vtSpeciesList3d pSpeciesList)

Set the list of plant species that this terrain should use. Using this method allows a set of species to be shared between many terrains.

void vtTerrain::SetTextureColorMap ( ColorMap colors)

Set the array of colors to be used when automatically generating the terrain texture from the elevation values. This is the color map which is used for automatic generation of texture from elevation, when the terrain is built normally with the "Derived" texture option. The colors brackets go from the lowest elevation value to the highest.

Parameters
colorsA pointer to a colormap. The terrain takes ownership of the ColorMap object so it will be deleted when the terrain is deleted.
Example:
ColorMap *colors = new ColorMap;
colors->m_bRelative = false;
colors->Add(100, RGBi(0,255,0));
colors->Add(200, RGBi(255,200,150));
pTerr->SetTextureColorMap(colors);
void vtTerrain::SetTextureContours ( float  fInterval,
float  fSize 
)

This method sets the terrain's color map to a series of white and black bands which indicate elevation contour lines. This is the color map which is used for automatic generation of texture from elevation, when the terrain is built normally with the "Derived" texture option.

You can use this function either before the terrain is built, or afterwards if you intend to re-build the textures.

Example:
vtTerrain *pTerr = new vtTerrain;
pTerr->SetTextureContours(100, 4);
Parameters
fIntervalThe vertical spacing between the contours. For example, if the elevation range of your data is from 50 to 350 meters, then an fIterval of 100 will place contour bands at 100,200,300 meters.
fSizeThe vertical thickness of each contour band, generally a few meters. A band of this thickness will be centered on each contour line of the desired elevation.
void vtTerrain::SetTin ( vtTin3d pTin)

This method allows you to give the terrain a TIN to use directly instead of loading a .tin file as specified in the TParams.

void vtTerrain::TranslateFromGMT ( vtTime time)

Given a time value, convert it to the LT (local time) of the center of this terrain from GMT. Local time is defined precisely by longitude, e.g. at noon local time, the sun is exactly halfway across the sky.

Note that this is different that the "standard time" of a given place, which involves finding out what time zone is in effect (complicated!)

void vtTerrain::TranslateToGMT ( vtTime time)

Given a time value, convert it from the LT (local time) of the center of this terrain to GMT. Local time is defined precisely by longitude, e.g. at noon local time, the sun is exactly halfway across the sky.

Note that this is different that the "standard time" of a given place, which involves finding out what time zone is in effect (complicated!)

void vtTerrain::UpdateElevation ( )

If you have told vtTerrain to preserve a copy of the original elevation grid in memory, you can modify that grid, then call this method to update the CLOD surface. This can take up a few seconds, depending on the size of your grid.