Skip to content

Commit 1a0db1d

Browse files
committed
Document TetrahedralAabbHierarchy
1 parent 8fd7cac commit 1a0db1d

File tree

1 file changed

+102
-25
lines changed

1 file changed

+102
-25
lines changed

source/pbat/geometry/TetrahedralAabbHierarchy.h

Lines changed: 102 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
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
313

414
#include "AxisAlignedBoundingBox.h"
515
#include "BoundingVolumeHierarchy.h"
@@ -17,65 +27,132 @@
1727
namespace pbat {
1828
namespace geometry {
1929

30+
/**
31+
* @brief Tetrahedral AABB hierarchy class.
32+
*/
2033
class TetrahedralAabbHierarchy : public BoundingVolumeHierarchy<
2134
TetrahedralAabbHierarchy,
2235
AxisAlignedBoundingBox<3>,
2336
IndexVector<4>,
2437
3>
2538
{
2639
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
3147

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+
*/
3254
PBAT_API TetrahedralAabbHierarchy(
3355
Eigen::Ref<MatrixX const> const& V,
3456
Eigen::Ref<IndexMatrixX const> const& C,
3557
std::size_t maxPointsInLeaf = 10ULL);
3658

59+
/**
60+
* @brief Returns the primitive at index p
61+
* @param p Index of the primitive
62+
* @return The primitive at index p
63+
*/
3764
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+
*/
3970
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+
*/
4177
template <class RPrimitiveIndices>
4278
BoundingVolumeType BoundingVolumeOf(RPrimitiveIndices&& pinds) const;
43-
79+
/**
80+
* @brief Updates the AABBs
81+
*/
4482
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+
*/
4690
PBAT_API IndexMatrixX
4791
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+
*/
49101
template <class TDerivedP, class FCull>
50102
IndexVectorX PrimitivesContainingPoints(
51103
Eigen::MatrixBase<TDerivedP> const& P,
52104
FCull fCull,
53105
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+
*/
55113
template <class TDerivedP>
56114
IndexVectorX PrimitivesContainingPoints(
57115
Eigen::MatrixBase<TDerivedP> const& P,
58116
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+
*/
60124
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+
*/
65132
[[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+
*/
67138
template <class TDerivedP>
68139
void SetV(Eigen::MatrixBase<TDerivedP> const& P)
69140
{
70141
V = P;
71142
}
72-
143+
/**
144+
* @brief Returns this BVH's mesh's vertex positions
145+
* @return This BVH's mesh's vertex positions
146+
*/
73147
[[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+
*/
75152
[[maybe_unused]] auto GetC() const { return C; }
76153

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
79156
};
80157

81158
template <class RPrimitiveIndices>
@@ -136,9 +213,9 @@ inline IndexVectorX TetrahedralAabbHierarchy::PrimitivesContainingPoints(
136213
}
137214

138215
template <class TDerivedP>
139-
inline std::pair<IndexVectorX, VectorX> TetrahedralAabbHierarchy::NearestPrimitivesToPoints(
216+
inline auto TetrahedralAabbHierarchy::NearestPrimitivesToPoints(
140217
Eigen::MatrixBase<TDerivedP> const& P,
141-
bool bParallelize) const
218+
bool bParallelize) const -> std::pair<IndexVectorX, VectorX>
142219
{
143220
PBAT_PROFILE_NAMED_SCOPE("pbat.geometry.TetrahedralAabbHierarchy.NearestPrimitivesToPoints");
144221
using math::linalg::mini::FromEigen;
@@ -180,4 +257,4 @@ inline std::pair<IndexVectorX, VectorX> TetrahedralAabbHierarchy::NearestPrimiti
180257
} // namespace geometry
181258
} // namespace pbat
182259

183-
#endif // PBAT_GEOMETRY_TETRAHEDRAL_AABB_HIERARCHY_H
260+
#endif // PBAT_GEOMETRY_TETRAHEDRALAABBHIERARCHY_H

0 commit comments

Comments
 (0)