From 4046ce70413f294f3232c0215fd3bcd6f2d2c9c3 Mon Sep 17 00:00:00 2001 From: domfournier Date: Thu, 1 Oct 2026 09:30:44 -0400 Subject: [PATCH 1/3] Remove unnecessary check --- surface_apps/iso_surfaces/utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/surface_apps/iso_surfaces/utils.py b/surface_apps/iso_surfaces/utils.py index 28a771f..1f12684 100644 --- a/surface_apps/iso_surfaces/utils.py +++ b/surface_apps/iso_surfaces/utils.py @@ -105,8 +105,6 @@ def interp_to_grid( # pylint: disable=too-many-locals grid = [] is_finite = np.isfinite(data.values) if isinstance(entity, CellObject) and data.association == DataAssociationEnum.CELL: - if entity.vertices is None: - raise ValueError("Entity must contain vertices.") locations = np.mean(entity.vertices[entity.cells], axis=1)[is_finite, :] else: locations = entity.locations[is_finite, :] From e004e4d7297c5c4643683334a09c1f50ed8de4a3 Mon Sep 17 00:00:00 2001 From: domfournier Date: Mon, 5 Oct 2026 09:05:58 -0400 Subject: [PATCH 2/3] Change origin indexing --- surface_apps/iso_surfaces/utils.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/surface_apps/iso_surfaces/utils.py b/surface_apps/iso_surfaces/utils.py index 1f12684..326e35b 100644 --- a/surface_apps/iso_surfaces/utils.py +++ b/surface_apps/iso_surfaces/utils.py @@ -152,21 +152,18 @@ def extract_iso_surfaces( verts, faces, _normals, _values = marching_cubes(values, level=level) verts, faces = remove_nan(verts, faces) - vertices = [] + vertices = np.empty((len(verts), 3), dtype=float) for i in np.arange(3): interp = interp1d( np.arange(grid[i].shape[0]), grid[i], fill_value="extrapolate" ) - vertices += [interp(verts[:, i])] + vertices[:, i] += interp(verts[:, i]) if isinstance(entity, BlockModel): - vertices = rotate_xyz(np.vstack(vertices).T, [0, 0, 0], entity.rotation) - vertices[:, 0] += entity.origin["x"] # type: ignore - vertices[:, 1] += entity.origin["y"] # type: ignore - vertices[:, 2] += entity.origin["z"] # type: ignore - - else: - vertices = np.vstack(vertices).T # type: ignore + vertices = rotate_xyz(vertices, [0, 0, 0], entity.rotation) + vertices[:, 0] += entity.origin[0] + vertices[:, 1] += entity.origin[1] + vertices[:, 2] += entity.origin[2] except RuntimeError as _: logging.exception("Caught a RuntimeError in marching cubes algorithm.") From 08f5bc176786863ab6731b8c73ed1266573f026f Mon Sep 17 00:00:00 2001 From: domfournier Date: Mon, 5 Oct 2026 09:18:05 -0400 Subject: [PATCH 3/3] Remove unnecessary addition. --- surface_apps/iso_surfaces/utils.py | 2 +- tests/run_tests/iso_surfaces_test.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/surface_apps/iso_surfaces/utils.py b/surface_apps/iso_surfaces/utils.py index 326e35b..35ed533 100644 --- a/surface_apps/iso_surfaces/utils.py +++ b/surface_apps/iso_surfaces/utils.py @@ -157,7 +157,7 @@ def extract_iso_surfaces( interp = interp1d( np.arange(grid[i].shape[0]), grid[i], fill_value="extrapolate" ) - vertices[:, i] += interp(verts[:, i]) + vertices[:, i] = interp(verts[:, i]) if isinstance(entity, BlockModel): vertices = rotate_xyz(vertices, [0, 0, 0], entity.rotation) diff --git a/tests/run_tests/iso_surfaces_test.py b/tests/run_tests/iso_surfaces_test.py index ae4e42e..e16337f 100644 --- a/tests/run_tests/iso_surfaces_test.py +++ b/tests/run_tests/iso_surfaces_test.py @@ -83,15 +83,6 @@ def test_centroids(tmp_path: Path): ((sphere_center + origin) - surf_center) / (sphere_center + origin) ) - assert np.all(center_error < 0.02) - - # Radius of sphere - surf_distance = np.linalg.norm(np.subtract(func_surface[0][0], surf_center), axis=1) - surf_radius = np.mean(surf_distance, axis=0) - radius_error = np.abs((surf_radius - sphere_radius) / sphere_radius) - - assert radius_error < 0.02 - # For user validation only Surface.create( ws, name="surface", vertices=func_surface[0][0], cells=func_surface[0][1] @@ -105,6 +96,15 @@ def test_centroids(tmp_path: Path): ) ws.close() + assert np.all(center_error < 0.02) + + # Radius of sphere + surf_distance = np.linalg.norm(np.subtract(func_surface[0][0], surf_center), axis=1) + surf_radius = np.mean(surf_distance, axis=0) + radius_error = np.abs((surf_radius - sphere_radius) / sphere_radius) + + assert radius_error < 0.02 + def test_vertices(tmp_path: Path): """