94 Graph(std::vector<float> x, std::vector<float> y);
102 void add_edge(
int u,
int v,
float weight);
117 void add_edge(glm::ivec2 edge,
float weight);
187 size_t degree(
int u) const;
201 std::vector<
int>
dijkstra(
int source_point_index,
202 int target_point_index) const;
322 bool color_by_edge_weight = true) const;
340 float persistence = 1.
f) const;
354 Array *p_noise_x =
nullptr,
355 Array *p_noise_y =
nullptr,
363 void to_csv(
const std::string &fname_xy,
364 const std::string &fname_edges)
const;
371 void to_png(
const std::string &fname, glm::ivec2 shape = {512, 512})
const;
374 std::vector<Edge> edge_list;
375 std::vector<std::vector<Neighbor>> adj_list;
377 static const std::vector<Neighbor> empty_neighbors;
379 void ensure_adj_capacity(
size_t node_count);
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
Represents a collection of unordered points in 2D space.
Definition cloud.hpp:61
Cloud()
Default constructor for the Cloud class.
std::vector< Point > points
Points of the cloud.
Definition cloud.hpp:663
std::vector< float > get_edge_x_pairs() const
Return x coordinates of the edges (as pairs).
Definition graph.cpp:700
std::vector< float > get_lengths() const
Get the Euclidean lengths of all the edges.
Definition graph.cpp:737
void to_png(const std::string &fname, glm::ivec2 shape={512, 512}) const
Export the graph as a PNG image file.
Definition graph.cpp:997
std::vector< float > compute_flow_accumulation() const
Compute accumulated upstream flow length along directed stream edges.
Definition graph.cpp:211
void to_array(Array &array, const BBox2D &bbox, bool color_by_edge_weight=true) const
Project the graph to an array and optionally color by edge weight.
Definition graph.cpp:902
void enforce_downhill_elevation(float min_slope=0.001f)
Enforce monotonic downhill elevations on all graph nodes.
Definition graph.cpp:520
void print() const
Print the graph data to the standard output.
Definition graph.cpp:813
bool empty_edges() const noexcept
Check whether the graph has no edges.
Definition graph.cpp:678
std::vector< float > compute_distance_to_outlet() const
Compute the distance to the downstream outlet for each node in the graph.
Definition graph.cpp:104
std::vector< float > get_edge_y_pairs() const
Return y coordinates of the edges (as pairs).
Definition graph.cpp:716
Graph()=default
Construct a new Graph object.
void to_csv(const std::string &fname_xy, const std::string &fname_edges) const
Export graph data to CSV files.
Definition graph.cpp:983
const std::vector< Edge > & get_edges() const noexcept
Get the edge list.
Definition graph.cpp:732
const std::vector< Neighbor > & neighbors(int u) const
Get the neighbors of node u.
Definition graph.cpp:801
void add_edge(int u, int v, float weight)
Add an edge connecting two node indices with explicit weight.
Definition graph.cpp:63
Graph minimum_spanning_tree_prim() const
Generate a Minimum Spanning Tree (MST) using Prim's algorithm.
Definition graph.cpp:751
std::vector< float > compute_relative_widths(float exponent=1.0f) const
Compute relative channel width ratio in [0, 1] for each node in the graph.
Definition graph.cpp:300
Edge get_edge(size_t k) const
Get an edge by index.
Definition graph.cpp:683
Graph remove_orphan_points() const
Remove orphan points (points with no connected edges).
Definition graph.cpp:836
size_t num_edges() const noexcept
Get the number of edges in the graph.
Definition graph.cpp:808
void to_array_fractalize(Array &array, const BBox2D &bbox, int iterations, std::uint32_t seed, float sigma=0.3f, int orientation=0, float persistence=1.f) const
Apply fractalization to graph edges and project to an array.
Definition graph.cpp:926
size_t degree(int u) const
Get the degree (number of incident edges) of node u.
Definition graph.cpp:608
Array to_array_sdf(glm::ivec2 shape, const BBox2D &bbox, Array *p_noise_x=nullptr, Array *p_noise_y=nullptr, const BBox2D &bbox_array=BBox2D{}) const
Generate an array filled with the Signed Distance Function (SDF) to the graph.
Definition graph.cpp:968
std::vector< int > compute_strahler_order() const
Compute the Strahler stream order for each node in the graph.
Definition graph.cpp:396
void clear_edges() noexcept
Clear all edges from the graph.
Definition graph.cpp:98
float get_edge_length(size_t k) const
Get the Euclidean length of edge k.
Definition graph.cpp:689
size_t get_nedges() const noexcept
Get the number of edges in the graph.
Definition graph.cpp:746
std::vector< int > dijkstra(int source_point_index, int target_point_index) const
Return the shortest route between two points using Dijkstra's algorithm.
Definition graph.cpp:615
void set_edge_weight(size_t k, float weight)
Set the weight of edge k.
Definition graph.cpp:869
Definition of the Cloud class for manipulating sets of 2D points.
Axis-aligned 2D bounding box in world coordinates.
Definition bbox2d.hpp:25
Graph edge connecting two node indices with an associated weight.
Definition graph.hpp:38
int u
First node index.
Definition graph.hpp:39
float weight
Edge weight (cost or length).
Definition graph.hpp:41
int v
Second node index.
Definition graph.hpp:40
Graph neighbor information for adjacency representation.
Definition graph.hpp:48
float weight
Edge weight.
Definition graph.hpp:50
int target
Neighbor node index.
Definition graph.hpp:49
int edge_index
Index into the edge list.
Definition graph.hpp:51