9#ifndef PECLET_CORE_GEOM_GRID_SDF_HPP
10#define PECLET_CORE_GEOM_GRID_SDF_HPP
40 for (
int d = 0; d < 3; ++d) {
42 c = std::clamp(
c, 0.0,
static_cast<double>(
dims[d] - 1));
43 i0[d] =
static_cast<Index>(std::floor(
c));
44 i1[d] = std::min<Index>(
i0[d] + 1,
dims[d] - 1);
45 f[d] =
c -
static_cast<double>(
i0[d]);
55 double c0 =
c00 * (1 -
f[1]) +
c10 *
f[1];
57 return c0 * (1 -
f[2]) +
c1 *
f[2];
68 g.
values.resize(
static_cast<std::size_t
>(dims[0]) * dims[1] * dims[2]);
69 for (
Index k = 0; k < dims[2]; ++k)
71 for (
Index i = 0;
i < dims[0]; ++
i) {
72 Vec<3> p{origin[0] +
i * spacing[0], origin[1] +
j * spacing[1],
73 origin[2] + k * spacing[2]};
74 g.
values[
i + dims[0] * (
j + dims[1] * k)] =
static_cast<float>(shape.eval(p));
GridSdf sample(const S &shape, IVec< 3 > dims, Vec< 3 > origin, Vec< 3 > spacing)
Sample any analytic SDF onto a grid, producing a GridSdf (e.g. to bake geometry for a solver).
Kokkos::View< T *, MemSpace > View
1D device array.
std::int64_t Index
Signed index type for grids and particles (supersedes block_decomposer's long int IndxT).
A signed-distance field sampled on a regular axis-aligned grid (negative inside solid).
double at(Index i, Index j, Index k) const
Raw sample lookup at integer grid index (i,j,k); no bounds checking.
Vec< 3 > origin
World position of sample (0,0,0).
std::vector< float > values
Sample values, x-fastest: idx = i + j*nx + k*nx*ny.
Vec< 3 > spacing
World-space distance between samples per axis.
double eval(const Vec< 3 > &p) const
Trilinearly-interpolated signed distance at world point p.
IVec< 3 > dims
Sample count per axis (nx, ny, nz).