18 #ifndef GZ_MATH_VOLUMETRIC_GRID_LOOKUP_FIELD_HH_
19 #define GZ_MATH_VOLUMETRIC_GRID_LOOKUP_FIELD_HH_
26 #include <gz/math/detail/InterpolationPoint.hh>
28 #include <gz/math/detail/AxisIndex.hh>
33 inline namespace GZ_MATH_VERSION_NAMESPACE {
34 template<
typename T,
typename I = std::
size_t>
42 private: AxisIndex<T> z_indices_by_depth;
44 private: AxisIndex<T> x_indices_by_lat;
46 private: AxisIndex<T> y_indices_by_lon;
63 x_indices_by_lat.AddIndexIfNotFound(pt.X());
64 y_indices_by_lon.AddIndexIfNotFound(pt.Y());
65 z_indices_by_depth.AddIndexIfNotFound(pt.Z());
68 int num_x = x_indices_by_lat.GetNumUniqueIndices();
69 int num_y = y_indices_by_lon.GetNumUniqueIndices();
70 int num_z = z_indices_by_depth.GetNumUniqueIndices();
72 index_table.resize(num_z);
73 for(
int i = 0; i < num_z; ++i)
75 index_table[i].resize(num_y);
76 for(
int j = 0; j < num_y; ++j)
78 index_table[i][j].resize(num_x);
84 const auto &pt = _cloud[i];
86 x_indices_by_lat.GetIndex(pt.X()).value();
88 y_indices_by_lon.GetIndex(pt.Y()).value();
90 z_indices_by_depth.GetIndex(pt.Z()).value();
91 index_table[z_index][y_index][x_index] = i;
111 const double _xTol = 1e-6,
112 const double _yTol = 1e-6,
113 const double _zTol = 1e-6)
const
117 auto x_indices = x_indices_by_lat.GetInterpolators(_pt.
X(), _xTol);
118 auto y_indices = y_indices_by_lon.GetInterpolators(_pt.
Y(), _yTol);
119 auto z_indices = z_indices_by_depth.GetInterpolators(_pt.
Z(), _zTol);
121 for(
const auto &x_index : x_indices)
123 for(
const auto &y_index : y_indices)
125 for(
const auto &z_index : z_indices)
128 index_table[z_index.index][y_index.index][x_index.index];
130 InterpolationPoint3D<T>{
142 return interpolators;
152 assert(_indices.
size() == _cloud.size());
158 for(
auto pt : _cloud)
160 x_indices_by_lat.AddIndexIfNotFound(pt.X());
161 y_indices_by_lon.AddIndexIfNotFound(pt.Y());
162 z_indices_by_depth.AddIndexIfNotFound(pt.Z());
165 int num_x = x_indices_by_lat.GetNumUniqueIndices();
166 int num_y = y_indices_by_lon.GetNumUniqueIndices();
167 int num_z = z_indices_by_depth.GetNumUniqueIndices();
169 index_table.resize(num_z);
170 for(
int i = 0; i < num_z; ++i)
172 index_table[i].resize(num_y);
173 for(
int j = 0; j < num_y; ++j)
175 index_table[i][j].resize(num_x);
181 const auto &pt = _cloud[i];
183 x_indices_by_lat.GetIndex(pt.X()).value();
185 y_indices_by_lon.GetIndex(pt.Y()).value();
187 z_indices_by_depth.GetIndex(pt.Z()).value();
188 index_table[z_index][y_index][x_index] = _indices[i];
199 public:
template<
typename V>
203 const V &_default = V(0))
const
205 auto interpolators = GetInterpolators(_pt);
206 return EstimateValueUsingTrilinear(
224 public:
template<
typename V>
226 const std::vector<InterpolationPoint3D<T>> _interpolators,
229 const V &_default = V(0))
const
231 if (_interpolators.size() == 0)
235 else if (_interpolators.size() == 1)
237 if (!_interpolators[0].index.has_value())
241 return _values[_interpolators[0].index.value()];
243 else if (_interpolators.size() == 2)
245 return LinearInterpolate(_interpolators[0], _interpolators[1],
246 _values, _pt, _default);
248 else if (_interpolators.size() == 4)
250 return BiLinearInterpolate(
251 _interpolators, 0, _values, _pt, _default);
253 else if (_interpolators.size() == 8)
255 return TrilinearInterpolate(_interpolators, _values, _pt, _default);
270 x_indices_by_lat.MinKey(),
271 y_indices_by_lon.MinKey(),
272 z_indices_by_depth.MinKey()
275 x_indices_by_lat.MaxKey(),
276 y_indices_by_lon.MaxKey(),
277 z_indices_by_depth.MaxKey()