Skip to content

Commit

Permalink
raise an error when calling cell_normals before compute_normals()
Browse files Browse the repository at this point in the history
Right now if you call cell_normals before calling compute_normals(), it will simply return an empty array.  This is incorrect, and is especially confusing because if a user is new to vedo they will have no way of knowing that there's another function they need to call first unless they happen to notice it in the API.

This commit has it throw an error instead, thus preventing it from returning the wrong answer and informing the user how to fix the problem.
  • Loading branch information
jkunimune authored Aug 8, 2024
1 parent b53ce12 commit 76c0413
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vedo/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ def cell_normals(self):
Check out also `compute_normals(cells=True)` and `compute_normals_with_pca()`.
"""
vtknormals = self.dataset.GetCellData().GetNormals()
return vtk2numpy(vtknormals)
numpy_normals = vtk2numpy(vtknormals)
if len(numpy_normals) == 0 and len(self.cells) != 0:
raise ValueError("VTK failed to return any normal vectors. You may need to call `Mesh.compute_normals()` before accessing `Mesh.cell_normals`.")
return numpy_normals

def compute_normals(self, points=True, cells=True, feature_angle=None, consistency=True) -> Self:
"""
Expand Down

0 comments on commit 76c0413

Please sign in to comment.