header_utils
Loading...
Searching...
No Matches
point_cloud.h
1
4
5#pragma once
6
7#include <array>
8#include "geometry_common.h"
9#include "points.h"
10#include "triangles.h"
11
12namespace ghassanpl::geometry
13{
14 static inline constexpr size_t invalid_index = std::numeric_limits<size_t>::max();
15
16 template <typename T>
17 struct vertex_weight
18 {
19 size_t index = invalid_index;
20 T weight = {};
21 };
24
25 template <typename T>
27 {
28 using tvec = glm::tvec2<T>;
29
30 tvec_span<T> points;
31 std::vector<tindexed_triangle<>> triangles;
35
36 size_t triangle_at(tvec const& pt) const;
37
38 std::array<vertex_weight<T>, 3> interpolation_of(tvec const& pt) const
39 {
40 const auto idx = triangle_at(pt);
41 if (idx == invalid_index)
42 return {};
43 const auto tri = triangles[idx].as_triangle(points);
44 const auto bary = tri.barycentric_coords_of(pt);
45 return {
46 vertex_weight{triangles[idx].indices[0], bary.x},
47 vertex_weight{triangles[idx].indices[1], bary.y},
48 vertex_weight{triangles[idx].indices[2], bary.z}
49 };
50 }
51 };
52
53 template <typename T, typename FUNC>
54 auto linear_interpolation(std::span<vertex_weight<T>> weights, FUNC&& value_func)
55 {
56 auto result = T{};
57 auto weight_sum = T{};
58 for (auto const& vw : weights)
59 {
60 result += vw.weight * value_func(vw.index);
61 weight_sum += vw.weight;
62 }
63 return result /= weight_sum;
64 }
65}
TODO: https://github.com/delfrrr/delaunator-cpp/blob/master/include/delaunator.hpp https://en....
Definition point_cloud.h:27
size_t triangle_at(tvec const &pt) const
TODO: hull TODO: halfedges TODO: voronoi data.