fwilliams / point-cloud-utils

An easy-to-use Python library for processing and manipulating 3D point clouds and meshes.
https://www.fwilliams.info/point-cloud-utils/
MIT License
1.33k stars 107 forks source link

Bug: `deduplicate_mesh_vertices` produces degenerate faces #94

Open nvibd opened 3 months ago

nvibd commented 3 months ago

Using deduplicate_mesh_vertices on a triangular mesh leads to sporadic degenerate faces.

I have some mesh vertex and face data, v and f, which I clean using deduplicate_mesh_vertices. I validate that the faces are non-degenerate by asserting that a face does not contain a vertex multiple times.

This code illustrates the test:

import numpy as np
import point_cloud_utils as pcu

# v and f are produced from Poisson reconstruction
v = np.load("...")
f = np.load("...")

def validate_faces(faces):
    for face in faces:
        assert len(set(list(face))) == len(list(face))

validate_faces(f) # Passes without issues

v_clean, f_clean, _, _ = pcu.deduplicate_mesh_vertices(v, f, 1e-7)

validate_faces(f_clean) # Assertion error

I have dumped the data before and after the deduplication, which should allow you to reproduce the issue. Here's the data, four files zipped: https://drive.google.com/file/d/1e_vJRHqNEyB4eGFnLj1J3EfYtqtw-5XB/view?usp=sharing

I am using PCU version 0.30.4, which is the latest version as of creation of this bug report.

nvibd commented 3 months ago

I have tried building my own version of PCU with an updated version (v2.5.0 of the IGL library. However, it did not resolve the issue.