HighMap library (C++)
Loading...
Searching...
No Matches
flow_graph.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
11#pragma once
12#include <cstdint>
13#include <vector>
14
15#include "highmap/array.hpp"
17
18namespace hmap
19{
20
21enum FlowGraphFlag : uint8_t
22{
23 F_CLOSED = 1, // already reached by the flood
24 F_PIT = 2, // reached through the pit queue: flat or closed depression
25 F_OUTLET = 4 // fixed base-level cell
26};
27
29{
30 int nx = 0, ny = 0, n = 0;
31 Array zf; // routing surface: z with the depressions filled
32 std::vector<int> order; // flood order, receivers before donors
33 std::vector<int> rank; // inverse permutation of order
34 std::vector<int> rcv; // receiver of each cell, itself for an outlet
35 std::vector<uint8_t> flag;
36 Array area; // drainage area in cells, or accumulated rain
37 Array steep; // upstream sum of the relative slope excess
38
39 std::vector<int> lake; // lake index of a flooded cell, else -1
40 std::vector<int> lake_outlet; // spill cell of each lake
41 std::vector<int>
42 lake_root; // first flooded cell visited upstream-to-downstream
44 std::vector<float> lake_lo, lake_hi, lake_level;
45 std::vector<double> lake_acc;
46 std::vector<int> pitq; // all flooded cells, in flood order
47 int pit_cells = 0;
48
49 RadixHeap<int> heap; // exact flood
50 std::vector<int> bhead, bnext; // bucket queue of the fast flood
51
52 void resize(int nx_, int ny_);
53 float dist(int i) const;
54 bool submerged(int i, const Array &z) const;
55 void flood(const Array &z_arr,
56 const uint8_t *outlet,
57 bool fast,
58 bool seed_borders = true);
59 void receivers(float p, uint32_t seed);
60 void accumulate(const Array &z_arr, const Array *p_rain, float talus_cell);
61};
62
63} // 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:31
Definition opencv.hpp:20
FlowGraphFlag
Definition flow_graph.hpp:22
@ F_OUTLET
Definition flow_graph.hpp:25
@ F_PIT
Definition flow_graph.hpp:24
@ F_CLOSED
Definition flow_graph.hpp:23
Monotone priority queue (radix heap) and IEEE-754 float-to-uint32 order-preserving key helpers.
Definition flow_graph.hpp:29
std::vector< int > bhead
Definition flow_graph.hpp:50
Array steep
Definition flow_graph.hpp:37
std::vector< uint8_t > flag
Definition flow_graph.hpp:35
int ny
Definition flow_graph.hpp:30
std::vector< double > lake_acc
Definition flow_graph.hpp:45
std::vector< int > pitq
Definition flow_graph.hpp:46
std::vector< int > rank
Definition flow_graph.hpp:33
std::vector< int > lake_outlet
Definition flow_graph.hpp:40
void receivers(float p, uint32_t seed)
Definition flow_graph.cpp:223
Array zf
Definition flow_graph.hpp:31
std::vector< int > order
Definition flow_graph.hpp:32
std::vector< int > lake
Definition flow_graph.hpp:39
std::vector< float > lake_lo
Definition flow_graph.hpp:44
Array area
Definition flow_graph.hpp:36
void resize(int nx_, int ny_)
Definition flow_graph.cpp:28
void accumulate(const Array &z_arr, const Array *p_rain, float talus_cell)
Definition flow_graph.cpp:287
std::vector< float > lake_level
Definition flow_graph.hpp:44
int n
Definition flow_graph.hpp:30
std::vector< float > lake_volume
Definition flow_graph.hpp:43
int pit_cells
Definition flow_graph.hpp:47
std::vector< float > lake_sediment
Definition flow_graph.hpp:43
bool submerged(int i, const Array &z) const
Definition flow_graph.cpp:50
RadixHeap< int > heap
Definition flow_graph.hpp:49
std::vector< int > rcv
Definition flow_graph.hpp:34
std::vector< float > lake_hi
Definition flow_graph.hpp:44
std::vector< int > lake_root
Definition flow_graph.hpp:42
std::vector< int > bnext
Definition flow_graph.hpp:50
int nx
Definition flow_graph.hpp:30
float dist(int i) const
Definition flow_graph.cpp:44
std::vector< float > lake_target
Definition flow_graph.hpp:43
void flood(const Array &z_arr, const uint8_t *outlet, bool fast, bool seed_borders=true)
Definition flow_graph.cpp:55
Definition radix_heap.hpp:50