1#ifndef TATOOINE_DETAIL_POINTSET_MOVING_LEAST_SQUARES_SAMPLER3_H
2#define TATOOINE_DETAIL_POINTSET_MOVING_LEAST_SQUARES_SAMPLER3_H
4#if TATOOINE_FLANN_AVAILABLE
15template <
floating_po
int Real,
typename T, invocable<Real> Weighting>
17 :
field<moving_least_squares_sampler<Real, 3, T, Weighting>, Real, 3, T> {
25 typename pointset_type::template typed_vertex_property_type<T>;
40 m_weighting{std::
forward<decltype(weighting)>(weighting)} {}
56 [[nodiscard]] auto evaluate_0_neighbors()
const {
57 if constexpr (is_arithmetic<tensor_type>) {
58 return Real(0) / Real(0);
65 std::vector<int>
const& indices)
const {
70 std::vector<int>
const& indices,
71 std::vector<Real>
const& distances)
const {
75 auto d0 = distances[0];
76 auto d1 = distances[1];
78 auto const d_norm = 1 / (d0 + d1);
82 return p0 * d1 + p1 * d0;
86 return evaluate_0_neighbors();
90 std::vector<int>
const& indices, std::vector<Real>
const& distances,
92 auto const num_neighbors =
size(indices);
93 auto const w = construct_weights(num_neighbors, distances);
94 auto const F = construct_F(num_neighbors, indices);
95 auto const B = construct_B(num_neighbors, indices, q);
97 auto const C = *
solve(BtW * B, BtW * F);
99 if constexpr (tensor_num_components<T> == 1) {
103 for (std::size_t i = 0; i < tensor_num_components<T>; ++i) {
111 std::vector<int>
const& indices,
pos_type const& q)
const {
112 auto B = allocate_B(num_neighbors);
113 auto local_positions = std::vector<pos_type>(num_neighbors);
114 std::ranges::copy(indices | std::views::transform([&](
auto const i) {
117 begin(local_positions));
118 if (num_neighbors >= 4) {
119 construct_linear_part_of_B(local_positions, q, B);
121 if (num_neighbors >= 10) {
122 construct_quadratic_part_of_B(local_positions, q, B);
124 if (num_neighbors >= 20) {
125 construct_cubic_part_of_B(local_positions, q, B);
131 if (num_neighbors >= 20) {
134 if (num_neighbors >= 10) {
137 if (num_neighbors >= 4) {
145 auto i = std::size_t{};
146 for (
auto const& x : local_positions) {
155 std::vector<pos_type>
const& local_positions,
pos_type const& ,
157 auto i = std::size_t{};
158 for (
auto const& x : local_positions) {
159 B(i, 4) = x.x() * x.x();
160 B(i, 5) = x.x() * x.y();
161 B(i, 6) = x.x() * x.z();
162 B(i, 7) = x.y() * x.y();
163 B(i, 8) = x.y() * x.z();
164 B(i, 9) = x.z() * x.z();
171 auto i = std::size_t{};
172 for (
auto const& x : local_positions) {
173 B(i, 10) = x.x() * x.x() * x.x();
174 B(i, 11) = x.y() * x.y() * x.y();
175 B(i, 12) = x.z() * x.z() * x.z();
176 B(i, 13) = x.x() * x.x() * x.y();
177 B(i, 14) = x.x() * x.x() * x.z();
178 B(i, 15) = x.y() * x.y() * x.x();
179 B(i, 16) = x.y() * x.y() * x.z();
180 B(i, 17) = x.z() * x.z() * x.x();
181 B(i, 18) = x.z() * x.z() * x.y();
182 B(i, 19) = x.x() * x.y() * x.z();
188 std::vector<Real>
const& distances)
const {
190 for (std::size_t i = 0; i < num_neighbors; ++i) {
191 w(i) = m_weighting(distances[i] / m_radius);
198 std::vector<int>
const& indices)
const {
199 auto F = tensor_num_components<T> > 1
202 for (std::size_t i = 0; i < num_neighbors; ++i) {
203 if constexpr (tensor_num_components<T> == 1) {
206 for (std::size_t j = 0; j < tensor_num_components<T>; ++j) {
217 auto [indices, distances] =
219 switch (
size(indices)) {
221 return evaluate_0_neighbors(q);
225 return evaluate_2_neighbors(indices, distances);
227 return evaluate_3_neighbors();
229 return evaluate_more_than_3_neighbors(indices, distances, q);
238 "including <tatooine/detail/pointset/moving_least_squares_sampler2.h> without FLANN support.")
Definition: concepts.h:33
Definition: concepts.h:39
Definition: inverse_distance_weighting_sampler.h:4
auto size(vertex_container< Real, NumDimensions > verts)
Definition: vertex_container.h:269
auto begin(Range &&range)
Definition: iterator_facade.h:318
auto solve(polynomial< Real, 1 > const &p) -> std::vector< Real >
solve a + b*x
Definition: polynomial.h:187
auto transposed(dynamic_tensor auto &&t)
Definition: transposed_tensor.h:170
static constexpr forward_tag forward
Definition: tags.h:9
Definition: moving_least_squares_sampler3.h:17
property_type const & m_property
Definition: moving_least_squares_sampler3.h:29
auto construct_linear_part_of_B(std::vector< pos_type > const &local_positions, pos_type const &, auto &B) const
Definition: moving_least_squares_sampler3.h:143
auto construct_cubic_part_of_B(std::vector< pos_type > const &local_positions, pos_type const &, auto &B) const
Definition: moving_least_squares_sampler3.h:169
Weighting m_weighting
Definition: moving_least_squares_sampler3.h:31
auto evaluate_2_neighbors(std::vector< int > const &indices, std::vector< Real > const &distances) const
Definition: moving_least_squares_sampler3.h:69
auto construct_quadratic_part_of_B(std::vector< pos_type > const &local_positions, pos_type const &, auto &B) const
Definition: moving_least_squares_sampler3.h:154
moving_least_squares_sampler(moving_least_squares_sampler const &)=default
moving_least_squares_sampler(moving_least_squares_sampler &&) noexcept=default
auto evaluate_1_neighbors(std::vector< int > const &indices) const
Definition: moving_least_squares_sampler3.h:64
typename pointset_type::vertex_handle vertex_handle
Definition: moving_least_squares_sampler3.h:26
pointset_type const & m_pointset
Definition: moving_least_squares_sampler3.h:28
auto allocate_B(std::size_t const num_neighbors) const
Definition: moving_least_squares_sampler3.h:130
moving_least_squares_sampler(pointset_type const &ps, property_type const &property, arithmetic auto const radius, convertible_to< Weighting > auto &&weighting)
Definition: moving_least_squares_sampler3.h:33
auto construct_F(std::size_t const num_neighbors, std::vector< int > const &indices) const
Represents function values f(x_i)
Definition: moving_least_squares_sampler3.h:197
auto evaluate(pos_type const &q, Real const) const -> tensor_type
Definition: moving_least_squares_sampler3.h:215
auto evaluate_more_than_3_neighbors(std::vector< int > const &indices, std::vector< Real > const &distances, pos_type const &q) const
Definition: moving_least_squares_sampler3.h:89
Real m_radius
Definition: moving_least_squares_sampler3.h:30
auto evaluate_3_neighbors() const
Definition: moving_least_squares_sampler3.h:85
auto construct_B(std::size_t const num_neighbors, std::vector< int > const &indices, pos_type const &q) const
Definition: moving_least_squares_sampler3.h:110
auto construct_weights(std::size_t const num_neighbors, std::vector< Real > const &distances) const
Definition: moving_least_squares_sampler3.h:187
typename pointset_type::template typed_vertex_property_type< T > property_type
Definition: moving_least_squares_sampler3.h:25
Definition: moving_least_squares_samplerN.h:12
Definition: vertex_handle.h:10
Real real_type
Definition: field.h:17
T tensor_type
Definition: field.h:18
auto nearest_neighbors_radius_raw(pos_type const &x, Real const radius, flann::SearchParams const params={}) const -> std::pair< std::vector< int >, std::vector< Real > >
Definition: pointset.h:1088
auto vertex_at(vertex_handle const v) -> auto &
Definition: pointset.h:205
static constexpr auto zeros()
Definition: tensor.h:144
static constexpr auto ones()
Definition: tensor.h:146