HighMap library (C++)
Loading...
Searching...
No Matches
hmap::DrainageBasin Class Reference

Represents a drainage basin network constructed on a 3D terrain mesh. More...

#include <drainage_basin.hpp>

Public Member Functions

 DrainageBasin (std::vector< glm::vec3 > xyz_)
 Construct a new Drainage Basin object.
 
const std::vector< glm::vec3 > & get_xyz () const
 Get the 3D coordinates of the terrain vertices.
 
size_t size () const
 Get the number of vertices in the basin.
 
void to_csv (const std::string &filename) const
 Export the drainage basin data to a CSV file.
 
const TerrainTriMeshget_mesh () const
 Get the underlying terrain tri mesh (const).
 
TerrainTriMeshget_mesh ()
 Get the underlying terrain tri mesh (non-const).
 
std::vector< float > compute_vertex_areas () const
 Compute the area of each vertex in the mesh.
 
void remap (float zmin=0.f, float zmax=1.f)
 Remap the elevation (z) values of the mesh vertices to a target range.
 
void compute_receivers ()
 Compute the flow receiver for each vertex deterministically.
 
void compute_receivers (unsigned int seed, float noise_strength=0.25f)
 Compute the flow receiver for each vertex with noise for stochastic variations.
 
void update_stream_tree (unsigned int seed, float noise_strength)
 Update the stream tree stochastically.
 
void update_stream_tree ()
 Update the stream tree deterministically.
 
void update_traversals ()
 Update cached traversal orders for upstream/downstream computations.
 
std::vector< size_t > & get_outlets () const
 Get the indices of the outlets in the basin.
 
void set_outlets (const std::vector< size_t > &outlet_indices)
 Set the outlets of the basin.
 
const std::vector< size_t > & get_receivers () const
 Get the receiver index of each vertex.
 
void invert_receiver_map ()
 Invert the receiver map to build a map of children/downstream receivers.
 
std::vector< bool > compute_is_ridge_node () const
 Compute whether each vertex is a ridge node (no upstream flow).
 
std::vector< size_t > compute_strahler_order () const
 Compute the Strahler stream order for each vertex.
 
std::pair< std::vector< size_t >, bool > find_subroots ()
 Find subroots of the flow network.
 
std::vector< std::vector< size_t > > get_main_channels () const
 Get the main channel paths of the flow network.
 
void remove_lakes (const std::vector< size_t > &subroot)
 Remove lakes by draining local depressions.
 
std::vector< float > compute_response_times (const std::vector< float > &area_acc, const std::vector< float > &erodibility, float m_exp) const
 Compute response times of the basin vertices.
 
void flow_breach ()
 Perform flow breaching to resolve depressions.
 
std::vector< std::vector< glm::vec3 > > flow_breach_paths ()
 Compute the breaching paths for depressions.
 
float update_elevations (const std::vector< float > &response_times, float uplift_rate, const std::vector< float > &max_slope)
 Update terrain elevations based on response times and uplift.
 
void accumulate_area_by_outlet (const std::vector< float > &area, std::vector< float > &acc) const
 Accumulate contributing area down the network by outlet.
 
const std::vector< size_t > & for_each_upstream (size_t outlet) const
 Get the cached upstream traversal order from a specific outlet.
 
auto for_each_downstream (size_t outlet) const
 Get the cached downstream traversal order from a specific outlet.
 

Detailed Description

Represents a drainage basin network constructed on a 3D terrain mesh.

This class handles the construction and analysis of hydrological flow networks (receivers, streams, outlets) on a 3D triangular mesh. It allows simulating river network development, calculating Strahler orders, inverting receiver maps, breaching lakes, and updating elevations based on response times.

Constructor & Destructor Documentation

◆ DrainageBasin()

hmap::DrainageBasin::DrainageBasin ( std::vector< glm::vec3 >  xyz_)

Construct a new Drainage Basin object.

Parameters
xyz_Input 3D points representing the terrain vertices.

Member Function Documentation

◆ get_xyz()

const std::vector< glm::vec3 > & hmap::DrainageBasin::get_xyz ( ) const

Get the 3D coordinates of the terrain vertices.

Returns
A const reference to the vector of 3D coordinates.

◆ size()

size_t hmap::DrainageBasin::size ( ) const

Get the number of vertices in the basin.

Returns
The size as a size_t.

◆ to_csv()

void hmap::DrainageBasin::to_csv ( const std::string &  filename) const

Export the drainage basin data to a CSV file.

Parameters
filenamePath to the output CSV file.

◆ get_mesh() [1/2]

const TerrainTriMesh & hmap::DrainageBasin::get_mesh ( ) const

Get the underlying terrain tri mesh (const).

Returns
A const reference to the TerrainTriMesh.

◆ get_mesh() [2/2]

TerrainTriMesh & hmap::DrainageBasin::get_mesh ( )

Get the underlying terrain tri mesh (non-const).

Returns
A reference to the TerrainTriMesh.

◆ compute_vertex_areas()

std::vector< float > hmap::DrainageBasin::compute_vertex_areas ( ) const

Compute the area of each vertex in the mesh.

Returns
A vector containing the computed vertex areas.

◆ remap()

void hmap::DrainageBasin::remap ( float  zmin = 0.f,
float  zmax = 1.f 
)

Remap the elevation (z) values of the mesh vertices to a target range.

Parameters
zminMinimum target elevation value.
zmaxMaximum target elevation value.

◆ compute_receivers() [1/2]

void hmap::DrainageBasin::compute_receivers ( )

Compute the flow receiver for each vertex deterministically.

◆ compute_receivers() [2/2]

void hmap::DrainageBasin::compute_receivers ( unsigned int  seed,
float  noise_strength = 0.25f 
)

Compute the flow receiver for each vertex with noise for stochastic variations.

Parameters
seedSeed for random generation.
noise_strengthStrength of the noise added to elevations during receiver computation.

◆ update_stream_tree() [1/2]

void hmap::DrainageBasin::update_stream_tree ( unsigned int  seed,
float  noise_strength 
)

Update the stream tree stochastically.

Parameters
seedSeed for random generation.
noise_strengthStrength of noise.

◆ update_stream_tree() [2/2]

void hmap::DrainageBasin::update_stream_tree ( )

Update the stream tree deterministically.

◆ update_traversals()

void hmap::DrainageBasin::update_traversals ( )

Update cached traversal orders for upstream/downstream computations.

◆ get_outlets()

std::vector< size_t > & hmap::DrainageBasin::get_outlets ( ) const

Get the indices of the outlets in the basin.

Returns
A reference to the vector of outlet indices.

◆ set_outlets()

void hmap::DrainageBasin::set_outlets ( const std::vector< size_t > &  outlet_indices)

Set the outlets of the basin.

Parameters
outlet_indicesVector containing the new outlet indices.

◆ get_receivers()

const std::vector< size_t > & hmap::DrainageBasin::get_receivers ( ) const

Get the receiver index of each vertex.

Returns
A const reference to the vector of receiver indices.

◆ invert_receiver_map()

void hmap::DrainageBasin::invert_receiver_map ( )

Invert the receiver map to build a map of children/downstream receivers.

◆ compute_is_ridge_node()

std::vector< bool > hmap::DrainageBasin::compute_is_ridge_node ( ) const

Compute whether each vertex is a ridge node (no upstream flow).

Returns
A vector of booleans indicating ridge nodes.

◆ compute_strahler_order()

std::vector< size_t > hmap::DrainageBasin::compute_strahler_order ( ) const

Compute the Strahler stream order for each vertex.

Returns
A vector containing the Strahler order of each vertex.

◆ find_subroots()

std::pair< std::vector< size_t >, bool > hmap::DrainageBasin::find_subroots ( )

Find subroots of the flow network.

Returns
A pair containing a vector of subroots indices and a boolean status.

◆ get_main_channels()

std::vector< std::vector< size_t > > hmap::DrainageBasin::get_main_channels ( ) const

Get the main channel paths of the flow network.

Returns
A vector of main channels, each represented as a vector of vertex indices.

◆ remove_lakes()

void hmap::DrainageBasin::remove_lakes ( const std::vector< size_t > &  subroot)

Remove lakes by draining local depressions.

Parameters
subrootVector of subroot indices to process.

◆ compute_response_times()

std::vector< float > hmap::DrainageBasin::compute_response_times ( const std::vector< float > &  area_acc,
const std::vector< float > &  erodibility,
float  m_exp 
) const

Compute response times of the basin vertices.

Parameters
area_accAccumulated area for each vertex.
erodibilityErodibility coefficient for each vertex.
m_expErodibility exponent.
Returns
A vector of response times.

◆ flow_breach()

void hmap::DrainageBasin::flow_breach ( )

Perform flow breaching to resolve depressions.

◆ flow_breach_paths()

std::vector< std::vector< glm::vec3 > > hmap::DrainageBasin::flow_breach_paths ( )

Compute the breaching paths for depressions.

Returns
A vector of paths, each represented as a vector of 3D points.

◆ update_elevations()

float hmap::DrainageBasin::update_elevations ( const std::vector< float > &  response_times,
float  uplift_rate,
const std::vector< float > &  max_slope 
)

Update terrain elevations based on response times and uplift.

Parameters
response_timesVector of vertex response times.
uplift_rateRate of tectonic uplift.
max_slopeMaximum allowed slope for each vertex.
Returns
The maximum change in elevation.

◆ accumulate_area_by_outlet()

void hmap::DrainageBasin::accumulate_area_by_outlet ( const std::vector< float > &  area,
std::vector< float > &  acc 
) const

Accumulate contributing area down the network by outlet.

Parameters
areaInput area contribution of each vertex.
accOutput accumulated area.

◆ for_each_upstream()

const std::vector< size_t > & hmap::DrainageBasin::for_each_upstream ( size_t  outlet) const

Get the cached upstream traversal order from a specific outlet.

Parameters
outletIndex of the outlet.
Returns
Const reference to the vector of vertex indices in upstream order.

◆ for_each_downstream()

auto hmap::DrainageBasin::for_each_downstream ( size_t  outlet) const
inline

Get the cached downstream traversal order from a specific outlet.

Parameters
outletIndex of the outlet.
Returns
A pair of reverse iterators for traversing downstream.

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