Tatooine
inverse_distance_weighting_vertex_property_sampler.h
Go to the documentation of this file.
1#ifndef TATOOINE_DETAIL_RECTILINEAR_GRID_INVERSE_DISTANCE_WEIGHTING_VERTEX_PROPERTY_SAMPLER_H
2#define TATOOINE_DETAIL_RECTILINEAR_GRID_INVERSE_DISTANCE_WEIGHTING_VERTEX_PROPERTY_SAMPLER_H
3//==============================================================================
4#include <tatooine/field.h>
5#include <tatooine/pointset.h>
6//==============================================================================
8//==============================================================================
9template <typename Grid, typename Property>
12 inverse_distance_weighting_vertex_property_sampler<Grid, Property>,
13 typename Grid::real_type, Grid::num_dimensions(),
14 typename Property::value_type> {
15 static auto constexpr num_dimensions() -> std::size_t {
16 return Grid::num_dimensions();
17 }
18
19 using this_type =
21 using grid_type = Grid;
22 using property_type = Property;
23 using real_type = typename Grid::real_type;
24 using value_type = typename Property::value_type;
27 using typename parent_type::pos_type;
28 using typename parent_type::tensor_type;
30 tatooine::pointset<typename Grid::real_type, Grid::num_dimensions()>;
31 //----------------------------------------------------------------------------
32 Grid const& m_grid;
33 Property const& m_property;
36 //----------------------------------------------------------------------------
38 Property const& p,
39 real_type const radius)
40 : m_grid{g}, m_property{p}, m_radius{radius} {
41 m_points.vertices().reserve(m_grid.vertices().size());
42 m_grid.vertices().iterate_indices([this](auto const... is) {
43 m_points.insert_vertex(m_grid.vertex_at(is...));
44 });
45 }
46 //----------------------------------------------------------------------------
47 auto evaluate(pos_type const& x, real_type const /*t*/) const -> tensor_type {
48 auto [indices, squared_distances] =
50 if (indices.empty()) {
52 }
53 auto accumulated_prop_val = tensor_type{};
54 auto accumulated_weight = real_type{};
55
56 auto index_it = begin(indices);
57 auto squared_dist_it = begin(squared_distances);
58 for (; index_it != end(indices); ++index_it, ++squared_dist_it) {
59 auto const& property_value = m_property.plain_at(*index_it);
60 if (*squared_dist_it == 0) {
61 return property_value;
62 };
63 auto const dist = std::sqrt(*squared_dist_it);
64 auto const weight = 1 / (dist * dist * dist);
65 accumulated_prop_val += property_value * weight;
66 accumulated_weight += weight;
67 }
68 return accumulated_prop_val / accumulated_weight;
69 }
70};
71//==============================================================================
72} // namespace tatooine::detail::rectilinear_grid
73//==============================================================================
74#endif
Definition: cell_container.h:15
auto end(vertex_container< Dimensions... > const &c)
Definition: vertex_container.h:142
auto begin(vertex_container< Dimensions... > const &c)
Definition: vertex_container.h:137
Definition: inverse_distance_weighting_vertex_property_sampler.h:14
Grid const & m_grid
Definition: inverse_distance_weighting_vertex_property_sampler.h:32
real_type m_radius
Definition: inverse_distance_weighting_vertex_property_sampler.h:35
typename Grid::real_type real_type
Definition: inverse_distance_weighting_vertex_property_sampler.h:23
Property const & m_property
Definition: inverse_distance_weighting_vertex_property_sampler.h:33
pointset_type m_points
Definition: inverse_distance_weighting_vertex_property_sampler.h:34
typename Property::value_type value_type
Definition: inverse_distance_weighting_vertex_property_sampler.h:24
Grid grid_type
Definition: inverse_distance_weighting_vertex_property_sampler.h:21
auto evaluate(pos_type const &x, real_type const) const -> tensor_type
Definition: inverse_distance_weighting_vertex_property_sampler.h:47
inverse_distance_weighting_vertex_property_sampler< Grid, Property > this_type
Definition: inverse_distance_weighting_vertex_property_sampler.h:20
inverse_distance_weighting_vertex_property_sampler(Grid const &g, Property const &p, real_type const radius)
Definition: inverse_distance_weighting_vertex_property_sampler.h:37
static auto constexpr num_dimensions() -> std::size_t
Definition: inverse_distance_weighting_vertex_property_sampler.h:15
Property property_type
Definition: inverse_distance_weighting_vertex_property_sampler.h:22
Definition: field.h:134
vec< real_type, NumDimensions > pos_type
Definition: field.h:20
Tensor tensor_type
Definition: field.h:18
auto insert_vertex(arithmetic auto const ... ts)
Definition: pointset.h:243
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 vertices() const
Definition: pointset.h:226
static auto constexpr ood_tensor()
Definition: field.h:21
Definition: vec.h:12