Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions surface_apps/iso_surfaces/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, :]
Expand Down Expand Up @@ -154,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.")
Expand Down
18 changes: 9 additions & 9 deletions tests/run_tests/iso_surfaces_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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):
"""
Expand Down
Loading