Skip to content

Commit 45b2d08

Browse files
author
plu
committed
refactor the plot speos feature preview to private function
1 parent 60777b4 commit 45b2d08

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

src/ansys/speos/core/project.py

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,46 @@ def local2absolute(local_vertice: np.ndarray, coordinates) -> np.ndarray:
904904
part_mesh_info = part_mesh_info.append_polydata(face_mesh_data)
905905
return part_mesh_info
906906

907+
def _create_speos_feature_preview(
908+
self, plotter: Plotter, speos_feature: Union[SensorCamera, SensorRadiance, SensorIrradiance]
909+
) -> Plotter:
910+
"""Add speos feature visual preview to pyvista plotter object.
911+
912+
Parameters
913+
----------
914+
plotter: Plotter
915+
ansys.tools.visualization_interface.Plotter
916+
speos_feature: Union[SensorCamera, SensorRadiance, SensorIrradiance]
917+
speos feature whose visual data will be added.
918+
919+
Returns
920+
-------
921+
Plotter
922+
ansys.tools.visualization_interface.Plotter
923+
"""
924+
if not isinstance(speos_feature, (SensorIrradiance, SensorRadiance, SensorCamera)):
925+
return plotter
926+
plotter.plot(
927+
speos_feature.visual_data.data,
928+
show_edges=True,
929+
line_width=2,
930+
edge_color="red",
931+
color="orange",
932+
opacity=0.5,
933+
)
934+
match speos_feature:
935+
case SensorRadiance():
936+
plotter.plot(speos_feature.visual_data.coordinates.x_axis, color="red")
937+
plotter.plot(speos_feature.visual_data.coordinates.y_axis, color="green")
938+
case SensorIrradiance():
939+
plotter.plot(speos_feature.visual_data.coordinates.x_axis, color="red")
940+
plotter.plot(speos_feature.visual_data.coordinates.y_axis, color="green")
941+
plotter.plot(speos_feature.visual_data.coordinates.z_axis, color="blue")
942+
case SensorCamera():
943+
plotter.plot(speos_feature.visual_data.coordinates.x_axis, color="red")
944+
plotter.plot(speos_feature.visual_data.coordinates.y_axis, color="green")
945+
return plotter
946+
907947
@graphics_required
908948
def _create_preview(self, viz_args=None) -> Plotter:
909949
"""Create preview pyvista plotter object.
@@ -947,43 +987,9 @@ def _create_preview(self, viz_args=None) -> Plotter:
947987
viz_args["show_edges"] = True
948988
p.plot(_preview_mesh, **viz_args)
949989

950-
# Add sensor at the root part
990+
# Add speos visual data at the root part
951991
for feature in self._features:
952-
match feature:
953-
case SensorRadiance():
954-
p.plot(
955-
feature.visual_data.data,
956-
show_edges=True,
957-
line_width=2,
958-
edge_color="red",
959-
color="orange",
960-
opacity=0.5,
961-
)
962-
p.plot(feature.visual_data.coordinates.x_axis, color="red")
963-
p.plot(feature.visual_data.coordinates.y_axis, color="green")
964-
case SensorIrradiance():
965-
p.plot(
966-
feature.visual_data.data,
967-
show_edges=True,
968-
line_width=2,
969-
edge_color="red",
970-
color="orange",
971-
opacity=0.5,
972-
)
973-
p.plot(feature.visual_data.coordinates.x_axis, color="red")
974-
p.plot(feature.visual_data.coordinates.y_axis, color="green")
975-
p.plot(feature.visual_data.coordinates.z_axis, color="blue")
976-
case SensorCamera():
977-
p.plot(
978-
feature.visual_data.data,
979-
show_edges=True,
980-
line_width=2,
981-
edge_color="red",
982-
color="orange",
983-
opacity=0.5,
984-
)
985-
p.plot(feature.visual_data.coordinates.x_axis, color="red")
986-
p.plot(feature.visual_data.coordinates.y_axis, color="green")
992+
p = self._create_speos_feature_preview(p, feature)
987993
return p
988994

989995
@graphics_required

0 commit comments

Comments
 (0)