Heightfield 1.0
Public Member Functions | Protected Attributes | List of all members
LayerStack Class Reference

This class implements a layered heightfield. More...

#include <layers.h>

Inheritance diagram for LayerStack:
HeightFieldSediment Array2 Box2 LayerFieldErosion

Public Member Functions

 LayerStack ()
 Create an empty terrain.
 
 LayerStack (const Box2 &, int, int)
 Create a terrain with different material layers. More...
 
 LayerStack (const ScalarField2 &)
 Create terrain. More...
 
 LayerStack (const ScalarField2 &, const ScalarField2 &, const ScalarField2 &, const ScalarField2 &, const ScalarField2 &, const ScalarField2 &, const ScalarField2 &, const ScalarField2 &)
 Create a layered terrain model. More...
 
 ~LayerStack ()
 Empty.
 
void Subdivide ()
 Double the resolution of the terrain.
 
Box GetBox () const
 Compute the bounding box of the terrain. More...
 
double Vegetation (const Vector2 &) const
 Return the vegetation density. More...
 
double Vegetation (int, int) const
 Return the vegetation density. More...
 
double Grass (const Vector2 &) const
 Return the grass elevation. More...
 
double Grass (int, int) const
 Return the grass elevation. More...
 
double Water (const Vector2 &) const
 Return the water elevation. More...
 
double Water (int, int) const
 Return the water elevation. More...
 
double Rocks (const Vector2 &) const
 Return the rocks elevation. More...
 
double Rocks (int, int) const
 Return the rocks elevation. More...
 
ScalarField2GetRock ()
 Access to the rock scalar field.
 
ScalarField2GetWater ()
 Access to the water scalar field.
 
ScalarField2GetSnow ()
 Access to the snow scalar field.
 
ScalarField2GetGrass ()
 Access to the grass scalar field.
 
ScalarField2GetVegetation ()
 Access to the vegetation scalar field.
 
ScalarField2GetAlpha ()
 Access to the alpha scalar field.
 
HeightField GetHeightField (bool=true, bool=true) const
 Convert the layer model into a simple heightfield. More...
 
void UpdateHeightField (HeightField &, const QRect &=QRect(), bool=true, bool=true) const
 Convert the layer model into a simple heightfield. More...
 
bool Intersect (const Ray &, double &, Vector &) const
 Compute the intersection between a ray and the surface of the terrain. More...
 
LayerStack Crop (const QPoint &, const QPoint &) const
 Crops a rectangular region in the terrain. More...
 
void WaterFlood (const double &)
 Fill the terrain with a water body. More...
 
void WaterFlood (const Vector2 &, const double &)
 Flood fills a region with water. More...
 
void WaterDry (const Vector2 &)
 Dries a connex region, removing water using a flood fill algorithm. More...
 
void SandOverall (const double &)
 Add sand over the terrain. More...
 
void RockOverall (const double &)
 Add rock over the terrain. More...
 
QVector< VectorGetTrees () const
  Warning
 
Vector Vertex (int, int) const
 Compute the vertex corresponding to a given sample. More...
 
Vector Vertex (const Vector2 &) const
 Compute the elevation of a point, which is the sum of the bedrock, sand and rocks layers. More...
 
Vector Normal (int, int) const
 Compute the normal at a given sample. More...
 
Color GetColorVector (int, int) const
 Compute the vertex corresponding to a given sample. More...
 
double Height (const Vector2 &) const
 Compute the elevation of a point, which is the sum of the bedrock, sand and rocks layers. More...
 
Vector Normal (const Vector2 &, bool=false) const
 Compute the normal for a given position on the terrain. More...
 
void Scale (const double &)
 Scale the layer-field. More...
 
void Translate (const Vector2 &)
 Translate the layer-field. More...
 
void Save (const QString &) const
 Save structure as a set of images. More...
 
Mesh CreateWaterGeometry () const
 Create the geometry of the water on the terrain.
 
void CreateCubes (Box &, QVector< FrameScaled > &, QVector< FrameScaled > &, QVector< FrameScaled > &, QVector< FrameScaled > &, QVector< FrameScaled > &, QVector< FrameScaled > &, bool=true, bool=true, bool=true, bool=true, bool=true, bool=true) const
 Create a material stack representation of the model. More...
 
- Public Member Functions inherited from HeightFieldSediment
 HeightFieldSediment ()
 Create an empty terrain.
 
 HeightFieldSediment (const Box2 &, int, int)
 Create a flat terrain with no sediments. More...
 
 HeightFieldSediment (const ScalarField2 &)
 Create a terrain with no sediments from an elevation field. More...
 
 HeightFieldSediment (const ScalarField2 &, const ScalarField2 &)
 Create a terrain with sediments. More...
 
 ~HeightFieldSediment ()
 Empty.
 
Array2 GetArray () const
 Return the array representing the grid domain.
 
ScalarField2 AlphaBlend () const
 Compute the alpha blending between sand and bedrock.
 
HeightField GetHeightField () const
 Convert the layered model into a simple heightfield.
 
void SmoothRock (int=1)
 Smoothes the bedrock layer. More...
 
HeightFieldGetBedrock ()
 Access to the bedrock scalar field.
 
ScalarField2GetSand ()
 Access to the sand scalar field.
 
double Bedrock (const Vector2 &) const
 Compute the bedrock elevation. More...
 
double Bedrock (int, int) const
 Return the bedrock elevation. More...
 
double Sand (const Vector2 &) const
 Compute the sand thickness. More...
 
double Sand (int, int) const
 Return the sand thickness. More...
 
void Subdivide ()
 Double the resolution of the terrain.
 
void BedrockFlatten (const Vector2 &, const double &, const double &=0.25)
 Flatten the bedrock around the target point. More...
 
void BedrockLevel (const Vector2 &, const double &, const double &)
 Level the bedrock to the target elevation. More...
 
void BedrockUplift (const double &)
 Modify the bedrock using a uniform uplift. More...
 
void BedrockUplift (const ScalarField2 &)
 Uplift. More...
 
void ThermalImpact (const double &)
 Globally transform a thin layer of bedrock into sediments. More...
 
void ThermalImpactSlope (const double &)
 Globally transform a thin layer of bedrock into sediments. More...
 
void Stabilize (const double &, const double &=0.84)
 Stabilizes sediments over the entire terrain. More...
 
bool StabilizeStep (int, int, const double &, ScalarField2 &)
 Perform a stabilization step on the given layered cell. More...
 
int CheckFlowSlope (const QPoint &, FlowStruct &) const
 Compute the flow directions at a given point. More...
 
int CheckFlowDirectionsAngle (const QPoint &, const double &, QPoint *, double *, double *, double *) const
 Compute the flow directions at a given point. More...
 
bool SelectFlowDirection (const QPoint &, QPoint &, double &) const
 Select flow direction. More...
 
void TRUC (const QPoint &q, const double &slope, const double &V_T, double &V_T_S, double &V_E_R, double &V_E_S, double &V_D_S)
 Compute eroded material.
 

Protected Attributes

ScalarField2 rocks
 Rocks.
 
ScalarField2 water
 Water.
 
ScalarField2 grass
 Grass.
 
ScalarField2 vegetation
 Vegetation.
 
ScalarField2 snow
 Snow.
 
ScalarField2 alpha
 Alpha.
 
- Protected Attributes inherited from HeightFieldSediment
HeightField bedrock
 Bedrock.
 
ScalarField2 sand
 Sand, i.e., sediments.
 

Additional Inherited Members

- Protected Member Functions inherited from HeightFieldSediment
void Evaporate (const double &, const double &, double &, double &, double &)
 Evaporate some water from the droplet.
 

Detailed Description

This class implements a layered heightfield.

Constructor & Destructor Documentation

◆ LayerStack() [1/3]

LayerStack::LayerStack ( const Box2 box,
int  x,
int  y 
)
explicit

Create a terrain with different material layers.

Parameters
x,ySubdivision of the terrain.
boxDomain.

◆ LayerStack() [2/3]

LayerStack::LayerStack ( const ScalarField2 b)
explicit

Create terrain.

Parameters
bBedrock layer.

◆ LayerStack() [3/3]

LayerStack::LayerStack ( const ScalarField2 bedrock,
const ScalarField2 rocks,
const ScalarField2 sand,
const ScalarField2 water,
const ScalarField2 grass,
const ScalarField2 vegetation,
const ScalarField2 snow,
const ScalarField2 alpha 
)
explicit

Create a layered terrain model.

Parameters
bedrock,rocks,sand,water,grass,vegetation,snow,alphaSet of layers.

Member Function Documentation

◆ CreateCubes()

void LayerStack::CreateCubes ( Box cube,
QVector< FrameScaled > &  bedrockcubes,
QVector< FrameScaled > &  rockscubes,
QVector< FrameScaled > &  sandcubes,
QVector< FrameScaled > &  watercubes,
QVector< FrameScaled > &  vegetationcubes,
QVector< FrameScaled > &  grasscubes,
bool  b = true,
bool  r = true,
bool  s = true,
bool  w = true,
bool  v = true,
bool  g = true 
) const

Create a material stack representation of the model.

Parameters
cubeDomain.
bedrockcubes,rockscubes,sandcubes,watercubes,vegetationcubes,grasscubesSet of cubes.

Stacks are defined as scaled boxes, with a different box for every material.

Parameters
b,r,s,w,v,gBooleans defining whether the corresponding material should be generated.

◆ Crop()

LayerStack LayerStack::Crop ( const QPoint &  a,
const QPoint &  b 
) const

Crops a rectangular region in the terrain.

Parameters
a,bRectangular region.

◆ GetBox()

Box LayerStack::GetBox ( ) const

Compute the bounding box of the terrain.

This function may be expensive as it finds the minimum and maximum elevations of the terrains.

◆ GetColorVector()

Color LayerStack::GetColorVector ( int  i,
int  j 
) const

Compute the vertex corresponding to a given sample.

Parameters
i,jInteger coordinates of the sample.

◆ GetHeightField()

HeightField LayerStack::GetHeightField ( bool  r = true,
bool  s = true 
) const

Convert the layer model into a simple heightfield.

Rock and sand layers may be added to bedrock according to Boolean parameters.

Parameters
rRock flag.
sSand flag.

◆ Grass() [1/2]

double LayerStack::Grass ( const Vector2 p) const
inline

Return the grass elevation.

Parameters
pPoint.

◆ Grass() [2/2]

double LayerStack::Grass ( int  i,
int  j 
) const
inline

Return the grass elevation.

Parameters
i,jInteger coordinates.

◆ Height()

double LayerStack::Height ( const Vector2 p) const

Compute the elevation of a point, which is the sum of the bedrock, sand and rocks layers.

Parameters
pPoint.

◆ Intersect()

bool LayerStack::Intersect ( const Ray ray,
double &  t,
Vector q 
) const

Compute the intersection between a ray and the surface of the terrain.

The algorithm uses a ray marching approach, therefore this function may require many iterations and the resulting intersection may not be accurate.

Parameters
rayThe ray.
tIntersection depth.
qIntersection point.

◆ Normal() [1/2]

Vector LayerStack::Normal ( const Vector2 p,
bool  triangular = false 
) const

Compute the normal for a given position on the terrain.

Note that this function may be expensive to compute.

Parameters
pPoint.
triangularBoolean, use triangle normals if set to true, bilinear interpolation of normals at vertices otherwize.

◆ Normal() [2/2]

Vector LayerStack::Normal ( int  i,
int  j 
) const

Compute the normal at a given sample.

This function uses the weighted sum (area) of the normals of the triangles sharing the point on the grid. The returned vector is normalized.

Parameters
i,jInteger coordinates of the sample.

◆ RockOverall()

void LayerStack::RockOverall ( const double &  s)

Add rock over the terrain.

Parameters
sRock thickness.

◆ Rocks() [1/2]

double LayerStack::Rocks ( const Vector2 p) const
inline

Return the rocks elevation.

Parameters
pPoint.

◆ Rocks() [2/2]

double LayerStack::Rocks ( int  i,
int  j 
) const
inline

Return the rocks elevation.

Parameters
i,jInteger coordinates.

◆ SandOverall()

void LayerStack::SandOverall ( const double &  s)

Add sand over the terrain.

Parameters
sSand thickness.

◆ Save()

void LayerStack::Save ( const QString &  name) const

Save structure as a set of images.

Parameters
nameName.

◆ Scale()

void LayerStack::Scale ( const double &  s)

Scale the layer-field.

Parameters
sScaling factor.

◆ Translate()

void LayerStack::Translate ( const Vector2 t)

Translate the layer-field.

Parameters
tTranslation vector.

◆ UpdateHeightField()

void LayerStack::UpdateHeightField ( HeightField e,
const QRect &  a = QRect(),
bool  r = true,
bool  s = true 
) const

Convert the layer model into a simple heightfield.

Rock and sand layers may be added to bedrock according to Boolean parameters.

Parameters
eReturned updated elevation.
aArea.
r,sRock and flags.

◆ Vegetation() [1/2]

double LayerStack::Vegetation ( const Vector2 p) const
inline

Return the vegetation density.

Parameters
pPoint.

◆ Vegetation() [2/2]

double LayerStack::Vegetation ( int  i,
int  j 
) const
inline

Return the vegetation density.

Parameters
i,jInteger coordinates.

◆ Vertex() [1/2]

Vector LayerStack::Vertex ( const Vector2 p) const

Compute the elevation of a point, which is the sum of the bedrock, sand and rocks layers.

Parameters
pPoint.

◆ Vertex() [2/2]

Vector LayerStack::Vertex ( int  i,
int  j 
) const

Compute the vertex corresponding to a given sample.

Parameters
i,jInteger coordinates of the sample.

◆ Water() [1/2]

double LayerStack::Water ( const Vector2 p) const
inline

Return the water elevation.

Parameters
pPoint.

◆ Water() [2/2]

double LayerStack::Water ( int  i,
int  j 
) const
inline

Return the water elevation.

Parameters
i,jInteger coordinates.

◆ WaterDry()

void LayerStack::WaterDry ( const Vector2 p)

Dries a connex region, removing water using a flood fill algorithm.

Parameters
pStarting point where the drying process starts.

◆ WaterFlood() [1/2]

void LayerStack::WaterFlood ( const double &  height)

Fill the terrain with a water body.

This function also updates the vegetation and snow layers.

Parameters
heightWater height.

◆ WaterFlood() [2/2]

void LayerStack::WaterFlood ( const Vector2 p,
const double &  h 
)

Flood fills a region with water.

Parameters
pStarting point where the flood starts.
hWater height.