Lagrange
Loading...
Searching...
No Matches
EdgeAABBTree.h
1/*
2 * Copyright 2020 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/bvh/AABB.h>
15#include <lagrange/common.h>
16#include <lagrange/utils/function_ref.h>
17
18#include <Eigen/Core>
19#include <Eigen/Geometry>
20
21namespace lagrange {
22namespace bvh {
23
26
27// AABB tree for an edge graph
28template <typename VertexArray, typename EdgeArray, int Dim = 3>
29struct EdgeAABBTree
30{
31 using Scalar = typename VertexArray::Scalar;
32 using Index = typename EdgeArray::Scalar;
33 using AlignedBoxType = typename AABB<Scalar, Dim>::Box;
34 using RowVectorType = Eigen::Matrix<Scalar, 1, Dim>;
35
36private:
37 const VertexArray* m_vertices = nullptr;
38 const EdgeArray* m_edges = nullptr;
39
40 // Use AABB for spatial indexing
41 AABB<Scalar, Dim> m_aabb;
42
43public:
45 using ActionCallback = function_ref<void(Scalar, Index, const RowVectorType&)>;
46
47 EdgeAABBTree() = default; // Default empty constructor
48
55 EdgeAABBTree(const VertexArray& V, const EdgeArray& E);
56
62 bool empty() const { return m_aabb.empty(); }
63
73 const RowVectorType& p,
74 Index element_id,
75 RowVectorType& closest_point,
76 Scalar& closest_sq_dist) const;
77
85 void foreach_element_in_radius(const RowVectorType& p, Scalar sq_dist, ActionCallback func)
86 const;
87
98 void foreach_element_containing(const RowVectorType& p, ActionCallback func) const;
99
114 const RowVectorType& p,
115 Index& element_id,
116 RowVectorType& closest_point,
117 Scalar& closest_sq_dist,
118 function_ref<bool(Index)> filter_func = [](Index) { return true; }) const;
119};
120
122
123} // namespace bvh
124} // namespace lagrange
125
126// Templated definitions
127#include <lagrange/bvh/EdgeAABBTree.impl.h>
Axis-Aligned Bounding Box (AABB) tree for efficient spatial queries.
Definition AABB.h:39
A lightweight non-owning reference to a callable.
Definition function_ref.h:47
void get_element_closest_point(const RowVectorType &p, Index element_id, RowVectorType &closest_point, Scalar &closest_sq_dist) const
Gets the closest point to a given element.
Definition EdgeAABBTree.impl.h:151
void get_closest_point(const RowVectorType &p, Index &element_id, RowVectorType &closest_point, Scalar &closest_sq_dist, function_ref< bool(Index)> filter_func=[](Index) { return true;}) const
Gets the closest point to an element of the tree.
Definition EdgeAABBTree.impl.h:213
function_ref< void(Scalar, Index, const RowVectorType &)> ActionCallback
closest_sq_dist x element_id x closest_point
Definition EdgeAABBTree.h:45
bool empty() const
Test whether the tree is empty.
Definition EdgeAABBTree.h:62
void foreach_element_containing(const RowVectorType &p, ActionCallback func) const
Iterate over edges that contain exactly a given query point.
Definition EdgeAABBTree.impl.h:188
void foreach_element_in_radius(const RowVectorType &p, Scalar sq_dist, ActionCallback func) const
Iterate over edges within a prescribed distance from a query point.
Definition EdgeAABBTree.impl.h:170
EdgeAABBTree(const VertexArray &V, const EdgeArray &E)
Construct an AABB over the given edge graph.
Definition EdgeAABBTree.impl.h:125
Main namespace for Lagrange.