22#ifndef PECLET_CORE_GEOM_SCENE_HPP
23#define PECLET_CORE_GEOM_SCENE_HPP
126template <
class Real,
class Pool>
128 const Real fx = (p.
x -
d.origin.x) *
d.invSpacing.x;
129 const Real fy = (p.
y -
d.origin.y) *
d.invSpacing.y;
130 const Real fz = (p.
z -
d.origin.z) *
d.invSpacing.z;
140 const int off =
d.offset;
141 const auto at = [&](
int x,
int y,
int z) {
142 return (
Real)
pool(off + (
long)z *
nxny + (
long)y *
d.nx + x);
153 const Real rx = (
d.invSpacing.x >
Real(0)) ? (
fx - cx) /
d.invSpacing.x :
Real(0);
154 const Real ry = (
d.invSpacing.y >
Real(0)) ? (
fy - cy) /
d.invSpacing.y :
Real(0);
155 const Real rz = (
d.invSpacing.z >
Real(0)) ? (
fz - cz) /
d.invSpacing.z :
Real(0);
162template <
class Real,
class Gr
ids,
class Pool>
253template <
class Real,
class Nodes,
class Gr
ids,
class Pool>
271 const auto& n = nodes(
root);
278 const auto& n = nodes(
f.node);
283 }
else if (
f.stage == 0) {
287 const auto& c = nodes(n.aux0);
291 }
else if (
f.stage == 1) {
296 const auto& c = nodes(n.aux1);
319template <
class Real,
class Gr
ids,
class Pool>
343 const Real hx =
Real(0.5) /
d.invSpacing.x, hy =
Real(0.5) /
d.invSpacing.y,
344 hz =
Real(0.5) /
d.invSpacing.z;
376template <
class Real,
class Nodes,
class Gr
ids,
class Pool>
397 const auto& n = nodes(
root);
405 const auto& n = nodes(
f.node);
411 }
else if (
f.stage == 0) {
417 const auto& c = nodes(n.aux0);
426 }
else if (
f.stage == 1) {
434 const auto& c = nodes(n.aux1);
477 return inst.transform.scale *
d;
501 for (
int i = 0;
i <
sc.instanceCount; ++
i) {
PECLET_HD Real hdMin(Real a, Real b)
PECLET_HD Real hdMax(Real a, Real b)
PECLET_HD Real hdSqrt(Real v)
constexpr int kMaxTreeDepth
Maximum shape-tree depth the iterative evaluator supports.
PECLET_HD Real evalTreeGrad(const Nodes &nodes, int nodeCount, int root, Vec3< Real > p, const Grids &grids, const Pool &pool, Vec3< Real > &grad)
evalTree WITH its analytic gradient, one traversal (Layer 0's runtime layer catching up with the comp...
@ kSphere
params[0] = radius
@ kDifference
max(L, -R) — L minus R
@ kEllipsoid
params[0..2] = rx, ry, rz (BOUND, under-estimates)
@ kTorus
params[0..1] = majorRadius, minorRadius (exact, y axis)
@ kBox
params[0..2] = hx, hy, hz
@ kSuperquadric
params[0..3] = rx, ry, rz, exponent (BOUND, under-estimates)
@ kGrid
sampled field; aux0 = index into the GridDesc table
@ kHollowCylinderShell
params[0..2] = rOuter, rInner, height (sign-exact, z axis)
@ kCapsule
params[0..1] = radius, halfLength (exact, y axis)
@ kCone
params[0..2] = rBottom, rTop, halfHeight (exact, y axis)
@ kHollowCylinder
params[0..2] = rOuter, height, thickness (distance-exact, y axis)
@ kUnion
min(L, R) — aux0/aux1 = child node indices
PECLET_HD Real evalCandidates(const SceneView< Real > &sc, Vec3< Real > p, const int *candidates, int nCandidates)
Signed distance of a scene over a CANDIDATE LIST (contract 9): the union of the listed instances,...
PECLET_HD Vec3< Real > instanceVelocity(const Instance< Real > &inst, Vec3< Real > p)
PECLET_HD Vec3< Real > instanceCentre(const Instance< Real > &inst)
Rigid-body surface velocity of instance inst at world point p: linVel + angVel x (p - c),...
PECLET_HD Real evalLeaf(const ShapeNode< Real > &n, Vec3< Real > p, const Grids &grids, const Pool &pool)
Evaluate a single LEAF node at a point already in that node's canonical frame.
PECLET_HD Real evalTree(const Nodes &nodes, int nodeCount, int root, Vec3< Real > p, const Grids &grids, const Pool &pool)
Evaluate the shape tree rooted at root at point p (in the root's parent frame).
PECLET_HD Vec3< Real > leafGrad(const ShapeNode< Real > &n, Vec3< Real > p, const Grids &grids, const Pool &pool)
Closed-form gradient of one leaf in its canonical frame (unnormalised, mirroring the prim::* contract...
PECLET_HD Real evalScene(const SceneView< Real > &sc, Vec3< Real > p)
Convenience: the union of EVERY instance.
PECLET_HD Real sampleGrid(Vec3< Real > p, const GridDesc< Real > &d, const Pool &pool)
Trilinear sample of a grid field, with the clamp-plus-residual off-grid extension selected by d....
GridExtension
NOT YET A NODE KIND: prim::Rounded (offset/rounding) stays a compile-time wrapper for now.
PECLET_HD Real evalInstance(const SceneView< Real > &sc, int i, Vec3< Real > p)
Signed distance of ONE instance at world point p.
PECLET_HD Vec3< Real > toCanonical(const Transform< Real > &tr, Vec3< Real > p)
Map a point from the parent frame into this transform's canonical frame.
PECLET_HD Vec3< Real > rotate(Quat< Real > q, Vec3< Real > v)
Rotate v by q.
PECLET_HD Vec3< Real > add(Vec3< Real > a, Vec3< Real > b)
PECLET_HD Vec3< Real > invRotate(Quat< Real > q, Vec3< Real > v)
Rotate v by the conjugate of q — dem invRotateVector.
Kokkos::View< T *, MemSpace > View
1D device array.
PECLET_HD Vec3< Real > sub(Vec3< Real > a, Vec3< Real > b)
PECLET_HD Vec3< Real > scale(Vec3< Real > a, Real s)
PECLET_HD Vec3< Real > cross(Vec3< Real > a, Vec3< Real > b)
double Real
Default host floating type. Device kernels may use float; conversions happen at the boundary.
Descriptor for one sampled field inside a shared sample pool.
Vec3< Real > invSpacing
1 / node spacing, per axis (dem stores the inverse too)
int offset
start index of this field's samples in the pool
One placed copy of a shape tree (contract 7).
int materialId
consumer-defined; -1 = unset
bool centerPinned
true: center is an explicit world point (the origin included); false: the centre follows the body (co...
Vec3< Real > center
reference point of the rotation, in world coordinates
Transform< Real > transform
int shapeRoot
index of the root ShapeNode of this instance's tree
Adaptors so a raw pointer can stand in for a Kokkos View (Views already provide operator()),...
PECLET_HD T operator()(long i) const
Non-owning bundle of everything a scene evaluation needs (resolved decision 4).
const Instance< Real > * instances
const GridDesc< Real > * grids
const ShapeNode< Real > * nodes
One node of a flat shape tree. POD, trivially copyable, safe in a Kokkos View.
int aux0
CSG: left child index. kGrid: GridDesc table index.
Transform< Real > transform
int aux1
CSG: right child index.
PECLET_HD const T & operator()(long i) const
Axis-aligned solid box of half-extents (hx, hy, hz), centred on the origin.
Solid capsule about the y axis: a segment from (0,-halfLength,0) to (0,+halfLength,...
Solid capped cone (frustum) about the y axis: radius rBottom at y = -halfHeight, radius rTop at y = +...
Solid ellipsoid with semi-axes (rx, ry, rz), centred on the origin.
Solid tube wall about the z axis as a CSG intersection of half-spaces: max(r - rOuter,...
Solid tube wall about the y axis: outer radius rOuter, full height height, wall thickness thickness (...
Solid ball of radius radius, centred on the origin.
Solid superquadric with semi-axes (rx, ry, rz) and exponent e: the implicit |x/rx|^e + |y/ry|^e + |z/...
Solid torus with its axis along y: tube of minor radius minorRadius swept around a circle of radius m...