Skip to content

Commit 8768a78

Browse files
authored
Integrate SimpleBVH Broad Phase (#75)
1 parent 1d1a1b9 commit 8768a78

30 files changed

+476
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,4 @@ tests/src/tests/config.hpp
265265
docs/_doxygen
266266

267267
notebooks/*.[ch]pp
268+
tests/data/cloth_ball_bf_ccd_candidated.json

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ else()
149149
target_link_libraries(ipc_toolkit PUBLIC evouga::ccd)
150150
endif()
151151

152+
# SimpleBVH
153+
include(simple_bvh)
154+
target_link_libraries(ipc_toolkit PUBLIC simple_bvh::simple_bvh)
155+
152156
# Logger
153157
include(spdlog)
154158
target_link_libraries(ipc_toolkit PUBLIC spdlog::spdlog)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ The following libraries are used in this project:
6363
* [libigl](https://github.com/libigl/libigl): basic geometry functions and predicates
6464
* [TBB](https://github.com/wjakob/tbb): parallelization
6565
* [Tight-Inclusion](https://github.com/Continuous-Collision-Detection/Tight-Inclusion): correct (conservative) CCD
66+
* [SimpleBVH](https://github.com/ipc-sim/SimpleBVH): a simple bounding volume hierarchy data structure
6667
* [spdlog](https://github.com/gabime/spdlog): logging information
6768

6869
#### Optional

cmake/recipes/simple_bvh.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# BVH
2+
# License: MIT
3+
4+
if(TARGET simple_bvh::simple_bvh)
5+
return()
6+
endif()
7+
8+
message(STATUS "Third-party: creating target 'simple_bvh::simple_bvh'")
9+
10+
include(CPM)
11+
CPMAddPackage("gh:ipc-sim/SimpleBVH#2117898eb366647d6aacdb82860b9315fb42d6ad")

docs/source/cpp-api/broad_phase.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ Spatial Hash
2525

2626
.. doxygenclass:: ipc::SpatialHash
2727

28+
BVH
29+
---
30+
31+
.. doxygenclass:: ipc::BVH
32+
2833
Sweep and Tiniest Queue
2934
-----------------------
3035

docs/source/python-api/broad_phase.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ Spatial Hash
3535

3636
.. autoclasstoc::
3737

38+
BVH
39+
---
40+
41+
.. autoclass:: ipctk.BVH
42+
43+
.. autoclasstoc::
44+
3845
Sweep and Tiniest Queue
3946
-----------------------
4047

python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pybind11_add_module(ipctk
1111
src/broad_phase/aabb.cpp
1212
src/broad_phase/broad_phase.cpp
1313
src/broad_phase/brute_force.cpp
14+
src/broad_phase/bvh.cpp
1415
src/broad_phase/hash_grid.cpp
1516
src/broad_phase/spatial_hash.cpp
1617
src/broad_phase/sweep_and_tiniest_queue.cpp

python/src/bindings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PYBIND11_MODULE(ipctk, m)
1818
define_aabb(m);
1919
define_broad_phase(m);
2020
define_brute_force(m);
21+
define_bvh(m);
2122
define_hash_grid(m);
2223
define_spatial_hash(m);
2324
define_sweep(m);

python/src/broad_phase/bindings.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace py = pybind11;
77
void define_aabb(py::module_& m);
88
void define_broad_phase(py::module_& m);
99
void define_brute_force(py::module_& m);
10+
void define_bvh(py::module_& m);
1011
void define_hash_grid(py::module_& m);
1112
void define_spatial_hash(py::module_& m);
1213
void define_sweep(py::module_& m);

python/src/broad_phase/bvh.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#include <pybind11/pybind11.h>
2+
#include <pybind11/stl.h>
3+
#include <pybind11/iostream.h>
4+
#include <pybind11/operators.h>
5+
6+
#include <ipc/broad_phase/bvh.hpp>
7+
8+
namespace py = pybind11;
9+
using namespace ipc;
10+
11+
void define_bvh(py::module_& m)
12+
{
13+
py::class_<BVH, BroadPhase>(m, "BVH")
14+
.def(
15+
"build",
16+
py::overload_cast<
17+
const Eigen::MatrixXd&, const Eigen::MatrixXi&,
18+
const Eigen::MatrixXi&, const double>(&BVH::build),
19+
R"ipc_Qu8mg5v7(
20+
Build the broad phase for static collision detection.
21+
22+
Parameters:
23+
V0: Positions of the vertices.
24+
E: Edges of the mesh.
25+
F: Faces of the mesh.
26+
inflation_radius: Radius of inflation around all elements.
27+
)ipc_Qu8mg5v7",
28+
py::arg("V"), py::arg("E"), py::arg("F"),
29+
py::arg("inflation_radius") = 0)
30+
.def(
31+
"build",
32+
py::overload_cast<
33+
const Eigen::MatrixXd&, const Eigen::MatrixXd&,
34+
const Eigen::MatrixXi&, const Eigen::MatrixXi&, const double>(
35+
&BVH::build),
36+
R"ipc_Qu8mg5v7(
37+
Build the broad phase for continuous collision detection.
38+
39+
Parameters:
40+
V0: Starting positions of the vertices.
41+
V1: Ending positions of the vertices.
42+
E: Edges of the mesh.
43+
F: Faces of the mesh.
44+
inflation_radius: Radius of inflation around all elements.
45+
)ipc_Qu8mg5v7",
46+
py::arg("V0"), py::arg("V1"), py::arg("E"), py::arg("F"),
47+
py::arg("inflation_radius") = 0)
48+
.def("clear", &BVH::clear, "Clear any built data.")
49+
.def(
50+
"detect_vertex_vertex_candidates",
51+
[](BVH& self) {
52+
std::vector<VertexVertexCandidate> candidates;
53+
self.detect_vertex_vertex_candidates(candidates);
54+
return candidates;
55+
},
56+
R"ipc_Qu8mg5v7(
57+
Find the candidate vertex-vertex collisions.
58+
59+
Returns:
60+
The candidate vertex-vertex collisions.
61+
)ipc_Qu8mg5v7")
62+
.def(
63+
"detect_edge_vertex_candidates",
64+
[](BVH& self) {
65+
std::vector<EdgeVertexCandidate> candidates;
66+
self.detect_edge_vertex_candidates(candidates);
67+
return candidates;
68+
},
69+
R"ipc_Qu8mg5v7(
70+
Find the candidate edge-vertex collisions.
71+
72+
Returns:
73+
The candidate edge-vertex collisions.
74+
)ipc_Qu8mg5v7")
75+
.def(
76+
"detect_edge_edge_candidates",
77+
[](BVH& self) {
78+
std::vector<EdgeEdgeCandidate> candidates;
79+
self.detect_edge_edge_candidates(candidates);
80+
return candidates;
81+
},
82+
R"ipc_Qu8mg5v7(
83+
Find the candidate edge-edge collisions.
84+
85+
Returns:
86+
The candidate edge-edge collisions.
87+
)ipc_Qu8mg5v7")
88+
.def(
89+
"detect_face_vertex_candidates",
90+
[](BVH& self) {
91+
std::vector<FaceVertexCandidate> candidates;
92+
self.detect_face_vertex_candidates(candidates);
93+
return candidates;
94+
},
95+
R"ipc_Qu8mg5v7(
96+
Find the candidate face-vertex collisions.
97+
98+
Returns:
99+
The candidate face-vertex collisions.
100+
)ipc_Qu8mg5v7")
101+
.def(
102+
"detect_edge_face_candidates",
103+
[](BVH& self) {
104+
std::vector<EdgeFaceCandidate> candidates;
105+
self.detect_edge_face_candidates(candidates);
106+
return candidates;
107+
},
108+
R"ipc_Qu8mg5v7(
109+
Find the candidate edge-face intersections.
110+
111+
Returns:
112+
The candidate edge-face intersections.
113+
)ipc_Qu8mg5v7");
114+
}

0 commit comments

Comments
 (0)