My Project
|
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 | |
TTerrain * | GetTerrainData () |
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) |
Perform filtering on a terrain height field.
set or get the terrain data by calling GetTerrainData() function.
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.
elevation | the desired height |
factor | value is between [0,1]. 1 means fully transformed; 0 means nothing is changed |
center_x | the center of the affected circle. value in the range [0,1] |
center_y | the center of the affected circle.value in the range [0,1] |
radius | the radius of the affected circle.value in the range [0,0.5] |
TTerrain * CTerrainFilters::GetTerrainData | ( | ) |
get the terrain data that is associated with this filter.
The user can read from or write to this terrain data.
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.
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.
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.
radius | The ramp's half width |
borderpercentage | borderpercentage*radius is how long the ramp boarder is to linearly interpolate with the original terrain. specify 0 for sharp ramp border. |
factor | in 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
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.
roughen | true for sharpening, false for smoothing. |
big_grid | true for 8 neighboring cells, false for 4. |
factor | value is between [0,1]. 1 means fully transformed; 0 means nothing is changed |
void CTerrainFilters::SetConstEdgeHeight | ( | float | fHeight = 0 , |
int | nSmoothPixels = 7 |
||
) |
load height field from file
fHeight | : height of the edge |
nSmoothPixels | the 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,
|