1#if TATOOINE_CGAL_AVAILABLE
2#ifndef TATOOINE_DETAIL_POINTSET_NATURAL_NEIGHBOR_COORDINATES_SAMPLER_WITH_GRADIENTS_H
3#define TATOOINE_DETAIL_POINTSET_NATURAL_NEIGHBOR_COORDINATES_SAMPLER_WITH_GRADIENTS_H
5#include <CGAL/natural_neighbor_coordinates_2.h>
6#include <CGAL/natural_neighbor_coordinates_3.h>
13template <floating_point Real, std::size_t NumDimensions,
typename ValueType,
17 :
field<natural_neighbor_coordinates_sampler_with_gradients<
18 Real, NumDimensions, ValueType, Gradient>,
19 Real, NumDimensions, ValueType> {
30 typename pointset_type::template typed_vertex_property_type<ValueType>;
32 typename pointset_type::template typed_vertex_property_type<Gradient>;
34 using cgal_kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
38 using cgal_point =
typename cgal_triangulation_type::Point;
49 :
m_p{ps},
m_z{property},
m_g{gradients_property} {
50 auto points = std::vector<std::pair<cgal_point, vertex_handle>>{};
51 points.reserve(ps.
vertices().size());
53 auto const& p = ps[v];
55 points.emplace_back(
cgal_point{ps[v](0), ps[v](1)}, v);
77 template <std::
size_t... Is>
79 std::index_sequence<Is...> ) const
81 using nnc_per_vertex_type =
82 std::vector<std::pair<
typename cgal_triangulation_type::Vertex_handle,
86 auto nnc_per_vertex = nnc_per_vertex_type{};
87 auto const result = CGAL::natural_neighbor_coordinates_2(
89 std::back_inserter(nnc_per_vertex),
91 std::pair<
typename cgal_triangulation_type::Vertex_handle,
96 auto const norm = 1 / result.second;
99 auto sum = ValueType{};
100 for (
auto const& [cgal_handle, coeff] : nnc_per_vertex) {
101 auto const v = cgal_handle->info();
102 auto const lambda_i = coeff *
norm;
109 auto numerator = ValueType{};
111 for (
auto const& [cgal_handle, coeff] : nnc_per_vertex) {
112 auto const v = cgal_handle->info();
113 auto const lambda_i = coeff *
norm;
114 auto const& p_i =
m_p[v];
115 auto const& g_i =
m_g[v];
116 auto const xi_i = [&] {
117 if constexpr (tensor_rank<ValueType> == 0) {
118 return m_z[v] +
dot(g_i, x - p_i);
124 numerator += w * xi_i;
127 return numerator / denominator;
131 auto numerator = ValueType{};
133 for (
auto const& [cgal_handle, coeff] : nnc_per_vertex) {
134 auto const v = cgal_handle->info();
135 auto const lambda_i = coeff *
norm;
136 auto const& p_i =
m_p[v];
138 numerator += lambda_i;
141 return numerator / denominator;
146 for (
auto const& [cgal_handle, coeff] : nnc_per_vertex) {
147 auto const v = cgal_handle->info();
148 auto const lambda_i = coeff *
norm;
149 auto const& p_i =
m_p[v];
155 return (alpha * Z0 + beta * xi) / (alpha + beta);
161 return evaluate(x, std::make_index_sequence<NumDimensions>{});
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
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
constexpr auto dot(base_tensor< Tensor0, T0, N > const &lhs, base_tensor< Tensor1, T1, N > const &rhs)
Definition: tensor_operations.h:120
auto transposed(dynamic_tensor auto &&t)
Definition: transposed_tensor.h:170
constexpr auto squared_euclidean_distance(base_tensor< Tensor0, T0, N > const &lhs, base_tensor< Tensor1, T1, N > const &rhs)
Definition: distance.h:11
constexpr auto sum(base_tensor< Tensor, T, VecDim > const &v)
sum of all components of a vector
Definition: tensor_operations.h:110
constexpr auto euclidean_distance(base_tensor< Tensor0, T0, N > const &lhs, base_tensor< Tensor1, T1, N > const &rhs)
Definition: distance.h:19
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:19
gradient_vertex_property_type const & m_g
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:43
vertex_property_type const & m_z
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:42
auto evaluate(pos_type const &x, real_type const) const -> tensor_type
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:159
cgal_triangulation_type m_triangulation
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:44
auto evaluate(pos_type const &x, std::index_sequence< Is... >) const -> tensor_type
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:78
typename pointset_type::template typed_vertex_property_type< ValueType > vertex_property_type
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:30
natural_neighbor_coordinates_sampler_with_gradients(natural_neighbor_coordinates_sampler_with_gradients &&) noexcept=default
natural_neighbor_coordinates_sampler_with_gradients(natural_neighbor_coordinates_sampler_with_gradients const &)=default
typename pointset_type::vertex_handle vertex_handle
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:28
pointset_type const & m_p
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:41
typename cgal_triangulation_type::Point cgal_point
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:38
typename pointset_type::template typed_vertex_property_type< Gradient > gradient_vertex_property_type
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:32
CGAL::Exact_predicates_inexact_constructions_kernel cgal_kernel
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:34
cgal::delaunay_triangulation_with_info< NumDimensions, cgal_kernel, vertex_handle > cgal_triangulation_type
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:37
natural_neighbor_coordinates_sampler_with_gradients(pointset_type const &ps, vertex_property_type const &property, gradient_vertex_property_type const &gradients_property)
Definition: natural_neighbor_coordinates_sampler_with_gradients.h:46
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: pointset.h:83
Definition: pointset.h:69
auto vertices() const
Definition: pointset.h:226
static auto constexpr ood_tensor()
Definition: field.h:21