def monomodalSliceRender(input_data=None,draw=True, show=True, max_shape=256, description="Volume Electron Micrographs"):
"""
Show a volumetric rendering of a nanoscale EM micrographs in 3D
Initial rending made and by https://github.com/maartenbreddels
# First inspired by http://graphicsrunner.blogspot.com/2009/01/volume-rendering-102-transfer-functions.html
Monomodal options made by Matthew Madany
"""
import ipyvolume as ipv
from scipy.interpolate import interp1d
# First part is a simpler version of setting up the transfer function. Interpolation with higher order
# splines does not work well, the original must do sth different
colors = [[*[.1]*3,0.0],[*[.2]*3,155], [*[.3]*3,256]]
print(colors)
x = np.array([k[-1] for k in colors])
rgb = np.array([k[:3] for k in colors])
N = 256
xnew = np.linspace(0, 256, N)
tf_data = np.zeros((N, 4))
kind = 'linear'
for channel in range(3):
f = interp1d(x, rgb[:, channel], kind=kind)
ynew = f(xnew)
tf_data[:, channel] = ynew
alphas = [[.1,0], [.1,155], [.1,256]]
x = np.array([k[1] * 1.0 for k in alphas])
y = np.array([k[0] * 1.0 for k in alphas])
f = interp1d(x, y, kind=kind)
ynew = f(xnew)
tf_data[:, 3] = ynew
tf = ipv.TransferFunction(rgba=tf_data.astype(np.float32))
if draw:
vol = ipv.volshow(input_data, tf=tf, max_shape=max_shape, description=description, max_opacity=0)
if show:
ipv.show()
return vol
else:
return input_data