PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
VertexTriangleMixedCcdDcd.cuh
1#ifndef PBAT_GPU_IMPL_CONTACT_VERTEXTRIANGLEMIXEDCCDDCD_H
2#define PBAT_GPU_IMPL_CONTACT_VERTEXTRIANGLEMIXEDCCDDCD_H
3
5#include "pbat/gpu/Aliases.h"
6#include "pbat/gpu/impl/common/Buffer.cuh"
7#include "pbat/gpu/impl/geometry/Aabb.cuh"
8#include "pbat/gpu/impl/geometry/Bvh.cuh"
9#include "pbat/gpu/impl/geometry/Morton.cuh"
11
12namespace pbat::gpu::impl::contact {
13
18{
19 public:
20 static auto constexpr kDims = 3;
21 static auto constexpr kMaxNeighbours =
22 8;
23
32 Eigen::Ref<GpuIndexVectorX const> const& B,
33 Eigen::Ref<GpuIndexVectorX const> const& V,
34 Eigen::Ref<GpuIndexMatrixX const> const& F);
52 geometry::Morton::Bound const& wmin,
53 geometry::Morton::Bound const& wmax);
61 void UpdateActiveSet(common::Buffer<GpuScalar, 3> const& x, bool bComputeBoxes = true);
68 void FinalizeActiveSet(common::Buffer<GpuScalar, 3> const& x, bool bComputeBoxes = true);
76 template <class FOnNearestNeighbourFound>
79 FOnNearestNeighbourFound fOnNearestNeighbourFound);
86
87 public:
95
106};
107
108template <class FOnNearestNeighbourFound>
111 FOnNearestNeighbourFound fOnNearestNeighbourFound)
112{
113 using namespace pbat::math::linalg::mini;
114 auto fGetQueryObject = [x = x.Raw(), V = V.Raw(), av = av.Raw()] PBAT_DEVICE(GpuIndex q) {
115 GpuIndex const v = av[q];
116 return FromBuffers<3, 1>(x, V[v]);
117 };
118 auto fMinDistanceToBox = [] PBAT_DEVICE(
119 SVector<GpuScalar, 3> const& xi,
120 SVector<GpuScalar, 3> const& L,
121 SVector<GpuScalar, 3> const& U) {
123 };
124 auto fDistanceToLeaf =
125 [x = x.Raw(), V = V.Raw(), F = F.Raw(), B = B.Raw(), av = av.Raw()] PBAT_DEVICE(
126 GpuIndex q,
127 SVector<GpuScalar, 3> const& xi,
128 [[maybe_unused]] GpuIndex leaf,
129 GpuIndex f) {
130 GpuIndex const i = V[av[q]];
131 auto fv = FromBuffers<3, 1>(F, f);
132 bool const bFromSameBody = B[i] == B[fv[0]];
133 if (bFromSameBody)
134 return std::numeric_limits<GpuScalar>::max();
135
136 SMatrix<GpuScalar, 3, 3> const xf = FromBuffers(x, fv.Transpose());
138 xi,
139 xf.Col(0),
140 xf.Col(1),
141 xf.Col(2));
142 };
143 auto fDistanceUpperBound = [dupper = dupper.Raw(), av = av.Raw()] PBAT_DEVICE(GpuIndex q) {
144 // Try warm-starting the NN search!
145 return dupper[av[q]];
146 };
147 Fbvh.NearestNeighbours<
148 decltype(fGetQueryObject),
149 decltype(fMinDistanceToBox),
150 decltype(fDistanceToLeaf),
151 decltype(fDistanceUpperBound),
152 decltype(fOnNearestNeighbourFound),
154 Faabbs,
155 nActive,
156 fGetQueryObject,
157 fMinDistanceToBox,
158 fDistanceToLeaf,
159 fDistanceUpperBound,
160 fOnNearestNeighbourFound,
161 eps);
162}
163
164} // namespace pbat::gpu::impl::contact
165
166#endif // PBAT_GPU_IMPL_CONTACT_VERTEXTRIANGLEMIXEDCCDDCD_H
This file contains functions to answer distance queries.
This file includes all the mini linear algebra headers.
Definition Buffer.cuh:21
VertexTriangleMixedCcdDcd(Eigen::Ref< GpuIndexVectorX const > const &B, Eigen::Ref< GpuIndexVectorX const > const &V, Eigen::Ref< GpuIndexMatrixX const > const &F)
Construct a new Vertex Triangle Mixed Ccd Dcd object.
Definition VertexTriangleMixedCcdDcd.cu:22
void UpdateActiveSet(common::Buffer< GpuScalar, 3 > const &x, bool bComputeBoxes=true)
The active set is updated by recomputing nearest neighbours f of i, using current distances d(i,...
Definition VertexTriangleMixedCcdDcd.cu:149
static auto constexpr kDims
Spatial dimensionality of the problem.
Definition VertexTriangleMixedCcdDcd.cuh:20
geometry::Aabb< kDims > Paabbs
|# verts| axis-aligned bounding boxes of swept vertices (i.e. line segments)
Definition VertexTriangleMixedCcdDcd.cuh:99
static auto constexpr kMaxNeighbours
Maximum number of nearest neighbours to consider per vertex.
Definition VertexTriangleMixedCcdDcd.cuh:21
geometry::Aabb< kDims > Faabbs
|# tris| axis-aligned bounding boxes of (potentially swept) triangles
Definition VertexTriangleMixedCcdDcd.cuh:101
GpuScalar eps
Tolerance for NN searches.
Definition VertexTriangleMixedCcdDcd.cuh:105
void ForEachNearestNeighbour(common::Buffer< GpuScalar, 3 > const &x, FOnNearestNeighbourFound fOnNearestNeighbourFound)
Definition VertexTriangleMixedCcdDcd.cuh:109
void FinalizeActiveSet(common::Buffer< GpuScalar, 3 > const &x, bool bComputeBoxes=true)
Finalizes the active set by removing all pairs (i, f) such that sd(i,f) > 0.
Definition VertexTriangleMixedCcdDcd.cu:174
common::Buffer< GpuScalar > dupper
|# verts| NN search radius
Definition VertexTriangleMixedCcdDcd.cuh:104
common::Buffer< bool > active
|# verts| active mask
Definition VertexTriangleMixedCcdDcd.cuh:103
geometry::Morton morton
|# verts| morton codes for vertices
Definition VertexTriangleMixedCcdDcd.cuh:97
void UpdateBvh(common::Buffer< GpuScalar, 3 > const &x)
Definition VertexTriangleMixedCcdDcd.cu:205
common::Buffer< GpuIndex > inds
|# verts| vertex indices v
Definition VertexTriangleMixedCcdDcd.cuh:96
common::Buffer< GpuIndex > av
Active vertices.
Definition VertexTriangleMixedCcdDcd.cuh:88
GpuIndex nActive
Number of active vertices.
Definition VertexTriangleMixedCcdDcd.cuh:89
common::Buffer< GpuIndex > B
|# pts| body map
Definition VertexTriangleMixedCcdDcd.cuh:92
void InitializeActiveSet(common::Buffer< GpuScalar, 3 > const &xt, common::Buffer< GpuScalar, 3 > const &xtp1, geometry::Morton::Bound const &wmin, geometry::Morton::Bound const &wmax)
Computes the initial active set.
Definition VertexTriangleMixedCcdDcd.cu:51
common::Buffer< GpuIndex, 3 > F
Triangles.
Definition VertexTriangleMixedCcdDcd.cuh:94
common::Buffer< GpuIndex > nn
Definition VertexTriangleMixedCcdDcd.cuh:90
geometry::Bvh Fbvh
Bounding volume hierarchy over (potentially swept) triangles.
Definition VertexTriangleMixedCcdDcd.cuh:102
common::Buffer< GpuIndex > V
Vertices.
Definition VertexTriangleMixedCcdDcd.cuh:93
Radix-tree linear BVH.
Definition Bvh.cuh:34
Definition Morton.cuh:16
Definition Matrix.h:121
Type aliases for GPU code.
PBAT_HOST_DEVICE auto PointTriangle(TMatrixP const &P, TMatrixA const &A, TMatrixB const &B, TMatrixC const &C) -> typename TMatrixP::ScalarType
Obtain squared distance between point P and triangle ABC.
Definition DistanceQueries.h:217
PBAT_HOST_DEVICE auto PointAxisAlignedBoundingBox(TMatrixP const &P, TMatrixL const &L, TMatrixU const &U) -> typename TMatrixP::ScalarType
Obtain squared distance between point P and axis-aligned box (L,U)
Definition DistanceQueries.h:199
Mini linear algebra related functionality.
Definition Assign.h:12
float GpuScalar
Scalar type for GPU code.
Definition Aliases.h:19
std::int32_t GpuIndex
Index type for GPU code.
Definition Aliases.h:20
Definition Aabb.cuh:24