Debian Codegraph @

pyvista/plotting/actor_properties.py

raw
1 """Module containing pyvista implementation of :vtk:`vtkProperty`."""
2
3 from __future__ import annotations
4
5 from typing import TYPE_CHECKING
6
7 from pyvista.core.utilities.misc import _NoNewAttrMixin
8
9 from .opts import InterpolationType
10 from .opts import RepresentationType
11
12 if TYPE_CHECKING:
13 from pyvista import _vtk
14
15
16 class ActorProperties(_NoNewAttrMixin):
17 """Properties wrapper for :vtk:`vtkProperty`.
18
19 Contains the surface properties of the object.
20
21 Parameters
22 ----------
23 properties : :vtk:`vtkProperty`
24 VTK properties of the current object.
25
26 Examples
27 --------
28 Access the properties of the z-axis shaft.
29
30 >>> import pyvista as pv
31
32 >>> axes = pv.Axes()
33 >>> z_axes_prop = axes.axes_actor.z_axis_shaft_properties
34 >>> z_axes_prop.color = (1.0, 1.0, 0.0)
35 >>> z_axes_prop.opacity = 0.5
36 >>> axes.axes_actor.shaft_type = axes.axes_actor.ShaftType.CYLINDER
37
38 >>> pl = pv.Plotter()
39 >>> _ = pl.add_actor(axes.axes_actor)
40 >>> _ = pl.add_mesh(pv.Sphere())
41 >>> pl.show()
42
43 """
44
45 def __init__(self, properties: _vtk.vtkProperty) -> None:
46 super().__init__()
47 self.properties = properties
48
49 @property
50 def color(self): # numpydoc ignore=RT01
51 """Return or set the color of the actor."""
52 return self.properties.GetColor()
53
54 @color.setter
55 def color(self, color: tuple[float, float, float]):
56 self.properties.SetColor(color[0], color[1], color[2])
57
58 @property
59 def metallic(self): # numpydoc ignore=RT01
60 """Return or set the metallic coefficient of the surface."""
61 return self.properties.GetMetallic()
62
63 @metallic.setter
64 def metallic(self, value: float):
65 self.properties.SetMetallic(value)
66
67 @property
68 def roughness(self): # numpydoc ignore=RT01
69 """Return or set the roughness of the surface."""
70 return self.properties.GetRoughness()
71
72 @roughness.setter
73 def roughness(self, value: float):
74 self.properties.SetRoughness(value)
75
76 @property
77 def anisotropy(self): # numpydoc ignore=RT01
78 """Return or set the anisotropy coefficient."""
79 return self.properties.GetAnisotropy()
80
81 @anisotropy.setter
82 def anisotropy(self, value: float):
83 self.properties.SetAnisotropy(value)
84
85 @property
86 def anisotropy_rotation(self): # numpydoc ignore=RT01
87 """Return or set the anisotropy rotation coefficient."""
88 return self.properties.GetAnisotropyRotation()
89
90 @anisotropy_rotation.setter
91 def anisotropy_rotation(self, value: float):
92 self.properties.SetAnisotropyRotation(value)
93
94 @property
95 def lighting(self): # numpydoc ignore=RT01
96 """Return or set the lighting activation flag."""
97 return self.properties.GetLighting()
98
99 @lighting.setter
100 def lighting(self, flag: bool):
101 self.properties.SetLighting(flag)
102
103 @property
104 def interpolation_model(self): # numpydoc ignore=RT01
105 """Return or set the interpolation model.
106
107 Can be any of the options in :class:`pyvista.plotting.opts.InterpolationType` enum.
108 """
109 return InterpolationType.from_any(self.properties.GetInterpolation())
110
111 @interpolation_model.setter
112 def interpolation_model(self, model: InterpolationType):
113 self.properties.SetInterpolation(model.value)
114
115 @property
116 def index_of_refraction(self): # numpydoc ignore=RT01
117 """Return or set the Index Of Refraction of the base layer."""
118 return self.properties.GetBaseIOR()
119
120 @index_of_refraction.setter
121 def index_of_refraction(self, value: float):
122 self.properties.SetBaseIOR(value)
123
124 @property
125 def opacity(self): # numpydoc ignore=RT01
126 """Return or set the opacity of the actor."""
127 return self.properties.GetOpacity()
128
129 @opacity.setter
130 def opacity(self, value: float):
131 self.properties.SetOpacity(value)
132
133 @property
134 def shading(self): # numpydoc ignore=RT01
135 """Return or set the flag to activate the shading."""
136 return self.properties.GetShading()
137
138 @shading.setter
139 def shading(self, is_active: bool):
140 self.properties.SetShading(is_active)
141
142 @property
143 def representation(self) -> RepresentationType: # numpydoc ignore=RT01
144 """Return or set the representation of the actor.
145
146 Can be any of the options in :class:`pyvista.plotting.opts.RepresentationType` enum.
147 """
148 return RepresentationType.from_any(self.properties.GetRepresentation())
149
150 @representation.setter
151 def representation(self, value: RepresentationType):
152 self.properties.SetRepresentation(RepresentationType.from_any(value).value)