| 1 |
"""Module containing pyvista implementation of :vtk:`vtkAxes`.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
from pyvista import _vtk |
| 6 |
from pyvista._deprecate_positional_args import _deprecate_positional_args |
| 7 |
from pyvista.core._vtk_utilities import DisableVtkSnakeCase |
| 8 |
from pyvista.core.utilities.misc import _NoNewAttrMixin |
| 9 |
|
| 10 |
from .actor import Actor |
| 11 |
from .axes_actor import AxesActor |
| 12 |
|
| 13 |
|
| 14 |
class Axes(_NoNewAttrMixin, DisableVtkSnakeCase, _vtk.vtkAxes): |
| 15 |
"""PyVista wrapper for the VTK Axes class. |
| 16 |
|
| 17 |
Parameters |
| 18 |
---------- |
| 19 |
show_actor : bool, optional |
| 20 |
Hide or show the actor of these axes. Default ``False``. |
| 21 |
|
| 22 |
actor_scale : float, optional |
| 23 |
Scale the size of the axes actor. Default ``1``. |
| 24 |
|
| 25 |
line_width : float, optional |
| 26 |
Width of the axes lines. Default ``1``. |
| 27 |
|
| 28 |
symmetric : bool, optional |
| 29 |
If true, the axis continue to negative values. |
| 30 |
|
| 31 |
Examples |
| 32 |
-------- |
| 33 |
Create an instance of axes at the pyvista module level. |
| 34 |
|
| 35 |
>>> import pyvista as pv |
| 36 |
>>> axes = pv.Axes() |
| 37 |
|
| 38 |
""" |
| 39 |
|
| 40 |
@_deprecate_positional_args |
| 41 |
def __init__( # noqa: PLR0917 |
| 42 |
self, |
| 43 |
show_actor: bool = False, # noqa: FBT001, FBT002 |
| 44 |
actor_scale=1, |
| 45 |
line_width=1.0, |
| 46 |
symmetric: bool = False, # noqa: FBT001, FBT002 |
| 47 |
): # numpydoc ignore=PR01,RT01 |
| 48 |
"""Initialize a new axes descriptor.""" |
| 49 |
super().__init__() |
| 50 |
self.SetSymmetric(symmetric) |
| 51 |
# Add the axes mapper |
| 52 |
self.mapper = _vtk.vtkPolyDataMapper() |
| 53 |
self.mapper.SetInputConnection(self.GetOutputPort()) |
| 54 |
# Add the axes actor |
| 55 |
self.actor = Actor(mapper=self.mapper) |
| 56 |
self.axes_actor = AxesActor() |
| 57 |
self.actor.visibility = show_actor |
| 58 |
self.actor.scale = actor_scale |
| 59 |
self.actor.prop.line_width = line_width |
| 60 |
|
| 61 |
@property |
| 62 |
def origin(self): # numpydoc ignore=RT01 |
| 63 |
"""Return or set th origin of the axes in world coordinates. |
| 64 |
|
| 65 |
Examples |
| 66 |
-------- |
| 67 |
>>> import pyvista as pv |
| 68 |
>>> axes = pv.Axes() |
| 69 |
>>> axes.origin |
| 70 |
(0.0, 0.0, 0.0) |
| 71 |
|
| 72 |
Set the origin of the camera. |
| 73 |
|
| 74 |
>>> axes.origin = (2.0, 1.0, 1.0) |
| 75 |
>>> axes.origin |
| 76 |
(2.0, 1.0, 1.0) |
| 77 |
|
| 78 |
""" |
| 79 |
return self.GetOrigin() |
| 80 |
|
| 81 |
@origin.setter |
| 82 |
def origin(self, value): |
| 83 |
self.SetOrigin(value) |
| 84 |
|
| 85 |
def show_actor(self): |
| 86 |
"""Show an actor of axes. |
| 87 |
|
| 88 |
Examples |
| 89 |
-------- |
| 90 |
>>> import pyvista as pv |
| 91 |
>>> axes = pv.Axes() |
| 92 |
>>> axes.show_actor() |
| 93 |
|
| 94 |
""" |
| 95 |
self.actor.visibility = True |
| 96 |
|
| 97 |
def hide_actor(self): |
| 98 |
"""Hide an actor of axes. |
| 99 |
|
| 100 |
Examples |
| 101 |
-------- |
| 102 |
>>> import pyvista as pv |
| 103 |
>>> axes = pv.Axes() |
| 104 |
>>> axes.hide_actor() |
| 105 |
|
| 106 |
""" |
| 107 |
self.actor.visibility = False |
| 108 |
|
| 109 |
def show_symmetric(self): |
| 110 |
"""Show symmetric of axes. |
| 111 |
|
| 112 |
Examples |
| 113 |
-------- |
| 114 |
>>> import pyvista as pv |
| 115 |
>>> axes = pv.Axes() |
| 116 |
>>> axes.show_symmetric() |
| 117 |
|
| 118 |
""" |
| 119 |
self.SymmetricOn() |
| 120 |
|
| 121 |
def hide_symmetric(self): |
| 122 |
"""Hide symmetric of axes. |
| 123 |
|
| 124 |
Examples |
| 125 |
-------- |
| 126 |
>>> import pyvista as pv |
| 127 |
>>> axes = pv.Axes() |
| 128 |
>>> axes.hide_symmetric() |
| 129 |
|
| 130 |
""" |
| 131 |
self.SymmetricOff() |
| 132 |
|
| 133 |
def __del__(self): |
| 134 |
"""Clean the attributes of the class.""" |
| 135 |
self.axes_actor = None # type: ignore[assignment] |
| 136 |
self.actor = None # type: ignore[assignment] |
| 137 |
self.mapper = None # type: ignore[assignment] |