12#include <autodiff/forward/real.hpp>
24 static_assert(Coordinates::dim == 3,
"TexLinearInterpolator3D requires 3D coordinates");
58 if (!
owner)
throw std::runtime_error(
"Cannot update data of non-owner interpolator");
60 if constexpr (std::is_same_v<NT2, autodiff::real>)
88 auto [idx_x, idx_y, idx_z] =
coordinates.backward(x, y, z);
90 if constexpr (std::is_same_v<ReturnType, autodiff::real>)
91 return std::array<double, 2>{tex3D<float>(
texture, idx_z + 0.5f, idx_y + 0.5f, idx_x + 0.5f),
92 tex3D<float>(
texture_AD, idx_z + 0.5f, idx_y + 0.5f, idx_x + 0.5f)};
93 else if constexpr (std::is_same_v<ReturnType, float>)
94 return tex3D<float>(
texture, idx_z + 0.5f, idx_y + 0.5f, idx_x + 0.5f);
101 idx_x = max(
static_cast<decltype(idx_x)
>(0), min(idx_x,
static_cast<decltype(idx_x)
>(
shape[0] - 1)));
102 idx_y = max(
static_cast<decltype(idx_y)
>(0), min(idx_y,
static_cast<decltype(idx_y)
>(
shape[1] - 1)));
103 idx_z = max(
static_cast<decltype(idx_z)
>(0), min(idx_z,
static_cast<decltype(idx_z)
>(
shape[2] - 1)));
105 uint x1 = min(ceil(idx_x +
static_cast<decltype(idx_x)
>(1e-16)),
static_cast<decltype(idx_x)
>(
shape[0] - 1));
106 const auto x0 = x1 - 1;
107 uint y1 = min(ceil(idx_y +
static_cast<decltype(idx_y)
>(1e-16)),
static_cast<decltype(idx_y)
>(
shape[1] - 1));
108 const auto y0 = y1 - 1;
109 uint z1 = min(ceil(idx_z +
static_cast<decltype(idx_z)
>(1e-16)),
static_cast<decltype(idx_z)
>(
shape[2] - 1));
110 const auto z0 = z1 - 1;
121 const auto ret = corner000 * (x1 - idx_x) * (y1 - idx_y) * (z1 - idx_z) +
122 corner001 * (x1 - idx_x) * (y1 - idx_y) * (idx_z - z0) +
123 corner010 * (x1 - idx_x) * (idx_y - y0) * (z1 - idx_z) +
124 corner011 * (x1 - idx_x) * (idx_y - y0) * (idx_z - z0) +
125 corner100 * (idx_x - x0) * (y1 - idx_y) * (z1 - idx_z) +
126 corner101 * (idx_x - x0) * (y1 - idx_y) * (idx_z - z0) +
127 corner110 * (idx_x - x0) * (idx_y - y0) * (z1 - idx_z) +
128 corner111 * (idx_x - x0) * (idx_y - y0) * (idx_z - z0);
130 if constexpr (std::is_same_v<ReturnType, autodiff::real>) {
140 const auto ret_AD = corner000_AD * (x1 - idx_x) * (y1 - idx_y) * (z1 - idx_z) +
141 corner001_AD * (x1 - idx_x) * (y1 - idx_y) * (idx_z - z0) +
142 corner010_AD * (x1 - idx_x) * (idx_y - y0) * (z1 - idx_z) +
143 corner011_AD * (x1 - idx_x) * (idx_y - y0) * (idx_z - z0) +
144 corner100_AD * (idx_x - x0) * (y1 - idx_y) * (z1 - idx_z) +
145 corner101_AD * (idx_x - x0) * (y1 - idx_y) * (idx_z - z0) +
146 corner110_AD * (idx_x - x0) * (idx_y - y0) * (z1 - idx_z) +
147 corner111_AD * (idx_x - x0) * (idx_y - y0) * (idx_z - z0);
149 return std::array<double, 2>{{ret, ret_AD}};
150 }
else if constexpr (std::is_same_v<ReturnType, float>)
A linear interpolator for 3D data, using texture memory on the GPU and floating point arithmetic on t...
Definition tex_linear_interpolation_3D.hh:23
const ReturnType & operator[](const uint i) const
const uint size
Definition tex_linear_interpolation_3D.hh:166
cudaTextureObject_t texture_AD
Definition tex_linear_interpolation_3D.hh:176
TexLinearInterpolator3D(const Coordinates &coordinates)
Construct a TexLinearInterpolator3D with internal, zeroed data and a coordinate system.
cudaArray_t device_array_AD
Definition tex_linear_interpolation_3D.hh:175
TexLinearInterpolator3D(const NT *data, const Coordinates &coordinates)
Construct a TexLinearInterpolator3D object from a pointer to data and a coordinate system.
~TexLinearInterpolator3D()
__device__ __host__ ReturnType operator()(const float x, const float y, const float z) const
Interpolate the data at a given point.
Definition tex_linear_interpolation_3D.hh:86
ReturnType & operator[](const uint i)
const Coordinates & get_coordinates() const
Get the coordinate system of the data.
Definition tex_linear_interpolation_3D.hh:163
typename internal::__TLITypes< NT >::ReturnType ReturnType
Definition tex_linear_interpolation_3D.hh:76
cudaArray_t device_array
Definition tex_linear_interpolation_3D.hh:171
TexLinearInterpolator3D(const TexLinearInterpolator3D &other)
Construct a copy of a TexLinearInterpolator3D object.
void update(const NT2 *data)
Definition tex_linear_interpolation_3D.hh:56
const Coordinates coordinates
Definition tex_linear_interpolation_3D.hh:168
TexLinearInterpolator3D(const std::vector< NT > &data, const Coordinates &coordinates)
Construct a TexLinearInterpolator3D object from a vector of data and a coordinate system.
const bool owner
Definition tex_linear_interpolation_3D.hh:178
const std::array< uint, 3 > shape
Definition tex_linear_interpolation_3D.hh:167
std::shared_ptr< float[]> m_data
Definition tex_linear_interpolation_3D.hh:170
std::shared_ptr< float[]> m_data_AD
Definition tex_linear_interpolation_3D.hh:174
cudaTextureObject_t texture
Definition tex_linear_interpolation_3D.hh:172
Definition complex_math.hh:14
unsigned int uint
Definition utils.hh:22