Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

[bug]fill_holes: wrong triangle direction

Open lslzl3000 opened this issue 1 year ago • 2 comments

Checklist

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.: Screenshot 2024-03-07 at 16 15 56 and cannot be fixed by compute_vertex_normals: Screenshot 2024-03-07 at 16 18 33

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

lslzl3000 avatar Mar 07 '24 08:03 lslzl3000

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

lslzl3000 avatar Mar 10 '24 20:03 lslzl3000

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

stormboy avatar Jun 05 '24 06:06 stormboy