isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
10.93k stars 2.24k forks source link

compute_vertex_normals produces wrong results when mesh previous has incorrect normals #6848

Closed JunzheJosephZhu closed 1 week ago

JunzheJosephZhu commented 4 weeks ago

Checklist

Describe the issue

When I call compute_vertex normals() on a mesh already with incorrect normals, the result would be wrong: image

However, if I set the existing normals to zeros and call compute_vertex_normals(), the result is correct. I think this is due to the code here not zeroing out previous normals here before accumulating: https://github.com/isl-org/Open3D/pull/4224/commits/19551b189a82060b4cd44cc80faaccd9e4bfcb63 image

Steps to reproduce the bug

# load any mesh
mesh = mesh.compute_triangle_normals(normalized=False)
if reproduce_error:
    mesh.vertex_normals = o3d.utility.Vector3dVector(np.random.randn(len(mesh.vertices), 3))
else:   
    mesh.vertex_normals = o3d.utility.Vector3dVector(np.zeros_like(np.asarray(mesh.vertices)))
mesh.compute_vertex_normals()

# make a point cloud with vertices and vertex normals to show
pcd = o3d.geometry.PointCloud()
pcd.points = mesh.vertices
pcd.normals = mesh.vertex_normals
o3d.visualization.draw_geometries([pcd], point_show_normal=True)

Error message

No response

Expected behavior

No response

Open3D, Python and System information

- Operating system: Ubuntu 20.04 
- Python version: Python 3.9
- Open3D version: 0.18.0
- System architecture: x86 
- Is this a remote workstation?: no
- How did you install Open3D?: pip

Additional information

No response

benjaminum commented 2 weeks ago

@JunzheJosephZhu Thanks a lot for finding this bug. Since you already identified where the problematic code is could you create a PR fixing the bug?

JunzheJosephZhu commented 2 weeks ago

I haven't really compiled open3d and dont intend to do it in the short term. Ideally, someone can just add a line that zeros out vertex normals here https://github.com/isl-org/Open3D/commit/19551b189a82060b4cd44cc80faaccd9e4bfcb63#diff-ace2240cda6c6014f5a91df75ff46050c6ba940dd076810a18f2e1d3d73b61a3R148 next time they work on the codebase. Joseph Zhu

On Thu, Jul 11, 2024 at 1:19 AM Benjamin Ummenhofer < @.***> wrote:

@JunzheJosephZhu https://github.com/JunzheJosephZhu Thanks a lot for finding this bug. Since you already identified where the problematic code is could you create a PR fixing the bug?

— Reply to this email directly, view it on GitHub https://github.com/isl-org/Open3D/issues/6848#issuecomment-2221063518, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF2C6G5MNQGILNA3WCA2ZCLZLVUKPAVCNFSM6AAAAABKEKKSK6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRRGA3DGNJRHA . You are receiving this because you were mentioned.Message ID: @.***>

benjaminum commented 2 weeks ago

Missed opportunity to become a contributor 😉
Thanks again for reporting the bug @JunzheJosephZhu !