Heightfield 1.0
Public Member Functions | Static Public Attributes | List of all members
HeightField Class Reference

A simple height field. More...

#include <heightfield.h>

Inheritance diagram for HeightField:
ScalarField2 Array2 Box2 HeightFieldErosion HeightFieldShader

Public Member Functions

 HeightField ()
 Empty.
 
 HeightField (const ScalarField2 &)
 Create a heightfield from a scalar field. More...
 
 HeightField (const Box2 &, const QImage &, const double &=0.0, const double &=256.0 *256.0 - 1.0, bool=true)
 Create a heightfield from an image. More...
 
 HeightField (const Box2 &, int, int, const double &=0.0)
 Create a flat heightfield. More...
 
 HeightField (const Box2 &, int, int, const QVector< double > &)
 Create a heightfield. More...
 
 ~HeightField ()
 Empty.
 
double GetHeight (const Vector2 &) const
 Compute the height at a given position. More...
 
Vector Vertex (const Vector2 &, bool=true) const
 Compute the vertex position on the terrain. More...
 
Vector Vertex (int, int) const
 Compute the vertex corresponding to a given sample. More...
 
QVector< VectorArrayVertexes (const QVector< QPoint > &) const
 Compute the coordinates of a set of points on the grid. More...
 
Vector Normal (const Vector2 &, bool=true) const
 Compute the normal for a given position on the terrain. More...
 
Vector Normal (int, int) const
 Compute the normal at a given sample. More...
 
double Slope (int, int) const
 Compute the slope at a given integer point on the terrain. More...
 
double Slope (const QPoint &, const QPoint &) const
 Compute the slope between two points. More...
 
double AverageSlope (int, int) const
 Compute the average slope at a given integer point on the terrain. More...
 
double Aspect (int, int) const
 Compute the aspect (face orientation) at a given integer point on the terrain. More...
 
double K () const
 Compute the Lipschitz constant of the signed distance field defined as f(x,y,z)=z-h(x,y).
 
void Subdivide (const double &, Random &=Random::R239)
 Refine the terrain. More...
 
ScalarField2 StreamArea () const
 Compute the stream area field of the terrain. More...
 
ScalarField2 StreamAreaWeighted (const double &=2.0) const
 Compute the stream area field of the terrain. More...
 
ScalarField2 StreamAreaSteepest () const
 Compute the stream area field of the terrain. More...
 
ScalarField2 StreamAreaLimited (const double &) const
 Compute the stream area field of the terrain using a limited flow propagation. More...
 
ScalarField2 StreamLength (bool=false) const
 Compute the stream length. More...
 
ScalarField2 StreamSourceElev (bool=false) const
 Return the maximum source elevation of the flows converging to each point in the height field. More...
 
VectorField2 FlowField (ScalarField2 &) const
 Compute the flow field of the terrain. More...
 
ScalarField2 AverageSlope () const
 Compute the average slope field of the terrain.
 
ScalarField2 Slope (bool=false) const
 Compute the maximum slope field of the terrain. More...
 
ScalarField2 Aspect () const
 Compute the aspect field (face orientation) of the terrain.
 
ScalarField2 WetnessIndex (const double &=1.0e-3, bool=false) const
 Compute the wetness index field of the terrain. More...
 
ScalarField2 StreamPower (bool=false) const
 Compute the stream power field of the terrain. More...
 
ScalarField2 StreamPower (double, double) const
 Compute the stream power field of the terrain. More...
 
ScalarField2 ReliefSteepness (const double &) const
 Compute the omni-directional relief and steepness. More...
 
ScalarField2 Peakedness (const double &) const
 Compute the peakedness of a terrain, defined as the percentage of cells in a disk that have lower or equal elevation than the center position. More...
 
ScalarField2 TopographicPositionIndex (const double &r) const
 Compute the TPI, an index that measures how much a cell rises with respect to the mean elevation of a given radius. It is very similar in spirit to Peakedness, but here we obtain a value in m instead of the % of cells below it. More...
 
ScalarField2 LocalVariance (int=3) const
 Compute the local variance. More...
 
ScalarField2 SurfaceRoughness (int=3) const
 Compute the surface roughness. More...
 
ScalarField2 HillslopeAsymmetry (double, double=0, double=45) const
 Compute the hillslope asymmetry map for a given direction. More...
 
ScalarField2 Accessibility (const double &, int=16) const
 Compute the accessibility. More...
 
ScalarField2 Light (const Vector &, bool=false) const
 Compute the direct lighting. More...
 
int FillDepressions ()
 Fills all pits and removes all digital dams from the HeightField. More...
 
int FillDepressions (const double &)
 Modifies the HeightField to guarantee drainage. More...
 
int FillDepressions (ScalarField2 &) const
 Fills all pits and removes all digital dams from the HeightField. More...
 
int FillDepressions (const double &, ScalarField2 &) const
 Modifies the HeightField to guarantee drainage. More...
 
void CompleteBreach ()
 Breach depressions. More...
 
bool Intersect (const Ray &, double &, Vector &, const Box &, const double &, const double &=1.0e8, const double &=1.0e-4) const
 Compute the intersection between a ray and the surface of the heightfield. More...
 
bool Intersect (const Ray &, QVector< double > &, QVector< Vector > &, const Box &, const double &) const
 Compute the intersection between a ray and the surface of the heightfield. More...
 
bool IntersectBox (const Ray &, double &, Vector &, Vector &, const Box &) const
 Compute the intersection between a ray and the surface border of the heightfield. More...
 
double Shade (const Vector &, const QVector< Vector > &, const QVector< double > &, const double &) const
 Shade a vector of the terrain. More...
 
ScalarField2 Sun (const double &, int=5, int=1, int=0, int=12) const
 Compute the average direct lighting from the sun over a year. More...
 
ScalarField2 SelfShadow (const Vector &) const
 Compute the self shadowing map. More...
 
ArrayInteger2 Flow (bool=false) const
 Compute the flow topology. More...
 
ArrayInteger2 Geomorphons (const double &=0.02) const
 Compute the geomorphon index map. More...
 
ArrayInteger2 GeomorphonsTangent (double, double=0.02) const
 Compute the geomorphon index map. More...
 
ArrayInteger2 GeomorphonsAggregated (const double &=0.02) const
 Compute the aggregated geomorphon index map. More...
 
Box GetBox () const
 Get the bounding box of the heightfield. More...
 
double Signed (const Vector &) const
 Compute the signed distance do the heightfield. More...
 
void Scale (const Vector &)
 Scale the height field. More...
 
void Unity ()
 Scale the heightfield so that the compact support should fit within unit box. More...
 
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draw a heightfield. More...
 
QVector< QPoint > Up (int, int) const
 Compute the cells that are uphill of input point. More...
 
QVector< QPoint > Down (int, int) const
 Compute the cells that are downhill of input point. More...
 
int CheckFlowSlope (const QPoint &, FlowStruct &) const
 Compute the flow directions at a given point. More...
 
int CheckFlowSlopeWeighted (const QPoint &, FlowStruct &, const double &=2.0) const
 Compute the flow directions at a given point, using an L2 metric. More...
 
int CheckFlowDirectionsAngle (const QPoint &, const double &, FlowStruct &) const
 Compute the flow directions at a given point. More...
 
Mesh CreateMesh (bool=true, bool=false, const double &=0.0) const
 Create the geometry of the heightfield. More...
 
Mesh CreateMeshSide (const double &=0.0) const
 Create the geometry of the border of the terrain. More...
 
void CreateCubes (Box &, QVector< FrameScaled > &, const double &=-10.0) const
 Create a stack representation of the model. More...
 
void Carve (const CubicCurve &, const double &, const double &)
 Carve the terrain using a cubic curve, whose elevation define the prescribed elevation along the curve. More...
 
void Carve (const QuadricCurve &, const double &, const double &)
 Carve the terrain using a quadric curve, whose elevation define the prescribed elevation along the curve. More...
 
void Carve (const CubicCurveSet &, const double &, const double &)
 Carve the terrain using a piecewise cubic curve, whose elevation define the prescribed elevation along the curve. More...
 
void Carve (const QuadricCurveSet &, const double &, const double &)
 Carve the terrain using a piecewise quadric curve, whose elevation define the prescribed elevation along the curve. More...
 
void Carve (const Segment &, const double &, const double &)
 Carve the terrain using a segment, whose elevation define the prescribed elevation along the curve. More...
 
void Carve (const SmoothDisc2 &, const double &)
 Flatten the scalar field. More...
 
ScalarField2 GradientDistance (const HeightField &) const
 Compute the gradient distance between two heightfields. More...
 
ScalarField2 Sea (const double &=0.0) const
 Compute the water elevation in every cell according to a uniform sea level. More...
 
QVector< double > Cross (const Vector2 &, const Vector2 &, int) const
 Compute the elevation along a segment. More...
 
void SmoothBreachMultiScale (const QVector< double > &)
 Smooth breaching with a given input series. More...
 
void SmoothBreachGeometric (double, double)
 Smooth breaching with a geometric series. More...
 
void SmoothBreachLinear (double)
 Smooth breaching process. More...
 

Static Public Attributes

static const double flat = 1.0e-8
 Small negative epsilon value used in breaching and flow algorithms.
 

Detailed Description

A simple height field.

Constructor & Destructor Documentation

◆ HeightField() [1/4]

HeightField::HeightField ( const ScalarField2 s)

Create a heightfield from a scalar field.

This constructor provides implicit conversion.

Parameters
sScalar field.

◆ HeightField() [2/4]

HeightField::HeightField ( const Box2 box,
const QImage &  image,
const double &  a = 0.0,
const double &  b = 256.0 * 256.0 - 1.0,
bool  grayscale = true 
)
explicit

Create a heightfield from an image.

Parameters
boxRectangle domain of the terrain.
imageElevation image.
a,bMinimum and maximum elevation range.
grayscaleBoolean set to false if the image is provided in color.

◆ HeightField() [3/4]

HeightField::HeightField ( const Box2 box,
int  nx,
int  ny,
const double &  v = 0.0 
)
explicit

Create a flat heightfield.

Parameters
boxRectangle domain of the terrain.
nx,nySamples.
vConstant elevation.

◆ HeightField() [4/4]

HeightField::HeightField ( const Box2 box,
int  nx,
int  ny,
const QVector< double > &  v 
)
explicit

Create a heightfield.

Parameters
boxRectangle domain of the terrain.
nx,nySamples.
vSet of elevation values.

Member Function Documentation

◆ Accessibility()

ScalarField2 HeightField::Accessibility ( const double &  r,
int  n = 16 
) const

Compute the accessibility.

Parameters
rRadius.
nNumber of rays.

◆ ArrayVertexes()

QVector< Vector > HeightField::ArrayVertexes ( const QVector< QPoint > &  p) const

Compute the coordinates of a set of points on the grid.

See also
Array2::ArrayVertexes
Parameters
pSet of point.

◆ Aspect()

double HeightField::Aspect ( int  i,
int  j 
) const

Compute the aspect (face orientation) at a given integer point on the terrain.

Parameters
i,jInteger coordinates

◆ AverageSlope()

double HeightField::AverageSlope ( int  i,
int  j 
) const

Compute the average slope at a given integer point on the terrain.

Simply average the slope in 8 directions.

Parameters
i,jInteger coordinates

◆ Carve() [1/6]

void HeightField::Carve ( const CubicCurve c,
const double &  r,
const double &  b 
)

Carve the terrain using a cubic curve, whose elevation define the prescribed elevation along the curve.

Parameters
cCurve.
rRadius.
bBlending radius.

◆ Carve() [2/6]

void HeightField::Carve ( const CubicCurveSet c,
const double &  r,
const double &  b 
)

Carve the terrain using a piecewise cubic curve, whose elevation define the prescribed elevation along the curve.

Parameters
cCurve.
rRadius.
bBlending radius.

◆ Carve() [3/6]

void HeightField::Carve ( const QuadricCurve c,
const double &  r,
const double &  b 
)

Carve the terrain using a quadric curve, whose elevation define the prescribed elevation along the curve.

Parameters
cCurve.
rRadius.
bBlending radius.

◆ Carve() [4/6]

void HeightField::Carve ( const QuadricCurveSet c,
const double &  r,
const double &  b 
)

Carve the terrain using a piecewise quadric curve, whose elevation define the prescribed elevation along the curve.

Parameters
cCurve.
rRadius.
bBlending radius.

◆ Carve() [5/6]

void HeightField::Carve ( const Segment c,
const double &  r,
const double &  b 
)

Carve the terrain using a segment, whose elevation define the prescribed elevation along the curve.

Parameters
sSegment.
rRadius.
bBlending radius.

◆ Carve() [6/6]

void HeightField::Carve ( const SmoothDisc2 disc,
const double &  e 
)

Flatten the scalar field.

Parameters
discSmooth disc reion.
eTarget elevation.

◆ CheckFlowDirectionsAngle()

int HeightField::CheckFlowDirectionsAngle ( const QPoint &  p,
const double &  s,
FlowStruct &  flow 
) const

Compute the flow directions at a given point.

Parameters
pPoint.
sSlope.
flowFlow information.

◆ CheckFlowSlope()

int HeightField::CheckFlowSlope ( const QPoint &  p,
FlowStruct &  flow 
) const

Compute the flow directions at a given point.

Compute both the flow directions using an Lp metric, and the steepest slope.

Parameters
pPoint.
flowFlow information.

◆ CheckFlowSlopeWeighted()

int HeightField::CheckFlowSlopeWeighted ( const QPoint &  p,
FlowStruct &  flow,
const double &  power = 2.0 
) const

Compute the flow directions at a given point, using an L2 metric.

Parameters
pPoint.
flowFlow information.
powerPower, set to 1.0 for diffusive flow routing, converges to steepest slope as power increases to infinity.

◆ CompleteBreach()

void HeightField::CompleteBreach ( )

Breach depressions.

Depression breaching drills a path from a depression's pit cell (its lowest point) along the least-cost (Priority-Flood) path to the nearest cell outside the depression to have the same or lower elevation.

See https://rbarnes.org/

See https://github.com/r-barnes/richdem

See https://github.com/r-barnes/richdem/blob/master/include/richdem/depressions/Lindsay2016.hpp

Author
John Lindsay, implementation by Richard Barnes (rbarn.nosp@m.es@u.nosp@m.mn.ed.nosp@m.u).

◆ CreateCubes()

void HeightField::CreateCubes ( Box cube,
QVector< FrameScaled > &  frames,
const double &  z = -10.0 
) const

Create a stack representation of the model.

Stacks are defined as scaled boxes.

Parameters
cubeReference cube.
framesSet of instances.
zBase elevation.

◆ CreateMesh()

Mesh HeightField::CreateMesh ( bool  surface = true,
bool  side = false,
const double &  z = 0.0 
) const

Create the geometry of the heightfield.

Parameters
surfaceGenerate the surface elevation of the heightfield.
sideGenerate the side of the heightfield.
zThe height of the base of the block.

◆ CreateMeshSide()

Mesh HeightField::CreateMeshSide ( const double &  z = 0.0) const

Create the geometry of the border of the terrain.

Parameters
zThe height of the base of the block.

◆ Cross()

QVector< double > HeightField::Cross ( const Vector2 a,
const Vector2 b,
int  n 
) const

Compute the elevation along a segment.

Parameters
a,bSegment.
nNumber of samples.

◆ Down()

QVector< QPoint > HeightField::Down ( int  x,
int  y 
) const

Compute the cells that are downhill of input point.

Parameters
x,yInteger coordinates of the point.

◆ Draw()

void HeightField::Draw ( QGraphicsScene &  scene,
const QPen &  pen = QPen(),
const QBrush &  brush = QBrush() 
) const

Draw a heightfield.

Parameters
sceneGraphics scene.
penThe pen.
brushThe brush.

◆ FillDepressions() [1/4]

int HeightField::FillDepressions ( )

Fills all pits and removes all digital dams from the HeightField.

See also
FillDepressions(ScalarField2&) const
Author
Mathieu Gaillard
Returns
The number of cells where a significant alteration of the DEM has occurred.

◆ FillDepressions() [2/4]

int HeightField::FillDepressions ( const double &  eps)

Modifies the HeightField to guarantee drainage.

See also
FillDepressions(const double&, ScalarField2&) const
Author
Mathieu Gaillard
Parameters
epsThe minimal elevation difference between two cells.
Returns
The number of cells where a significant alteration of the DEM has occurred.

◆ FillDepressions() [3/4]

int HeightField::FillDepressions ( const double &  eps,
ScalarField2 depression_field 
) const

Modifies the HeightField to guarantee drainage.

Algorithm: Priority-flood: An optimal depression-filling and watershed-labeling algorithm for digital elevation models. Barnes, R., Lehman, C., Mulla, D., 2014.

This version of Priority-Flood starts on the edges of the DEM and then works its way inwards using a priority queue to determine the lowest cell which has a path to the edge. The neighbours of this cell are added to the priority queue if they are higher. If they are lower, then their elevation is increased by a small amount to ensure that they have a drainage path and they are added to a "pit" queue which is used to flood pits. Cells which are higher than a pit being filled are added to the priority queue. In this way, pits are filled without incurring the expense of the priority queue.

The values to fill the depressions are added to the depression field.

The depression field should have the exact same size as the HeightField. If the given depression field does not have the exact same size as the height field, returns the total number of vertices in the heightfield.

To be sure that the height field is never flat, elevations are always increased by std::nextafter(elevation) + eps. Thus, even if eps == 0, the terrain is never flat.

Warning, because the method is const it is not recommended to use it like that

// Not recommended, although it works.
hf.FillDepressions(0.0, hf);
Author
Mathieu Gaillard
Parameters
epsThe minimal elevation difference between two cells.
depression_fieldA scalar field in which the values to fill depressions are added
Returns
The number of cells where a significant alteration of the DEM has occurred.

◆ FillDepressions() [4/4]

int HeightField::FillDepressions ( ScalarField2 d) const

Fills all pits and removes all digital dams from the HeightField.

Algorithm: Priority-flood: An optimal depression-filling and watershed-labeling algorithm for digital elevation models. Barnes, R., Lehman, C., Mulla, D., 2014.

Priority-Flood starts on the edges of the DEM and then works its way inwards using a priority queue to determine the lowest cell which has a path to the edge. The neighbours of this cell are added to the priority queue if they are higher. If they are lower, they are raised to the elevation of the cell adding them, thereby filling in pits. The neighbors are then added to a "pit" queue which is used to flood pits. Cells which are higher than a pit being filled are added to the priority queue. In this way, pits are filled without incurring the expense of the priority queue.

The values to fill the depressions are added to the depression field.

The depression field should have the exact same size as the HeightField. If the given depression field does not have the exact same size as the height field, returns the total number of vertices in the heightfield.

Warning, because the method is const it is not recommended to use it like that

// Not recommended, although it works.
hf.FillDepressions(hf);
Author
Mathieu Gaillard
Parameters
dA scalar field in which the values to fill depressions are added
Returns
The number of cells where a significant alteration of the DEM has occurred.

◆ Flow()

ArrayInteger2 HeightField::Flow ( bool  steep = false) const

Compute the flow topology.

Parameters
steepFlag, set to true if we rely on the steepest slope, false for multiple convergent and divergent flows.

◆ FlowField()

VectorField2 HeightField::FlowField ( ScalarField2 stream) const

Compute the flow field of the terrain.

The direction if the average downhill flow.

This function differs slightly from HeightField::StreamArea(). Pits have a null flow vector, although the stream area is a local maximum.

The stream area is computed as a fraction of cells, independtly of the surface area of a cell.

Parameters
streamReturned stream area;

◆ Geomorphons()

ArrayInteger2 HeightField::Geomorphons ( const double &  t = 0.02) const

Compute the geomorphon index map.

Geomorphon classify cells into ten categories: flat, peak, ridge, shoulder, hollow, slope, spur, footslope, valley, and pit.

Parameters
tSlope threshold.

◆ GeomorphonsAggregated()

ArrayInteger2 HeightField::GeomorphonsAggregated ( const double &  t = 0.02) const

Compute the aggregated geomorphon index map.

Aggregation classifies into only five categories: flat (flat), ridges (ridge, peak, spur, shoulder), slope (slope), valley (valley, pit, hollow) and foot slope (foot slope).

Parameters
tSlope threshold.

◆ GeomorphonsTangent()

ArrayInteger2 HeightField::GeomorphonsTangent ( double  maxDist,
double  flatTangent = 0.02 
) const

Compute the geomorphon index map.

Geomorphon classify cells into ten categories: flat, peak, ridge, shoulder, hollow, slope, spur, footslope, valley, and pit.

Parameters
maxDistmaximum ray traversal distance.
flatTangentthreshold for considering a ray angle as flat.

◆ GetBox()

Box HeightField::GetBox ( ) const

Get the bounding box of the heightfield.

Note that although this function has the same name as Array2::GetBox(), it computes the minimum and maximum elevation of the terrain (computationally intensive).

See also
Array2::GetBox()

◆ GetHeight()

double HeightField::GetHeight ( const Vector2 p) const
inline

Compute the height at a given position.

Parameters
pPoint.

◆ GradientDistance()

ScalarField2 HeightField::GradientDistance ( const HeightField h) const

Compute the gradient distance between two heightfields.

Parameters
hSecond heightfield.

◆ HillslopeAsymmetry()

ScalarField2 HeightField::HillslopeAsymmetry ( double  km,
double  direction = 0,
double  tolerance = 45 
) const

Compute the hillslope asymmetry map for a given direction.

Poulos et al 2012. Hillslope asymmetry maps reveal widespread, multi-scale organization

The authors define hillsope asymmetry as the difference in median slope between slopes of opposite orientation inside an area.

NOTE: I used average slopes instead of median. First, for a reason of efficiency. Second, it also makes more sense in my opinion. In any case, results visually very similar. It is possible to change the behavior in the code, just set MEDIAN_ASYMMETRY = true

Parameters
kmSide length of area in which analysis is performed.
Directionangle (in degrees, 0 is +X).
Tolerancehow much we can deviate from this angle.
Author
Oscar Argudo

◆ Intersect() [1/2]

bool HeightField::Intersect ( const Ray ray,
double &  t,
Vector q,
const Box box,
const double &  k,
const double &  length = 1.0e8,
const double &  epsilon = 1.0e-4 
) const

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

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.
tReturned distance along the ray.
boxBox where intersection will be computed.
qReturned intersection point.
kLipschitz constant.
lengthMaximum distance along the ray.
epsilonMinimum stepping distance.

◆ Intersect() [2/2]

bool HeightField::Intersect ( const Ray ray,
QVector< double > &  tv,
QVector< Vector > &  q,
const Box box,
const double &  k 
) const

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

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

Parameters
rayThe ray.
tvReturned distance along the ray.
boxBox where intersection will be computed.
qReturned intersection point.
kLipschitz constant.

◆ IntersectBox()

bool HeightField::IntersectBox ( const Ray ray,
double &  t,
Vector p,
Vector n,
const Box box 
) const

Compute the intersection between a ray and the surface border of the heightfield.

Parameters
rayThe ray.
tDistance along the ray.
boxBox where intersection will be computed.
pReturned intersection point.
nReturned normal.

◆ Light()

ScalarField2 HeightField::Light ( const Vector u,
bool  cosine = false 
) const

Compute the direct lighting.

Parameters
uLight direction.
cosineBoolean, set to true to use scalar product between normal and light, false to use (1+c)/2.

◆ LocalVariance()

ScalarField2 HeightField::LocalVariance ( int  w = 3) const

Compute the local variance.

Woodcock and Strahler 1987. The factor of scale in remote sensing. Dragut et al. 2011. Local variance for multi-scale analysis in geomorphometry.

Local variance is defined as the standard deviation of a window centered around the cell.

Compute the local variance of every cell and take the average over all the domain.

Authors plot the mean local variance with respect to image scale, and show that peaks in this graph occur at 1/2 to 3/4 the size of objects in the image, so it could be used as a scale indicator.

Parameters
wWindow size (authors recommend 3).
Author
Oscar Argudo

◆ Normal() [1/2]

Vector HeightField::Normal ( const Vector2 p,
bool  triangular = true 
) 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 HeightField::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.

◆ Peakedness()

ScalarField2 HeightField::Peakedness ( const double &  r) const

Compute the peakedness of a terrain, defined as the percentage of cells in a disk that have lower or equal elevation than the center position.

See Llobera 2001, Building Past Landscape Perception With GIS: Understanding Topographic Prominence. Although the author calls it prominence, it is not the same definition as used in orometry for peak prominence.

See Arge et al. 2013: Algorithms for Computing Prominence on Grid Terrains for faster implementations.

Parameters
rRadius of the disk (we actually use a squared window).
Author
Oscar Argudo

◆ ReliefSteepness()

ScalarField2 HeightField::ReliefSteepness ( const double &  r) const

Compute the omni-directional relief and steepness.

See Earl and Metzler 2015, Cloud-Capped Towers: Capturing Terrain Characteristics Using Topographic Functionals.

From a theoretical point of view, ORS is the value that results from convergence when we integrate all distances. ORS monotonically increases as we make this cut-off bigger, since the function we integrate is always positive. From my experience (and by definition) after only a few km of distance 10-20, the value is already a good approximation but also, different radius cut-off highlight different interesting properties. If we use a small radius, those points with a very steep edge nearby or even needle-shaped secondary small peaks will have large values of ORS, more than other bigger but gentler peaks. When the radius increases, bigger peaks shadow them with larger ORS values.

Parameters
rRadius for cutting the computation at some point.
Author
Oscar Argudo

◆ Scale()

void HeightField::Scale ( const Vector s)

Scale the height field.

The domain is scaled using the x and y components of the scaling vector, whereas the heights of the heightfield are scaled using the z component.

Parameters
sScaling factor.

◆ Sea()

ScalarField2 HeightField::Sea ( const double &  height = 0.0) const

Compute the water elevation in every cell according to a uniform sea level.

Returns
The amount of water in every cell.

◆ SelfShadow()

ScalarField2 HeightField::SelfShadow ( const Vector light) const

Compute the self shadowing map.

Parameters
lightLight direction.

◆ Shade()

double HeightField::Shade ( const Vector p,
const QVector< Vector > &  lights,
const QVector< double > &  intensity,
const double &  sum 
) const

Shade a vector of the terrain.

Parameters
pTerrain coordinates.
lightsSet of lights.
intensitySet of light intensities.
sumSum.

◆ Signed()

double HeightField::Signed ( const Vector p) const

Compute the signed distance do the heightfield.

This function uses ScalarField2::BiCubicValue to compute the elevation.

The volume delimited by the heightfield is embedded an infinite vertical box.

Parameters
pPoint.

◆ Slope() [1/3]

ScalarField2 HeightField::Slope ( bool  a = false) const

Compute the maximum slope field of the terrain.

Simply compute the norm of the gradient.

This function may be used to perform hill-slope erosion simulation.

Parameters
aBoolean, use average slope if set to true, and slope otherwize.
See also
(), Slope(), AverageSlope(), GradientNorm()

◆ Slope() [2/3]

double HeightField::Slope ( const QPoint &  pa,
const QPoint &  pb 
) const

Compute the slope between two points.

Parameters
pa,pbPoints.

◆ Slope() [3/3]

double HeightField::Slope ( int  i,
int  j 
) const

Compute the slope at a given integer point on the terrain.

This is a convenience function corresponding to the following piece of code:

double s=Norm(heightfield.Gradient(i, j));
Parameters
i,jInteger coordinates

◆ SmoothBreachGeometric()

void HeightField::SmoothBreachGeometric ( double  r,
double  a 
)

Smooth breaching with a geometric series.

Parameters
rRadius, breaching will be performed at the corresponding resolution.
aAttenuation.
Author
Hugo Schott

◆ SmoothBreachLinear()

void HeightField::SmoothBreachLinear ( double  r)

Smooth breaching process.

Parameters
rRadius, breaching will be performed at the corresponding resolution with linear attenuation.
Author
Hugo Schott

◆ SmoothBreachMultiScale()

void HeightField::SmoothBreachMultiScale ( const QVector< double > &  ri)

Smooth breaching with a given input series.

Parameters
riSet of radii, breaching will be performed at the corresponding resolutions.
Author
Hugo Schott

◆ StreamArea()

ScalarField2 HeightField::StreamArea ( ) const

Compute the stream area field of the terrain.

The stream area is computed as a fraction of cells, independtly of the surface area of a cell.

◆ StreamAreaLimited()

ScalarField2 HeightField::StreamAreaLimited ( const double &  r) const

Compute the stream area field of the terrain using a limited flow propagation.

Parameters
rFlow propagation range, this function is the same as HeightField::StreamArea() if range is infinitely large.
See also
HeightField::StreamArea()

◆ StreamAreaSteepest()

ScalarField2 HeightField::StreamAreaSteepest ( ) const

Compute the stream area field of the terrain.

See also
HeightField::StreamArea()

◆ StreamAreaWeighted()

ScalarField2 HeightField::StreamAreaWeighted ( const double &  power = 2.0) const

Compute the stream area field of the terrain.

The stream area is computed as a fraction of cells, independtly of the surface area of a cell.

Parameters
powerPower.

◆ StreamLength()

ScalarField2 HeightField::StreamLength ( bool  steepest = false) const

Compute the stream length.

The stream length is computed, for all cells, as the maximum distance to a spring, which are the peaks.

◆ StreamPower() [1/2]

ScalarField2 HeightField::StreamPower ( bool  a = false) const

Compute the stream power field of the terrain.

The algorithm works as follows: first compute the stream area for every terrain sample, and then compute the stream power index.

Parameters
aBoolean, use average slope if set to true, and slope otherwize.

◆ StreamPower() [2/2]

ScalarField2 HeightField::StreamPower ( double  m,
double  n 
) const

Compute the stream power field of the terrain.

The algorithm works as follows: first compute the stream area for every terrain sample, and then compute the stream power index.

Parameters
m,nExponent for the stream area and slope, n should be twice as m.

◆ StreamSourceElev()

ScalarField2 HeightField::StreamSourceElev ( bool  steepest = false) const

Return the maximum source elevation of the flows converging to each point in the height field.

Parameters
steepestIf true, uses D8 routing algorithm. Otherwise, MFD

◆ Subdivide()

void HeightField::Subdivide ( const double &  e,
Random r = Random::R239 
)

Refine the terrain.

This function subdivides the samples and uses a smooth interpolation. A random elevation may be added to the samples.

Parameters
eAmplitude of the random elevation added to the samples.
rRandom number generator.

◆ Sun()

ScalarField2 HeightField::Sun ( const double &  latitude,
int  daystep = 5,
int  hourstep = 1,
int  dayoffset = 0,
int  houroffset = 12 
) const

Compute the average direct lighting from the sun over a year.

Parameters
latitudeLatitude of the terrain, longitude is set to 0.0.

◆ SurfaceRoughness()

ScalarField2 HeightField::SurfaceRoughness ( int  w = 3) const

Compute the surface roughness.

Lindsay et al 2019. Scale-optimized surface roughness for topographic analysis.

The authors associate surface normals dispersion to roughness, a measure of texture complexity. In particular, they measure the spherical standard deviation in a window w × w, i.e. the angular spread of the normal directions in the window. It will be 0 for flat and inclined planes, and increase with surface texture complexity.

They also propose to remove lower frequencies by doing a gaussian low-pass filter on the DEM, to obtain a signature that depends only on current scale (otherwise, it increases monotonically with w).

Parameters
wWindow size.
Author
Oscar Argudo

◆ TopographicPositionIndex()

ScalarField2 HeightField::TopographicPositionIndex ( const double &  r) const

Compute the TPI, an index that measures how much a cell rises with respect to the mean elevation of a given radius. It is very similar in spirit to Peakedness, but here we obtain a value in m instead of the % of cells below it.

This function is widely used (or was) to classify landforms, and it is integrated in many GIS packages.

See Weiss 2001: Topographic position and landforms analysis (poster) And Wilson and Gallant 2000: Primary Topographic Attributes (chapter 3 in "Terrain Analysis: Principles and Applications")

Parameters
rRadius of the disk (we actually use a squared window).
Author
Oscar Argudo

◆ Unity()

void HeightField::Unity ( )

Scale the heightfield so that the compact support should fit within unit box.

Centers the terrain and scales it.

◆ Up()

QVector< QPoint > HeightField::Up ( int  x,
int  y 
) const

Compute the cells that are uphill of input point.

Parameters
x,yInteger coordinates of the point.

◆ Vertex() [1/2]

Vector HeightField::Vertex ( const Vector2 p,
bool  triangular = true 
) const

Compute the vertex position on the terrain.

Parameters
pPoint.
triangularBoolean, use triangular interpolation if set to true, bilinear interpolation otherwize.

◆ Vertex() [2/2]

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

Compute the vertex corresponding to a given sample.

Parameters
i,jInteger coordinates of the sample.

◆ WetnessIndex()

ScalarField2 HeightField::WetnessIndex ( const double &  c = 1.0e-3,
bool  a = false 
) const

Compute the wetness index field of the terrain.

The algorithm works as follows: first compute the stream area for every terrain sample, and then compute the wetness index.

Note that the wetness index is defined as ln ( A / s ) where s is the slope, however the definition does not work well for small slopes, therefore the implementation defines the wetness index as ln ( A / ( e + s ) ), where e is 0.001.

Parameters
cCoefficent for slope factor, if set to 0 the function will compute the logarithm of the drainage area.
aBoolean, use average slope if set to true, and slope otherwize.
See also
Slope(), AverageSlope()