From a4433159f958657ed4d2042afee8c5b4a13e1902 Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Sat, 7 Feb 2026 09:22:39 -0500 Subject: [PATCH 1/3] Set default broad phase to LBVH --- docs/source/tutorials/getting_started.rst | 2 +- src/ipc/broad_phase/default_broad_phase.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/tutorials/getting_started.rst b/docs/source/tutorials/getting_started.rst index 90a41b8dd..381df0f87 100644 --- a/docs/source/tutorials/getting_started.rst +++ b/docs/source/tutorials/getting_started.rst @@ -531,7 +531,7 @@ The ``Candidates`` class represents the culled set of candidate pairs and is bui candidates.build( mesh, vertices_t0, vertices_t1, broad_phase=ipctk.HashGrid()) -Possible values for ``broad_phase`` are: ``BruteForce`` (parallel brute force culling), ``HashGrid`` (default), ``SpatialHash`` (implementation from the original IPC codebase), ``BVH`` (`SimpleBVH `_), ``LBVH`` (CPU implementation of :cite:t:`Karras2012HPG` using TBB), ``SweepAndPrune`` (a.k.a. Sort-and-Sweep from :cite:t:`Baraff1992PhD`), or ``SweepAndTiniestQueue`` (method of :cite:t:`Belgrod2023Time`; requires CUDA). +Possible values for ``broad_phase`` are: ``BruteForce`` (parallel brute force culling), ``HashGrid``, ``SpatialHash`` (implementation from the original IPC codebase), ``BVH`` (`SimpleBVH `_), ``LBVH`` (CPU implementation of :cite:t:`Karras2012HPG` using TBB), ``SweepAndPrune`` (a.k.a. Sort-and-Sweep from :cite:t:`Baraff1992PhD`), or ``SweepAndTiniestQueue`` (method of :cite:t:`Belgrod2023Time`; requires CUDA). The default is ``LBVH``. Narrow-Phase ^^^^^^^^^^^^ diff --git a/src/ipc/broad_phase/default_broad_phase.hpp b/src/ipc/broad_phase/default_broad_phase.hpp index 723a84c1c..cba6aa116 100644 --- a/src/ipc/broad_phase/default_broad_phase.hpp +++ b/src/ipc/broad_phase/default_broad_phase.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include @@ -8,7 +8,7 @@ namespace ipc { inline std::unique_ptr make_default_broad_phase() { - return std::make_unique(); + return std::make_unique(); } } // namespace ipc \ No newline at end of file From c6341bc6ed7ae748a36f127f7dda2fa5da1322cd Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Sat, 7 Feb 2026 12:13:50 -0500 Subject: [PATCH 2/3] Check BVH sizes before collision detection - Replace has_*() checks with bvh.size() <= 1 so functions require at least two primitives for collision tests. --- .gitignore | 1 + src/ipc/broad_phase/lbvh.cpp | 6 +++--- tests/src/tests/broad_phase/brute_force_comparison.cpp | 3 ++- tests/src/tests/potential/test_barrier_potential.cpp | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index afbdfcdc7..338ed6b7f 100644 --- a/.gitignore +++ b/.gitignore @@ -672,3 +672,4 @@ python/update_bindings.py tests/data notebooks/*.png CMakeGraphVizOptions.cmake +.zed/* \ No newline at end of file diff --git a/src/ipc/broad_phase/lbvh.cpp b/src/ipc/broad_phase/lbvh.cpp index 7f3f5d311..ce6179cb5 100644 --- a/src/ipc/broad_phase/lbvh.cpp +++ b/src/ipc/broad_phase/lbvh.cpp @@ -662,7 +662,7 @@ void LBVH::detect_candidates( void LBVH::detect_vertex_vertex_candidates( std::vector& candidates) const { - if (!has_vertices()) { + if (vertex_bvh.size() <= 1) { // Need at least 2 vertices for a collision return; } @@ -690,7 +690,7 @@ void LBVH::detect_edge_vertex_candidates( void LBVH::detect_edge_edge_candidates( std::vector& candidates) const { - if (!has_edges()) { + if (edge_bvh.size() <= 1) { // Need at least 2 edges for a collision return; } @@ -734,7 +734,7 @@ void LBVH::detect_edge_face_candidates( void LBVH::detect_face_face_candidates( std::vector& candidates) const { - if (!has_faces()) { + if (face_bvh.size() <= 1) { // Need at least 2 faces for a collision return; } diff --git a/tests/src/tests/broad_phase/brute_force_comparison.cpp b/tests/src/tests/broad_phase/brute_force_comparison.cpp index b71fb281a..42d93cf63 100644 --- a/tests/src/tests/broad_phase/brute_force_comparison.cpp +++ b/tests/src/tests/broad_phase/brute_force_comparison.cpp @@ -89,8 +89,9 @@ void save_candidates( bool load_candidates(const std::string& filename, ipc::Candidates& candidates) { std::ifstream f(filename); - if (!f) + if (!f) { return false; + } nlohmann::json in; f >> in; diff --git a/tests/src/tests/potential/test_barrier_potential.cpp b/tests/src/tests/potential/test_barrier_potential.cpp index 56842e808..df361f379 100644 --- a/tests/src/tests/potential/test_barrier_potential.cpp +++ b/tests/src/tests/potential/test_barrier_potential.cpp @@ -36,7 +36,6 @@ TEST_CASE( double dhat = -1; std::string mesh_name; - bool all_vertices_on_surface = true; SECTION("cube") { dhat = sqrt(2.0); @@ -210,6 +209,8 @@ TEST_CASE( < dhat * dhat); } + REQUIRE(vertices.size() > 0); + const CollisionMesh mesh(vertices, edges, faces); NormalCollisions collisions; From 3314478f65163bea09e15502adc6fbe55d2fe7fa Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Sat, 7 Feb 2026 12:15:38 -0500 Subject: [PATCH 3/3] Use LBVH in getting_started tutorial examples --- docs/source/tutorials/getting_started.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/tutorials/getting_started.rst b/docs/source/tutorials/getting_started.rst index 381df0f87..fced64b82 100644 --- a/docs/source/tutorials/getting_started.rst +++ b/docs/source/tutorials/getting_started.rst @@ -519,7 +519,7 @@ The ``Candidates`` class represents the culled set of candidate pairs and is bui #include ipc::Candidates candidates; - ipc::HashGrid broad_phase; + ipc::LBVH broad_phase; candidates.build( mesh, vertices_t0, vertices_t1, /*inflation_radius=*/0.0, broad_phase); @@ -529,7 +529,7 @@ The ``Candidates`` class represents the culled set of candidate pairs and is bui candidates = ipctk.Candidates() candidates.build( - mesh, vertices_t0, vertices_t1, broad_phase=ipctk.HashGrid()) + mesh, vertices_t0, vertices_t1, broad_phase=ipctk.LBVH()) Possible values for ``broad_phase`` are: ``BruteForce`` (parallel brute force culling), ``HashGrid``, ``SpatialHash`` (implementation from the original IPC codebase), ``BVH`` (`SimpleBVH `_), ``LBVH`` (CPU implementation of :cite:t:`Karras2012HPG` using TBB), ``SweepAndPrune`` (a.k.a. Sort-and-Sweep from :cite:t:`Baraff1992PhD`), or ``SweepAndTiniestQueue`` (method of :cite:t:`Belgrod2023Time`; requires CUDA). The default is ``LBVH``.