dtTerrain::HeightField Class Reference

This class wraps an array of elevation posts. More...

#include <heightfield.h>

List of all members.

Public Member Functions

 HeightField ()
 Constructs the heightfield.
 HeightField (unsigned int numCols, unsigned int numRows)
 Constructs the heightfield while at the same time allocated memory to store data of the desired number of rows and columns.
void Allocate (unsigned int numCols, unsigned int numRows)
 Allocates enough memory to store data of the desired number of rows and columns.
short GetHeight (unsigned int c, unsigned int r) const
 Gets the height stored at the given row and column.
float GetInterpolatedHeight (float x, float y) const
 Gets a bi-linearly interpolated height value from the specified height field.
void SetHeight (unsigned int c, unsigned int r, short newHeight)
 Sets the height stored at the given row and column.
const short * GetHeightFieldData () const
 Gets a pointer directly to the array of height values.
unsigned int GetNumColumns () const
 Gets the number of columns in this heightfield.
unsigned int GetNumRows () const
 Gets the number of rows in this heightfield.
osg::Image * ConvertToImage () const
 Converts this heightfield into a valid Image.
void ConvertFromImage (const osg::Image &image)
 Converts the specified image into a valid heightfield.
void ConvertFromRaw (unsigned int numColumns, unsigned int numRows, short *heightData)
 Copies a chunk of raw data values into this heightfield.
void SetXInterval (float interval)
void SetYInterval (float interval)
float GetXInterval () const
float GetYInterval () const

Protected Member Functions

virtual ~HeightField ()
 Destroys the memory in use by the heightfield.


Detailed Description

This class wraps an array of elevation posts.

The elevation data is 16-bit short values, therefore, the elevation can be a maximum of SHRT_MAX (32767) and a minimum of SHRT_MIN (-32768) with zero equaling "flat" or at sea-level. This range should satisfy the needs of most applications. For example, the highest peak in the world is located on Mount Everest which sits at 8850 meters or 29,035 feet.


Constructor & Destructor Documentation

dtTerrain::HeightField::HeightField (  ) 

Constructs the heightfield.

Note, the data is invalid at this point until is gets allocated.

See also:
Allocate

dtTerrain::HeightField::HeightField ( unsigned int  numCols,
unsigned int  numRows 
)

Constructs the heightfield while at the same time allocated memory to store data of the desired number of rows and columns.

Parameters:
numCols Number of columns stored in the heightfield.
numRows Number of rows stored in the heightfield.
See also:
Allocate

dtTerrain::HeightField::~HeightField (  )  [protected, virtual]

Destroys the memory in use by the heightfield.


Member Function Documentation

void dtTerrain::HeightField::Allocate ( unsigned int  numCols,
unsigned int  numRows 
)

Allocates enough memory to store data of the desired number of rows and columns.

Any exising data is destroyed before allocating room for the new data.

Parameters:
numCols Number of columns stored in the heightfield.
numRows Number of rows stored in the heightfield.
Exceptions:
HeightFieldException::OUT_OF_BOUNDS if either the number of rows or columns is equal to zero.

short dtTerrain::HeightField::GetHeight ( unsigned int  c,
unsigned int  r 
) const

Gets the height stored at the given row and column.

Parameters:
c Column in the heightfield.
r Row in the heightfield.
Exceptions:
HeightFieldException::OUT_OF_BOUNDS if c or r is greater than the number of rows or columns in the heightfield.

float dtTerrain::HeightField::GetInterpolatedHeight ( float  x,
float  y 
) const

Gets a bi-linearly interpolated height value from the specified height field.

void dtTerrain::HeightField::SetHeight ( unsigned int  c,
unsigned int  r,
short  newHeight 
)

Sets the height stored at the given row and column.

Parameters:
c Column in the heightfield.
r Row in the heightfield.
Exceptions:
HeightFieldException::OUT_OF_BOUNDS if c or r is greater than the number of rows or columns in the heightfield.

const short* dtTerrain::HeightField::GetHeightFieldData (  )  const [inline]

Gets a pointer directly to the array of height values.

Returns:
The height values array. Note, this cannot be modified or destroyed.

unsigned int dtTerrain::HeightField::GetNumColumns (  )  const [inline]

Gets the number of columns in this heightfield.

Returns:
The current number of columns or zero if the data is invalid.

unsigned int dtTerrain::HeightField::GetNumRows (  )  const [inline]

Gets the number of rows in this heightfield.

Returns:
The current number of rows or zero if the data is invalid.

osg::Image * dtTerrain::HeightField::ConvertToImage (  )  const

Converts this heightfield into a valid Image.

Returns:
A 16-bit (565) image.

void dtTerrain::HeightField::ConvertFromImage ( const osg::Image &  image  ) 

Converts the specified image into a valid heightfield.

Parameters:
image The image to convert.
Note:
The image should be a 24-bit image representing a 16-bit heightfield. Internally,this is converted into 16-bit shorts which are inserted into this heightfield.

void dtTerrain::HeightField::ConvertFromRaw ( unsigned int  numColumns,
unsigned int  numRows,
short *  heightData 
)

Copies a chunk of raw data values into this heightfield.

Space for the data is automatically allocated so there is no need to call Allocate() on the heightfield first.

Parameters:
numColumns Number of columns in the data.
numRows Number of rows in the data.
heightData Pointer to the actual data values. If this is NULL, no action is taken.

void dtTerrain::HeightField::SetXInterval ( float  interval  )  [inline]

void dtTerrain::HeightField::SetYInterval ( float  interval  )  [inline]

float dtTerrain::HeightField::GetXInterval (  )  const [inline]

float dtTerrain::HeightField::GetYInterval (  )  const [inline]


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