From 76c04134c6b528a9c6e3767e87cf8c80c34a630a Mon Sep 17 00:00:00 2001 From: Justin Kunimune Date: Thu, 8 Aug 2024 13:51:01 -0400 Subject: [PATCH] raise an error when calling cell_normals before compute_normals() 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. --- vedo/mesh.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vedo/mesh.py b/vedo/mesh.py index e976e151..b8c2b507 100644 --- a/vedo/mesh.py +++ b/vedo/mesh.py @@ -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: """