Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit c7f8b9d

Browse files
committed
orientable flag
1 parent e0c68dc commit c7f8b9d

File tree

9 files changed

+26
-11
lines changed

9 files changed

+26
-11
lines changed

python/src/collision_mesh.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void define_collision_mesh(py::module_& m)
153153
py::arg("displacement_map") = Eigen::SparseMatrix<double>())
154154
.def(
155155
py::init<
156-
const std::vector<bool>&, Eigen::ConstRef<Eigen::MatrixXd>,
156+
const std::vector<bool>&, const std::vector<bool>&, Eigen::ConstRef<Eigen::MatrixXd>,
157157
Eigen::ConstRef<Eigen::MatrixXi>,
158158
Eigen::ConstRef<Eigen::MatrixXi>,
159159
const Eigen::SparseMatrix<double>&>(),
@@ -162,12 +162,13 @@ void define_collision_mesh(py::module_& m)
162162
163163
Parameters:
164164
include_vertex: Vector of bools indicating whether each vertex should be included in the collision mesh.
165+
orient_vertex: Vector of bools indicating whether each vertex is orientable.
165166
full_rest_positions: The vertices of the full mesh at rest (#V × dim).
166167
edges: The edges of the collision mesh indexed into the full mesh vertices (#E × 2).
167168
faces: The faces of the collision mesh indexed into the full mesh vertices (#F × 3).
168169
displacement_map: The displacement mapping from displacements on the full mesh to the collision mesh.
169170
)ipc_Qu8mg5v7",
170-
py::arg("include_vertex"), py::arg("full_rest_positions"),
171+
py::arg("include_vertex"), py::arg("orient_vertex"), py::arg("full_rest_positions"),
171172
py::arg("edges") = Eigen::MatrixXi(),
172173
py::arg("faces") = Eigen::MatrixXi(),
173174
py::arg("displacement_map") = Eigen::SparseMatrix<double>())

src/ipc/collision_mesh.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CollisionMesh::CollisionMesh(
2121
const Eigen::SparseMatrix<double>& displacement_map)
2222
: CollisionMesh(
2323
std::vector<bool>(rest_positions.rows(), true),
24+
std::vector<bool>(rest_positions.rows(), false),
2425
rest_positions,
2526
edges,
2627
faces,
@@ -30,6 +31,7 @@ CollisionMesh::CollisionMesh(
3031

3132
CollisionMesh::CollisionMesh(
3233
const std::vector<bool>& include_vertex,
34+
const std::vector<bool>& orient_vertex,
3335
Eigen::ConstRef<Eigen::MatrixXd> full_rest_positions,
3436
Eigen::ConstRef<Eigen::MatrixXi> edges,
3537
Eigen::ConstRef<Eigen::MatrixXi> faces,
@@ -90,6 +92,12 @@ CollisionMesh::CollisionMesh(
9092
m_rest_positions = m_select_vertices * full_rest_positions;
9193
// m_rest_positions = vertices(full_rest_positions);
9294

95+
assert(orient_vertex.size() == full_rest_positions.rows());
96+
m_is_orient_vertex.assign(m_rest_positions.rows(), false);
97+
for (int i = 0; i < m_is_orient_vertex.size(); i++) {
98+
m_is_orient_vertex[i] = orient_vertex[m_vertex_to_full_vertex[i]];
99+
}
100+
93101
// Map faces and edges to only included vertices
94102
if (!include_all_vertices) {
95103
for (int i = 0; i < m_edges.rows(); i++) {

src/ipc/collision_mesh.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ class CollisionMesh {
2626

2727
/// @brief Construct a new Collision Mesh object from a full mesh vertices.
2828
/// @param include_vertex Vector of bools indicating whether each vertex should be included in the collision mesh.
29+
/// @param orient_vertex Vector of bools indicating whether each vertex is orientable.
2930
/// @param full_rest_positions The vertices of the full mesh at rest (|V| × dim).
3031
/// @param edges The edges of the collision mesh indexed into the full mesh vertices (|E| × 2).
3132
/// @param faces The faces of the collision mesh indexed into the full mesh vertices (|F| × 3).
3233
/// @param displacement_map The displacement mapping from displacements on the full mesh to the collision mesh.
3334
CollisionMesh(
3435
const std::vector<bool>& include_vertex,
36+
const std::vector<bool>& orient_vertex,
3537
Eigen::ConstRef<Eigen::MatrixXd> full_rest_positions,
3638
Eigen::ConstRef<Eigen::MatrixXi> edges = Eigen::MatrixXi(),
3739
Eigen::ConstRef<Eigen::MatrixXi> faces = Eigen::MatrixXi(),
@@ -49,7 +51,7 @@ class CollisionMesh {
4951
Eigen::ConstRef<Eigen::MatrixXi> faces = Eigen::MatrixXi())
5052
{
5153
return CollisionMesh(
52-
construct_is_on_surface(full_rest_positions.rows(), edges),
54+
construct_is_on_surface(full_rest_positions.rows(), edges), std::vector<bool>(full_rest_positions.rows(), false),
5355
full_rest_positions, edges, faces);
5456
}
5557

@@ -99,6 +101,8 @@ class CollisionMesh {
99101

100102
bool is_codim_vertex(const long& v) const { return m_is_codim_vertex[v]; }
101103

104+
bool is_orient_vertex(const long& v) const { return m_is_orient_vertex[v]; }
105+
102106
/// @brief Get the indices of codimensional edges of the collision mesh (#CE x 1).
103107
const Eigen::VectorXi& codim_edges() const { return m_codim_edges; }
104108

@@ -322,6 +326,8 @@ class CollisionMesh {
322326
Eigen::MatrixXd m_rest_positions;
323327
/// @brief The mask of codimensional vertices (#V).
324328
std::vector<bool> m_is_codim_vertex;
329+
/// @brief The mask of orientable vertices (#V).
330+
std::vector<bool> m_is_orient_vertex;
325331
/// @brief The indices of codimensional vertices (#CV x 1).
326332
Eigen::VectorXi m_codim_vertices;
327333
/// @brief The mask of codimensional edges (#E).

src/ipc/smooth_contact/primitives/edge2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Edge2::Edge2(
1111
{
1212
_vert_ids = { { mesh.edges()(id, 0), mesh.edges()(id, 1) } };
1313

14-
is_active_ = mesh.is_codim_edge(id)
14+
is_active_ = (mesh.is_orient_vertex(_vert_ids[0]) && mesh.is_orient_vertex(_vert_ids[1]))
1515
|| Math<double>::cross2(
1616
d, vertices.row(_vert_ids[1]) - vertices.row(_vert_ids[0]))
1717
> 0;

src/ipc/smooth_contact/primitives/edge3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ Edge3::Edge3(
375375
const ParameterType& param)
376376
: Primitive(id, param)
377377
{
378-
orientable = !mesh.is_codim_edge(id);
378+
orientable = (mesh.is_orient_vertex(mesh.edges()(id, 0)) && mesh.is_orient_vertex(mesh.edges()(id, 0)));
379379

380380
std::array<long, 4> neighbors { { -1, -1, -1, -1 } };
381381
{

src/ipc/smooth_contact/primitives/face.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ Face::Face(
3333
Vector3d a = vertices.row(_vert_ids[1]) - vertices.row(_vert_ids[0]);
3434
Vector3d b = vertices.row(_vert_ids[2]) - vertices.row(_vert_ids[0]);
3535

36-
bool orientable = !mesh.is_codim_vertex(_vert_ids[0])
37-
&& !mesh.is_codim_vertex(_vert_ids[1])
38-
&& !mesh.is_codim_vertex(_vert_ids[2]);
36+
bool orientable = mesh.is_orient_vertex(_vert_ids[0])
37+
&& mesh.is_orient_vertex(_vert_ids[1])
38+
&& mesh.is_orient_vertex(_vert_ids[2]);
3939
is_active_ = !orientable || a.cross(b).dot(d) > 0;
4040
}
4141
int Face::n_vertices() const { return n_face_neighbors_3d; }

src/ipc/smooth_contact/primitives/point2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Point2::Point2(
8686
const ParameterType& param)
8787
: Primitive(id, param)
8888
{
89-
orientable = !mesh.is_codim_vertex(id);
89+
orientable = mesh.is_orient_vertex(id);
9090
auto neighbor_verts = mesh.find_vertex_adjacent_vertices(id);
9191
has_neighbor_1 = neighbor_verts[0] >= 0;
9292
has_neighbor_2 = neighbor_verts[1] >= 0;

src/ipc/smooth_contact/primitives/point3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Point3::Point3(
1313
: Primitive(id, param)
1414
{
1515
orientable =
16-
!mesh.is_codim_vertex(id) && mesh.vertices_to_faces()[id].size() > 0;
16+
mesh.is_orient_vertex(id) && mesh.vertices_to_faces()[id].size() > 0;
1717

1818
// Build index mapping from all vertices to one-ring neighbors
1919
{

tests/src/tests/friction/test_force_jacobian.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ TEST_CASE(
318318

319319
std::vector<bool> is_on_surface =
320320
CollisionMesh::construct_is_on_surface(X.rows(), E);
321-
CollisionMesh mesh(is_on_surface, X, E, F);
321+
CollisionMesh mesh(is_on_surface, std::vector<bool>(X.rows(), false), X, E, F);
322322
mesh.init_area_jacobians();
323323

324324
X = mesh.vertices(X);

0 commit comments

Comments
 (0)