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 <limits>
25
26#include "highmap/array.hpp"
28
29namespace hmap
30{
31
47Array d8_compute_ndip(const Array &d8);
48
63void find_flow_sinks(const Array &z,
64 std::vector<int> &is,
65 std::vector<int> &js);
66
83Array flooding_uniform_level(const Array &z, float zref);
84
105Array flooding_from_boundaries(const Array &z,
106 float zref,
107 bool from_east = true,
108 bool from_west = true,
109 bool from_north = true,
110 bool from_south = true);
111
130Array flooding_from_point(const Array &z,
131 int i,
132 int j,
133 float depth_min = std::numeric_limits<float>::max());
134
152Array flooding_from_point(const Array &z,
153 const std::vector<int> &i,
154 const std::vector<int> &j,
155 float depth_min = std::numeric_limits<float>::max());
156
183Array flooding_lake_system(const Array &z,
184 int iterations = 500,
185 float epsilon = 1e-3f);
186
209Array flow_accumulation_d8(const Array &z);
210
237Array flow_accumulation_dinf(const Array &z, float talus_ref);
238
255Array flow_direction_d8(const Array &z);
256
274std::vector<Array> flow_direction_dinf(const Array &z, float talus_ref);
275
309Path flow_stream(const Array &z,
310 const Vec2<int> ij_start,
311 const float elevation_ratio = 0.5f,
312 const float distance_exponent = 2.f,
313 const float upward_penalization = 100.f);
314
361Array generate_riverbed(const Path &path,
362 Vec2<int> shape,
363 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f},
364 bool bezier_smoothing = false,
365 float depth_start = 0.01f,
366 float depth_end = 1.f,
367 float slope_start = 64.f,
368 float slope_end = 32.f,
369 float shape_exponent_start = 1.f,
370 float shape_exponent_end = 10.f,
371 float k_smoothing = 0.5f,
372 int post_filter_ir = 0,
373 Array *p_noise_x = nullptr,
374 Array *p_noise_y = nullptr,
375 Array *p_noise_r = nullptr);
376
387Array merge_water_depths(const Array &depth1,
388 const Array &depth2,
389 float k_smooth = 0.f);
390
429Array water_depth_from_mask(const Array &z,
430 const Array &mask,
431 float mask_threshold = 0.f,
432 int iterations_max = 10000,
433 float tolerance = 1e-2f,
434 float omega = 1.8f);
435
460void water_depth_dry_out(Array &water_depth,
461 float dry_out_ratio = 0.5f,
462 const Array *p_mask = nullptr,
463 float depth_max = std::numeric_limits<float>::max());
464
486Array water_depth_increase(const Array &water_depth,
487 const Array &z,
488 float additional_depth);
489
506Array water_mask(const Array &water_depth);
507
530Array water_mask(const Array &water_depth,
531 const Array &z,
532 float additional_depth);
533
534} // namespace hmap
535
536namespace hmap::gpu
537{
538
540Array flow_direction_d8(const Array &z);
541
543Array generate_riverbed(const Path &path,
544 Vec2<int> shape,
545 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f},
546 bool bezier_smoothing = false,
547 float depth_start = 0.01f,
548 float depth_end = 1.f,
549 float slope_start = 64.f,
550 float slope_end = 32.f,
551 float shape_exponent_start = 1.f,
552 float shape_exponent_end = 10.f,
553 float k_smoothing = 0.5f,
554 int post_filter_ir = 0,
555 Array *p_noise_x = nullptr,
556 Array *p_noise_y = nullptr,
557 Array *p_noise_r = nullptr);
558
559} // namespace hmap::gpu
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Definition blending.hpp:186
Array generate_riverbed(const Path &path, Vec2< int > shape, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f}, 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:16
Array flow_direction_d8(const Array &z)
See hmap::flow_direction_d8.
Definition flow_accumulation_d8_gpu.cpp:10
Definition algebra.hpp:28
Array water_depth_from_mask(const Array &z, const Array &mask, float mask_threshold=0.f, int iterations_max=10000, float tolerance=1e-2f, float omega=1.8f)
Compute water depth over a masked terrain using harmonic interpolation.
Definition flooding.cpp:224
Array water_depth_increase(const Array &water_depth, const Array &z, float additional_depth)
Simulates the increase in water depth over a terrain.
Definition flooding.cpp:248
Array flooding_uniform_level(const Array &z, float zref)
Compute water depth for a uniform flooding level.
Definition flooding.cpp:18
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:49
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)
Compute flooding starting from the lowest boundary points.
Definition flooding.cpp:28
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:27
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 flooding.cpp:196
Array flooding_lake_system(const Array &z, int iterations=500, float epsilon=1e-3f)
Estimate lake water depths on a terrain by filling depressions.
Definition flooding.cpp:164
Array flow_accumulation_dinf(const Array &z, float talus_ref)
Computes the flow accumulation for each cell using the Multiple Flow Direction (MFD) model.
Definition flow_accumulation_dinf.cpp:36
Path flow_stream(const Array &z, const Vec2< int > ij_start, const float elevation_ratio=0.5f, const float distance_exponent=2.f, const float upward_penalization=100.f)
Computes the optimal flow path from a starting point to the boundary of a given elevation array.
Definition flow_stream.cpp:46
Array merge_water_depths(const Array &depth1, const Array &depth2, float k_smooth=0.f)
Merge two water depth fields.
Definition flooding.cpp:180
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:107
Array generate_riverbed(const Path &path, Vec2< int > shape, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f}, 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:16
Array water_mask(const Array &water_depth)
Generates a binary mask representing water presence.
Definition flooding.cpp:373
Array flooding_from_point(const Array &z, int i, int j, float depth_min=std::numeric_limits< float >::max())
Flood terrain starting from a single seed point.
Definition flooding.cpp:110
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:10
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:100
Path class for manipulating and analyzing paths in 2D space.