Menge Plugin Examples
A Collection of Example Plugins for the Menge Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Terrain::HeightField Class Reference

A heightfield. A uniform discretization of space which supports queries on height and normal of field. More...

#include <HeightField.h>

Inheritance diagram for Terrain::HeightField:
Menge::Resource

Public Member Functions

 HeightField (const std::string &fileName)
 Constructor. More...
 
bool initialize (const std::string &imgName, float cellSize, float vertScale, float xpos, float zpos, float smoothParam=0.f)
 Initialize the height field. The heightfield is positioned with the "minimum" corner at the origin and extending into the first quadrant of the x-z plane based on cell size and image resolution. More...
 
virtual const std::string & getLabel () const
 Returns a unique resource label to be used to identify different resource types which use the same underlying file data.
 
void computeNormals ()
 Given the height field information, computes normals for the data.
 
float getHeightAt (float x, float y) const
 Returns the height at the given world position. If the world position lies outside of the domain of the height field, the height at the nearest cell center is returned. More...
 
Vector3 getNormalAt (float x, float y) const
 Returns the height field normal at the given world position. If the world position lies outside of the domain of the height field, the normal of the nearest cell center is returned. More...
 
float getHeightAtCell (int x, int y) const
 Returns the height at the given cell center. The behavior is undefined if the indices fall outside the array of cell values. More...
 
Vector3 getNormalAtCell (int x, int y) const
 Returns the normal at the given cell center. The behavior is undefined if the indices fall outside the array of cell values. More...
 
int getW () const
 Return the number of cells in the width direction of the field. More...
 
int getH () const
 Return the number of cells in the height direction of the field. More...
 
float getCellSize () const
 Returns the cellSize of the height field. More...
 
float getCornerX () const
 Returns the x-position of the mininum corner of the grid. More...
 
float getCornerY () const
 Returns the y-position of the mininum corner of the grid. More...
 

Static Public Member Functions

static Resourceload (const std::string &fileName)
 Parses a graph definition and returns a pointer to it. More...
 

Static Public Attributes

static const std::string LABEL
 The unique label for this data type to be used with resource management.
 

Protected Member Functions

 ~HeightField ()
 Destructor.
 
void smoothElevation (float smooth)
 Smooth the elevation using a symmetric 2D gaussian kernel. More...
 

Protected Attributes

float _cellSize
 The size of a cell in the heightfield (in world coordinates)
 
int _W
 The number of cells in the width (x) direction.
 
int _H
 The number of cells in the height (z) direction.
 
float ** _heightMap
 The data for the height field.
 
Vector3 ** _normalMap
 The data for the normals of the height field.
 
float _xpos
 The x-position of the minimum corner of the heightfield.
 
float _ypos
 The y-position of the minimum corner of the heightfield.
 

Detailed Description

A heightfield. A uniform discretization of space which supports queries on height and normal of field.

Constructor & Destructor Documentation

Terrain::HeightField::HeightField ( const std::string &  fileName)

Constructor.

Parameters
fileNameThe height field specification file used to define the height field.

Member Function Documentation

float Terrain::HeightField::getCellSize ( ) const
inline

Returns the cellSize of the height field.

Returns
The size of the side of the square cell.
float Terrain::HeightField::getCornerX ( ) const
inline

Returns the x-position of the mininum corner of the grid.

Returns
The minimum corner of the grid.
float Terrain::HeightField::getCornerY ( ) const
inline

Returns the y-position of the mininum corner of the grid.

Returns
The minimum corner of the grid.
int Terrain::HeightField::getH ( ) const
inline

Return the number of cells in the height direction of the field.

Returns
The number of cells in the height (y) direction.
float Terrain::HeightField::getHeightAt ( float  x,
float  y 
) const

Returns the height at the given world position. If the world position lies outside of the domain of the height field, the height at the nearest cell center is returned.

Parameters
xThe position along the x-axis.
yThe position along the y-axis.
Returns
The height at the position (x, y).
float Terrain::HeightField::getHeightAtCell ( int  x,
int  y 
) const

Returns the height at the given cell center. The behavior is undefined if the indices fall outside the array of cell values.

Parameters
xThe index along the x-axis..
yThe index along the y-axis.
Returns
The height at the cell center with indices[ x, y ].
Vector3 Terrain::HeightField::getNormalAt ( float  x,
float  y 
) const

Returns the height field normal at the given world position. If the world position lies outside of the domain of the height field, the normal of the nearest cell center is returned.

Parameters
xThe position along the x-axis.
yThe position along the y-axis.
Returns
The normal at the position (x, y).
Vector3 Terrain::HeightField::getNormalAtCell ( int  x,
int  y 
) const

Returns the normal at the given cell center. The behavior is undefined if the indices fall outside the array of cell values.

Parameters
xThe index along the x-axis..
yThe index along the y-axis.
Returns
The normal at the cell center with indices[ x, y ].
int Terrain::HeightField::getW ( ) const
inline

Return the number of cells in the width direction of the field.

Returns
The number of cells in the width (x) direction.
bool Terrain::HeightField::initialize ( const std::string &  imgName,
float  cellSize,
float  vertScale,
float  xpos,
float  zpos,
float  smoothParam = 0.f 
)

Initialize the height field. The heightfield is positioned with the "minimum" corner at the origin and extending into the first quadrant of the x-z plane based on cell size and image resolution.

Parameters
imgNameThe image file used to define the height field.
cellSizeThe size of each cell in the image in world coordinates.
vertScaleThe values of the image (in the range [0, 255] are normalized to the range [0, 1] and then multiplied by this vertical scale.
xposThe x-coordinate of the terrain's origin
zposThe z-coordinate of the terrain's origin
smoothParamThe smoothing parameter for the elevation values. It is interpreted as the standard deviation of a 2D symmetric gaussian kernel. If zero, no smoothing will be performed.
Returns
true if initalization was successful
Resource * Terrain::HeightField::load ( const std::string &  fileName)
static

Parses a graph definition and returns a pointer to it.

This function works in conjunction with the ResourceManager. That is why it returns a pointer, not to a Graph, but to a Resource. The ResourceManager uses it to load and instantiate Graph instances.

Parameters
fileNameThe path to the file containing the VectorField definition.
Returns
A pointer to the new Graph (if the file is valid), NULL if invalid.
void Terrain::HeightField::smoothElevation ( float  smooth)
protected

Smooth the elevation using a symmetric 2D gaussian kernel.

Parameters
smoothThe smoothing parameter (standard deviation) of the kernel.

The documentation for this class was generated from the following files: