HighMap library (C++)
Loading...
Searching...
No Matches
drainage_basin_cell_based.hpp
Go to the documentation of this file.
1/* Copyright (c) 2026 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4#pragma once
5#include <functional>
6#include <limits>
7
8#include "highmap/array.hpp"
9
10namespace hmap
11{
12
18
20{
21public:
22 // --- Construction ---
23
26
27 // --- Geometry / Mesh ---
28
29 const Array &get_z() const;
30
31 // --- Flow graph construction ---
32
33 void compute_receivers(unsigned int seed = 0, float noise_strength = 0.f);
35 void update_stream_tree(unsigned int seed, float noise_strength);
36 void update_traversals();
37
38 std::vector<glm::ivec2> get_outlets() const;
39 void set_outlets(const std::vector<glm::ivec2> &outlet_indices);
40
41 std::vector<std::vector<glm::ivec2>> compute_upstream_traversals();
42
43 // --- Basin topology utilities ---
44
45 std::pair<Mat<glm::ivec2>, bool> find_subroots();
46 void remove_lakes(const Mat<glm::ivec2> &subroot);
47
48 std::vector<std::vector<glm::ivec2>> get_main_channels() const;
49
50 // --- Hydrology computations ---
51
52 Array compute_response_times(const Array &area_acc,
53 const Array &erodibility,
54 float m_exp) const;
55
56 float update_elevations(const Array &response_times,
57 float uplift_rate,
58 const Array &max_slope);
59
60 void accumulate_area_by_outlet(Array &acc) const;
61
62 // --- Members ---
63
65
70
71 std::unordered_map<glm::ivec2, std::vector<glm::ivec2>, IVec2Hash> traversals;
72
73 const glm::ivec2 null_cell = glm::ivec2(-1, -1);
74
75private:
76 // constants
77 const int di[8] = {1, 1, 0, -1, -1, -1, 0, 1};
78 const int dj[8] = {0, -1, -1, -1, 0, 1, 1, 1};
79 const float cd[8] =
80 {1.f, M_SQRT1_2, 1.f, M_SQRT1_2, 1.f, M_SQRT1_2, 1.f, M_SQRT1_2};
81};
82
83Mat<std::vector<glm::ivec2>> invert_receiver_map(
84 const Mat<glm::ivec2> &receivers);
85
86} // namespace hmap
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:32
Definition drainage_basin_cell_based.hpp:20
void update_stream_tree(unsigned int seed, float noise_strength)
Definition drainage_basin_cell_based.cpp:499
void compute_receivers(unsigned int seed=0, float noise_strength=0.f)
Definition drainage_basin_cell_based.cpp:46
std::vector< std::vector< glm::ivec2 > > get_main_channels() const
Definition drainage_basin_cell_based.cpp:286
std::unordered_map< glm::ivec2, std::vector< glm::ivec2 >, IVec2Hash > traversals
Definition drainage_basin_cell_based.hpp:71
std::vector< glm::ivec2 > get_outlets() const
Definition drainage_basin_cell_based.cpp:324
Mat< glm::ivec2 > receivers
Definition drainage_basin_cell_based.hpp:67
std::vector< std::vector< glm::ivec2 > > compute_upstream_traversals()
Definition drainage_basin_cell_based.cpp:202
void compute_receivers_priority_flood()
Definition drainage_basin_cell_based.cpp:97
Array z
Definition drainage_basin_cell_based.hpp:64
Array compute_response_times(const Array &area_acc, const Array &erodibility, float m_exp) const
Definition drainage_basin_cell_based.cpp:165
void accumulate_area_by_outlet(Array &acc) const
Definition drainage_basin_cell_based.cpp:27
Mat< std::vector< glm::ivec2 > > children
Definition drainage_basin_cell_based.hpp:68
void remove_lakes(const Mat< glm::ivec2 > &subroot)
Definition drainage_basin_cell_based.cpp:343
Mat< int > outlets_mask
Definition drainage_basin_cell_based.hpp:66
void set_outlets(const std::vector< glm::ivec2 > &outlet_indices)
Definition drainage_basin_cell_based.cpp:441
const Array & get_z() const
Definition drainage_basin_cell_based.cpp:338
float update_elevations(const Array &response_times, float uplift_rate, const Array &max_slope)
Definition drainage_basin_cell_based.cpp:451
void update_traversals()
Definition drainage_basin_cell_based.cpp:510
const glm::ivec2 null_cell
Definition drainage_basin_cell_based.hpp:73
Mat< glm::ivec2 > roots
Definition drainage_basin_cell_based.hpp:69
std::pair< Mat< glm::ivec2 >, bool > find_subroots()
Definition drainage_basin_cell_based.cpp:235
Definition algebra.hpp:23
FlowDirectionMethod
Definition drainage_basin_cell_based.hpp:14
@ FDM_PRIORITY_FLOOD
Definition drainage_basin_cell_based.hpp:16
@ FDM_D8
Definition drainage_basin_cell_based.hpp:15
std::vector< std::vector< size_t > > invert_receiver_map(const std::vector< size_t > &receivers)
Definition drainage_basin.cpp:845
Definition algebra.hpp:119
Mat class for basic manipulation of 2D matrices.
Definition algebra.hpp:180