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

Commit 1f7c102

Browse files
committed
3D codimensional edge/face
1 parent 512fda2 commit 1f7c102

File tree

9 files changed

+783
-701
lines changed

9 files changed

+783
-701
lines changed

src/ipc/collision_mesh.cpp

Lines changed: 36 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ void CollisionMesh::init_adjacencies()
264264

265265
void CollisionMesh::init_areas()
266266
{
267-
// m_vertices_to_edges.resize(num_vertices());
268-
// for (int i = 0; i < m_edges.rows(); i++) {
269-
// for (int j = 0; j < m_edges.cols(); j++) {
270-
// m_vertices_to_edges[m_edges(i, j)].push_back(i);
271-
// }
272-
// }
273-
//
267+
m_vertices_to_edges.resize(num_vertices());
268+
for (int i = 0; i < m_edges.rows(); i++) {
269+
for (int j = 0; j < m_edges.cols(); j++) {
270+
m_vertices_to_edges[m_edges(i, j)].push_back(i);
271+
}
272+
}
273+
274274
m_vertices_to_faces.resize(num_vertices());
275275
for (int i = 0; i < m_faces.rows(); i++) {
276276
for (int j = 0; j < m_faces.cols(); j++) {
@@ -534,71 +534,46 @@ std::vector<long> CollisionMesh::find_vertex_adjacent_vertices(const long &v) co
534534
}
535535
else
536536
{
537-
std::unordered_map<long, long> map;
538-
for (auto f : vertices_to_faces()[v])
537+
if (vertices_to_faces()[v].size() > 0)
539538
{
540-
for (int lv = 0; lv < 3; lv++)
539+
// construct a map of neighboring vertices, it maps every neighbor to the next counter-clockwise neighbor
540+
std::unordered_map<long, long> map;
541+
for (auto f : vertices_to_faces()[v])
541542
{
542-
if (faces()(f, lv) == v)
543+
for (int lv = 0; lv < 3; lv++)
543544
{
544-
map[faces()(f, (lv+1)%3)] = faces()(f, (lv+2)%3);
545-
break;
545+
if (faces()(f, lv) == v)
546+
{
547+
map[faces()(f, (lv+1)%3)] = faces()(f, (lv+2)%3);
548+
break;
549+
}
546550
}
547551
}
548-
}
549-
if (vertices_to_faces()[v].size() != map.size())
550-
throw std::runtime_error("Non-manifold vertex! Map size smaller than neighbor!");
551-
552-
auto iter = map.find(map.begin()->first);
553-
while (neighbors.empty() || iter->first != neighbors.front())
554-
{
555-
neighbors.push_back(iter->first);
556-
iter = map.find(iter->second);
557-
if (iter == map.end())
552+
if (vertices_to_faces()[v].size() != map.size())
553+
throw std::runtime_error("Non-manifold vertex! Map size smaller than neighbor!");
554+
555+
// verify that the neighboring vertices form a loop
556+
auto iter = map.find(map.begin()->first);
557+
while (neighbors.empty() || iter->first != neighbors.front())
558558
{
559-
logger().error("neighbor faces {}, map {}", vertices_to_faces()[v].size(), map);
560-
throw std::runtime_error("Non-manifold vertex! Cannot find next neighbor!");
561-
}
562-
}
563-
if (neighbors.size() != map.size())
564-
throw std::runtime_error("Non-manifold vertex!");
565-
}
566-
return neighbors;
567-
}
568-
569-
/// @brief
570-
/// @param e edge id
571-
/// @return 4 vertices of the 2 faces adjacent to this edge, in the order of [e0, e1, f0, f1]
572-
/// the two faces are [f0, e0, e1] and [f1, e1, e0]
573-
std::array<long, 4> CollisionMesh::find_edge_adjacent_vertices(const long &e) const
574-
{
575-
std::array<long, 4> neighbors;
576-
if (dim() == 2)
577-
throw std::runtime_error("find_edge_adjacent_vertices is only for 3d collision mesh!");
578-
579-
std::array<long, 2> lf = {{edges_to_faces()(e, 0), edges_to_faces()(e, 1)}};
580-
581-
for (int j : {0, 1})
582-
{
583-
int i;
584-
for (i = 0; i < 3; i++)
585-
{
586-
const auto va = faces()(lf[j], i);
587-
588-
if (va != edges()(e, 0) && va != edges()(e, 1))
589-
{
590-
neighbors[2 + j] = va;
591-
break;
559+
neighbors.push_back(iter->first);
560+
iter = map.find(iter->second);
561+
if (iter == map.end())
562+
{
563+
logger().error("neighbor faces {}, map {}", vertices_to_faces()[v].size(), map);
564+
throw std::runtime_error("Non-manifold vertex! Cannot find next neighbor!");
565+
}
592566
}
567+
if (neighbors.size() != map.size())
568+
throw std::runtime_error("Non-manifold vertex!");
593569
}
594-
595-
if (j == 0)
570+
else
596571
{
597-
neighbors[0] = faces()(lf[j], (i+1) % 3);
598-
neighbors[1] = faces()(lf[j], (i+2) % 3);
572+
for (int eid : vertices_to_edges()[v])
573+
neighbors.push_back(
574+
edges()(eid, 0) == v ? edges()(eid, 1) : edges()(eid, 0));
599575
}
600576
}
601-
602577
return neighbors;
603578
}
604579

src/ipc/collision_mesh.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ class CollisionMesh {
118118
double edge_length(const int& edge_id) const;
119119
double max_edge_length() const;
120120

121-
// const std::vector<std::vector<int>>& vertices_to_edges() const
122-
// {
123-
// return m_vertices_to_edges;
124-
// }
121+
const std::vector<std::vector<int>>& vertices_to_edges() const
122+
{
123+
return m_vertices_to_edges;
124+
}
125125

126126
const std::vector<std::vector<int>>& vertices_to_faces() const
127127
{
@@ -131,7 +131,6 @@ class CollisionMesh {
131131
const Eigen::MatrixXi& edges_to_faces() const { return m_edges_to_faces; }
132132

133133
std::vector<long> find_vertex_adjacent_vertices(const long& v) const;
134-
std::array<long, 4> find_edge_adjacent_vertices(const long& e) const;
135134

136135
// -----------------------------------------------------------------------
137136

@@ -363,7 +362,7 @@ class CollisionMesh {
363362
std::vector<unordered_set<int>> m_edge_vertex_adjacencies;
364363

365364
std::vector<std::vector<int>> m_vertices_to_faces;
366-
// std::vector<std::vector<int>> m_vertices_to_edges;
365+
std::vector<std::vector<int>> m_vertices_to_edges;
367366

368367
/// @brief Is vertex on the boundary of the triangle mesh in 3D or polyline in 2D?
369368
std::vector<bool> m_is_vertex_on_boundary;

0 commit comments

Comments
 (0)