Computes the edges of a minimum spanning tree using Prim's algorithm.
33{
36 {
37 return result;
38 }
39
40
42 {
43
44
46 return result;
47 }
50
51 std::unordered_map<const Point*, coordf_t> smallest_distance;
52 std::unordered_map<const Point*, const Point*> smallest_distance_to;
53 smallest_distance.reserve(vertices_list.size());
54 smallest_distance_to.reserve(vertices_list.size());
55 for (size_t vertex_index = 1; vertex_index < vertices_list.size(); vertex_index++)
56 {
57 const auto& vert = vertices_list[vertex_index];
59 smallest_distance_to[&vert] = &vertices_list[0];
60 }
61
62 while (result.size() < vertices_list.size())
63 {
64
65
66
67
68
69
70
71 using MapValue = std::pair<const Point*, coordf_t>;
72 const auto closest = std::min_element(smallest_distance.begin(), smallest_distance.end(),
73 [](const MapValue& a, const MapValue& b) {
74 if (a.second != b.second)
75 return a.second < b.second;
76 return *a.first < *b.first;
77 });
78
79
81 const Point other_end = *smallest_distance_to[closest_point];
82 if (result.find(*closest_point) == result.end())
83 {
84 result[*closest_point] = std::vector<Edge>();
85 }
86 result[*closest_point].push_back({*closest_point, other_end});
87 if (result.find(other_end) == result.end())
88 {
89 result[other_end] = std::vector<Edge>();
90 }
91 result[other_end].push_back({other_end, *closest_point});
92 smallest_distance.erase(closest_point);
93 smallest_distance_to.erase(closest_point);
94
95
96 for (std::pair<const Point*, coordf_t> point_and_distance : smallest_distance)
97 {
99 const coordf_t old_distance = point_and_distance.second;
100 if (new_distance < old_distance)
101 {
102 smallest_distance[point_and_distance.first] = new_distance;
103 smallest_distance_to[point_and_distance.first] = closest_point;
104 }
105 }
106 }
107
108 return result;
109}
std::unordered_map< Point, std::vector< Edge >, PointHash > AdjacencyGraph_t
Definition MinimumSpanningTree.hpp:63
Foot closest(const Contour &c, const Vec2d &p, double stop=-1.0, const std::vector< Vec2d > *source_normals=nullptr, double normal_cosine=0.0)
Definition SeamContour.cpp:36
Kernel::Point_3 Point
Definition MeshRepair.cpp:81
double coordf_t
Definition GUI_ObjectList.hpp:46
double vsize2_with_unscale(const Point pt)
Definition MinimumSpanningTree.cpp:22