Lagrange
Loading...
Searching...
No Matches
TriangleAABBTree.h
1/*
2 * Copyright 2025 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/SurfaceMesh.h>
15#include <lagrange/bvh/AABB.h>
16#include <lagrange/utils/function_ref.h>
17
18#include <Eigen/Core>
19#include <Eigen/Geometry>
20
21namespace lagrange::bvh {
22
25
37template <typename Scalar, typename Index, int Dim = 3>
39{
40public:
41 using AlignedBoxType = typename AABB<Scalar, Dim>::Box;
42 using RowVectorType = Eigen::Matrix<Scalar, 1, Dim>;
43
44public:
46 using ActionCallback = function_ref<void(Scalar, Index, const RowVectorType&)>;
47
54
60 bool empty() const { return m_aabb.empty(); }
61
69 void foreach_triangle_in_radius(const RowVectorType& p, Scalar sq_dist, ActionCallback func)
70 const;
71
85 const RowVectorType& p,
86 Index& triangle_id,
87 RowVectorType& closest_point,
88 Scalar& closest_sq_dist) const;
89
90private:
92
93 // Use AABB for spatial indexing
94 AABB<Scalar, Dim> m_aabb;
95};
96
98
99} // namespace lagrange::bvh
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:66
Axis-Aligned Bounding Box (AABB) tree for efficient spatial queries.
Definition AABB.h:39
void foreach_triangle_in_radius(const RowVectorType &p, Scalar sq_dist, ActionCallback func) const
Iterate over triangles within a prescribed distance from a query point.
Definition TriangleAABBTree.cpp:56
TriangleAABBTree(const SurfaceMesh< Scalar, Index > &mesh)
Construct an AABB tree over the given triangle mesh.
Definition TriangleAABBTree.cpp:27
function_ref< void(Scalar, Index, const RowVectorType &)> ActionCallback
Callback signature: (squared_distance, triangle_id, closest_point)
Definition TriangleAABBTree.h:46
bool empty() const
Test whether the tree is empty.
Definition TriangleAABBTree.h:60
bool get_closest_point(const RowVectorType &p, Index &triangle_id, RowVectorType &closest_point, Scalar &closest_sq_dist) const
Gets the nearest triangle to a query point using automatic hint optimization.
Definition TriangleAABBTree.cpp:87
A lightweight non-owning reference to a callable.
Definition function_ref.h:47
@ Scalar
Mesh attribute must have exactly 1 channel.
Definition AttributeFwd.h:56