A heightfield. A uniform discretization of space which supports queries on height and normal of field.
More...
#include <HeightField.h>
|
| 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 Resource * | load (const std::string &fileName) |
| Parses a graph definition and returns a pointer to it. More...
|
|
|
static const std::string | LABEL |
| The unique label for this data type to be used with resource management.
|
|
|
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.
|
|
A heightfield. A uniform discretization of space which supports queries on height and normal of field.
Terrain::HeightField::HeightField |
( |
const std::string & |
fileName | ) |
|
Constructor.
- Parameters
-
fileName | The height field specification file used to define the height field. |
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
-
x | The position along the x-axis. |
y | The 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
-
x | The index along the x-axis.. |
y | The 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
-
x | The position along the x-axis. |
y | The 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
-
x | The index along the x-axis.. |
y | The 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
-
imgName | The image file used to define the height field. |
cellSize | The size of each cell in the image in world coordinates. |
vertScale | The values of the image (in the range [0, 255] are normalized to the range [0, 1] and then multiplied by this vertical scale. |
xpos | The x-coordinate of the terrain's origin |
zpos | The z-coordinate of the terrain's origin |
smoothParam | The 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
-
fileName | The 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
-
smooth | The smoothing parameter (standard deviation) of the kernel. |
The documentation for this class was generated from the following files:
- src/Plugins/Terrain/HeightField.h
- src/Plugins/Terrain/HeightField.cpp