예제 #1
0
"""Modify a Volume dataset and
colorize voxels individually
"""
from vedo import Volume, show
import numpy as np

vol = Volume(dims=(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, __doc__, axes=1)
예제 #2
0
"""Load and render a 3D Volume

mode=0, composite rendering
mode=1, maximum-projection rendering"""
from vedo import dataurl, Volume, show

vol1 = Volume(dataurl + "vase.vti")

# 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.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]).addScalarBar3D(title='composite shade',
                                                   c='k')
vol1.scalarbar.scale(0.8).x(20)

# mode = 1 is maximum-projection volume rendering
vol2 = Volume(dataurl + "vase.vti").mode(1).shift(60, 0, 0)
vol2.addScalarBar3D(title='maximum-projection', c='k')
vol2.scalarbar.scale(0.8).x(160)

# show command creates and returns an instance of class Plotter
show(vol1, vol2, __doc__, size=(800, 600), zoom=1.5).close()
예제 #3
0
"""Custom color and transparency maps for Volumes"""
from vedo import Volume, dataurl, show
from vedo.pyplot import CornerHistogram

# Build a Volume object.
# A set of color/transparency values - of any length - can be passed
# to define the transfer function in the range of the scalar.
#  E.g.: setting alpha=[0, 0, 0, 1, 0, 0, 0] would make visible
#  only voxels with value close to center of the range (see histogram).
vol = Volume(dataurl + 'embryo.slc')
vol.color([
    (0, "green"),
    (49, "green"),
    (50, "blue"),
    (109, "blue"),
    (110, "red"),
    (180, "red"),
])
# vol.mode('max-projection')
vol.alpha([0., 1.])
vol.alphaUnit(8)  # absorption unit, higher factors = higher transparency
vol.addScalarBar3D(title='color~\dot~alpha transfer function', c='k')

ch = CornerHistogram(vol, logscale=True, pos='bottom-left')

# show both Volume and Mesh
show(vol, ch, __doc__, axes=1, zoom=1.2).close()