Tatooine
inverse_distance_weighting_sampler.h
Go to the documentation of this file.
1#ifndef TATOOINE_DETAIL_POINTSET_INVERSE_DISTANCE_WEIGHTING_SAMPLER_H
2#define TATOOINE_DETAIL_POINTSET_INVERSE_DISTANCE_WEIGHTING_SAMPLER_H
3//==============================================================================
5//==============================================================================
6template <floating_point Real, std::size_t NumDimensions, typename T>
7 requires(flann_available())
10 NumDimensions, T> {
13 using typename parent_type::pos_type;
14 using typename parent_type::real_type;
15 using typename parent_type::tensor_type;
19 typename pointset_t::template typed_vertex_property_type<T>;
20 //==========================================================================
23 Real m_radius = 1;
24 //==========================================================================
26 vertex_property_type const& property,
27 Real const radius = 1)
28 : m_pointset{ps}, m_property{property}, m_radius{radius} {}
29 //--------------------------------------------------------------------------
31 inverse_distance_weighting_sampler const&) = default;
32 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34 inverse_distance_weighting_sampler&&) noexcept = default;
35 //--------------------------------------------------------------------------
38 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 auto operator=(inverse_distance_weighting_sampler&&) noexcept
41 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43 //==========================================================================
44 [[nodiscard]] auto evaluate(pos_type const& x, real_type const /*t*/) const
45 -> tensor_type {
46 auto [indices, squared_distances] =
47 m_pointset.nearest_neighbors_radius_raw(x, m_radius);
48 if (indices.empty()) {
49 return parent_type::ood_tensor();
50 }
51 auto accumulated_prop_val = T{};
52 auto accumulated_weight = Real{};
53
54 auto index_it = begin(indices);
55 auto squared_dist_it = begin(squared_distances);
56 for (; index_it != end(indices); ++index_it, ++squared_dist_it) {
57 auto const& property_value = m_property[vertex_handle{*index_it}];
58 if (*squared_dist_it == 0) {
59 return property_value;
60 };
61 auto const weight = 1 / *squared_dist_it;
62 accumulated_prop_val += property_value * weight;
63 accumulated_weight += weight;
64 }
65 return accumulated_prop_val / accumulated_weight;
66 }
67};
68//==============================================================================
69} // namespace tatooine::detail::pointset
70//==============================================================================
71#endif
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
Definition: inverse_distance_weighting_sampler.h:10
pointset_t const & m_pointset
Definition: inverse_distance_weighting_sampler.h:21
typename pointset_t::template typed_vertex_property_type< T > vertex_property_type
Definition: inverse_distance_weighting_sampler.h:19
inverse_distance_weighting_sampler(pointset_t const &ps, vertex_property_type const &property, Real const radius=1)
Definition: inverse_distance_weighting_sampler.h:25
inverse_distance_weighting_sampler(inverse_distance_weighting_sampler &&) noexcept=default
typename pointset_t::vertex_handle vertex_handle
Definition: inverse_distance_weighting_sampler.h:17
vertex_property_type const & m_property
Definition: inverse_distance_weighting_sampler.h:22
inverse_distance_weighting_sampler(inverse_distance_weighting_sampler const &)=default
Definition: field.h:134
Real real_type
Definition: field.h:17
Definition: pointset.h:83
Definition: pointset.h:69
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
Definition: vec.h:12