"""Embed a 3D scene in a webpage with x3d""" from vedo import dataurl, Plotter, Volume, Text3D plt = Plotter(size=(800, 600), bg='GhostWhite') embryo = Volume(dataurl + 'embryo.tif').isosurface().decimate(0.5) coords = embryo.points() embryo.cmap('PRGn', coords[:, 1]) # add dummy colors along y txt = Text3D(__doc__, font='Bongas', s=350, c='red2', depth=0.05) txt.pos(2500, 300, 500) plt.show(embryo, txt, txt.box(pad=250), axes=1, viewup='z', zoom=1.2) # This exports the scene and generates 2 files: # embryo.x3d and an example embryo.html to inspect in the browser plt.export('embryo.x3d', binary=False) print("Type: \n firefox embryo.html")
import numpy as np from vedo import dataurl, Volume, Axes, show from vedo.pyplot import histogram, plot cmap = 'nipy_spectral' alpha = np.array([0, 0, 0.05, 0.2, 0.8, 1]) vol = Volume(dataurl + "embryo.slc") vol.cmap(cmap).alpha(alpha).addScalarBar3D(c='w') xvals = np.linspace(*vol.scalarRange(), len(alpha)) p = histogram(vol, logscale=True, c=cmap, bc='white') p += plot(xvals, alpha * p.ybounds()[1], '--ow').z(1) show( [(vol, Axes(vol, c='w'), f"Original Volume\ncolor map: {cmap}"), (p, "Voxel scalar histogram\nand opacity transfer function")], N=2, sharecam=False, bg=(82, 87, 110), )