# volume¶

Submodule extending the vtkVolume object functionality.

## Volume¶

class vtkplotter.volume.Volume(inputobj, c=('b', 'lb', 'lg', 'y', 'r'), alpha=(0.0, 0.0, 0.2, 0.4, 0.8, 1), alphaGradient=None, mode=0, origin=None, spacing=None, shape=None, mapperType='gpu')[source]

Bases: vtkRenderingCorePython.vtkVolume, vtkplotter.base.ActorBase

Derived class of vtkVolume. Can be initialized with a numpy object, see e.g.: numpy2volume.py

Parameters
• c (float, list) – sets colors along the scalar range, or a matplotlib color map name

• alphas – sets transparencies along the scalar range

• origin (list) – set volume origin coordinates

• spacing (list) – voxel dimensions in x, y and z.

• shape (list) – specify the shape.

• mapperType (str) – either ‘gpu’, ‘opengl_gpu’, ‘fixed’ or ‘smart’

• mode (int) –

define the volumetric rendering style:

• 0, Composite rendering

• 1, maximum projection rendering

• 2, minimum projection

• 3, average projection

Hint

if a list of values is used for alphas this is interpreted as a transfer function along the range of the scalar.

alpha(alpha)[source]

Assign a set of tranparencies to a volume along the range of the scalar value. A single constant value can also be assigned.

E.g.: say alpha=(0.0, 0.3, 0.9, 1) and the scalar range goes from -10 to 150. Then all voxels with a value close to -10 will be completely transparent, voxels at 1/4 of the range will get an alpha equal to 0.3 and voxels with value close to 150 will be completely opaque.

alphaGradient(alphaGrad)[source]

Assign a set of tranparencies to a volume’s gradient along the range of the scalar value. A single constant value can also be assigned. The gradient function is used to decrease the opacity in the “flat” regions of the volume while maintaining the opacity at the boundaries between material types. The gradient is measured as the amount by which the intensity changes over unit distance.

append(volumes, axis='z', preserveExtents=False)[source]

Take the components from multiple inputs and merges them into one output. Except for the append axis, all inputs must have the same extent. All inputs must have the same number of scalar components. The output has the same origin and spacing as the first input. The origin and spacing of all other inputs are ignored. All inputs must have the same scalar type.

Parameters
• axis (int,str) – axis expanded to hold the multiple images.

• preserveExtents (bool) – if True, the extent of the inputs is used to place the image in the output. The whole extent of the output is the union of the input whole extents. Any portion of the output not covered by the inputs is set to zero. The origin and spacing is taken from the first input.

from vtkplotter import load, datadir
vol.append(vol, axis='x').show()

center(center=None)[source]

Set/get the volume coordinates of its center. Position is reset to (0,0,0).

color(col)[source]

Assign a color or a set of colors to a volume along the range of the scalar value. A single constant color can also be assigned. Any matplotlib color map name is also accepted, e.g. volume.color('jet').

E.g.: say that your voxel scalar runs from -3 to 6, and you want -3 to show red and 1.5 violet and 6 green, then just set:

volume.color(['red', 'violet', 'green'])

crop(top=None, bottom=None, right=None, left=None, front=None, back=None, VOI=())[source]

Crop a Volume object.

Parameters
• top (float) – fraction to crop from the top plane (positive z)

• bottom (float) – fraction to crop from the bottom plane (negative z)

• front (float) – fraction to crop from the front plane (positive y)

• back (float) – fraction to crop from the back plane (negative y)

• right (float) – fraction to crop from the right plane (positive x)

• left (float) – fraction to crop from the left plane (negative x)

• VOI (list) –

extract Volume Of Interest expressed in voxel numbers

Eg.: vol.crop(VOI=(xmin, xmax, ymin, ymax, zmin, zmax)) # all integers nrs

cutWithPlane(origin=(0, 0, 0), normal=(1, 0, 0))[source]

Cuts Volume with the plane defined by a point and a normal creating a tetrahedral mesh object. Makes sense only if the plane is not along any of the cartesian planes, otherwise use crop() which is way faster.

Parameters
• origin – the cutting plane goes through this point

• normal – normal of the cutting plane

dimensions()[source]

Return the nr. of voxels in the 3 dimensions.

imagedata()[source]

Return the underlying vtkImagaData object.

isosurface(threshold=True, connectivity=False)[source]

Return an Mesh isosurface extracted from the Volume object.

Parameters
• threshold (float, list) – value or list of values to draw the isosurface(s)

• connectivity (bool) – if True only keeps the largest portion of the polydata

jittering(status=None)[source]

If jittering is True, each ray traversal direction will be perturbed slightly using a noise-texture to get rid of wood-grain effects.

legosurface(vmin=None, vmax=None, cmap='afmhot_r')[source]

Represent a Volume as lego blocks (voxels). By default colors correspond to the volume’s scalar. Returns an Mesh.

Parameters
• vmin (float) – the lower threshold, voxels below this value are not shown.

• vmax (float) – the upper threshold, voxels above this value are not shown.

• cmap (str) – color mapping of the scalar associated to the voxels.

mirror(axis='x')[source]

Mirror flip along one of the cartesian axes.

Note

axis='n', will flip only mesh normals.

mode(mode=None)[source]

Define the volumetric rendering style.

• 0, Composite rendering

• 1, maximum projection rendering

• 2, minimum projection

• 3, average projection

normalize()[source]

Normalize that scalar components for each point.

permuteAxes(x, y, z)[source]

Reorder the axes of the Volume by specifying the input axes which are supposed to become the new X, Y, and Z.

resample(newSpacing, interpolation=1)[source]

Resamples a Volume to be larger or smaller.

This method modifies the spacing of the input. Linear interpolation is used to resample the data.

Parameters
• newSpacing (list) – a list of 3 new spacings for the 3 axes.

• interpolation (int) – 0=nearest_neighbor, 1=linear, 2=cubic

resize(*newdims)[source]

Increase or reduce the number of voxels of a Volume with interpolation.

scaleVoxels(scale=1)[source]

Scale the voxel content by factor scale.

spacing(s=None)[source]

Set/get the voxels size in the 3 dimensions.

threshold(vmin=None, vmax=None, replaceWith=0)[source]

Binary or continuous volume thresholding. Find the voxels that contain the value below/above or inbetween [vmin, vmax] and replaces it with the provided value (default is 0).

xSlice(i)[source]

Extract the slice at index i of volume along x-axis.

ySlice(j)[source]

Extract the slice at index j of volume along y-axis.

zSlice(k)[source]

Extract the slice at index i of volume along z-axis.