|
1 |
| -#ifndef PBAT_GEOMETRY_TETRAHEDRAL_AABB_HIERARCHY_H |
2 |
| -#define PBAT_GEOMETRY_TETRAHEDRAL_AABB_HIERARCHY_H |
| 1 | +/** |
| 2 | + * @file TetrahedralAabbHierarchy.h |
| 3 | + * @author Quoc-Minh Ton-That ([email protected]) |
| 4 | + * @brief This file contains the TetrahedralAabbHierarchy class. |
| 5 | + * @date 2025-02-12 |
| 6 | + * |
| 7 | + * @copyright Copyright (c) 2025 |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +#ifndef PBAT_GEOMETRY_TETRAHEDRALAABBHIERARCHY_H |
| 12 | +#define PBAT_GEOMETRY_TETRAHEDRALAABBHIERARCHY_H |
3 | 13 |
|
4 | 14 | #include "AxisAlignedBoundingBox.h"
|
5 | 15 | #include "BoundingVolumeHierarchy.h"
|
|
17 | 27 | namespace pbat {
|
18 | 28 | namespace geometry {
|
19 | 29 |
|
| 30 | +/** |
| 31 | + * @brief Tetrahedral AABB hierarchy class. |
| 32 | + */ |
20 | 33 | class TetrahedralAabbHierarchy : public BoundingVolumeHierarchy<
|
21 | 34 | TetrahedralAabbHierarchy,
|
22 | 35 | AxisAlignedBoundingBox<3>,
|
23 | 36 | IndexVector<4>,
|
24 | 37 | 3>
|
25 | 38 | {
|
26 | 39 | public:
|
27 |
| - static auto constexpr kDims = 3; |
28 |
| - using SelfType = TetrahedralAabbHierarchy; |
29 |
| - using BaseType = |
30 |
| - BoundingVolumeHierarchy<SelfType, AxisAlignedBoundingBox<kDims>, IndexVector<4>, kDims>; |
| 40 | + static auto constexpr kDims = 3; ///< Dimension of the space |
| 41 | + using SelfType = TetrahedralAabbHierarchy; ///< Type of this class |
| 42 | + using BaseType = BoundingVolumeHierarchy< |
| 43 | + SelfType, |
| 44 | + AxisAlignedBoundingBox<kDims>, |
| 45 | + IndexVector<4>, |
| 46 | + kDims>; ///< Base type |
31 | 47 |
|
| 48 | + /** |
| 49 | + * @brief Construct a TetrahedralAabbHierarchy from a tetrahedral mesh (V,C) |
| 50 | + * @param V `|kDims|x|# verts|` vertex positions |
| 51 | + * @param C `4x|# tetrahedra|` cell indices into V |
| 52 | + * @param maxPointsInLeaf Maximum number of points in a leaf node |
| 53 | + */ |
32 | 54 | PBAT_API TetrahedralAabbHierarchy(
|
33 | 55 | Eigen::Ref<MatrixX const> const& V,
|
34 | 56 | Eigen::Ref<IndexMatrixX const> const& C,
|
35 | 57 | std::size_t maxPointsInLeaf = 10ULL);
|
36 | 58 |
|
| 59 | + /** |
| 60 | + * @brief Returns the primitive at index p |
| 61 | + * @param p Index of the primitive |
| 62 | + * @return The primitive at index p |
| 63 | + */ |
37 | 64 | PBAT_API PrimitiveType Primitive(Index p) const;
|
38 |
| - |
| 65 | + /** |
| 66 | + * @brief Returns the location of the primitive |
| 67 | + * @param primitive The primitive |
| 68 | + * @return The location of the primitive |
| 69 | + */ |
39 | 70 | PBAT_API Vector<kDims> PrimitiveLocation(PrimitiveType const& primitive) const;
|
40 |
| - |
| 71 | + /** |
| 72 | + * @brief Returns the bounding volume of the primitive |
| 73 | + * @tparam RPrimitiveIndices Index range type |
| 74 | + * @param pinds Range of primitive indices |
| 75 | + * @return The bounding volume of the primitives pinds |
| 76 | + */ |
41 | 77 | template <class RPrimitiveIndices>
|
42 | 78 | BoundingVolumeType BoundingVolumeOf(RPrimitiveIndices&& pinds) const;
|
43 |
| - |
| 79 | + /** |
| 80 | + * @brief Updates the AABBs |
| 81 | + */ |
44 | 82 | PBAT_API void Update();
|
45 |
| - |
| 83 | + /** |
| 84 | + * @brief Returns the overlapping primitives of this BVH and another BVH |
| 85 | + * @param bvh The other BVH |
| 86 | + * @param reserve Estimated number of overlapping primitives to reserve memory for |
| 87 | + * @return `2x|# overlaps|` matrix `O` of overlapping primitive pairs s.t. primitives `O(0,o)` |
| 88 | + * in this bvh, and `O(1,o)` in the other bvh overlap. |
| 89 | + */ |
46 | 90 | PBAT_API IndexMatrixX
|
47 | 91 | OverlappingPrimitives(TetrahedralAabbHierarchy const& bvh, std::size_t reserve = 1000ULL) const;
|
48 |
| - |
| 92 | + /** |
| 93 | + * @brief For each point in P, returns the index of the primitive containing it |
| 94 | + * @tparam TDerivedP Eigen matrix type |
| 95 | + * @tparam FCull Culling function type |
| 96 | + * @param P `|kDims|x|# points|` matrix of points |
| 97 | + * @param fCull Culling function |
| 98 | + * @param bParallelize Whether to parallelize the computation |
| 99 | + * @return `|# points|` vector of primitive indices containing the points |
| 100 | + */ |
49 | 101 | template <class TDerivedP, class FCull>
|
50 | 102 | IndexVectorX PrimitivesContainingPoints(
|
51 | 103 | Eigen::MatrixBase<TDerivedP> const& P,
|
52 | 104 | FCull fCull,
|
53 | 105 | bool bParallelize = true) const;
|
54 |
| - |
| 106 | + /** |
| 107 | + * @brief For each point in P, returns the index of the primitive containing it |
| 108 | + * @tparam TDerivedP Eigen matrix type |
| 109 | + * @param P `|kDims|x|# points|` matrix of points |
| 110 | + * @param bParallelize Whether to parallelize the computation |
| 111 | + * @return `|# points|` vector of primitive indices containing the points |
| 112 | + */ |
55 | 113 | template <class TDerivedP>
|
56 | 114 | IndexVectorX PrimitivesContainingPoints(
|
57 | 115 | Eigen::MatrixBase<TDerivedP> const& P,
|
58 | 116 | bool bParallelize = true) const;
|
59 |
| - |
| 117 | + /** |
| 118 | + * @brief For each point in P, returns the index of the nearest primitive to it |
| 119 | + * @tparam TDerivedP Eigen matrix type |
| 120 | + * @param P `|kDims|x|# points|` matrix of points |
| 121 | + * @param bParallelize Whether to parallelize the computation |
| 122 | + * @return `|# points|` vector of nearest primitive indices to the points |
| 123 | + */ |
60 | 124 | template <class TDerivedP>
|
61 |
| - std::pair<IndexVectorX, VectorX> NearestPrimitivesToPoints( |
62 |
| - Eigen::MatrixBase<TDerivedP> const& P, |
63 |
| - bool bParallelize = true) const; |
64 |
| - |
| 125 | + auto |
| 126 | + NearestPrimitivesToPoints(Eigen::MatrixBase<TDerivedP> const& P, bool bParallelize = true) const |
| 127 | + -> std::pair<IndexVectorX, VectorX>; |
| 128 | + /** |
| 129 | + * @brief Returns this BVH's bounding volumes |
| 130 | + * @return This BVH's bounding volumes |
| 131 | + */ |
65 | 132 | [[maybe_unused]] auto const& GetBoundingVolumes() const { return mBoundingVolumes; }
|
66 |
| - |
| 133 | + /** |
| 134 | + * @brief Updates this BVH's mesh's vertex positions |
| 135 | + * @tparam TDerivedP Eigen matrix type |
| 136 | + * @param P `|kDims|x|# verts|` matrix of vertex positions |
| 137 | + */ |
67 | 138 | template <class TDerivedP>
|
68 | 139 | void SetV(Eigen::MatrixBase<TDerivedP> const& P)
|
69 | 140 | {
|
70 | 141 | V = P;
|
71 | 142 | }
|
72 |
| - |
| 143 | + /** |
| 144 | + * @brief Returns this BVH's mesh's vertex positions |
| 145 | + * @return This BVH's mesh's vertex positions |
| 146 | + */ |
73 | 147 | [[maybe_unused]] auto GetV() const { return V; }
|
74 |
| - |
| 148 | + /** |
| 149 | + * @brief Returns this BVH's mesh's cell indices |
| 150 | + * @return This BVH's mesh's cell indices |
| 151 | + */ |
75 | 152 | [[maybe_unused]] auto GetC() const { return C; }
|
76 | 153 |
|
77 |
| - Eigen::Ref<MatrixX const> V; |
78 |
| - Eigen::Ref<IndexMatrixX const> C; |
| 154 | + Eigen::Ref<MatrixX const> V; ///< `|kDims|x|# verts|` vertex positions |
| 155 | + Eigen::Ref<IndexMatrixX const> C; ///< `4x|# tetrahedra|` cell indices into V |
79 | 156 | };
|
80 | 157 |
|
81 | 158 | template <class RPrimitiveIndices>
|
@@ -136,9 +213,9 @@ inline IndexVectorX TetrahedralAabbHierarchy::PrimitivesContainingPoints(
|
136 | 213 | }
|
137 | 214 |
|
138 | 215 | template <class TDerivedP>
|
139 |
| -inline std::pair<IndexVectorX, VectorX> TetrahedralAabbHierarchy::NearestPrimitivesToPoints( |
| 216 | +inline auto TetrahedralAabbHierarchy::NearestPrimitivesToPoints( |
140 | 217 | Eigen::MatrixBase<TDerivedP> const& P,
|
141 |
| - bool bParallelize) const |
| 218 | + bool bParallelize) const -> std::pair<IndexVectorX, VectorX> |
142 | 219 | {
|
143 | 220 | PBAT_PROFILE_NAMED_SCOPE("pbat.geometry.TetrahedralAabbHierarchy.NearestPrimitivesToPoints");
|
144 | 221 | using math::linalg::mini::FromEigen;
|
@@ -180,4 +257,4 @@ inline std::pair<IndexVectorX, VectorX> TetrahedralAabbHierarchy::NearestPrimiti
|
180 | 257 | } // namespace geometry
|
181 | 258 | } // namespace pbat
|
182 | 259 |
|
183 |
| -#endif // PBAT_GEOMETRY_TETRAHEDRAL_AABB_HIERARCHY_H |
| 260 | +#endif // PBAT_GEOMETRY_TETRAHEDRALAABBHIERARCHY_H |
0 commit comments