File: volume.py

package info (click to toggle)
python-pyvista 0.46.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176,968 kB
  • sloc: python: 94,346; sh: 216; makefile: 70
file content (128 lines) | stat: -rw-r--r-- 3,479 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"""PyVista volume module."""

from __future__ import annotations

from typing import TYPE_CHECKING

from pyvista._deprecate_positional_args import _deprecate_positional_args

from . import _vtk
from .prop3d import Prop3D

if TYPE_CHECKING:
    from typing_extensions import Self

    from .mapper import _BaseMapper
    from .volume_property import VolumeProperty


class Volume(Prop3D, _vtk.vtkVolume):
    """Wrapper class for VTK volume.

    This class represents a volume in a rendered scene. It inherits
    functions related to the volume's position, orientation and origin
    from Prop3D.

    """

    def __init__(self):
        """Initialize volume."""
        super().__init__()

    @property
    def mapper(self) -> _BaseMapper:  # numpydoc ignore=RT01
        """Return or set the mapper of the volume.

        Examples
        --------
        Add a volume to a :class:`pyvista.Plotter` and get its mapper.

        >>> import pyvista as pv
        >>> vol = pv.ImageData(dimensions=(10, 10, 10))
        >>> vol['scalars'] = 255 - vol.z * 25
        >>> pl = pv.Plotter()
        >>> actor = pl.add_volume(vol)
        >>> actor.mapper.bounds
        BoundsTuple(x_min = 0.0,
                    x_max = 9.0,
                    y_min = 0.0,
                    y_max = 9.0,
                    z_min = 0.0,
                    z_max = 9.0)

        """
        return self.GetMapper()  # type: ignore[return-value]

    @mapper.setter
    def mapper(self, obj):
        self.SetMapper(obj)

    @property
    def prop(self):  # numpydoc ignore=RT01
        """Return or set the property of this actor.

        Examples
        --------
        Create an volume and get its properties.

        >>> import pyvista as pv
        >>> vol = pv.ImageData(dimensions=(10, 10, 10))
        >>> vol['scalars'] = 255 - vol.z * 25
        >>> pl = pv.Plotter()
        >>> actor = pl.add_volume(vol)
        >>> actor.prop.GetShade()
        0

        """
        return self.GetProperty()

    @prop.setter
    def prop(self, obj: VolumeProperty):
        self.SetProperty(obj)

    @_deprecate_positional_args
    def copy(self: Self, deep: bool = True) -> Self:  # noqa: FBT001, FBT002
        """Create a copy of this volume.

        Parameters
        ----------
        deep : bool, default: True
            Create a shallow or deep copy of the volume. A deep copy will have a
            new property and mapper, while a shallow copy will use the mapper
            and property of this volume.

        Returns
        -------
        Volume
            Deep or shallow copy of this volume.

        Examples
        --------
        Create a volume of by adding it to a :class:`~pyvista.Plotter`
        and then copy the volume.

        >>> import pyvista as pv
        >>> mesh = pv.Wavelet()
        >>> pl = pv.Plotter()
        >>> volume = pl.add_volume(mesh, diffuse=0.5)
        >>> new_volume = volume.copy()

        Change the copy's properties. A deep copy is made by default, so the original
        volume is not affected.

        >>> new_volume.prop.diffuse = 1.0
        >>> new_volume.prop.diffuse
        1.0

        >>> volume.prop.diffuse
        0.5

        """
        new_actor = type(self)()
        if deep:
            if self.mapper is not None:
                new_actor.mapper = self.mapper.copy()
            new_actor.prop = self.prop.copy()
        else:
            new_actor.ShallowCopy(self)
        return new_actor