Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

TeHeightMap Class Reference

#include <TeHeightMap.h>

List of all members.


Detailed Description

Height map representation.

This class provides many methods that cover all relevant operations that can be done with heightmap values.

The methods can be devided into several categories:


Public Member Functions

 TeHeightMap ()
 TeHeightMap (const SbVec2s resolution)
 TeHeightMap (const int resx, const int resy)
 TeHeightMap (const TeHeightMap &hmap)
 TeHeightMap (const TeHeightMap *hmap, const SbVec2s origin, const SbVec2s size)
 ~TeHeightMap ()
TeHeightMapoperator= (const TeHeightMap &hmap)
SbVec2s getResolution () const
void getResolution (int &x, int &y) const
void setResolution (const SbVec2s &newRes)
void setValue (const int x, const int y, const float value)
void setAllValues (const float value)
float getValue (const int x, const int y) const
const float * getValues () const
const float * operator[] (int i) const
float * startEditing ()
void finishEditing ()
void getStats (float *min, float *max, float *average)
float getMinValue ()
float getMaxValue ()
float getAverageValue ()
void shift (const float delta)
void shiftMinValue (const float value)
void shiftMinValue (const float value, const float old)
void shiftMaxValue (const float value)
void shiftMaxValue (const float value, const float old)
void shiftAverageValue (const float value)
void shiftAverageValue (const float value, const float old)
void copyFrom (const TeHeightMap *hmap)
void copyFrom (const TeHeightMap *hmap, const SbVec2s &sorigin, const SbVec2s &size, const SbVec2s &dorigin=SbVec2s(0, 0))
void addFrom (const TeHeightMap *hmap, const float rate)
void addFrom (const TeHeightMap *hmap, const SbVec2s &sorigin, const SbVec2s &size, const SbVec2s &dorigin, const float rate)
void addAll (const float value)
void subtractFrom (const TeHeightMap *hmap, const float rate)
void subtractFrom (const TeHeightMap *hmap, const SbVec2s &sorigin, const SbVec2s &size, const SbVec2s &dorigin, const float rate)
void subtractAll (const float value)
void multiplyFrom (const TeHeightMap *hmap, const float rate)
void multiplyFrom (const TeHeightMap *hmap, const SbVec2s &sorigin, const SbVec2s &size, const SbVec2s &dorigin, const float rate)
void multiplyAll (const float value)
void filter_Linear (const float coef, const int times)
void generate_FaultFormation (const unsigned int seed, const int num_faults, const float min_delta, const float max_delta)
void generate_4HMOverlap_Mask ()
void dump ()

Private Member Functions

void resetFlags ()

Private Attributes

int resx
int resy
float * values
float minValue
float maxValue
float averageValue
struct {
   unsigned int   minUpdated: 1
   unsigned int   maxUpdated: 1
   unsigned int   averageUpdated: 1
flags

Friends

class TeFaultFormation
class TeLinearFilter


Constructor & Destructor Documentation

TeHeightMap::TeHeightMap  ) 
 

Simple default constructor.

Creates empty object (zero dimensions, no allocated memory).

TeHeightMap::TeHeightMap const SbVec2s  resolution  ) 
 

Constructor that sets dimensions and allocates memory.

Creates initialized object with known dimensions and allocated memory to store generated values.

Parameters:
resolution Desired heightmap resolution.

TeHeightMap::TeHeightMap const int  rx,
const int  ry
 

Constructor that sets dimensions and allocates memory.

Creates initialized object with known dimensions and allocated memory to store generated values.

Parameters:
rx Desired resolution in X-axis direction.
ry Desired resolution in Y-axis direction.

TeHeightMap::TeHeightMap const TeHeightMap hmap  ) 
 

Copy-constructor.

Creates new heightmap as a copy of source heightmap.

Parameters:
hmap Reference to source heightmap.

TeHeightMap::TeHeightMap const TeHeightMap hmap,
const SbVec2s  origin,
const SbVec2s  asize
 

Constructor that copies only specified part of source heightmap.

New heightmap will have the same resolution as the source hmap. Values are copied from the source hmap. The rectangular area of values being copied is defined by origin and asize parameters. The values are pasted at (0,0) coordinates.

Parameters:
hmap Pointer to source heightmap.
origin Top-left corner of the copied area in the source heightmap.
asize Size of copied area.

TeHeightMap::~TeHeightMap  ) 
 

Destructor.

Releases memory.


Member Function Documentation

void TeHeightMap::addAll const float  value  ) 
 

Adds constant to all heightmap values.

Same as shift(value).

Parameters:
value Constant to be added to all heightmap values.
See also:
shift()

void TeHeightMap::addFrom const TeHeightMap hmap,
const SbVec2s &  sorigin,
const SbVec2s &  size,
const SbVec2s &  dorigin,
const float  rate
 

Two heightmaps specified-values adding.

Values from source heightmap will be added to "this" heightmap according to a "blend-rate" rate. This should be greater than 0.0f. All source values are multiplied by rate before adding to target values.

Selected source area is specified by its top-left corner sorogin and its size. Target area is specified by its top-left corner dorogin.

Parameters:
hmap Pointer to the source heightmap.
sorigin Top-left corner of selected area in source heightmap.
size Size of selected area.
dorigin Top-left corner of area in target heightmap.
rate Blend-rate showing how much of source heightmap to be added to the target.

void TeHeightMap::addFrom const TeHeightMap hmap,
const float  rate
 

Two heightmaps all-values adding.

Values from source heightmap will be added to "this" heightmap according to a "blend-rate" rate. This should be greater than 0.0f. All source values are multiplied by rate before adding to target values.

All possible values will be added, both source and target top-left corners are in (0,0) coordinates.

Parameters:
hmap Pointer to the source heightmap.
rate Blend-rate showing how much of source heightmap to be added to the target.

void TeHeightMap::copyFrom const TeHeightMap hmap,
const SbVec2s &  sorigin,
const SbVec2s &  size,
const SbVec2s &  dorigin = SbVec2s(0,0)
 

Copies selected part of source heightmap.

Copied area is specified by its top-left corner sorigin and size, values are pasted at dorigin coordinates.

Parameters:
hmap Pointer to the source heightmap.
sorigin Top-left corner of selected area in source heightmap.
size Size of selected area.
dorigin Top-left corner of area in target heightmap.

void TeHeightMap::copyFrom const TeHeightMap hmap  ) 
 

Copies all possible values from source heightmap.

Does NOT CHANGE SIZE of the heightmap. If size of heightmaps differs, only subset is copied.

Parameters:
hmap Pointer to the source heightmap.

void TeHeightMap::dump  ) 
 

Dumps itself to stdout.

This method is meant to be for DEBUGGING only and can be removed at any time.

void TeHeightMap::filter_Linear const float  coef,
const int  times
 

Linear filtering of heightmap values.

In one cycle, the filter goes through the data in all rows and columns in both directions and changes the values according to the neighbours and filtration coefficient coef. This value should be between (0.0f-1.0f). When large - smaller changes, when small - huge filtering will be done. This cycle will be done times -times.

Parameters:
coef Filtration coefficient, when large - little change, when small - huge filtering.
times Filtering will be done times -times
See also:
TeLinearFilter

void TeHeightMap::finishEditing  ) 
 

Finishes editing.

It performs resetFlags().

void TeHeightMap::generate_4HMOverlap_Mask  ) 
 

Generates mask that can used when building heightmap from 4 others.

Heightmaps have to be squares sized (2^x)+1 !!!

Todo:
This method is obsolete and should be removed.

void TeHeightMap::generate_FaultFormation const unsigned int  seed,
const int  num_faults,
const float  min_delta,
const float  max_delta
 

Generates heightmap values using fault-formation algorithm.

The algorithm works as follows:

  • Two points in the heightmap are selected. These points define the fault vector. The selection is done randomly (the generator is initialized with seed as random seed).
  • According to current iteration number, min_delta and max_delta, the height of the fault is computed.
  • All values in one half-plane specified by the fault are increased by computed value. Rest of values is left unchanged.
  • This cycle is done num_faults -times.
Parameters:
seed Random seed that defines terrain shape.
num_faults Number of faults to be generated (number of iterations).
min_delta Minimal fault height.
max_delta Maximal fault height.
See also:
TeFaultFormation

float TeHeightMap::getAverageValue  ) 
 

Computes average value from entire heightmap.

Uses TeHeightMap::flags for speedup.

Returns:
Average height from the heightmap values.
See also:
getStats(), averageValue

float TeHeightMap::getMaxValue  ) 
 

Finds maximal value in entire heightmap.

Uses TeHeightMap::flags for speedup.

Returns:
Maximal height from the heightmap values.
See also:
getStats(), maxValue

float TeHeightMap::getMinValue  ) 
 

Finds minimal value in entire heightmap.

Uses TeHeightMap::flags for speedup.

Returns:
Minimal height from the heightmap values.
See also:
getStats(), minValue

void TeHeightMap::getResolution int &  x,
int &  y
const
 

Returns size.

Parameters:
x Reference to the output variable for x-resolution.
y Reference to the output variable for y-resolution.

SbVec2s TeHeightMap::getResolution  )  const
 

Returns size.

Returns:
Vector representing resolution of heightmap.

void TeHeightMap::getStats float *  min,
float *  max,
float *  average
 

Statistics gathering (fast single-pass).

Returns stats faster than when calling standalone routines, uses TeHeightMap::flags so we can save even more time.

If you do not need all the values, pass NULL as no-wanted args when calling this function.

Parameters:
min Pointer to the output variable for minimal value.
max Pointer to the output variable for maximal value.
average Pointer the to output variable for average value.
See also:
minValue, maxValue, averageValue, getMinValue(), getMaxValue(), getAverageValue()

float TeHeightMap::getValue const int  x,
const int  y
const
 

Returns value at specified coordinates.

Parameters:
x X coordinate of the point.
y Y coordinate of the point.
Returns:
Value at specified coordinates

const float * TeHeightMap::getValues  )  const
 

Returns values array.

Returns:
Pointer to memory location, where heightmap values are stored.

void TeHeightMap::multiplyAll const float  value  ) 
 

Multiplies all heightmap values by a constant.

Parameters:
value All heightmap values will be multiplied by this constant.

void TeHeightMap::multiplyFrom const TeHeightMap hmap,
const SbVec2s &  sorigin,
const SbVec2s &  size,
const SbVec2s &  dorigin,
const float  rate
 

Two heightmaps specified-values multiplying.

Values in target heightmap will be multiplied by values in the source heightmap according to a "blend-rate" rate. This should be greater than 0.0f. All source values are multiplied by rate before multiplying the target values.

Selected source area is specified by its top-left corner sorogin and its size. Target area is specified by its top-left corner dorogin.

Parameters:
hmap Pointer to the source heightmap.
sorigin Top-left corner of selected area in source heightmap.
size Size of selected area.
dorigin Top-left corner of area in target heightmap.
rate Blend-rate showing how much of source heightmap to be multiplied with.

void TeHeightMap::multiplyFrom const TeHeightMap hmap,
const float  rate
 

Two heightmaps all-values multiplying.

Values in target heightmap will be multiplied by values in the source heightmap according to a "blend-rate" rate. This should be greater than 0.0f. All source values are multiplied by rate before multiplying the target values.

All possible values will be multiplied, both source and target top-left corners are in (0,0) coordinates.

Parameters:
hmap Pointer to the source heightmap.
rate Blend-rate showing how much of source heightmap to be multiplied with.

TeHeightMap & TeHeightMap::operator= const TeHeightMap hmap  ) 
 

Assignment operator.

Parameters:
hmap Reference to source heightmap.
Returns:
Reference to itself.

const float * TeHeightMap::operator[] int  i  )  const
 

One row getting operator.

Useful for coding like height=hmap[y][x].

Parameters:
i Row index
Returns:
Pointer to memory location of specified row.

void TeHeightMap::resetFlags  )  [private]
 

Resets TeHeightMap::flags to zero, marks all stored statistics as invalid.

See also:
minValue, maxValue, averageValue

void TeHeightMap::setAllValues const float  value  ) 
 

Sets all heightmap values to specified value.

Parameters:
value Float number to be set everywhere.

Todo:
Consider implementing this using memset. Memset wants int argument, but for zero it should be fine too and it should be faster.

void TeHeightMap::setResolution const SbVec2s &  newRes  ) 
 

Sets new resolution.

If map was larger cut off previous values, if map was smaller set new points to zero, old will be in the top-left corner.

Parameters:
newRes Desired heightmap size.

void TeHeightMap::setValue const int  x,
const int  y,
const float  value
 

Sets one heightmap value.

Sets value at (x, y) to value. If (x, y) is out of bounds does nothing.

Parameters:
x X coordinate of the point.
y Y coordinate of the point.
value Value to be placed at that point.

void TeHeightMap::shift const float  delta  ) 
 

Adds delta to all values.

Parameters:
delta This value will be added to all heightmap values.

void TeHeightMap::shiftAverageValue const float  value,
const float  old
 

Shifts heightmap values, value will become its average value.

We know old average value, so we do not have to compute it (it's faster, no check).

Parameters:
value Value that will become new average value in the heightmap.
old Old average value (no check).

void TeHeightMap::shiftAverageValue const float  value  ) 
 

Shifts heightmap values, value will become its average value.

Parameters:
value Value that will become new average value in the heightmap.

void TeHeightMap::shiftMaxValue const float  value,
const float  old
 

Shifts heightmap values, value will become its maximal value.

We know old maximal value, so we do not have to compute it (it's faster, no check).

Parameters:
value Value that will become new maximal value in the heightmap.
old Old maximal value (no check).

void TeHeightMap::shiftMaxValue const float  value  ) 
 

Shifts heightmap values, value will become its maximal value.

Parameters:
value Value that will become new maximal value in the heightmap.

void TeHeightMap::shiftMinValue const float  value,
const float  old
 

Shifts heightmap values, value will become its minimal value.

We know old minimal value, so we do not have to compute it (it's faster, no check).

Parameters:
value Value that will become new minimal value in the heightmap.
old Old minimal value (no check).

void TeHeightMap::shiftMinValue const float  value  ) 
 

Shifts heightmap values, value will become its minimal value.

Parameters:
value Value that will become new minimal value in the heightmap.

float * TeHeightMap::startEditing  ) 
 

Starts editing.

Returns:
Pointer to memory location, where heightmap values are stored.

void TeHeightMap::subtractAll const float  value  ) 
 

Subtracts constant from all heightmap values.

Same as shift(-value).

Parameters:
value Constant to be subtracted from all heightmap values.
See also:
shift()

void TeHeightMap::subtractFrom const TeHeightMap hmap,
const SbVec2s &  sorigin,
const SbVec2s &  size,
const SbVec2s &  dorigin,
const float  rate
 

Two heightmaps specified-values subtracting.

Values from source heightmap will be subtracted from "this" heightmap according to a "blend-rate" rate. This should be greater than 0.0f. All source values are multiplied by rate before subtracting from target values.

Selected source area is specified by its top-left corner sorogin and its size. Target area is specified by its top-left corner dorogin.

Parameters:
hmap Pointer to the source heightmap.
sorigin Top-left corner of selected area in source heightmap.
size Size of selected area.
dorigin Top-left corner of area in target heightmap.
rate Blend-rate showing how much of source heightmap to be subtracted from the target.

void TeHeightMap::subtractFrom const TeHeightMap hmap,
const float  rate
 

Two heightmaps all-values subtracting.

Values from source heightmap will be subtracted from "this" heightmap according to a "blend-rate" rate. This should be greater than 0.0f. All source values are multiplied by rate before subtracting from target values.

All possible values will be subtracted, both source and target top-left corners are in (0,0) coordinates.

Parameters:
hmap Pointer to the source heightmap.
rate Blend-rate showing how much of source heightmap to be subtracted from the target.


Member Data Documentation

float TeHeightMap::averageValue [private]
 

Average height storage.

See also:
getAverageValue(), getStats()

struct { ... } TeHeightMap::flags [private]
 

Bitfield to store flags that indicates which statistics are valid.

See also:
resetFlags(), minValue, maxValue, averageValue

float TeHeightMap::maxValue [private]
 

Maximal height storage.

See also:
getMaxValue(), getStats()

float TeHeightMap::minValue [private]
 

Minimal height storage.

See also:
getMinValue(), getStats()

int TeHeightMap::resx [private]
 

Heightmap x size.

See also:
getResolution(), setResolution()

int TeHeightMap::resy [private]
 

Heightmap y size.

See also:
getResolution(), setResolution()

float* TeHeightMap::values [private]
 

Array to store heightmap values.

See also:
getValues(), startEditing()


Generated on Sun May 8 16:45:06 2005 for TerrainEngine by Doxygen 1.4.1