在 Open3d 中,如果你想从三角形网格创建 HalfEdge,请确保你的网格是流形的并且没有奇异顶点。如果一个顶点有多个输出半边,则会出现运行时错误。在最新版本的 Open3d 中,此错误尚未修复。Open3d 链接
for (size_t triangle_index = 0;
triangle_index < mesh_cpy->triangles_.size(); triangle_index++) {
const Eigen::Vector3i &triangle = mesh_cpy->triangles_[triangle_index];
size_t num_half_edges = het_mesh->half_edges_.size();
size_t he_0_index = num_half_edges;
size_t he_1_index = num_half_edges + 1;
size_t he_2_index = num_half_edges + 2;
HalfEdge he_0(Eigen::Vector2i(triangle(0), triangle(1)),
int(triangle_index), int(he_1_index), -1);
HalfEdge he_1(Eigen::Vector2i(triangle(1), triangle(2)),
int(triangle_index), int(he_2_index), -1);
HalfEdge he_2(Eigen::Vector2i(triangle(2), triangle(0)),
int(triangle_index), int(he_0_index), -1);
if (vertex_indices_to_half_edge_index.find(he_0.vertex_indices_) !=
vertex_indices_to_half_edge_index.end() ||
vertex_indices_to_half_edge_index.find(he_1.vertex_indices_) !=
vertex_indices_to_half_edge_index.end() ||
vertex_indices_to_half_edge_index.find(he_2.vertex_indices_) !=
vertex_indices_to_half_edge_index.end()) {
utility::LogError(
"ComputeHalfEdges failed. Duplicated half-edges.");//Throw a runtime error.
}
het_mesh->half_edges_.push_back(he_0);
het_mesh->half_edges_.push_back(he_1);
het_mesh->half_edges_.push_back(he_2);
vertex_indices_to_half_edge_index[he_0.vertex_indices_] = he_0_index;
vertex_indices_to_half_edge_index[he_1.vertex_indices_] = he_1_index;
vertex_indices_to_half_edge_index[he_2.vertex_indices_] = he_2_index;
}
奇异顶点
就像红色箭头顶点一样。在这些顶点中,会发生错误。如果你想找到边界,请尝试Openmesh或Libigl。Openmesh和 Libigl 都有 python 版本。