Search code examples
pythonmeshopen3d

Open3D ERROR ComputeHalfEdges failed. Duplicated half-edges


Does anyone know how I can process a triangle mesh to allow conversion into a HalfEdgeTriangleMesh. I am trying to use the get_boundaries in HalfEdge to detect edges, which is not an included function in TriangleMesh

The last line gives the error.

mesh = mesh.remove_duplicated_triangles()
mesh = mesh.remove_degenerate_triangles()
mesh = mesh.remove_duplicated_vertices()
mesh = mesh.remove_non_manifold_edges()
mesh = mesh.remove_unreferenced_vertices()
half_edge_mesh = o3d.geometry.HalfEdgeTriangleMesh.create_from_triangle_mesh(mesh)

Solution

  • In Open3d,if you want to create HalfEdge from triangle mesh,please make sure your mesh is manifold and without singular vertex.In the case of a vertex has more than one output halfedge,runtime error will occur.In the newest version of Open3d,this bug has not been repaired.Open3d Link

        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;
    }
    

    singular vertices just like red arrows vertices.In these vertices,error will occur. If you want to find boundary,please try Openmesh or Libigl.Both Openmesh and Libigl have python version.