Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
from_grid.hpp
1// Copyright 2021 Arnaud Becheler <abechele@umich.edu>
2
10
11#pragma once
12
13#include "detail/bound_policy.hpp"
14#include "detail/concepts.hpp"
15#include "detail/vicinity.hpp"
16
17namespace quetzal::geography
18{
19
28template<
29 two_dimensional SpatialGrid,
30 directional Directionality,
31 class VertexProperty,
32 class EdgeProperty,
33 class Vicinity,
34 class Policy
35>
36auto from_grid(SpatialGrid const &grid, VertexProperty const &v, EdgeProperty const &e, Vicinity const &vicinity,
37 Directionality dir, Policy const &bounding_policy)
38{
39 namespace geo = quetzal::geography;
40 using connectedness = Vicinity::connectedness;
42 using vertex_t = graph_type::vertex_descriptor;
43
44 graph_type graph( grid.width() * grid.height() + bounding_policy.num_extra_vertices() ) ;
45 vicinity.connect(graph, grid, bounding_policy);
46
47 if constexpr ( ! std::is_same_v<VertexProperty, no_property>) {
48 for( auto vertex : graph.vertices() ){
49 graph[vertex] = v;
50 }
51 }
52
53 if constexpr ( ! std::is_same_v<EdgeProperty, no_property>) {
54 for(auto edge : graph.edges()){
55 if constexpr (std::constructible_from<VertexProperty, vertex_t, vertex_t, SpatialGrid>){
56 graph[edge] = EdgeProperty(edge.source(), edge.target(), grid);
57 } else {
58 static_assert(std::is_default_constructible_v<EdgeProperty>);
59 graph[edge] = e;
60 }
61 }
62 }
63
64 return graph;
65}
66
67} // namespace quetzal::geography
Definition graph.hpp:262
Concept to represent the connectedness of a graph.
Definition concepts.hpp:89
Geospatial data formatting and processing.
Definition geography.hpp:17
auto from_grid(SpatialGrid const &grid, VertexProperty const &v, EdgeProperty const &e, Vicinity const &vicinity, Directionality dir, Policy const &bounding_policy)
Spatial graph construction method.
Definition from_grid.hpp:36