Tatooine
natural_neighbor_coordinates_sampler.h
Go to the documentation of this file.
1#if TATOOINE_CGAL_AVAILABLE
2#ifndef TATOOINE_DETAIL_POINTSET_NATURAL_NEIGHBOR_COORDINATES_SAMPLER_H
3#define TATOOINE_DETAIL_POINTSET_NATURAL_NEIGHBOR_COORDINATES_SAMPLER_H
4//==============================================================================
5#include <CGAL/natural_neighbor_coordinates_2.h>
6#include <CGAL/natural_neighbor_coordinates_3.h>
7#include <tatooine/cgal.h>
8#include <tatooine/concepts.h>
9//==============================================================================
11//==============================================================================
12template <floating_point Real, std::size_t NumDimensions, typename T>
14 : field<natural_neighbor_coordinates_sampler<Real, NumDimensions, T>, Real,
15 NumDimensions, T> {
16 using this_type =
19 using typename parent_type::pos_type;
20 using typename parent_type::real_type;
21 using typename parent_type::tensor_type;
25 typename pointset_type::template typed_vertex_property_type<T>;
26
27 using cgal_kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
28 using cgal_triangulation_type = std::conditional_t<
29 NumDimensions == 2,
31 std::conditional_t<
32 NumDimensions == 3,
36 3, cgal_kernel>>,
37 void>>;
38 using cgal_point = typename cgal_triangulation_type::Point;
39 //==========================================================================
40 private:
44 //==========================================================================
45 public:
47 vertex_property_type const &property)
48 : m_pointset{ps}, m_property{property} {
49 auto points = std::vector<std::pair<cgal_point, vertex_handle>>{};
50 points.reserve(ps.vertices().size());
51 [&]<std::size_t... Is>(std::index_sequence<Is...> /*seq*/) {
52 for (auto v : ps.vertices()) {
53 auto const &p = ps[v];
54 if (!p.isnan()) {
55 points.emplace_back(cgal_point{p(Is)...}, v);
56 }
57 }
58 }
59 (std::make_index_sequence<NumDimensions>{});
61 }
62 //--------------------------------------------------------------------------
64 natural_neighbor_coordinates_sampler const &) = default;
65 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
67 natural_neighbor_coordinates_sampler &&) noexcept = default;
68 //--------------------------------------------------------------------------
71 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72 auto operator=(natural_neighbor_coordinates_sampler &&) noexcept
74 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
76 //==========================================================================
77 private:
78 template <std::size_t... Is>
79 [[nodiscard]] auto evaluate(pos_type const &x,
80 std::index_sequence<Is...> /*seq*/) const
81 -> tensor_type {
82 // coordinates computation
83 auto const [result, coords] = cgal::natural_neighbor_coordinates<
84 NumDimensions, typename cgal_triangulation_type::Geom_traits,
85 typename cgal_triangulation_type::Triangulation_data_structure>(
86 m_triangulation, cgal_point{x(Is)...});
87 if (!result.third) {
89 }
90 auto const norm = 1 / result.second;
91 auto t = tensor_type{};
92 for (auto const &[handle, coeff] : coords) {
93 t += m_property[handle->info()] * coeff * norm;
94 }
95 return t;
96 }
97 //----------------------------------------------------------------------------
98 public:
99 [[nodiscard]] auto evaluate(pos_type const &x, real_type const /*t*/) const
100 -> tensor_type {
101 return evaluate(x, std::make_index_sequence<NumDimensions>{});
102 }
103};
104//==============================================================================
105} // namespace tatooine::detail::pointset
106//==============================================================================
107#endif
108#endif
delaunay_triangulation< NumDimensions, Traits, triangulation_data_structure< NumDimensions, Traits, triangulation_vertex_base_with_info< NumDimensions, Info, Traits >, SimplexBase > > delaunay_triangulation_with_info
Definition: delaunay_triangulation.h:50
CGAL::Delaunay_triangulation_cell_base_with_circumcenter_3< Traits, SimplexBase > delaunay_triangulation_simplex_base_with_circumcenter
Definition: triangulation_simplex_base.h:44
auto natural_neighbor_coordinates(delaunay_triangulation< NumDimensions, Traits, TriangulationDataStructure > const &triangulation, typename delaunay_triangulation< NumDimensions, Traits, TriangulationDataStructure >::Point const &query)
Definition: natural_neighbor_coordinates.h:19
Definition: inverse_distance_weighting_sampler.h:4
auto begin(Range &&range)
Definition: iterator_facade.h:318
auto end(Range &&range)
Definition: iterator_facade.h:322
constexpr auto norm(base_tensor< Tensor, T, N > const &t, unsigned p=2) -> T
Definition: norm.h:23
Definition: natural_neighbor_coordinates_sampler.h:15
typename cgal_triangulation_type::Point cgal_point
Definition: natural_neighbor_coordinates_sampler.h:38
auto evaluate(pos_type const &x, real_type const) const -> tensor_type
Definition: natural_neighbor_coordinates_sampler.h:99
std::conditional_t< NumDimensions==2, cgal::delaunay_triangulation_with_info< 2, vertex_handle, cgal_kernel >, std::conditional_t< NumDimensions==3, cgal::delaunay_triangulation_with_info< 3, vertex_handle, cgal_kernel, cgal::delaunay_triangulation_simplex_base_with_circumcenter< 3, cgal_kernel > >, void > > cgal_triangulation_type
Definition: natural_neighbor_coordinates_sampler.h:37
typename pointset_type::template typed_vertex_property_type< T > vertex_property_type
Definition: natural_neighbor_coordinates_sampler.h:25
CGAL::Exact_predicates_inexact_constructions_kernel cgal_kernel
Definition: natural_neighbor_coordinates_sampler.h:27
natural_neighbor_coordinates_sampler(pointset_type const &ps, vertex_property_type const &property)
Definition: natural_neighbor_coordinates_sampler.h:46
pointset_type const & m_pointset
Definition: natural_neighbor_coordinates_sampler.h:41
natural_neighbor_coordinates_sampler(natural_neighbor_coordinates_sampler &&) noexcept=default
vertex_property_type const & m_property
Definition: natural_neighbor_coordinates_sampler.h:42
cgal_triangulation_type m_triangulation
Definition: natural_neighbor_coordinates_sampler.h:43
typename pointset_type::vertex_handle vertex_handle
Definition: natural_neighbor_coordinates_sampler.h:23
auto evaluate(pos_type const &x, std::index_sequence< Is... >) const -> tensor_type
Definition: natural_neighbor_coordinates_sampler.h:79
natural_neighbor_coordinates_sampler(natural_neighbor_coordinates_sampler const &)=default
Definition: field.h:134
Real real_type
Definition: field.h:17
vec< real_type, NumDimensions > pos_type
Definition: field.h:20
Tensor tensor_type
Definition: field.h:18
Definition: handle.h:14
Definition: pointset.h:83
Definition: pointset.h:69
auto vertices() const
Definition: pointset.h:226
static auto constexpr ood_tensor()
Definition: field.h:21
Definition: vec.h:12