Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/tutorials/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ The ``Candidates`` class represents the culled set of candidate pairs and is bui
#include <ipc/candidates/candidates.hpp>

ipc::Candidates candidates;
ipc::HashGrid broad_phase;
candidates.build(
mesh, vertices_t0, vertices_t1, /*inflation_radius=*/0.0,
/*broad_phase=*/std::make_shared<ipc::HashGrid>());
mesh, vertices_t0, vertices_t1, /*inflation_radius=*/0.0, broad_phase);

.. md-tab-item:: Python

Expand Down
15 changes: 6 additions & 9 deletions python/src/candidates/candidates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ void define_candidates(py::module_& m)
"build",
py::overload_cast<
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
const double, const std::shared_ptr<BroadPhase>&>(
&Candidates::build),
const double, BroadPhase*>(&Candidates::build),
R"ipc_Qu8mg5v7(
Initialize the set of discrete collision detection candidates.

Expand All @@ -24,13 +23,13 @@ void define_candidates(py::module_& m)
broad_phase: Broad phase to use.
)ipc_Qu8mg5v7",
"mesh"_a, "vertices"_a, "inflation_radius"_a = 0,
"broad_phase"_a = make_default_broad_phase())
"broad_phase"_a = nullptr)
.def(
"build",
py::overload_cast<
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
Eigen::ConstRef<Eigen::MatrixXd>, const double,
const std::shared_ptr<BroadPhase>&>(&Candidates::build),
Eigen::ConstRef<Eigen::MatrixXd>, const double, BroadPhase*>(
&Candidates::build),
R"ipc_Qu8mg5v7(
Initialize the set of continuous collision detection candidates.

Expand All @@ -45,8 +44,7 @@ void define_candidates(py::module_& m)
broad_phase: Broad phase to use.
)ipc_Qu8mg5v7",
"mesh"_a, "vertices_t0"_a, "vertices_t1"_a,
"inflation_radius"_a = 0,
"broad_phase"_a = make_default_broad_phase())
"inflation_radius"_a = 0, "broad_phase"_a = nullptr)
.def("__len__", &Candidates::size)
.def("empty", &Candidates::empty)
.def("clear", &Candidates::clear)
Expand Down Expand Up @@ -124,8 +122,7 @@ void define_candidates(py::module_& m)
narrow_phase_ccd: Narrow phase CCD algorithm to use.
)ipc_Qu8mg5v7",
"mesh"_a, "vertices_t0"_a, "vertices_t1"_a, "dhat"_a,
"min_distance"_a = 0.0,
"broad_phase"_a = make_default_broad_phase(),
"min_distance"_a = 0.0, "broad_phase"_a = nullptr,
"narrow_phase_ccd"_a = DEFAULT_NARROW_PHASE_CCD)
.def(
"save_obj", &Candidates::save_obj, "filename"_a, "vertices"_a,
Expand Down
10 changes: 5 additions & 5 deletions python/src/collisions/normal/normal_collisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void define_smooth_collisions(py::module_& m, std::string name)
"build",
py::overload_cast<
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
const SmoothContactParameters, const bool,
const std::shared_ptr<BroadPhase>&>(&SmoothCollisions::build),
const SmoothContactParameters, const bool, BroadPhase*>(
&SmoothCollisions::build),
R"ipc_Qu8mg5v7(
Initialize the set of collisions used to compute the barrier potential.

Expand All @@ -37,7 +37,7 @@ void define_smooth_collisions(py::module_& m, std::string name)
)ipc_Qu8mg5v7",
py::arg("mesh"), py::arg("vertices"), py::arg("param"),
py::arg("use_adaptive_dhat") = false,
py::arg("broad_phase") = make_default_broad_phase())
py::arg("broad_phase") = nullptr)
.def(
"compute_minimum_distance",
&SmoothCollisions::compute_minimum_distance,
Expand Down Expand Up @@ -89,7 +89,7 @@ void define_normal_collisions(py::module_& m)
"build",
py::overload_cast<
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
const double, const double, const std::shared_ptr<BroadPhase>&>(
const double, const double, BroadPhase*>(
&NormalCollisions::build),
R"ipc_Qu8mg5v7(
Initialize the set of collisions used to compute the barrier potential.
Expand All @@ -102,7 +102,7 @@ void define_normal_collisions(py::module_& m)
broad_phase: Broad-phase to use.
)ipc_Qu8mg5v7",
"mesh"_a, "vertices"_a, "dhat"_a, "dmin"_a = 0,
"broad_phase"_a = make_default_broad_phase())
"broad_phase"_a = nullptr)
.def(
"build",
py::overload_cast<
Expand Down
6 changes: 3 additions & 3 deletions python/src/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void define_ipc(py::module_& m)
True if <b>any</b> collisions occur.
)ipc_Qu8mg5v7",
"mesh"_a, "vertices_t0"_a, "vertices_t1"_a, "min_distance"_a = 0.0,
"broad_phase"_a = make_default_broad_phase(),
"broad_phase"_a = nullptr,
"narrow_phase_ccd"_a = DEFAULT_NARROW_PHASE_CCD);

m.def(
Expand All @@ -54,7 +54,7 @@ void define_ipc(py::module_& m)
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.
)ipc_Qu8mg5v7",
"mesh"_a, "vertices_t0"_a, "vertices_t1"_a, "min_distance"_a = 0.0,
"broad_phase"_a = make_default_broad_phase(),
"broad_phase"_a = nullptr,
"narrow_phase_ccd"_a = DEFAULT_NARROW_PHASE_CCD);

m.def(
Expand All @@ -70,7 +70,7 @@ void define_ipc(py::module_& m)
Returns:
A boolean for if the mesh has intersections.
)ipc_Qu8mg5v7",
"mesh"_a, "vertices"_a, "broad_phase"_a = make_default_broad_phase());
"mesh"_a, "vertices"_a, "broad_phase"_a = nullptr);

m.def(
"edges",
Expand Down
6 changes: 4 additions & 2 deletions src/ipc/broad_phase/default_broad_phase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

#include <ipc/broad_phase/hash_grid.hpp>

#include <memory>

namespace ipc {

inline std::shared_ptr<BroadPhase> make_default_broad_phase()
inline std::unique_ptr<BroadPhase> make_default_broad_phase()
{
return std::make_shared<HashGrid>();
return std::make_unique<HashGrid>();
}

} // namespace ipc
18 changes: 13 additions & 5 deletions src/ipc/candidates/candidates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ void Candidates::build(
const CollisionMesh& mesh,
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const double inflation_radius,
const std::shared_ptr<BroadPhase>& broad_phase)
BroadPhase* broad_phase)
{
assert(broad_phase != nullptr);
std::unique_ptr<BroadPhase> default_broad_phase;
if (broad_phase == nullptr) {
default_broad_phase = make_default_broad_phase();
broad_phase = default_broad_phase.get();
}

const int dim = vertices.cols();

Expand Down Expand Up @@ -108,9 +112,13 @@ void Candidates::build(
Eigen::ConstRef<Eigen::MatrixXd> vertices_t0,
Eigen::ConstRef<Eigen::MatrixXd> vertices_t1,
const double inflation_radius,
const std::shared_ptr<BroadPhase>& broad_phase)
BroadPhase* broad_phase)
{
assert(broad_phase != nullptr);
std::unique_ptr<BroadPhase> default_broad_phase;
if (broad_phase == nullptr) {
default_broad_phase = make_default_broad_phase();
broad_phase = default_broad_phase.get();
}

const int dim = vertices_t0.cols();

Expand Down Expand Up @@ -301,7 +309,7 @@ double Candidates::compute_cfl_stepsize(
Eigen::ConstRef<Eigen::MatrixXd> vertices_t1,
const double dhat,
const double min_distance,
const std::shared_ptr<BroadPhase>& broad_phase,
BroadPhase* broad_phase,
const NarrowPhaseCCD& narrow_phase_ccd) const
{
assert(vertices_t0.rows() == mesh.num_vertices());
Expand Down
9 changes: 3 additions & 6 deletions src/ipc/candidates/candidates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class Candidates {
const CollisionMesh& mesh,
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const double inflation_radius = 0,
const std::shared_ptr<BroadPhase>& broad_phase =
make_default_broad_phase());
BroadPhase* broad_phase = nullptr);

/// @brief Initialize the set of continuous collision detection candidates.
/// @note Assumes the trajectory is linear.
Expand All @@ -41,8 +40,7 @@ class Candidates {
Eigen::ConstRef<Eigen::MatrixXd> vertices_t0,
Eigen::ConstRef<Eigen::MatrixXd> vertices_t1,
const double inflation_radius = 0,
const std::shared_ptr<BroadPhase>& broad_phase =
make_default_broad_phase());
BroadPhase* broad_phase = nullptr);

/// @brief Get the number of collision candidates.
/// @return The number of collision candidates.
Expand Down Expand Up @@ -120,8 +118,7 @@ class Candidates {
Eigen::ConstRef<Eigen::MatrixXd> vertices_t1,
const double dhat,
const double min_distance = 0.0,
const std::shared_ptr<BroadPhase>& broad_phase =
make_default_broad_phase(),
BroadPhase* broad_phase = nullptr,
const NarrowPhaseCCD& narrow_phase_ccd =
DEFAULT_NARROW_PHASE_CCD) const;

Expand Down
2 changes: 1 addition & 1 deletion src/ipc/collisions/normal/normal_collisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void NormalCollisions::build(
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const double dhat,
const double dmin,
const std::shared_ptr<BroadPhase>& broad_phase)
BroadPhase* broad_phase)
{
assert(vertices.rows() == mesh.num_vertices());

Expand Down
3 changes: 1 addition & 2 deletions src/ipc/collisions/normal/normal_collisions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class NormalCollisions {
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const double dhat,
const double dmin = 0,
const std::shared_ptr<BroadPhase>& broad_phase =
make_default_broad_phase());
BroadPhase* broad_phase = nullptr);

/// @brief Initialize the set of collisions used to compute the barrier potential.
/// @param candidates Distance candidates from which the collision set is built.
Expand Down
11 changes: 11 additions & 0 deletions src/ipc/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@
namespace ipc {

// Type definitions
#cmakedefine IPC_TOOLKIT_USE_64BIT_INDICES
#ifdef IPC_TOOLKIT_USE_64BIT_INDICES
using index_t = int64_t;
#else
using index_t = int32_t;
#endif

// #cmakedefine IPC_TOOLKIT_USE_DOUBLE_PRECISION
// #ifdef IPC_TOOLKIT_USE_DOUBLE_PRECISION
// using scalar_t = double;
// #else
// using scalar_t = float;
// #endif

Comment on lines +32 to 38
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to index_t type definitions and commented-out scalar_t definitions appear to be unrelated to the PR's stated purpose of removing const shared_ptr<T>& parameters. These changes introduce conditional 64-bit index support, which should be part of a separate PR focused on that feature.

Suggested change
// #cmakedefine IPC_TOOLKIT_USE_DOUBLE_PRECISION
// #ifdef IPC_TOOLKIT_USE_DOUBLE_PRECISION
// using scalar_t = double;
// #else
// using scalar_t = float;
// #endif

Copilot uses AI. Check for mistakes.
} // namespace ipc
20 changes: 15 additions & 5 deletions src/ipc/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool is_step_collision_free(
Eigen::ConstRef<Eigen::MatrixXd> vertices_t0,
Eigen::ConstRef<Eigen::MatrixXd> vertices_t1,
const double min_distance,
const std::shared_ptr<BroadPhase>& broad_phase,
BroadPhase* broad_phase,
const NarrowPhaseCCD& narrow_phase_ccd)
{
assert(vertices_t0.rows() == mesh.num_vertices());
Expand All @@ -43,13 +43,18 @@ double compute_collision_free_stepsize(
Eigen::ConstRef<Eigen::MatrixXd> vertices_t0,
Eigen::ConstRef<Eigen::MatrixXd> vertices_t1,
const double min_distance,
const std::shared_ptr<BroadPhase>& broad_phase,
BroadPhase* broad_phase,
const NarrowPhaseCCD& narrow_phase_ccd)
{
assert(broad_phase != nullptr);
assert(vertices_t0.rows() == mesh.num_vertices());
assert(vertices_t1.rows() == mesh.num_vertices());

std::unique_ptr<BroadPhase> default_broad_phase;
if (broad_phase == nullptr) {
default_broad_phase = make_default_broad_phase();
broad_phase = default_broad_phase.get();
}

#ifdef IPC_TOOLKIT_WITH_CUDA
if (broad_phase->name() == "SweepAndTiniestQueue") {
if (vertices_t0.cols() != 3) {
Expand Down Expand Up @@ -91,11 +96,16 @@ double compute_collision_free_stepsize(
bool has_intersections(
const CollisionMesh& mesh,
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const std::shared_ptr<BroadPhase>& broad_phase)
BroadPhase* broad_phase)
{
assert(broad_phase != nullptr);
assert(vertices.rows() == mesh.num_vertices());

std::unique_ptr<BroadPhase> default_broad_phase;
if (broad_phase == nullptr) {
default_broad_phase = make_default_broad_phase();
broad_phase = default_broad_phase.get();
}

const double conservative_inflation_radius =
1e-6 * world_bbox_diagonal_length(vertices);

Expand Down
7 changes: 3 additions & 4 deletions src/ipc/ipc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool is_step_collision_free(
Eigen::ConstRef<Eigen::MatrixXd> vertices_t0,
Eigen::ConstRef<Eigen::MatrixXd> vertices_t1,
const double min_distance = 0.0,
const std::shared_ptr<BroadPhase>& broad_phase = make_default_broad_phase(),
BroadPhase* broad_phase = nullptr,
const NarrowPhaseCCD& narrow_phase_ccd = DEFAULT_NARROW_PHASE_CCD);

/// @brief Computes a maximal step size that is collision free.
Expand All @@ -44,7 +44,7 @@ double compute_collision_free_stepsize(
Eigen::ConstRef<Eigen::MatrixXd> vertices_t0,
Eigen::ConstRef<Eigen::MatrixXd> vertices_t1,
const double min_distance = 0.0,
const std::shared_ptr<BroadPhase>& broad_phase = make_default_broad_phase(),
BroadPhase* broad_phase = nullptr,
const NarrowPhaseCCD& narrow_phase_ccd = DEFAULT_NARROW_PHASE_CCD);

// ============================================================================
Expand All @@ -58,7 +58,6 @@ double compute_collision_free_stepsize(
bool has_intersections(
const CollisionMesh& mesh,
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const std::shared_ptr<BroadPhase>& broad_phase =
make_default_broad_phase());
BroadPhase* broad_phase = nullptr);

} // namespace ipc
6 changes: 3 additions & 3 deletions src/ipc/potentials/barrier_potential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ BarrierPotential::BarrierPotential(
}

BarrierPotential::BarrierPotential(
const std::shared_ptr<Barrier>& barrier,
std::shared_ptr<Barrier> barrier,
const double dhat,
const bool use_physical_barrier)
: m_barrier(barrier)
: m_barrier(std::move(barrier))
, m_dhat(dhat)
, m_use_physical_barrier(use_physical_barrier)
{
assert(dhat > 0);
assert(barrier != nullptr);
assert(m_barrier != nullptr);
}

double BarrierPotential::force_magnitude(
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/potentials/barrier_potential.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BarrierPotential : public NormalPotential {
/// @param dhat The activation distance of the barrier.
/// @param use_physical_barrier Whether to use the physical barrier.
BarrierPotential(
const std::shared_ptr<Barrier>& barrier,
std::shared_ptr<Barrier> barrier,
const double dhat,
const bool use_physical_barrier = false);

Expand Down
4 changes: 2 additions & 2 deletions src/ipc/smooth_contact/smooth_collisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void SmoothCollisions::compute_adaptive_dhat(
const CollisionMesh& mesh,
Eigen::ConstRef<Eigen::MatrixXd> vertices, // set to zero for rest pose
const SmoothContactParameters params,
const std::shared_ptr<BroadPhase>& broad_phase)
BroadPhase* broad_phase)
{
assert(vertices.rows() == mesh.num_vertices());

Expand Down Expand Up @@ -118,7 +118,7 @@ void SmoothCollisions::build(
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const SmoothContactParameters params,
const bool use_adaptive_dhat,
const std::shared_ptr<BroadPhase>& broad_phase)
BroadPhase* broad_phase)
{
assert(vertices.rows() == mesh.num_vertices());

Expand Down
6 changes: 2 additions & 4 deletions src/ipc/smooth_contact/smooth_collisions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class SmoothCollisions {
const CollisionMesh& mesh,
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const SmoothContactParameters params,
const std::shared_ptr<BroadPhase>& broad_phase =
make_default_broad_phase());
BroadPhase* broad_phase = nullptr);

/// @brief Initialize the set of collisions used to compute the barrier potential.
/// @param mesh The collision mesh.
Expand All @@ -40,8 +39,7 @@ class SmoothCollisions {
Eigen::ConstRef<Eigen::MatrixXd> vertices,
const SmoothContactParameters params,
const bool use_adaptive_dhat = false,
const std::shared_ptr<BroadPhase>& broad_phase =
make_default_broad_phase());
BroadPhase* broad_phase = nullptr);

/// @brief Initialize the set of collisions used to compute the barrier potential.
/// @param candidates Distance candidates from which the collision set is built.
Expand Down
Loading