Skip to content

Commit c750dc4

Browse files
committed
Replace BroadPhaseMethod phase enum with shared_ptr<BroadPhase>
1 parent e12c685 commit c750dc4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+295
-250
lines changed

python/src/broad_phase/broad_phase.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,8 @@ using namespace ipc;
88

99
void define_broad_phase(py::module_& m)
1010
{
11-
py::enum_<BroadPhaseMethod>(
12-
m, "BroadPhaseMethod",
13-
"Enumeration of implemented broad phase methods.")
14-
.value("BRUTE_FORCE", BroadPhaseMethod::BRUTE_FORCE, "Brute force")
15-
.value("HASH_GRID", BroadPhaseMethod::HASH_GRID, "Hash grid")
16-
.value("SPATIAL_HASH", BroadPhaseMethod::SPATIAL_HASH, "Spatial hash")
17-
.value(
18-
"BOUNDING_VOLUME_HIERARCHY", BroadPhaseMethod::BVH,
19-
"Bounding volume hierarchy")
20-
.value(
21-
"SWEEP_AND_PRUNE", BroadPhaseMethod::SWEEP_AND_PRUNE,
22-
"Sweep and prune")
23-
.value(
24-
"SWEEP_AND_TINIEST_QUEUE",
25-
BroadPhaseMethod::SWEEP_AND_TINIEST_QUEUE,
26-
"Sweep and tiniest queue (GPU)")
27-
.export_values();
28-
29-
py::class_<BroadPhase>(m, "BroadPhase")
30-
.def_static(
31-
"make_broad_phase", &BroadPhase::make_broad_phase,
32-
R"ipc_Qu8mg5v7(
33-
Construct a registered broad phase object.
34-
35-
Parameters:
36-
method: The broad phase method to use.
37-
38-
Returns:
39-
The constructed broad phase object.
40-
)ipc_Qu8mg5v7",
41-
py::arg("method"))
11+
py::class_<BroadPhase, std::shared_ptr<BroadPhase>>(m, "BroadPhase")
12+
.def("name", &BroadPhase::name, "Get the name of the broad phase.")
4213
.def(
4314
"build",
4415
py::overload_cast<

python/src/broad_phase/brute_force.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ using namespace ipc;
77

88
void define_brute_force(py::module_& m)
99
{
10-
py::class_<BruteForce, BroadPhase>(m, "BruteForce").def(py::init());
10+
py::class_<BruteForce, BroadPhase, std::shared_ptr<BruteForce>>(
11+
m, "BruteForce")
12+
.def(py::init());
1113
}

python/src/broad_phase/bvh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ using namespace ipc;
77

88
void define_bvh(py::module_& m)
99
{
10-
py::class_<BVH, BroadPhase>(m, "BVH").def(py::init());
10+
py::class_<BVH, BroadPhase, std::shared_ptr<BVH>>(m, "BVH").def(py::init());
1111
}

python/src/broad_phase/hash_grid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void define_hash_grid(py::module_& m)
1818
.def_readwrite("key", &HashItem::key, "The key of the item.")
1919
.def_readwrite("id", &HashItem::id, "The value of the item.");
2020

21-
py::class_<HashGrid, BroadPhase>(m, "HashGrid")
21+
py::class_<HashGrid, BroadPhase, std::shared_ptr<HashGrid>>(m, "HashGrid")
2222
.def(py::init())
2323
.def_property_readonly("cell_size", &HashGrid::cell_size)
2424
.def_property_readonly(

python/src/broad_phase/spatial_hash.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ using namespace ipc;
77

88
void define_spatial_hash(py::module_& m)
99
{
10-
py::class_<SpatialHash, BroadPhase>(m, "SpatialHash")
10+
py::class_<SpatialHash, BroadPhase, std::shared_ptr<SpatialHash>>(
11+
m, "SpatialHash")
1112
.def(py::init())
1213
.def(
1314
py::init<

python/src/broad_phase/sweep_and_prune.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ using namespace ipc;
77

88
void define_sweep_and_prune(py::module_& m)
99
{
10-
py::class_<SweepAndPrune, BroadPhase>(m, "SweepAndPrune").def(py::init());
10+
py::class_<SweepAndPrune, BroadPhase, std::shared_ptr<SweepAndPrune>>(
11+
m, "SweepAndPrune")
12+
.def(py::init());
1113
}

python/src/broad_phase/sweep_and_tiniest_queue.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ using namespace ipc; // not defined if IPC_TOOLKIT_WITH_CUDA is not defined
1010
void define_sweep_and_tiniest_queue(py::module_& m)
1111
{
1212
#ifdef IPC_TOOLKIT_WITH_CUDA
13-
py::class_<SweepAndTiniestQueue, BroadPhase>(m, "SweepAndTiniestQueue")
13+
py::class_<
14+
SweepAndTiniestQueue, BroadPhase,
15+
std::shared_ptr<SweepAndTiniestQueue>>(m, "SweepAndTiniestQueue")
1416
.def(py::init());
1517
#endif
1618
}

python/src/candidates/candidates.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <common.hpp>
22

33
#include <ipc/candidates/candidates.hpp>
4+
#include <ipc/broad_phase/broad_phase.hpp>
45

56
namespace py = pybind11;
67
using namespace ipc;
@@ -13,25 +14,24 @@ void define_candidates(py::module_& m)
1314
"build",
1415
py::overload_cast<
1516
const CollisionMesh&, const Eigen::MatrixXd&, const double,
16-
const BroadPhaseMethod>(&Candidates::build),
17+
std::shared_ptr<BroadPhase>>(&Candidates::build),
1718
R"ipc_Qu8mg5v7(
1819
Initialize the set of discrete collision detection candidates.
1920
2021
Parameters:
2122
mesh: The surface of the collision mesh.
2223
vertices: Surface vertex positions (rowwise).
2324
inflation_radius: Amount to inflate the bounding boxes.
24-
broad_phase_method: Broad phase method to use.
25+
broad_phase: Broad phase to use.
2526
)ipc_Qu8mg5v7",
2627
py::arg("mesh"), py::arg("vertices"),
27-
py::arg("inflation_radius") = 0,
28-
py::arg("broad_phase_method") = DEFAULT_BROAD_PHASE_METHOD)
28+
py::arg("inflation_radius") = 0, py::arg("broad_phase") = nullptr)
2929
.def(
3030
"build",
3131
py::overload_cast<
3232
const CollisionMesh&, const Eigen::MatrixXd&,
33-
const Eigen::MatrixXd&, const double, const BroadPhaseMethod>(
34-
&Candidates::build),
33+
const Eigen::MatrixXd&, const double,
34+
std::shared_ptr<BroadPhase>>(&Candidates::build),
3535
R"ipc_Qu8mg5v7(
3636
Initialize the set of continuous collision detection candidates.
3737
@@ -43,11 +43,10 @@ void define_candidates(py::module_& m)
4343
vertices_t0: Surface vertex starting positions (rowwise).
4444
vertices_t1: Surface vertex ending positions (rowwise).
4545
inflation_radius: Amount to inflate the bounding boxes.
46-
broad_phase_method: Broad phase method to use.
46+
broad_phase: Broad phase to use.
4747
)ipc_Qu8mg5v7",
4848
py::arg("mesh"), py::arg("vertices_t0"), py::arg("vertices_t1"),
49-
py::arg("inflation_radius") = 0,
50-
py::arg("broad_phase_method") = DEFAULT_BROAD_PHASE_METHOD)
49+
py::arg("inflation_radius") = 0, py::arg("broad_phase") = nullptr)
5150
.def("__len__", &Candidates::size)
5251
.def("empty", &Candidates::empty)
5352
.def("clear", &Candidates::clear)
@@ -122,13 +121,13 @@ void define_candidates(py::module_& m)
122121
vertices_t0: Surface vertex starting positions (rowwise).
123122
vertices_t1: Surface vertex ending positions (rowwise).
124123
dhat: Barrier activation distance.
125-
min_distance: The minimum distance allowable between any two elements.
126-
narrow_phase_ccd: The narrow phase CCD algorithm to use.
124+
min_distance: Minimum distance allowable between any two elements.
125+
broad_phase: Broad phase algorithm to use.
126+
narrow_phase_ccd: Narrow phase CCD algorithm to use.
127127
)ipc_Qu8mg5v7",
128128
py::arg("mesh"), py::arg("vertices_t0"), py::arg("vertices_t1"),
129-
py::arg("dhat"),
130-
py::arg("broad_phase_method") = DEFAULT_BROAD_PHASE_METHOD,
131-
py::arg("min_distance") = 0.0,
129+
py::arg("dhat"), py::arg("min_distance") = 0.0,
130+
py::arg("broad_phase") = nullptr,
132131
py::arg("narrow_phase_ccd") = DEFAULT_NARROW_PHASE_CCD)
133132
.def(
134133
"save_obj", &Candidates::save_obj, py::arg("filename"),

python/src/collisions/normal/normal_collisions.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <common.hpp>
22

33
#include <ipc/collisions/normal/normal_collisions.hpp>
4+
#include <ipc/broad_phase/broad_phase.hpp>
45

56
namespace py = pybind11;
67
using namespace ipc;
@@ -13,7 +14,8 @@ void define_normal_collisions(py::module_& m)
1314
"build",
1415
py::overload_cast<
1516
const CollisionMesh&, const Eigen::MatrixXd&, const double,
16-
const double, const BroadPhaseMethod>(&NormalCollisions::build),
17+
const double, std::shared_ptr<BroadPhase>>(
18+
&NormalCollisions::build),
1719
R"ipc_Qu8mg5v7(
1820
Initialize the set of collisions used to compute the barrier potential.
1921
@@ -22,11 +24,10 @@ void define_normal_collisions(py::module_& m)
2224
vertices: Vertices of the collision mesh.
2325
dhat: The activation distance of the barrier.
2426
dmin: Minimum distance.
25-
broad_phase_method: Broad-phase method to use.
27+
broad_phase: Broad-phase to use.
2628
)ipc_Qu8mg5v7",
2729
py::arg("mesh"), py::arg("vertices"), py::arg("dhat"),
28-
py::arg("dmin") = 0,
29-
py::arg("broad_phase_method") = DEFAULT_BROAD_PHASE_METHOD)
30+
py::arg("dmin") = 0, py::arg("broad_phase") = nullptr)
3031
.def(
3132
"build",
3233
py::overload_cast<

python/src/ipc.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include <common.hpp>
22

33
#include <ipc/ipc.hpp>
4+
#include <ipc/broad_phase/broad_phase.hpp>
45
#include <ipc/config.hpp>
6+
57
#include <igl/edges.h>
68

79
namespace py = pybind11;
@@ -24,15 +26,14 @@ void define_ipc(py::module_& m)
2426
vertices_t0: Surface vertex vertices at start as rows of a matrix.
2527
vertices_t1: Surface vertex vertices at end as rows of a matrix.
2628
min_distance: The minimum distance allowable between any two elements.
27-
broad_phase_method: The broad phase method to use.
29+
broad_phase: Broad phase to use.
2830
narrow_phase_ccd: The narrow phase CCD algorithm to use.
2931
3032
Returns:
3133
True if <b>any</b> collisions occur.
3234
)ipc_Qu8mg5v7",
3335
py::arg("mesh"), py::arg("vertices_t0"), py::arg("vertices_t1"),
34-
py::arg("min_distance") = 0.0,
35-
py::arg("broad_phase_method") = DEFAULT_BROAD_PHASE_METHOD,
36+
py::arg("min_distance") = 0.0, py::arg("broad_phase") = nullptr,
3637
py::arg("narrow_phase_ccd") = DEFAULT_NARROW_PHASE_CCD);
3738

3839
m.def(
@@ -48,15 +49,14 @@ void define_ipc(py::module_& m)
4849
vertices_t0: Vertex vertices at start as rows of a matrix. Assumes vertices_t0 is intersection free.
4950
vertices_t1: Surface vertex vertices at end as rows of a matrix.
5051
min_distance: The minimum distance allowable between any two elements.
51-
broad_phase_method: The broad phase method to use.
52+
broad_phase: Broad phase to use.
5253
narrow_phase_ccd: The narrow phase CCD algorithm to use.
5354
5455
Returns:
5556
A step-size :math:`\in [0, 1]` that is collision free. A value of 1.0 if a full step and 0.0 is no step.
5657
)ipc_Qu8mg5v7",
5758
py::arg("mesh"), py::arg("vertices_t0"), py::arg("vertices_t1"),
58-
py::arg("min_distance") = 0.0,
59-
py::arg("broad_phase_method") = DEFAULT_BROAD_PHASE_METHOD,
59+
py::arg("min_distance") = 0.0, py::arg("broad_phase") = nullptr,
6060
py::arg("narrow_phase_ccd") = DEFAULT_NARROW_PHASE_CCD);
6161

6262
m.def(
@@ -67,13 +67,12 @@ void define_ipc(py::module_& m)
6767
Parameters:
6868
mesh: The collision mesh.
6969
vertices: Vertices of the collision mesh.
70-
broad_phase_method: The broad phase method to use.
70+
broad_phase: Broad phase to use.
7171
7272
Returns:
7373
A boolean for if the mesh has intersections.
7474
)ipc_Qu8mg5v7",
75-
py::arg("mesh"), py::arg("vertices"),
76-
py::arg("broad_phase_method") = DEFAULT_BROAD_PHASE_METHOD);
75+
py::arg("mesh"), py::arg("vertices"), py::arg("broad_phase") = nullptr);
7776

7877
m.def(
7978
"edges",

0 commit comments

Comments
 (0)