Skip to content

Commit 8649d35

Browse files
feat: Add StructuredGrid support
1 parent 4d22a05 commit 8649d35

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/ansys/tools/visualization_interface/backends/pyvista/pyvista_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def plot(
246246
self._show_edges = plotting_options["show_edges"]
247247

248248
# Check what kind of object we are dealing with
249-
if isinstance(plottable_object, (pv.PolyData, pv.UnstructuredGrid)):
249+
if isinstance(plottable_object, (pv.PolyData, pv.UnstructuredGrid, pv.StructuredGrid)):
250250
if "clipping_plane" in plotting_options:
251251
mesh = self.clip(plottable_object, plotting_options["clipping_plane"])
252252
plotting_options.pop("clipping_plane", None)

src/ansys/tools/visualization_interface/backends/pyvista/widgets/mesh_slider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def callback(self, state: bool) -> None:
8282
mesh_id = "UnstructuredGrid(" + mesh.memory_address + ")"
8383
elif isinstance(mesh, pv.MultiBlock):
8484
mesh_id = "MultiBlock(" + mesh.memory_address + ")"
85+
elif isinstance(mesh, pv.StructuredGrid):
86+
mesh_id = "StructuredGrid(" + mesh.memory_address + ")"
8587
self._mesh_actor_list.append(self.plotter_helper._pl.scene.actors[mesh_id])
8688
self.plotter_helper._pl.scene.remove_actor(mesh_id)
8789

tests/test_generic_plotter.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"""Test module for the generic plotter."""
2323
from pathlib import Path
2424

25+
import numpy as np
2526
import pyvista as pv
2627

2728
from ansys.tools.visualization_interface import ClipPlane, MeshObjectPlot, Plotter
@@ -52,6 +53,7 @@ def test_plotter_add_mb():
5253
pl.plot(mb)
5354
pl.show()
5455

56+
5557
def test_plotter_add_unstructured_grid():
5658
"""Adds unstructured grid to the plotter."""
5759
pl = Plotter()
@@ -60,6 +62,18 @@ def test_plotter_add_unstructured_grid():
6062
pl.plot(ug)
6163
pl.show()
6264

65+
66+
def test_plotter_add_structured_grid():
67+
"""Adds unstructured grid to the plotter."""
68+
pl = Plotter()
69+
xrng = np.arange(-10, 10, 2, dtype=np.float32)
70+
yrng = np.arange(-10, 10, 5, dtype=np.float32)
71+
zrng = np.arange(-10, 10, 1, dtype=np.float32)
72+
x, y, z = np.meshgrid(xrng, yrng, zrng, indexing='ij')
73+
grid = pv.StructuredGrid(x, y, z)
74+
pl.plot(grid)
75+
76+
6377
def test_plotter_add_custom():
6478
"""Adds a MeshObjectPlot object to the plotter."""
6579
sphere = pv.Sphere()
@@ -90,6 +104,19 @@ def test_clipping_plane():
90104
pl.show()
91105

92106

107+
def test_clipping_plane_structured_grid():
108+
"""Test clipping plane usage with unstructured grid."""
109+
pl = Plotter()
110+
xrng = np.arange(-10, 10, 2, dtype=np.float32)
111+
yrng = np.arange(-10, 10, 5, dtype=np.float32)
112+
zrng = np.arange(-10, 10, 1, dtype=np.float32)
113+
x, y, z = np.meshgrid(xrng, yrng, zrng, indexing='ij')
114+
grid = pv.StructuredGrid(x, y, z)
115+
clipping_plane = ClipPlane()
116+
pl.plot(grid, clipping_plane=clipping_plane)
117+
pl.show()
118+
119+
93120
def test_plotter_add_list():
94121
"""Adds a list to the plotter."""
95122
pl = Plotter()

0 commit comments

Comments
 (0)