My Project
Public Types | Public Member Functions | Static Public Member Functions | List of all members
ParaEngine::CTerrainFilters Class Reference

Perform filtering on a terrain height field. More...

#include <TerrainFilters.h>

Public Types

enum  MergeOperation {
  Addition =0, Subtract, Multiplication, Division,
  Minimum, Maximum
}
 used in the merge function
 
enum  FlattenOperation { Fill_Op, ShaveTop_Op, Flatten_Op }
 

Public Member Functions

TTerrainGetTerrainData ()
 get the terrain data that is associated with this filter. More...
 
void Flatten (FlattenOperation flatten_op, float elevation, float factor, float center_x, float center_y, float radius)
 Flatten the terrain both up and down to the specified elevation, using using the tightness parameter to determine how much the altered points are allowed to deviate from the specified elevation. More...
 
void RadialScale (float center_x, float center_y, float scale_factor, float min_dist, float max_dist, float smooth_factor, int frequency)
 Note: terrain data should be in normalized space with height in the range [0,1]. More...
 
void GaussianHill (float x, float y, float radius, float hscale, float standard_deviation, float smooth_factor)
 
void Spherical (float offset)
 offset in a spherical region
 
void Roughen_Smooth (bool roughen, bool big_grid, float factor)
 square filter for sharpening and smoothing. More...
 
void Ramp (float x1, float y1, float height1, float x2, float y2, float height2, float radius, float borderpercentage=0.5f, float factor=1.0f)
 create a ramp (inclined slope) from height(x1,y1) to height(x2,y2). More...
 
void SetConstEdgeHeight (float fHeight=0, int nSmoothPixels=7)
 load height field from file More...
 
void Merge (TTerrain *terrain_1, TTerrain *terrain_2, float weight_1, float weight_2, MergeOperation operation)
 merge two terrains, and save the result to the current terrain. More...
 

Static Public Member Functions

static float grid_neighbour_sum_size (TTerrain *terrain, int x, int y, int size)
 
static float grid_neighbour_average_size (TTerrain *terrain, int x, int y, int size)
 

Detailed Description

Perform filtering on a terrain height field.

set or get the terrain data by calling GetTerrainData() function.

Member Enumeration Documentation

§ FlattenOperation

Enumerator
Fill_Op 

Flatten the terrain up to the specified elevation.

ShaveTop_Op 

Flatten the terrain down to the specified elevation.

Flatten_Op 

Flatten the terrain up and down to the specified elevation.

Member Function Documentation

§ Flatten()

void CTerrainFilters::Flatten ( FlattenOperation  flatten_op,
float  elevation,
float  factor,
float  center_x,
float  center_y,
float  radius 
)

Flatten the terrain both up and down to the specified elevation, using using the tightness parameter to determine how much the altered points are allowed to deviate from the specified elevation.

Parameters
elevationthe desired height
factorvalue is between [0,1]. 1 means fully transformed; 0 means nothing is changed
center_xthe center of the affected circle. value in the range [0,1]
center_ythe center of the affected circle.value in the range [0,1]
radiusthe radius of the affected circle.value in the range [0,0.5]

§ GetTerrainData()

TTerrain * CTerrainFilters::GetTerrainData ( )

get the terrain data that is associated with this filter.

The user can read from or write to this terrain data.

§ Merge()

void CTerrainFilters::Merge ( TTerrain terrain_1,
TTerrain terrain_2,
float  weight_1,
float  weight_2,
MergeOperation  operation 
)

merge two terrains, and save the result to the current terrain.

The three terrains are aligned by their center. the input terrain can be the current terrain. The two input terrain must not be normalized.

§ RadialScale()

void CTerrainFilters::RadialScale ( float  center_x,
float  center_y,
float  scale_factor,
float  min_dist,
float  max_dist,
float  smooth_factor,
int  frequency 
)

Note: terrain data should be in normalized space with height in the range [0,1].

Picks a point and scales the surrounding terrain in a circular manner. Can be used to make all sorts of circular shapes. Still needs some work. radial_scale: pick a point (center_x, center_y) and scale the points where distance is mindist<=distance<=maxdist linearly. The formula we'll use for a nice sloping smoothing factor is (-cos(x*3)/2)+0.5.

§ Ramp()

void ParaEngine::CTerrainFilters::Ramp ( float  x1,
float  y1,
float  height1,
float  x2,
float  y2,
float  height2,
float  radius,
float  borderpercentage = 0.5f,
float  factor = 1.0f 
)

create a ramp (inclined slope) from height(x1,y1) to height(x2,y2).

create a ramp : inclined slope LiXizhi 2009.1.30

The ramp's half width is radius. this is usually used to created a slope path connecting a high land with a low land.

Parameters
radiusThe ramp's half width
borderpercentageborderpercentage*radius is how long the ramp boarder is to linearly interpolate with the original terrain. specify 0 for sharp ramp border.
factorin range[0,1]. it is the smoothness to merge with other border heights.Specify 1.0 for a complete merge

Let the point be C (Cx,Cy) and the line be AB (Ax,Ay) to (Bx,By). The length of the line segment AB is L:

L= sqrt( (Bx-Ax)^2 + (By-Ay)^2 ) .Let P be the point of perpendicular projection of C onto AB. Let r be a parameter to indicate P's location along the line containing AB, with the following meaning:

r=0 P = A r=1 P = B r<0 P is on the backward extension of AB r>1 P is on the forward extension of AB 0<r<1 P is interior to ABCompute r with this:

 (Ay-Cy)(Ay-By)-(Ax-Cx)(Bx-Ax)

r = ----------------------------- L^2

Use another parameter s to indicate the location along PC, with the following meaning:

s<0 C is left of AB s>0 C is right of AB s=0 C is on ABCompute s as follows:

  (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)

s = --------------------------— L^2

§ Roughen_Smooth()

void CTerrainFilters::Roughen_Smooth ( bool  roughen,
bool  big_grid,
float  factor 
)

square filter for sharpening and smoothing.

Use neighbour-averaging to roughen or smooth the height field. The factor determines how much of the computed roughening is actually applied to the height field. In it's default invocation, the 4 directly neighboring squares are used to calculate the roughening. If you select big sampling grid, all 8 neighboring cells will be used.

Parameters
roughentrue for sharpening, false for smoothing.
big_gridtrue for 8 neighboring cells, false for 4.
factorvalue is between [0,1]. 1 means fully transformed; 0 means nothing is changed

§ SetConstEdgeHeight()

void CTerrainFilters::SetConstEdgeHeight ( float  fHeight = 0,
int  nSmoothPixels = 7 
)

load height field from file

Parameters
fHeight: height of the edge
nSmoothPixelsthe number of pixels to smooth from the edge of the height field. if this is 0, the original height field will be loaded unmodified. if it is greater than 0, the loaded height field will be smoothed for nSmoothPixels from the edge, where the edge is always fHeight. The smooth function is linear. For example,
  • 0% of original height for the first pixel from the edge
  • 1/nSmoothPixels of original height for the second pixel from the edge. Lerp(1/nSmoothPixels, fheight, currentHeight)
  • 2/nSmoothPixels of original height for the third.Lerp(2/nSmoothPixels, fheight, currentHeight )
  • 100% for the nSmoothPixels-1 pixel

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