HighMap library (C++)
Loading...
Searching...
No Matches
hydrology.hpp
Go to the documentation of this file.
1/* Copyright (c) 2023 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
23#pragma once
24#include <cstdint>
25#include <functional>
26#include <limits>
27
28#include "highmap/array.hpp"
34
35namespace hmap
36{
37
38class Graph;
39class TerrainTriMesh;
40
60Array basin_id(const Array &z,
61 bool fast_approx = false,
62 bool remove_lakes = true);
63
90 const Array &z_river,
91 float talus_riverbank = 0.01f,
92 bool smooth_river_bottom = true,
93 float merging_distance = 8.f,
94 std::uint32_t seed = 0,
95 float riverbank_noise_ratio = 0.f,
96 const Array *p_noise_x = nullptr,
97 const Array *p_noise_y = nullptr);
98
114Array d8_compute_ndip(const Array &d8);
115
127void find_flow_apex(const Array &z, std::vector<int> &is, std::vector<int> &js);
128
143void find_flow_sinks(const Array &z,
144 std::vector<int> &is,
145 std::vector<int> &js);
146
156std::vector<glm::ivec2> find_flow_sinks(const Array &z);
157
167std::vector<glm::ivec2> find_flow_sinks_border(const Array &z);
168
185Array flooding_uniform_level(const Array &z, float zref);
186
210 const Array &z,
211 float zref,
212 bool from_east = true,
213 bool from_west = true,
214 bool from_north = true,
215 bool from_south = true,
216 const UvTile &region = UvTile::dummy(),
218
238 int i,
239 int j,
240 float depth_min = std::numeric_limits<float>::max(),
241 const UvTile &region = UvTile::dummy(),
243
264 const std::vector<int> &i,
265 const std::vector<int> &j,
266 float depth_min = std::numeric_limits<float>::max(),
267 const UvTile &region = UvTile::dummy(),
269
300 float surface_threshold = 0.f,
301 const UvTile &region = UvTile::dummy(),
303
327
365 int n_samples = 1 << 19,
366 std::uint32_t seed = 0,
367 const Array *p_source = nullptr,
368 const Array *p_decay = nullptr);
369
403 float talus_ref = 0.1f,
404 int iterations = 0,
405 const UvTile &region = {},
407
443
445 const Array &z,
446 float talus_ref,
447 int nsamples,
448 glm::vec2 kw,
449 std::uint32_t seed,
450 float amp,
451 const Array *p_perturb_scaling = nullptr,
452 const UvRect &uv_rect = UvRect::unit(),
453 int iterations = 0,
454 const UvTile &region = {},
456
474
492std::vector<Array> flow_direction_dinf(const Array &z, float talus_ref);
493
494std::vector<float> flow_direction_dinf_flat(const Array &z, float talus_ref);
495
500Array flow_direction_dinf_angle(const Array &z, float talus_ref);
501
502Array flow_fixing(const Array &z,
503 float riverbed_talus = 0.f,
504 int iterations = 5,
505 int prefilter_ir = 8,
506 bool carve_riverbed = true,
507 float merging_distance = 8.f, // pixels
508 const Array *p_noise_r = nullptr);
509
544 bool fast_approx = false,
545 float riverbed_talus = 1e-4f,
546 int iterations = 3,
547 bool carve_riverbed = false,
548 float talus_riverbank = 0.01f,
549 float merging_distance = 8.f,
550 std::uint32_t seed = 0,
551 float noise_strength = 0.f,
552 const Array *p_noise_x = nullptr,
553 const Array *p_noise_y = nullptr);
554
590 const Array &z,
591 float riverbed_talus = 0.f,
592 float elevation_ratio = 0.95f,
593 float distance_exponent = 2.f,
594 float upward_penalization = 0.1f,
595 float valley_affinity = 0.5f,
596 int prefilter_ir = 8,
597 float minimum_depth = 1e-4f,
598 bool carve_riverbed = true,
599 float merging_distance = 8.f,
601 float radial_profile_parameter = 2.f,
602 const Array *p_noise_r = nullptr,
603 bool use_midpoint = false,
604 float offset_ratio = 0.2f);
605
627std::vector<Path> flow_fixing_mst_paths(const TerrainTriMesh &mesh,
628 float riverbed_talus = 0.f,
629 float elevation_ratio = 0.95f,
630 float distance_exponent = 2.f,
631 float upward_penalization = 0.1f,
632 float minimum_depth = 1e-4f);
633
653std::vector<Path> flow_fixing_mst_paths(const Array &z,
654 size_t control_points_count = 2048,
655 std::uint32_t seed = 0,
656 float riverbed_talus = 0.f,
657 float elevation_ratio = 0.95f,
658 float distance_exponent = 2.f,
659 float upward_penalization = 0.1f,
660 float minimum_depth = 1e-4f);
661
688 const Array &z,
689 size_t control_points_count = 2048,
690 std::uint32_t seed = 0,
691 float riverbed_talus = 0.f,
692 float elevation_ratio = 0.95f,
693 float distance_exponent = 2.f,
694 float upward_penalization = 0.1f,
695 float minimum_depth = 1e-4f,
696 float merging_distance = 8.f,
698 float radial_profile_parameter = 2.f,
699 const Array *p_noise_r = nullptr);
700
743Path flow_stream(const Array &z,
744 const glm::ivec2 ij_start,
745 const float elevation_ratio = 0.5f,
746 const float distance_exponent = 2.f,
747 const float upward_penalization = 100.f,
748 const std::vector<Path> &existing_streams = {},
749 const int valley_radius = 2,
750 const float valley_factor = 0.35f,
751 const bool truncate_at_intersection = false);
752
779 size_t start_vertex_index,
780 float elevation_ratio = 0.5f,
781 float distance_exponent = 2.f,
782 float upward_penalization = 100.f,
783 bool favor_domain_center = false,
784 const std::vector<Path> &existing_streams = {},
785 float valley_radius = 0.02f,
786 float valley_factor = 0.35f,
787 bool truncate_at_intersection = false);
788
815 glm::vec2 xy_start,
816 float elevation_ratio = 0.5f,
817 float distance_exponent = 2.f,
818 float upward_penalization = 100.f,
819 bool favor_domain_center = false,
820 const std::vector<Path> &existing_streams = {},
821 float valley_radius = 0.02f,
822 float valley_factor = 0.35f,
823 bool truncate_at_intersection = false);
824
871Array generate_riverbed(const Path &path,
872 glm::ivec2 shape,
873 const UvRect &uv_rect = UvRect::unit(),
874 bool bezier_smoothing = false,
875 float depth_start = 0.01f,
876 float depth_end = 1.f,
877 float slope_start = 64.f,
878 float slope_end = 32.f,
879 float shape_exponent_start = 1.f,
880 float shape_exponent_end = 10.f,
881 float k_smoothing = 0.5f,
882 int post_filter_ir = 0,
883 Array *p_noise_x = nullptr,
884 Array *p_noise_y = nullptr,
885 Array *p_noise_r = nullptr);
886
898Graph hydrology_paths_to_graph(const std::vector<Path> &paths,
899 float snap_tolerance = 1e-4f);
900
911Array merge_water_depths(const Array &depth1,
912 const Array &depth2,
913 float k_smooth = 0.f);
914
941 float melt_start_elevation = 0.f,
942 float melt_end_elevation = 0.5f,
943 float elevation_strength = 1.f,
944 float elevation_exp = 1.f,
945 float sun_azimuth = 0.f,
946 float sun_zenith = 60.f,
947 float aspect_strength = 0.f,
948 float slope_exp = 1.f,
949 float slope_strength = 0.f);
950
988 const Array &mask,
989 float mask_threshold = 0.f,
990 int iterations_max = 10000,
991 float tolerance = 1e-2f);
992
1017void water_depth_dry_out(Array &water_depth,
1018 float dry_out_ratio = 0.5f,
1019 const Array *p_mask = nullptr,
1020 float depth_max = std::numeric_limits<float>::max());
1021
1057Array water_depth_increase(const Array &water_depth,
1058 const Array &z,
1059 float additional_depth);
1060
1096 const Array &z,
1097 float additional_depth);
1098
1121Array water_frontier_curvature(const Array &water_depth,
1122 int prefilter_ir,
1123 bool extend_values_from_interface = false);
1124
1141Array water_mask(const Array &water_depth);
1142
1165Array water_mask(const Array &water_depth,
1166 const Array &z,
1167 float additional_depth);
1168
1169} // namespace hmap
1170
1171namespace hmap::gpu
1172{
1173
1197Array coastal_fetch(const Array &z,
1198 int ndirections,
1199 const Array *p_compute_mask = nullptr);
1200
1231Array coastal_fetch_directional(const Array &z,
1232 float angle,
1233 float directional_exp,
1234 int ndirections,
1235 const Array *p_compute_mask = nullptr);
1236
1250Array flow_accumulation_from_velocity_field(const Array &u,
1251 const Array &v,
1252 int iterations);
1253
1258Array flow_accumulation_stochastic(const Array &z,
1259 int n_samples = 1 << 19,
1260 std::uint32_t seed = 0,
1261 const Array *p_source = nullptr,
1262 const Array *p_decay = nullptr);
1263
1265Array flow_direction_d8(const Array &z);
1266
1296Array flow_simulation(const Array &z,
1297 float water_depth,
1298 const Array &depth_map,
1299 int iterations,
1300 float dt = 0.5f,
1301 bool flux_diffusion = true,
1302 float flux_diffusion_strength = 0.01f,
1303 float dry_out_ratio = 0.f,
1304 const Array *p_rain_map = nullptr,
1305 float rain_rate = 0.f,
1306 float evap_rate = 0.f,
1307 bool outflow_boundaries = false,
1308 Array *p_vel_u = nullptr,
1309 Array *p_vel_v = nullptr,
1310 int sync_interval = 0,
1311 const UvTile &region = UvTile::dummy(),
1312 ICommunicator &comm = SingleArrayComm::instance());
1313
1337 const Array &z,
1338 float water_depth,
1339 const Array &depth_map,
1340 int iterations,
1341 float dt = -1.f,
1342 float dry_out_ratio = 0.f,
1343 float viscosity = 1.f,
1344 float power = 2.5f,
1345 float evap_rate = 0.f,
1346 bool outflow_boundaries = false,
1347 int sync_interval = 0,
1348 const UvTile &region = UvTile::dummy(),
1349 ICommunicator &comm = SingleArrayComm::instance());
1350
1352Array generate_riverbed(const Path &path,
1353 glm::ivec2 shape,
1354 const UvRect &uv_rect = UvRect::unit(),
1355 bool bezier_smoothing = false,
1356 float depth_start = 0.01f,
1357 float depth_end = 1.f,
1358 float slope_start = 64.f,
1359 float slope_end = 32.f,
1360 float shape_exponent_start = 1.f,
1361 float shape_exponent_end = 10.f,
1362 float k_smoothing = 0.5f,
1363 int post_filter_ir = 0,
1364 Array *p_noise_x = nullptr,
1365 Array *p_noise_y = nullptr,
1366 Array *p_noise_r = nullptr);
1367
1409Array snow_mantle(const Array &z,
1410 float strength = 0.1f,
1411 float snowline = 0.5f,
1412 float falloff = 0.1f,
1413 int prefilter_ir = 8,
1414 float talus_coverage = 0.8f,
1415 float talus_threshold = 0.001f,
1416 float directional = 0.f,
1417 float wind_direction = 0.f,
1418 float peaks = 0.2f,
1419 float melt = 0.f,
1420 float sun_azimuth = 180.f,
1421 float sun_zenith = 45.f,
1422 int thermal_iterations = 15,
1423 float thermal_talus = 0.15f,
1424 float coverage = 0.5f,
1425 const Array *p_existing_snow = nullptr,
1426 const Array *p_mask = nullptr,
1427 const Array *p_noise = nullptr);
1428
1463Array snow_simulation(const Array &z,
1464 float snow_depth,
1465 const Array &fall_map,
1466 const Array &melting_map,
1467 const Array &talus,
1468 int iterations,
1469 float dt = 0.5f,
1470 float fall_iterations_ratio = 1.f,
1471 float k_snow = 0.5f,
1472 float k_visc = 0.1f,
1473 float k_melt_factor = 0.8f,
1474 float k_depth_ratio = 1.f,
1475 float k_depth_slope_ratio = 1.f,
1476 float k_creep = 0.1f,
1477 bool post_filter = true,
1478 float thermal_talus_ratio = 0.2f,
1479 bool outflow_boundaries = true,
1480 float clamp_smin = 0.f,
1481 bool rebase_snow_depth_to_zero = true,
1482 int sync_interval = 0,
1483 const UvTile &region = UvTile::dummy(),
1484 ICommunicator &comm = SingleArrayComm::instance());
1485
1499void water_depth_filter(Array &depth,
1500 const Array &z,
1501 int ir,
1502 const Array *p_water_mask = nullptr,
1503 bool smooth_contour = false,
1504 float transition_ratio = 0.1f);
1505
1507Array water_frontier_curvature(const Array &water_depth,
1508 int prefilter_ir,
1509 bool extend_values_from_interface = false);
1510
1512Array water_depth_from_mask(const Array &z,
1513 const Array &mask,
1514 float mask_threshold = 0.f,
1515 int iterations_max = 10000,
1516 float tolerance = 1e-2f);
1517
1518} // namespace hmap::gpu
1519
1520namespace hmap::va
1521{
1522
1550std::vector<Path> flow_fixing_mst_paths(const ComputeMode &cm,
1551 const VirtualArray &z,
1552 size_t control_points_count = 2048,
1553 std::uint32_t seed = 0,
1554 float riverbed_talus = 0.f,
1555 float elevation_ratio = 0.95f,
1556 float distance_exponent = 2.f,
1557 float upward_penalization = 0.1f,
1558 float minimum_depth = 1e-4f);
1559
1560VirtualArray flow_fixing_mst_triangulated(
1561 const ComputeMode &cm,
1562 const VirtualArray &z,
1563 size_t control_points_count = 2048,
1564 std::uint32_t seed = 0,
1565 float riverbed_talus = 0.f,
1566 float elevation_ratio = 0.95f,
1567 float distance_exponent = 2.f,
1568 float upward_penalization = 0.1f,
1569 float minimum_depth = 1e-4f,
1570 float merging_distance = 8.f,
1572 float radial_profile_parameter = 2.f,
1573 const VirtualArray *p_noise_r = nullptr);
1574
1604Path flow_stream(const ComputeMode &cm,
1605 const VirtualArray &z,
1606 glm::vec2 start,
1607 std::uint32_t seed = 0,
1608 size_t control_points_count = 2048,
1609 float elevation_ratio = 0.5f,
1610 float distance_exponent = 2.f,
1611 float upward_penalization = 100.f,
1612 bool favor_domain_center = false,
1613 const std::vector<Path> &existing_streams = {},
1614 float valley_radius = 0.02f,
1615 float valley_factor = 0.35f,
1616 bool truncate_at_intersection = false);
1617
1618} // namespace hmap::va
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:31
Graph class, to manipulate graphs in 2D.
Definition graph.hpp:70
Abstract communicator interface providing MPI-style collective directives for single-source SPMD Arra...
Definition communicator_interface.hpp:60
Represents an ordered set of points in 2D, forming a polyline (open or closed).
Definition path.hpp:43
static SingleArrayComm & instance()
Definition communicator.cpp:78
Triangle mesh representation of a terrain surface.
Definition terrain_tri_mesh.hpp:32
Header file for FlowGraph structure.
Definition array_blending.hpp:225
Array flow_accumulation_from_velocity_field(const Array &u, const Array &v, int iterations)
Approximates flow accumulation from a 2D velocity field.
Definition flow_accumulation_from_velocity_field.cpp:16
Array snow_simulation(const Array &z, float snow_depth, const Array &fall_map, const Array &melting_map, const Array &talus, int iterations, float dt=0.5f, float fall_iterations_ratio=1.f, float k_snow=0.5f, float k_visc=0.1f, float k_melt_factor=0.8f, float k_depth_ratio=1.f, float k_depth_slope_ratio=1.f, float k_creep=0.1f, bool post_filter=true, float thermal_talus_ratio=0.2f, bool outflow_boundaries=true, float clamp_smin=0.f, bool rebase_snow_depth_to_zero=true, int sync_interval=0, const UvTile &region=UvTile::dummy(), ICommunicator &comm=SingleArrayComm::instance())
Simulate snow accumulation and redistribution over a terrain.
Definition snow_simulation.cpp:92
Array water_frontier_curvature(const Array &water_depth, int prefilter_ir, bool extend_values_from_interface=false)
See hmap::water_frontier_curvature.
Definition water_depth.cpp:438
Array flow_simulation(const Array &z, float water_depth, const Array &depth_map, int iterations, float dt=0.5f, bool flux_diffusion=true, float flux_diffusion_strength=0.01f, float dry_out_ratio=0.f, const Array *p_rain_map=nullptr, float rain_rate=0.f, float evap_rate=0.f, bool outflow_boundaries=false, Array *p_vel_u=nullptr, Array *p_vel_v=nullptr, int sync_interval=0, const UvTile &region=UvTile::dummy(), ICommunicator &comm=SingleArrayComm::instance())
GPU hydraulic flow simulation using a virtual-pipes model; simulates shallow-water transport over a h...
Definition flow_simulation.cpp:36
void water_depth_filter(Array &depth, const Array &z, int ir, const Array *p_water_mask=nullptr, bool smooth_contour=false, float transition_ratio=0.1f)
Filters water depth values using elevation data and a given radius.
Definition water_depth.cpp:369
Array water_depth_from_mask(const Array &z, const Array &mask, float mask_threshold=0.f, int iterations_max=10000, float tolerance=1e-2f)
See hmap::water_depth_from_mask.
Definition water_depth.cpp:413
Array coastal_fetch(const Array &z, int ndirections, const Array *p_compute_mask=nullptr)
Computes the omnidirectional coastal fetch for each cell.
Definition coastal_fetch.cpp:17
Array flow_simulation_viscous(const Array &z, float water_depth, const Array &depth_map, int iterations, float dt=-1.f, float dry_out_ratio=0.f, float viscosity=1.f, float power=2.5f, float evap_rate=0.f, bool outflow_boundaries=false, int sync_interval=0, const UvTile &region=UvTile::dummy(), ICommunicator &comm=SingleArrayComm::instance())
GPU viscous shallow-water flow simulation using non-linear thin-film diffusion with upwind mobility.
Definition flow_simulation.cpp:273
Array coastal_fetch_directional(const Array &z, float angle, float directional_exp, int ndirections, const Array *p_compute_mask=nullptr)
Computes directional coastal fetch weighted by alignment with a prevailing wind or wave direction.
Definition coastal_fetch.cpp:46
Array flow_accumulation_stochastic(const Array &z, int n_samples=1<< 19, std::uint32_t seed=0, const Array *p_source=nullptr, const Array *p_decay=nullptr)
GPU (OpenCL) variant of hmap::flow_accumulation_stochastic — see the CPU declaration for the algorith...
Definition flow_accumulation_stochastic_gpu.cpp:19
Array snow_mantle(const Array &z, float strength=0.1f, float snowline=0.5f, float falloff=0.1f, int prefilter_ir=8, float talus_coverage=0.8f, float talus_threshold=0.001f, float directional=0.f, float wind_direction=0.f, float peaks=0.2f, float melt=0.f, float sun_azimuth=180.f, float sun_zenith=45.f, int thermal_iterations=15, float thermal_talus=0.15f, float coverage=0.5f, const Array *p_existing_snow=nullptr, const Array *p_mask=nullptr, const Array *p_noise=nullptr)
Generates fine-scale snow mantle accumulation over terrain.
Definition snow_mantle.cpp:22
Array generate_riverbed(const Path &path, glm::ivec2 shape, const UvRect &uv_rect=UvRect::unit(), bool bezier_smoothing=false, float depth_start=0.01f, float depth_end=1.f, float slope_start=64.f, float slope_end=32.f, float shape_exponent_start=1.f, float shape_exponent_end=10.f, float k_smoothing=0.5f, int post_filter_ir=0, Array *p_noise_x=nullptr, Array *p_noise_y=nullptr, Array *p_noise_r=nullptr)
See hmap::generate_riverbed.
Definition generate_riverbed_gpu.cpp:20
Array flow_direction_d8(const Array &z)
See hmap::flow_direction_d8.
Definition flow_accumulation_d8_gpu.cpp:16
Definition deprecated.hpp:576
std::vector< Path > flow_fixing_mst_paths(const ComputeMode &cm, const VirtualArray &z, size_t control_points_count=2048, std::uint32_t seed=0, float riverbed_talus=0.f, float elevation_ratio=0.95f, float distance_exponent=2.f, float upward_penalization=0.1f, float minimum_depth=1e-4f)
Resolves flow sinks on a VirtualArray by computing an MST on a triangular mesh and distributing river...
Definition flow_fixing_mst.cpp:1065
VirtualArray flow_fixing_mst_triangulated(const ComputeMode &cm, const VirtualArray &z, size_t control_points_count=2048, std::uint32_t seed=0, float riverbed_talus=0.f, float elevation_ratio=0.95f, float distance_exponent=2.f, float upward_penalization=0.1f, float minimum_depth=1e-4f, float merging_distance=8.f, RadialProfile radial_profile=RadialProfile::RP_SMOOTHSTEP_UPPER, float radial_profile_parameter=2.f, const VirtualArray *p_noise_r=nullptr)
Definition flow_fixing_mst.cpp:1107
Path flow_stream(const ComputeMode &cm, const VirtualArray &z, glm::vec2 start, std::uint32_t seed=0, size_t control_points_count=2048, float elevation_ratio=0.5f, float distance_exponent=2.f, float upward_penalization=100.f, bool favor_domain_center=false, const std::vector< Path > &existing_streams={}, float valley_radius=0.02f, float valley_factor=0.35f, bool truncate_at_intersection=false)
Computes the optimal flow path from starting 2D coordinates across a VirtualArray using an intermedia...
Definition flow_stream.cpp:482
Definition opencv.hpp:20
void find_flow_apex(const Array &z, std::vector< int > &is, std::vector< int > &js)
Identifies flow apex (source) cells using D8 flow routing.
Definition find_flow_sinks.cpp:17
Graph hydrology_paths_to_graph(const std::vector< Path > &paths, float snap_tolerance=1e-4f)
Convert a collection of hydrology flow paths into a connected Graph.
Definition hydrology_paths_to_graph.cpp:22
Array water_depth_increase(const Array &water_depth, const Array &z, float additional_depth)
Simulates a local increase in water depth without global reflooding.
Definition water_depth.cpp:100
Array flow_fixing_mst(const Array &z, float riverbed_talus=0.f, float elevation_ratio=0.95f, float distance_exponent=2.f, float upward_penalization=0.1f, float valley_affinity=0.5f, int prefilter_ir=8, float minimum_depth=1e-4f, bool carve_riverbed=true, float merging_distance=8.f, RadialProfile radial_profile=RadialProfile::RP_SMOOTHSTEP_UPPER, float radial_profile_parameter=2.f, const Array *p_noise_r=nullptr, bool use_midpoint=false, float offset_ratio=0.2f)
Resolves flow sinks and unwanted upslopes using Dijkstra pathfinding and a Minimum Spanning Tree (MST...
Definition flow_fixing_mst.cpp:38
Array flooding_uniform_level(const Array &z, float zref)
Compute water depth for a uniform flooding level.
Definition flooding.cpp:24
Array flow_accumulation_d8(const Array &z)
Computes the flow accumulation for each cell using the D8 flow direction model.
Definition flow_accumulation_d8.cpp:50
RadialProfile
Radial profile type.
Definition profiles.hpp:51
@ RP_SMOOTHSTEP_UPPER
Definition profiles.hpp:56
Array flooding_lake_system(const Array &z, float surface_threshold=0.f, const UvTile &region=UvTile::dummy(), ICommunicator &comm=SingleArrayComm::instance())
Estimate lake water depths on a terrain by filling depressions.
Definition flooding.cpp:573
Array d8_compute_ndip(const Array &d8)
Computes the number of drainage paths for each cell based on the D8 flow direction model.
Definition flow_accumulation_d8.cpp:26
Array flow_accumulation_dinf_perturbed(const Array &z, float talus_ref, int nsamples, glm::vec2 kw, std::uint32_t seed, float amp, const Array *p_perturb_scaling=nullptr, const UvRect &uv_rect=UvRect::unit(), int iterations=0, const UvTile &region={}, ICommunicator &comm=SingleArrayComm::instance())
Computes averaged D-infinity flow accumulation with terrain perturbations.
Definition flow_accumulation_dinf.cpp:261
std::vector< Path > flow_fixing_mst_paths(const TerrainTriMesh &mesh, float riverbed_talus=0.f, float elevation_ratio=0.95f, float distance_exponent=2.f, float upward_penalization=0.1f, float minimum_depth=1e-4f)
Computes river flow paths resolving depressions via Minimum Spanning Tree (MST) on a triangular terra...
Definition flow_fixing_mst.cpp:620
Array water_depth_from_mask(const Array &z, const Array &mask, float mask_threshold=0.f, int iterations_max=10000, float tolerance=1e-2f)
Compute water depth over a masked terrain using harmonic interpolation.
Definition water_depth.cpp:78
void water_depth_dry_out(Array &water_depth, float dry_out_ratio=0.5f, const Array *p_mask=nullptr, float depth_max=std::numeric_limits< float >::max())
Apply a drying factor to a water depth field.
Definition water_depth.cpp:47
Path flow_stream(const Array &z, const glm::ivec2 ij_start, const float elevation_ratio=0.5f, const float distance_exponent=2.f, const float upward_penalization=100.f, const std::vector< Path > &existing_streams={}, const int valley_radius=2, const float valley_factor=0.35f, const bool truncate_at_intersection=false)
Computes the optimal flow path from a starting point to the boundary of a given elevation array.
Definition flow_stream.cpp:26
void falloff(Array &array, float strength=1.f, DistanceFunction dist_fct=DistanceFunction::EUCLIDIAN, const Array *p_noise=nullptr, const UvRect &uv_rect=UvRect::unit())
Applies a falloff effect to the input array based on distance.
Definition boundary.cpp:91
Array flow_fixing_mst_triangulated(const Array &z, size_t control_points_count=2048, std::uint32_t seed=0, float riverbed_talus=0.f, float elevation_ratio=0.95f, float distance_exponent=2.f, float upward_penalization=0.1f, float minimum_depth=1e-4f, float merging_distance=8.f, RadialProfile radial_profile=RadialProfile::RP_SMOOTHSTEP_UPPER, float radial_profile_parameter=2.f, const Array *p_noise_r=nullptr)
Resolves flow sinks on a heightmap by computing an MST on a triangular mesh and carving the resulting...
Definition flow_fixing_mst.cpp:1008
Array merge_water_depths(const Array &depth1, const Array &depth2, float k_smooth=0.f)
Merge two water depth fields.
Definition water_depth.cpp:30
Array carve_riverbed(const Array &z, const Array &z_river, float talus_riverbank=0.01f, bool smooth_river_bottom=true, float merging_distance=8.f, std::uint32_t seed=0, float riverbank_noise_ratio=0.f, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr)
Blends and carves smooth riverbanks around modified riverbed profiles.
Definition carve_riverbed.cpp:18
Array snow_melting_map(const Array &z, float melt_start_elevation=0.f, float melt_end_elevation=0.5f, float elevation_strength=1.f, float elevation_exp=1.f, float sun_azimuth=0.f, float sun_zenith=60.f, float aspect_strength=0.f, float slope_exp=1.f, float slope_strength=0.f)
Generate a spatial snow melting map from terrain features.
Definition snow_simulation.cpp:29
std::vector< Array > flow_direction_dinf(const Array &z, float talus_ref)
Computes the flow direction and weights for each direction using the Multiple Flow Direction (MFD) mo...
Definition flow_accumulation_dinf.cpp:304
std::vector< glm::ivec2 > find_flow_sinks_border(const Array &z)
Find flow sinks located on the domain border.
Definition find_flow_sinks.cpp:98
UvTile UvTile
Definition communicator_interface.hpp:49
Array flow_fixing_drainage_basin(const Array &z, bool fast_approx=false, float riverbed_talus=1e-4f, int iterations=3, bool carve_riverbed=false, float talus_riverbank=0.01f, float merging_distance=8.f, std::uint32_t seed=0, float noise_strength=0.f, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr)
Fixes flow paths and unwanted upslopes using a cell-based drainage basin tree network and elevation u...
Definition flow_fixing.cpp:291
Array flow_accumulation_dinf(const Array &z, float talus_ref=0.1f, int iterations=0, const UvTile &region={}, ICommunicator &comm=SingleArrayComm::instance())
Computes the flow accumulation for each cell using the Multiple Flow Direction (MFD) model.
Definition flow_accumulation_dinf.cpp:29
Array flow_accumulation_stochastic(const Array &z, int n_samples=1<< 19, std::uint32_t seed=0, const Array *p_source=nullptr, const Array *p_decay=nullptr)
Computes flow accumulation using a stochastic (Monte-Carlo) transport estimator.
Definition flow_accumulation_stochastic.cpp:43
std::vector< float > flow_direction_dinf_flat(const Array &z, float talus_ref)
Definition flow_accumulation_dinf.cpp:349
Array flooding_from_point(const Array &z, int i, int j, float depth_min=std::numeric_limits< float >::max(), const UvTile &region=UvTile::dummy(), ICommunicator &comm=SingleArrayComm::instance())
Flood terrain starting from a single seed point.
Definition flooding.cpp:394
Array basin_id(const Array &z, bool fast_approx=false, bool remove_lakes=true)
Label drainage basins using a priority-flood algorithm.
Definition basin_id.cpp:14
float angle(const Point &p1, const Point &p2)
Computes the angle between two points relative to the x-axis.
Definition points.cpp:65
Array flow_fixing(const Array &z, float riverbed_talus=0.f, int iterations=5, int prefilter_ir=8, bool carve_riverbed=true, float merging_distance=8.f, const Array *p_noise_r=nullptr)
Definition flow_fixing.cpp:28
Array water_frontier_curvature(const Array &water_depth, int prefilter_ir, bool extend_values_from_interface=false)
Compute the curvature of the water interface from a signed distance field.
Definition water_depth.cpp:304
Array flooding_from_boundaries(const Array &z, float zref, bool from_east=true, bool from_west=true, bool from_north=true, bool from_south=true, const UvTile &region=UvTile::dummy(), ICommunicator &comm=SingleArrayComm::instance())
Compute flooding starting from the lowest boundary points.
Definition flooding.cpp:36
Array flow_direction_dinf_angle(const Array &z, float talus_ref)
Computes the flow direction using the Multiple Flow Direction (MFD) model.
Definition flow_accumulation_dinf.cpp:408
Array water_mask(const Array &water_depth)
Generates a binary mask representing water presence.
Definition water_depth.cpp:336
Array generate_riverbed(const Path &path, glm::ivec2 shape, const UvRect &uv_rect=UvRect::unit(), bool bezier_smoothing=false, float depth_start=0.01f, float depth_end=1.f, float slope_start=64.f, float slope_end=32.f, float shape_exponent_start=1.f, float shape_exponent_end=10.f, float k_smoothing=0.5f, int post_filter_ir=0, Array *p_noise_x=nullptr, Array *p_noise_y=nullptr, Array *p_noise_r=nullptr)
Generates a 2D array representing a riverbed based on a specified path.
Definition generate_riverbed.cpp:20
void find_flow_sinks(const Array &z, std::vector< int > &is, std::vector< int > &js)
Identifies the indices of flow sinks within the heightmap.
Definition find_flow_sinks.cpp:40
Array flow_direction_d8(const Array &z)
Computes the flow direction from each cell to its downslope neighbor using the D8 model.
Definition flow_accumulation_d8.cpp:102
Array water_depth_increase_with_flooding(const Array &water_depth, const Array &z, float additional_depth)
Simulates a physical rise in water level with full domain flooding.
Definition water_depth.cpp:244
Path class for manipulating and analyzing paths in 2D space.
Axis-aligned rectangle in normalized [0, 1]^2 domain/UV space.
Definition uv_rect.hpp:30
static constexpr UvRect unit()
Definition uv_rect.hpp:46
Describes an Array tile's position within the normalized [0, 1]^2 UV domain and global index grid.
Definition uv_tile.hpp:46
static const UvTile & dummy()
Definition uv_tile.cpp:37