volume

Submodule extending the vtkVolume object functionality.

Volume

class vedo.volume.Volume(inputobj=None, c='RdBu_r', alpha=(0.0, 0.0, 0.2, 0.4, 0.8, 1.0), alphaGradient=None, alphaUnit=1, mode=0, shade=False, spacing=None, dims=None, origin=None, mapper='smart')[source]

Bases: vtkRenderingCorePython.vtkVolume, vedo.base.BaseGrid, vedo.volume.BaseVolume

Derived class of vtkVolume. Can be initialized with a numpy object, a vtkImageData or a list of 2D bmp files.

See e.g.: numpy2volume1.py

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

  • alphas (float,list) – sets transparencies along the scalar range

  • alphaUnit (float) – low values make composite rendering look brighter and denser

  • origin (list) – set volume origin coordinates

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

  • dims (list) – specify the dimensions of the volume.

  • mapper (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

    • 4, additive mode

    The default mode is “composite” where the scalar values are sampled through the volume and composited in a front-to-back scheme through alpha blending. The final color and opacity is determined using the color and opacity transfer functions specified in alpha keyword.

    Maximum and minimum intensity blend modes use the maximum and minimum scalar values, respectively, along the sampling ray. The final color and opacity is determined by passing the resultant value through the color and opacity transfer functions.

    Additive blend mode accumulates scalar values by passing each value through the opacity transfer function and then adding up the product of the value and its opacity. In other words, the scalar values are scaled using the opacity transfer function and summed to derive the final color. Note that the resulting image is always grayscale i.e. aggregated values are not passed through the color transfer function. This is because the final value is a derived value and not a real data value along the sampling ray.

    Average intensity blend mode works similar to the additive blend mode where the scalar values are multiplied by opacity calculated from the opacity transfer function and then added. The additional step here is to divide the sum by the number of samples taken through the volume. As is the case with the additive intensity projection, the final image will always be grayscale i.e. the aggregated values are not passed through the color transfer function.

Hint

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

read_volume2.py read_volume2.py

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.

The format for alphaGrad is the same as for method volume.alpha().

read_volume2.py read_volume2.py

cmap(c)[source]

Same as color() or c().

componentWeight(i, weight)[source]

Set the scalar component weight in range [0,1].

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.

mode(mode=None)[source]

Define the volumetric rendering style.

  • 0, composite rendering

  • 1, maximum projection rendering

  • 2, minimum projection rendering

  • 3, average projection rendering

  • 4, additive mode

The default mode is “composite” where the scalar values are sampled through the volume and composited in a front-to-back scheme through alpha blending. The final color and opacity is determined using the color and opacity transfer functions specified in alpha keyword.

Maximum and minimum intensity blend modes use the maximum and minimum scalar values, respectively, along the sampling ray. The final color and opacity is determined by passing the resultant value through the color and opacity transfer functions.

Additive blend mode accumulates scalar values by passing each value through the opacity transfer function and then adding up the product of the value and its opacity. In other words, the scalar values are scaled using the opacity transfer function and summed to derive the final color. Note that the resulting image is always grayscale i.e. aggregated values are not passed through the color transfer function. This is because the final value is a derived value and not a real data value along the sampling ray.

Average intensity blend mode works similar to the additive blend mode where the scalar values are multiplied by opacity calculated from the opacity transfer function and then added. The additional step here is to divide the sum by the number of samples taken through the volume. As is the case with the additive intensity projection, the final image will always be grayscale i.e. the aggregated values are not passed through the color transfer function.

shade(status=None)[source]

Set/Get the shading of a Volume. Shading can be further controlled with volume.lighting() method.

If shading is turned on, the mapper may perform shading calculations. In some cases shading does not apply (for example, in maximum intensity projection mode).

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

Extract the slice along a given plane position and normal.

slicePlane.py slicePlane.py

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.

VolumeSlice

class vedo.volume.VolumeSlice(inputobj=None)[source]

Bases: vtkRenderingCorePython.vtkImageSlice, vedo.base.Base3DProp, vedo.volume.BaseVolume

Derived class of vtkImageSlice. This class is equivalent to Volume except for its representation. The main purpose of this class is to be used in conjunction with Volume for visualization using interactorStyle="Image".

alpha(value)[source]

Set opacity to the slice

autoAdjustQuality(value=True)[source]

Automatically reduce the rendering quality for greater speed when interacting

bounds()[source]

Return the bounding box as [x0,x1, y0,y1, z0,z1]

colorize(lut=None, fixScalarRange=False)[source]

Assign a LUT (Look Up Table) to colorize the slice, leave it None to reuse an exisiting Volume color map. Use “bw” for automatic black and white.

faceCamera(value=True)[source]

Make the slice always face the camera or not.

fillBackground(value=True)[source]

Instead of rendering only to the image border, render out to the viewport boundary with the background color. The background color will be the lowest color on the lookup table that is being used for the image.

jumpToNearestSlice(value=True)[source]

This causes the slicing to occur at the closest slice to the focal point, instead of the default behavior where a new slice is interpolated between the original slices. Nothing happens if the plane is oblique to the original slices.

lighting(window, level, ambient=1.0, diffuse=0.0)[source]

Assign the values for window and color level.

slab(thickness=0, mode=0, sampleFactor=2)[source]

Make a thick slice (slab).

Parameters
  • thickness (float, optional) – set the slab thickness, for thick slicing

  • mode (int, optional) –

    The slab type:

    0 = min 1 = max 2 = mean 3 = sum

  • sampleFactor (float, optional) – Set the number of slab samples to use as a factor of the number of input slices within the slab thickness. The default value is 2, but 1 will increase speed with very little loss of quality.

interpolateToVolume

vedo.volume.interpolateToVolume(mesh, kernel='shepard', radius=None, N=None, bounds=None, nullValue=None, dims=(25, 25, 25))[source]

Generate a Volume by interpolating a scalar or vector field which is only known on a scattered set of points or mesh. Available interpolation kernels are: shepard, gaussian, or linear.

Parameters
  • kernel (str) – interpolation kernel type [shepard]

  • radius (float) – radius of the local search

  • bounds (list) – bounding box of the output Volume object

  • dims (list) – dimensions of the output Volume object

  • nullValue (float) – value to be assigned to invalid points

interpolateVolume.py interpolateVolume.py

mesh2Volume

vedo.volume.mesh2Volume(mesh, spacing=(1, 1, 1))[source]

Convert a mesh it into a Volume where the foreground (exterior) voxels value is 1 and the background (interior) voxels value is 0. Internally the vtkPolyDataToImageStencil class is used.

mesh2volume.py mesh2volume.py

signedDistanceFromPointCloud

vedo.volume.signedDistanceFromPointCloud(mesh, maxradius=None, bounds=None, dims=(20, 20, 20))[source]

Compute signed distances over a volume from an input point cloud. The output is a Volume object whose voxels contains the signed distance from the cloud.

Parameters
  • maxradius (float) – how far out to propagate distance calculation

  • bounds (list) – volume bounds.

  • dims (list) – dimensions (nr. of voxels) of the output volume.

volumeFromMesh

vedo.volume.volumeFromMesh(mesh, bounds=None, dims=(20, 20, 20), signed=True, negate=False)[source]

Compute signed distances over a volume from an input mesh. The output is a Volume object whose voxels contains the signed distance from the mesh.

Parameters
  • bounds (list) – bounds of the output volume.

  • dims (list) – dimensions (nr. of voxels) of the output volume.

See example script: volumeFromMesh.py