Open3D
Open3D copied to clipboard
[bug]fill_holes: wrong triangle direction
Checklist
- [X] I have searched for similar issues.
- [X] For Python issues, I have tested with the latest development wheel.
- [X] I have checked the release documentation and the latest documentation (for
mainbranch).
Describe the issue
Using fill_holes in open3d.t.geometry.TriangleMesh is simple and effective, but the result of filled triangles were create with wrong directions, e.g.:
and cannot be fixed by
compute_vertex_normals:
is this a bug? can we configure the triangle direction in fill_holes?
Or how to flip the directions of the filled holes?
Steps to reproduce the bug
import open3d as o3d
mesh = o3d.io.read_triangle_mesh('path')
# ....
# try fill holes
filled = o3d.t.geometry.TriangleMesh.from_legacy(mesh)
final = filled.fill_holes()
final.compute_vertex_normals()
o3d.visualization.draw(final)
Error message
No response
Expected behavior
No response
Open3D, Python and System information
- Operating system: macOS 10.15
- Python version: Python 3.11.4
- Open3D version: 0.18
- System architecture: apple-silicon
- How did you install Open3D?: pip
Additional information
The similar functions/filter in other software such as MeshLab, MeshFix would fix holes with right normal/direction
looks like this is a very old bug of vtkFillHolesFilter
https://gitlab.kitware.com/vtk/vtk/-/issues/19269
https://gitlab.kitware.com/vtk/vtk/-/issues/17763
Hope someone cloud fix it, or replace this filter with some new algorithm, like MeshLab/MeshFix does
I was able to work around this issue by editing the open3d::t::geometry::TriangleMesh implementation as follows.
TriangleMesh TriangleMesh::FillHoles(double hole_size) const {
using namespace vtkutils;
// do not include triangle attributes because they will not be preserved by
// the hole filling algorithm
auto polydata = CreateVtkPolyDataFromGeometry(
*this, GetVertexAttr().GetKeySet(), {}, {}, {}, false);
vtkNew<vtkFillHolesFilter> fill_holes;
fill_holes->SetInputData(polydata);
fill_holes->SetHoleSize(hole_size);
// make the triangle winding order consistent
vtkNew<vtkPolyDataNormals> normals;
normals->SetInputConnection(fill_holes->GetOutputPort());
normals->SetConsistency(true);
normals->SetSplitting(false);
normals->Update();
auto result = normals->GetOutput();
return CreateTriangleMeshFromVtkPolyData(result);
}
I've just created a pull request. https://github.com/isl-org/Open3D/pull/6816