def plot_err_field_vedo(X, Y, Z, scalar_field, fig_name): isomin = 1. * scalar_field.min() isomax = 1. * scalar_field.max() # isomin = 10 # isomax = 11 vol = Volume(scalar_field) # vol.addScalarBar3D() vol.addScalarBar3D(sy=1.5, title='height is the scalar') # generate an isosurface the volume for each thresholds ts = np.linspace(isomin, isomax, 6) # ts = [10.1, 10.25, 10.4] # Use c=None to use the default vtk color map. isos is of type Mesh isos = Volume(scalar_field).isosurface(threshold=ts).opacity(0.4) text1 = Text2D(f'Make a Volume from numpy.mgrid', c='blue') text2 = Text2D(f'its isosurface representation\nvmin={isomin:.2e}, vmax={isomax:.2e}', c='dr') print('numpy array from Volume:', vol.getPointArray().shape, vol.getDataArray().shape) # show([(vol, text1), (isos, text2)], N=2, azimuth=10, zoom=1.3) destination_path = os.path.join(plot_dir, fig_name) write(vol, destination_path) print(f'zapisano w: {destination_path}')
"""Create a Volume from a numpy array""" import numpy as np data_matrix = np.zeros([75, 75, 75], dtype=np.uint8) # all voxels have value zero except: data_matrix[0:35, 0:35, 0:35] = 1 data_matrix[35:55, 35:55, 35:55] = 2 data_matrix[55:74, 55:74, 55:74] = 3 from vedo import Volume, show vol = Volume(data_matrix, c=['white', 'b', 'g', 'r']) vol.addScalarBar3D() show(vol, __doc__, axes=1)
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()
"""A Volume can have multiple scalars associated to each voxel""" from vedo import dataurl, Volume, printc, show import numpy as np vol = Volume(dataurl + 'vase.vti') nx, ny, nz = vol.dimensions() r0, r1 = vol.scalarRange() vol.addScalarBar3D(title='original voxel scalars') # create a set of scalars and add it to the Volume vol.pointdata["myscalars1"] = np.linspace(r0, r1, num=nx * ny * nz) # create another set of scalars and add it to the Volume vol.pointdata["myscalars2"] = np.random.randint(-100, +100, nx * ny * nz) # make SLCImage scalars the active array (can set 0, to pick the first): printc('Arrays in Volume are:\n', vol.pointdata.keys(), invert=True) vol.pointdata.select( "SLCImage") # select the first data array as the active one # Build the isosurface of the active scalars, # but use testscals1 to colorize this isosurface, and then smooth it iso1 = vol.isosurface().cmap('jet', 'myscalars1').smooth().lw(0.1) iso1.addScalarBar3D(title='myscalars1') iso2 = vol.isosurface().cmap('viridis', 'myscalars2') iso2.addScalarBar3D(title='myscalars2') show([ (vol, __doc__),
"""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()