"""Modify a Volume dataset and colorize voxels individually """ from vtkplotter import Text2D, Volume, show import numpy as np vol = Volume(shape=(10,11,12), mode=0) vol.alpha(0.8).jittering(False) vol.interpolation(0) # nearest neighbour interpolation type # Overwrite the (sofar empty) voxel data with new data vol.imagedata().AllocateScalars(3, 4) # type 3 corresponds to np.uint8 arr = vol.getPointArray() arr[:] = np.random.randint(0,255, (10*11*12,4)).astype(np.uint8) # For 4 component data, the first 3 directly represent RGB, no lookup table. # (see https://vtk.org/doc/nightly/html/classvtkVolumeProperty.html): vol.GetProperty().IndependentComponentsOff() show(vol, Text2D(__doc__), axes=1)
reader.SetFileName(datadir + "vase.vti") reader.Update() img = reader.GetOutput() # vtkImageData object # NB: the above lines could be reduced to: #img = load(datadir+"vase.vti").imagedata() ################################# from vtkplotter import Volume, show, Text # can set colors and transparencies along the scalar range # from minimum to maximum value. In this example voxels with # the smallest value will be completely transparent (and white) # while voxels with highest value of the scalar will get alpha=0.8 # and color will be=(0,0,1) vol1 = Volume(img, mode=0) # composite rendering vol1.color(["white", "fuchsia", "dg", (0, 0, 1)]) #vol1.color('jet') # a matplotlib colormap name is also accepted vol1.alpha([0.0, 0.2, 0.3, 0.8]) # a transparency for the GRADIENT of the scalar can also be set: # in this case when the scalar is ~constant the gradient is ~zero # and the voxel are made transparent: vol1.alphaGradient([0.0, 0.5, 0.9]) # mode = 1 is maximum-projection volume rendering vol2 = load(datadir + "vase.vti").mode(1).addPos(60, 0, 0) # show command creates and returns an instance of class Plotter show(vol1, vol2, Text(__doc__), bg="w", axes=1)