1#ifndef PBAT_GPU_IMPL_GEOMETRY_AABB_H
2#define PBAT_GPU_IMPL_GEOMETRY_AABB_H
6#include "pbat/gpu/impl/common/Buffer.cuh"
8#include "pbat/math/linalg/mini/Matrix.h"
9#include "pbat/math/linalg/mini/UnaryOperations.h"
13#include <thrust/execution_policy.h>
14#include <thrust/for_each.h>
15#include <thrust/iterator/counting_iterator.h>
26 Aabb(
GpuIndex nBoxes) : b(nBoxes), e(nBoxes) {}
28 template <auto kSimplexVerts>
35 template <
class FLowerUpper>
36 void Construct(FLowerUpper&& fLowerUpper,
GpuIndex begin = 0,
GpuIndex end = -1);
38 template <auto kSimplexVerts>
50template <auto kSimplexVerts>
51inline Aabb<kDims>::Aabb(
59template <
class FLowerUpper>
60inline void Aabb<kDims>::Construct(FLowerUpper&& fLowerUpper,
GpuIndex begin,
GpuIndex end)
62 PBAT_PROFILE_CUDA_NAMED_SCOPE(
"pbat.gpu.impl.geometry.Aabb.Construct");
64 auto const nBoxes =
static_cast<GpuIndex>(b.Size());
65 end = end < 0 ? nBoxes : end;
68 thrust::counting_iterator<GpuIndex>(begin),
69 thrust::counting_iterator<GpuIndex>(end),
73 fLowerUpper = std::forward<FLowerUpper>(fLowerUpper)] PBAT_DEVICE(
GpuIndex i) {
75 mini::ToBuffers(LU.Col(0), b, i);
76 mini::ToBuffers(LU.Col(1), e, i);
81template <auto kSimplexVerts>
82inline void Aabb<kDims>::Construct(
83 common::Buffer<GpuScalar, kDims>
const& V,
84 common::Buffer<GpuIndex, kSimplexVerts>
const& S,
87 PBAT_PROFILE_CUDA_NAMED_SCOPE(
"pbat.gpu.impl.geometry.Aabb.Construct");
89 auto const nSimplices =
static_cast<GpuIndex>(S.Size());
90 if (Size() < nSimplices)
92 auto const end = std::min(begin + nSimplices, Size());
95 thrust::counting_iterator(begin),
96 thrust::counting_iterator(end),
97 [begin, b = b.Raw(), e = e.Raw(), V = V.Raw(), S = S.Raw()] PBAT_DEVICE(
GpuIndex i) {
99 auto inds = mini::FromBuffers<kSimplexVerts, 1>(S, s);
100 auto P = mini::FromBuffers(V, inds.Transpose());
102 b[d][i] = Min(P.Row(d));
103 e[d][i] = Max(P.Row(d));
109inline void Aabb<kDims>::Resize(
GpuIndex nBoxes)
111 PBAT_PROFILE_CUDA_NAMED_SCOPE(
"pbat.gpu.impl.geometry.Aabb.Resize");
Type aliases for GPU code.
Profiling utilities for host-side GPU code.
constexpr void ForRange(F &&f)
Compile-time for loop over a range of values.
Definition ConstexprFor.h:55
GPU algorithm implementations.
Definition VertexTriangleMixedCcdDcd.h:21
GPU related public functionality.
Definition Buffer.cu:16
Linear Algebra related functionality.
Definition FilterEigenvalues.h:7
The main namespace of the library.
Definition Aliases.h:15
std::int32_t GpuIndex
Index type for GPU code.
Definition Aliases.h:20