-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathcollision_stencil.cpp
More file actions
219 lines (188 loc) · 8.24 KB
/
collision_stencil.cpp
File metadata and controls
219 lines (188 loc) · 8.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <common.hpp>
#include <ipc/candidates/collision_stencil.hpp>
namespace py = pybind11;
using namespace ipc;
void define_collision_stencil(py::module_& m)
{
py::class_<CollisionStencil>(m, "CollisionStencil")
.def(
"num_vertices", &CollisionStencil::num_vertices,
"Get the number of vertices in the collision stencil.")
.def(
"dim", &CollisionStencil::dim,
R"ipc_Qu8mg5v7(
Get the dimension of the collision stencil.
Parameters:
ndof: Number of degrees of freedom in the stencil.
Returns:
The dimension of the collision stencil.
)ipc_Qu8mg5v7",
py::arg("ndof"))
.def(
"vertex_ids", &CollisionStencil::vertex_ids,
R"ipc_Qu8mg5v7(
Get the vertex IDs of the collision stencil.
Parameters:
edges: Collision mesh edges
faces: Collision mesh faces
Returns:
The vertex IDs of the collision stencil. Size is always 4, but elements i > num_vertices() are -1.
)ipc_Qu8mg5v7",
py::arg("edges"), py::arg("faces"))
.def(
"vertices", &CollisionStencil::vertices<double>,
R"ipc_Qu8mg5v7(
Get the vertex attributes of the collision stencil.
T Type of the attributes
Parameters:
vertices: Vertex attributes
edges: Collision mesh edges
faces: Collision mesh faces
Returns:
The vertex positions of the collision stencil. Size is always 4, but elements i > num_vertices() are NaN.
)ipc_Qu8mg5v7",
py::arg("vertices"), py::arg("edges"), py::arg("faces"))
.def(
"dof", &CollisionStencil::dof<double>,
R"ipc_Qu8mg5v7(
Select this stencil's DOF from the full matrix of DOF.
T Type of the DOF
Parameters:
X: Full matrix of DOF (rowwise).
edges: Collision mesh edges
faces: Collision mesh faces
Returns:
This stencil's DOF.
)ipc_Qu8mg5v7",
py::arg("X"), py::arg("edges"), py::arg("faces"))
.def(
"compute_distance",
py::overload_cast<
const Eigen::MatrixXd&, const Eigen::MatrixXi&,
const Eigen::MatrixXi&>(
&CollisionStencil::compute_distance, py::const_),
R"ipc_Qu8mg5v7(
Compute the distance of the stencil.
Parameters:
vertices: Collision mesh vertices.
edges: Collision mesh edges.
faces: Collision mesh faces.
Returns:
Distance of the stencil.
)ipc_Qu8mg5v7",
py::arg("vertices"), py::arg("edges"), py::arg("faces"))
.def(
"compute_distance_gradient",
py::overload_cast<
const Eigen::MatrixXd&, const Eigen::MatrixXi&,
const Eigen::MatrixXi&>(
&CollisionStencil::compute_distance_gradient, py::const_),
R"ipc_Qu8mg5v7(
Compute the distance gradient of the stencil w.r.t. the stencil's vertex positions.
Parameters:
vertices: Collision mesh vertices.
edges: Collision mesh edges.
faces: Collision mesh faces.
Returns:
Distance gradient of the stencil w.r.t. the stencil's vertex positions.
)ipc_Qu8mg5v7",
py::arg("vertices"), py::arg("edges"), py::arg("faces"))
.def(
"compute_distance_hessian",
py::overload_cast<
const Eigen::MatrixXd&, const Eigen::MatrixXi&,
const Eigen::MatrixXi&>(
&CollisionStencil::compute_distance_hessian, py::const_),
R"ipc_Qu8mg5v7(
Compute the distance Hessian of the stencil w.r.t. the stencil's vertex positions.
Parameters:
vertices: Collision mesh vertices.
edges: Collision mesh edges.
faces: Collision mesh faces.
Returns:
Distance Hessian of the stencil w.r.t. the stencil's vertex positions.
)ipc_Qu8mg5v7",
py::arg("vertices"), py::arg("edges"), py::arg("faces"))
.def(
"compute_distance",
py::overload_cast<const VectorMax12d&>(
&CollisionStencil::compute_distance, py::const_),
R"ipc_Qu8mg5v7(
Compute the distance of the stencil.
Note:
positions can be computed as stencil.dof(vertices, edges, faces)
Parameters:
positions: Stencil's vertex positions.
Returns:
Distance of the stencil.
)ipc_Qu8mg5v7",
py::arg("positions"))
.def(
"compute_distance_gradient",
py::overload_cast<const VectorMax12d&>(
&CollisionStencil::compute_distance_gradient, py::const_),
R"ipc_Qu8mg5v7(
Compute the distance gradient of the stencil w.r.t. the stencil's vertex positions.
Note:
positions can be computed as stencil.dof(vertices, edges, faces)
Parameters:
positions: Stencil's vertex positions.
Returns:
Distance gradient of the stencil w.r.t. the stencil's vertex positions.
)ipc_Qu8mg5v7",
py::arg("positions"))
.def(
"compute_distance_hessian",
py::overload_cast<const VectorMax12d&>(
&CollisionStencil::compute_distance_hessian, py::const_),
R"ipc_Qu8mg5v7(
Compute the distance Hessian of the stencil w.r.t. the stencil's vertex positions.
Note:
positions can be computed as stencil.dof(vertices, edges, faces)
Parameters:
positions: Stencil's vertex positions.
Returns:
Distance Hessian of the stencil w.r.t. the stencil's vertex positions.
)ipc_Qu8mg5v7",
py::arg("positions"))
.def(
"ccd",
[](const CollisionStencil& self, const VectorMax12d& vertices_t0,
const VectorMax12d& vertices_t1, const double min_distance,
const double tmax, const NarrowPhaseCCD& narrow_phase_ccd) {
double toi;
bool r = self.ccd(
vertices_t0, vertices_t1, toi, min_distance, tmax,
narrow_phase_ccd);
return std::make_tuple(r, toi);
},
R"ipc_Qu8mg5v7(
Perform narrow-phase CCD on the candidate.
Parameters:
vertices_t0: Stencil vertices at the start of the time step.
vertices_t1: Stencil vertices at the end of the time step.
min_distance: Minimum separation distance between primitives.
tmax: Maximum time (normalized) to look for collisions. Should be in [0, 1].
narrow_phase_ccd: The narrow phase CCD algorithm to use.
Returns:
Tuple of:
If the candidate had a collision over the time interval.
Computed time of impact (normalized).
)ipc_Qu8mg5v7",
py::arg("vertices_t0"), py::arg("vertices_t1"),
py::arg("min_distance") = 0.0, py::arg("tmax") = 1.0,
py::arg("narrow_phase_ccd") = DEFAULT_NARROW_PHASE_CCD)
.def(
"print_ccd_query",
[](const CollisionStencil& self, const VectorMax12d& vertices_t0,
const VectorMax12d& vertices_t1) -> void {
self.write_ccd_query(std::cout, vertices_t0, vertices_t1);
},
R"ipc_Qu8mg5v7(
Print the CCD query to cout.
Parameters:
vertices_t0: Stencil vertices at the start of the time step.
vertices_t1: Stencil vertices at the end of the time step.
)ipc_Qu8mg5v7",
py::arg("vertices_t0"), py::arg("vertices_t1"));
}