Skip to content

Commit 5564174

Browse files
authored
Add min_distance field in ccd. (#22)
* Add min_distance field in CCD
1 parent 7dc3536 commit 5564174

File tree

18 files changed

+112
-52
lines changed

18 files changed

+112
-52
lines changed

python/src/candidates/continuous_collision_candidate.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ void define_continuous_collision_candidate(py::module_& m)
1212
"ccd",
1313
[](ContinuousCollisionCandidate& self, const Eigen::MatrixXd& V0,
1414
const Eigen::MatrixXd& V1, const Eigen::MatrixXi& E,
15-
const Eigen::MatrixXi& F, const double tmax = 1.0,
15+
const Eigen::MatrixXi& F, const double min_distance = 0.0,
16+
const double tmax = 1.0,
1617
const double tolerance = DEFAULT_CCD_TOLERANCE,
1718
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,
1819
const double conservative_rescaling =
@@ -42,7 +43,8 @@ void define_continuous_collision_candidate(py::module_& m)
4243
Computed time of impact (normalized).
4344
)ipc_Qu8mg5v7",
4445
py::arg("V0"), py::arg("V1"), py::arg("E"), py::arg("F"),
45-
py::arg("tmax") = 1.0, py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
46+
py::arg("min_distance") = 0.0, py::arg("tmax") = 1.0,
47+
py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
4648
py::arg("max_iterations") = DEFAULT_CCD_MAX_ITERATIONS,
4749
py::arg("conservative_rescaling") =
4850
DEFAULT_CCD_CONSERVATIVE_RESCALING)

python/src/candidates/edge_edge.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ void define_edge_edge_candidate(py::module_& m)
4747
"ccd",
4848
[](EdgeEdgeCandidate& self, const Eigen::MatrixXd& V0,
4949
const Eigen::MatrixXd& V1, const Eigen::MatrixXi& E,
50-
const Eigen::MatrixXi& F, const double tmax = 1.0,
50+
const Eigen::MatrixXi& F, const double min_distance = 0.0,
51+
const double tmax = 1.0,
5152
const double tolerance = DEFAULT_CCD_TOLERANCE,
5253
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,
5354
const double conservative_rescaling =
@@ -77,7 +78,8 @@ void define_edge_edge_candidate(py::module_& m)
7778
Computed time of impact (normalized).
7879
)ipc_Qu8mg5v7",
7980
py::arg("V0"), py::arg("V1"), py::arg("E"), py::arg("F"),
80-
py::arg("tmax") = 1.0, py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
81+
py::arg("min_distance") = 0.0, py::arg("tmax") = 1.0,
82+
py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
8183
py::arg("max_iterations") = DEFAULT_CCD_MAX_ITERATIONS,
8284
py::arg("conservative_rescaling") =
8385
DEFAULT_CCD_CONSERVATIVE_RESCALING)

python/src/candidates/edge_vertex.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ void define_edge_vertex_candidate(py::module_& m)
4747
"ccd",
4848
[](EdgeVertexCandidate& self, const Eigen::MatrixXd& V0,
4949
const Eigen::MatrixXd& V1, const Eigen::MatrixXi& E,
50-
const Eigen::MatrixXi& F, const double tmax = 1.0,
50+
const Eigen::MatrixXi& F, const double min_distance = 0.0,
51+
const double tmax = 1.0,
5152
const double tolerance = DEFAULT_CCD_TOLERANCE,
5253
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,
5354
const double conservative_rescaling =
@@ -77,7 +78,8 @@ void define_edge_vertex_candidate(py::module_& m)
7778
Computed time of impact (normalized).
7879
)ipc_Qu8mg5v7",
7980
py::arg("V0"), py::arg("V1"), py::arg("E"), py::arg("F"),
80-
py::arg("tmax") = 1.0, py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
81+
py::arg("min_distance") = 0.0, py::arg("tmax") = 1.0,
82+
py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
8183
py::arg("max_iterations") = DEFAULT_CCD_MAX_ITERATIONS,
8284
py::arg("conservative_rescaling") =
8385
DEFAULT_CCD_CONSERVATIVE_RESCALING)

python/src/candidates/face_vertex.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ void define_face_vertex_candidate(py::module_& m)
4747
"ccd",
4848
[](FaceVertexCandidate& self, const Eigen::MatrixXd& V0,
4949
const Eigen::MatrixXd& V1, const Eigen::MatrixXi& E,
50-
const Eigen::MatrixXi& F, const double tmax = 1.0,
50+
const Eigen::MatrixXi& F, const double min_distance = 0.0,
51+
const double tmax = 1.0,
5152
const double tolerance = DEFAULT_CCD_TOLERANCE,
5253
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,
5354
const double conservative_rescaling =
@@ -59,7 +60,8 @@ void define_face_vertex_candidate(py::module_& m)
5960
return std::make_tuple(r, toi);
6061
},
6162
"", py::arg("V0"), py::arg("V1"), py::arg("E"), py::arg("F"),
62-
py::arg("tmax") = 1.0, py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
63+
py::arg("min_distance") = 0.0, py::arg("tmax") = 1.0,
64+
py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
6365
py::arg("max_iterations") = DEFAULT_CCD_MAX_ITERATIONS,
6466
py::arg("conservative_rescaling") =
6567
DEFAULT_CCD_CONSERVATIVE_RESCALING)

python/src/ccd/ccd.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void define_ccd(py::module_& m)
1212
[](const Eigen::Vector2d& p_t0, const Eigen::Vector2d& e0_t0,
1313
const Eigen::Vector2d& e1_t0, const Eigen::Vector2d& p_t1,
1414
const Eigen::Vector2d& e0_t1, const Eigen::Vector2d& e1_t1,
15-
const double tmax = 1.0,
15+
const double min_distance = 0.0, const double tmax = 1.0,
1616
const double tolerance = DEFAULT_CCD_TOLERANCE,
1717
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,
1818
const double conservative_rescaling =
@@ -25,15 +25,16 @@ void define_ccd(py::module_& m)
2525
},
2626
"", py::arg("p_t0"), py::arg("e0_t0"), py::arg("e1_t0"),
2727
py::arg("p_t1"), py::arg("e0_t1"), py::arg("e1_t1"),
28-
py::arg("tmax") = 1.0, py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
28+
py::arg("min_distance") = 0.0, py::arg("tmax") = 1.0,
29+
py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
2930
py::arg("max_iterations") = DEFAULT_CCD_MAX_ITERATIONS,
3031
py::arg("conservative_rescaling") = DEFAULT_CCD_CONSERVATIVE_RESCALING);
3132

3233
m.def(
3334
"point_point_ccd",
3435
[](const Eigen::Vector3d& p0_t0, const Eigen::Vector3d& p1_t0,
3536
const Eigen::Vector3d& p0_t1, const Eigen::Vector3d& p1_t1,
36-
const double tmax = 1.0,
37+
const double min_distance = 0.0, const double tmax = 1.0,
3738
const double tolerance = DEFAULT_CCD_TOLERANCE,
3839
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,
3940
const double conservative_rescaling =
@@ -45,7 +46,7 @@ void define_ccd(py::module_& m)
4546
return std::make_tuple(r, toi);
4647
},
4748
"", py::arg("p0_t0"), py::arg("p1_t0"), py::arg("p0_t1"),
48-
py::arg("p1_t1"), py::arg("tmax") = 1.0,
49+
py::arg("p1_t1"), py::arg("min_distance") = 0.0, py::arg("tmax") = 1.0,
4950
py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
5051
py::arg("max_iterations") = DEFAULT_CCD_MAX_ITERATIONS,
5152
py::arg("conservative_rescaling") = DEFAULT_CCD_CONSERVATIVE_RESCALING);
@@ -55,7 +56,7 @@ void define_ccd(py::module_& m)
5556
[](const Eigen::Vector3d& p_t0, const Eigen::Vector3d& e0_t0,
5657
const Eigen::Vector3d& e1_t0, const Eigen::Vector3d& p_t1,
5758
const Eigen::Vector3d& e0_t1, const Eigen::Vector3d& e1_t1,
58-
const double tmax = 1.0,
59+
const double min_distance = 0.0, const double tmax = 1.0,
5960
const double tolerance = DEFAULT_CCD_TOLERANCE,
6061
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,
6162
const double conservative_rescaling =
@@ -68,7 +69,8 @@ void define_ccd(py::module_& m)
6869
},
6970
"", py::arg("p_t0"), py::arg("e0_t0"), py::arg("e1_t0"),
7071
py::arg("p_t1"), py::arg("e0_t1"), py::arg("e1_t1"),
71-
py::arg("tmax") = 1.0, py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
72+
py::arg("min_distance") = 0.0, py::arg("tmax") = 1.0,
73+
py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
7274
py::arg("max_iterations") = DEFAULT_CCD_MAX_ITERATIONS,
7375
py::arg("conservative_rescaling") = DEFAULT_CCD_CONSERVATIVE_RESCALING);
7476

@@ -78,7 +80,7 @@ void define_ccd(py::module_& m)
7880
const Eigen::Vector3d& t1_t0, const Eigen::Vector3d& t2_t0,
7981
const Eigen::Vector3d& p_t1, const Eigen::Vector3d& t0_t1,
8082
const Eigen::Vector3d& t1_t1, const Eigen::Vector3d& t2_t1,
81-
const double tmax = 1.0,
83+
const double min_distance = 0.0, const double tmax = 1.0,
8284
const double tolerance = DEFAULT_CCD_TOLERANCE,
8385
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,
8486
const double conservative_rescaling =
@@ -91,7 +93,7 @@ void define_ccd(py::module_& m)
9193
},
9294
"", py::arg("p_t0"), py::arg("t0_t0"), py::arg("t1_t0"),
9395
py::arg("t2_t0"), py::arg("p_t1"), py::arg("t0_t1"), py::arg("t1_t1"),
94-
py::arg("t2_t1"), py::arg("tmax") = 1.0,
96+
py::arg("t2_t1"), py::arg("min_distance") = 0.0, py::arg("tmax") = 1.0,
9597
py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
9698
py::arg("max_iterations") = DEFAULT_CCD_MAX_ITERATIONS,
9799
py::arg("conservative_rescaling") = DEFAULT_CCD_CONSERVATIVE_RESCALING);
@@ -102,7 +104,7 @@ void define_ccd(py::module_& m)
102104
const Eigen::Vector3d& eb0_t0, const Eigen::Vector3d& eb1_t0,
103105
const Eigen::Vector3d& ea0_t1, const Eigen::Vector3d& ea1_t1,
104106
const Eigen::Vector3d& eb0_t1, const Eigen::Vector3d& eb1_t1,
105-
const double tmax = 1.0,
107+
const double min_distance = 0.0, const double tmax = 1.0,
106108
const double tolerance = DEFAULT_CCD_TOLERANCE,
107109
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,
108110
const double conservative_rescaling =
@@ -115,8 +117,8 @@ void define_ccd(py::module_& m)
115117
},
116118
"", py::arg("ea0_t0"), py::arg("ea1_t0"), py::arg("eb0_t0"),
117119
py::arg("eb1_t0"), py::arg("ea0_t1"), py::arg("ea1_t1"),
118-
py::arg("eb0_t1"), py::arg("eb1_t1"), py::arg("tmax") = 1.0,
119-
py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
120+
py::arg("eb0_t1"), py::arg("eb1_t1"), py::arg("min_distance") = 0.0,
121+
py::arg("tmax") = 1.0, py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
120122
py::arg("max_iterations") = DEFAULT_CCD_MAX_ITERATIONS,
121123
py::arg("conservative_rescaling") = DEFAULT_CCD_CONSERVATIVE_RESCALING);
122124

@@ -125,7 +127,7 @@ void define_ccd(py::module_& m)
125127
[](const VectorMax3d& p_t0, const VectorMax3d& e0_t0,
126128
const VectorMax3d& e1_t0, const VectorMax3d& p_t1,
127129
const VectorMax3d& e0_t1, const VectorMax3d& e1_t1,
128-
const double tmax = 1.0,
130+
const double min_distance = 0.0, const double tmax = 1.0,
129131
const double tolerance = DEFAULT_CCD_TOLERANCE,
130132
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,
131133
const double conservative_rescaling =
@@ -138,7 +140,8 @@ void define_ccd(py::module_& m)
138140
},
139141
"", py::arg("p_t0"), py::arg("e0_t0"), py::arg("e1_t0"),
140142
py::arg("p_t1"), py::arg("e0_t1"), py::arg("e1_t1"),
141-
py::arg("tmax") = 1.0, py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
143+
py::arg("min_distance") = 0.0, py::arg("tmax") = 1.0,
144+
py::arg("tolerance") = DEFAULT_CCD_TOLERANCE,
142145
py::arg("max_iterations") = DEFAULT_CCD_MAX_ITERATIONS,
143146
py::arg("conservative_rescaling") = DEFAULT_CCD_CONSERVATIVE_RESCALING);
144147
}

python/src/ipc.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void define_ipc(py::module_& m)
6666
py::overload_cast<
6767
const CollisionMesh&, const Eigen::MatrixXd&,
6868
const Eigen::MatrixXd&, const BroadPhaseMethod, const double,
69-
const long>(&is_step_collision_free),
69+
const double, const long>(&is_step_collision_free),
7070
R"ipc_Qu8mg5v7(
7171
Determine if the step is collision free.
7272
@@ -83,13 +83,14 @@ void define_ipc(py::module_& m)
8383
)ipc_Qu8mg5v7",
8484
py::arg("mesh"), py::arg("V0"), py::arg("V1"),
8585
py::arg("method") = BroadPhaseMethod::HASH_GRID,
86-
py::arg("tolerance") = 1e-6, py::arg("max_iterations") = long(1e7));
86+
py::arg("min_distance") = 0.0, py::arg("tolerance") = 1e-6,
87+
py::arg("max_iterations") = long(1e7));
8788

8889
m.def(
8990
"is_step_collision_free",
9091
py::overload_cast<
9192
const Candidates&, const CollisionMesh&, const Eigen::MatrixXd&,
92-
const Eigen::MatrixXd&, const double, const long>(
93+
const Eigen::MatrixXd&, const double, const double, const long>(
9394
&is_step_collision_free),
9495
R"ipc_Qu8mg5v7(
9596
Determine if the step is collision free from a set of candidates.
@@ -107,14 +108,15 @@ void define_ipc(py::module_& m)
107108
True if <b>any</b> collisions occur.
108109
)ipc_Qu8mg5v7",
109110
py::arg("candidates"), py::arg("mesh"), py::arg("V0"), py::arg("V1"),
110-
py::arg("tolerance") = 1e-6, py::arg("max_iterations") = long(1e7));
111+
py::arg("min_distance") = 0.0, py::arg("tolerance") = 1e-6,
112+
py::arg("max_iterations") = long(1e7));
111113

112114
m.def(
113115
"compute_collision_free_stepsize",
114116
py::overload_cast<
115117
const CollisionMesh&, const Eigen::MatrixXd&,
116118
const Eigen::MatrixXd&, const BroadPhaseMethod, const double,
117-
const long>(&compute_collision_free_stepsize),
119+
const double, const long>(&compute_collision_free_stepsize),
118120
R"ipc_Qu8mg5v7(
119121
Computes a maximal step size that is collision free.
120122
@@ -131,13 +133,14 @@ void define_ipc(py::module_& m)
131133
)ipc_Qu8mg5v7",
132134
py::arg("mesh"), py::arg("V0"), py::arg("V1"),
133135
py::arg("method") = BroadPhaseMethod::HASH_GRID,
134-
py::arg("tolerance") = 1e-6, py::arg("max_iterations") = long(1e7));
136+
py::arg("min_distance") = 0.0, py::arg("tolerance") = 1e-6,
137+
py::arg("max_iterations") = long(1e7));
135138

136139
m.def(
137140
"compute_collision_free_stepsize",
138141
py::overload_cast<
139142
const Candidates&, const CollisionMesh&, const Eigen::MatrixXd&,
140-
const Eigen::MatrixXd&, const double, const long>(
143+
const Eigen::MatrixXd&, const double, const double, const long>(
141144
&compute_collision_free_stepsize),
142145
R"ipc_Qu8mg5v7(
143146
Computes a maximal step size that is collision free using a set of collision candidates.
@@ -155,7 +158,8 @@ void define_ipc(py::module_& m)
155158
A step-size $\in [0, 1]$ that is collision free. A value of 1.0 if a full step and 0.0 is no step.
156159
)ipc_Qu8mg5v7",
157160
py::arg("candidates"), py::arg("mesh"), py::arg("V0"), py::arg("V1"),
158-
py::arg("tolerance") = 1e-6, py::arg("max_iterations") = long(1e7));
161+
py::arg("min_distance") = 0.0, py::arg("tolerance") = 1e-6,
162+
py::arg("max_iterations") = long(1e7));
159163

160164
m.def(
161165
"compute_minimum_distance", &compute_minimum_distance,

src/ipc/candidates/continuous_collision_candidate.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct ContinuousCollisionCandidate {
1818
/// @param[in] E Mesh edges as rows of indicies into V.
1919
/// @param[in] F Mesh triangular faces as rows of indicies into V.
2020
/// @param[out] toi Computed time of impact (normalized).
21+
/// @param[in] min_distance Minimum separation distance between primitives.
2122
/// @param[in] tmax Maximum time (normalized) to look for collisions. Should be in [0, 1].
2223
/// @param[in] tolerance CCD tolerance used by Tight-Inclusion CCD.
2324
/// @param[in] max_iterations Maximum iterations used by Tight-Inclusion CCD.
@@ -29,6 +30,7 @@ struct ContinuousCollisionCandidate {
2930
const Eigen::MatrixXi& E,
3031
const Eigen::MatrixXi& F,
3132
double& toi,
33+
const double min_distance = 0.0,
3234
const double tmax = 1.0,
3335
const double tolerance = DEFAULT_CCD_TOLERANCE,
3436
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,

src/ipc/candidates/edge_edge.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ bool EdgeEdgeCandidate::ccd(
6060
const Eigen::MatrixXi& E,
6161
const Eigen::MatrixXi& F,
6262
double& toi,
63+
const double min_distance,
6364
const double tmax,
6465
const double tolerance,
6566
const long max_iterations,
@@ -74,7 +75,8 @@ bool EdgeEdgeCandidate::ccd(
7475
V1.row(E(edge0_index, 0)), V1.row(E(edge0_index, 1)),
7576
// Edge 2 at t=1
7677
V1.row(E(edge1_index, 0)), V1.row(E(edge1_index, 1)), //
77-
toi, tmax, tolerance, max_iterations, conservative_rescaling);
78+
toi, min_distance, tmax, tolerance, max_iterations,
79+
conservative_rescaling);
7880
}
7981

8082
void EdgeEdgeCandidate::print_ccd_query(

src/ipc/candidates/edge_edge.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct EdgeEdgeCandidate : ContinuousCollisionCandidate {
5858
const Eigen::MatrixXi& E,
5959
const Eigen::MatrixXi& F,
6060
double& toi,
61+
const double min_distance = 0.0,
6162
const double tmax = 1.0,
6263
const double tolerance = DEFAULT_CCD_TOLERANCE,
6364
const long max_iterations = DEFAULT_CCD_MAX_ITERATIONS,

src/ipc/candidates/edge_vertex.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ bool EdgeVertexCandidate::ccd(
5656
const Eigen::MatrixXi& E,
5757
const Eigen::MatrixXi& F,
5858
double& toi,
59+
const double min_distance,
5960
const double tmax,
6061
const double tolerance,
6162
const long max_iterations,
@@ -70,7 +71,8 @@ bool EdgeVertexCandidate::ccd(
7071
V1.row(vertex_index),
7172
// Edge at t=1
7273
V1.row(E(edge_index, 0)), V1.row(E(edge_index, 1)), //
73-
toi, tmax, tolerance, max_iterations, conservative_rescaling);
74+
toi, min_distance, tmax, tolerance, max_iterations,
75+
conservative_rescaling);
7476
}
7577

7678
void EdgeVertexCandidate::print_ccd_query(

0 commit comments

Comments
 (0)