I have a simple OpenGL code, using glumpy
in python, to plot an interpolated 2D array:
I would like to plot a 3D interpolated array, in the following way: slice it into 10 (say) planes perpendicular to the viewer and adding transparency so as to give the impression of depth.
To start with, I would like to plot my 2D array above, but as a slice into a 3D cube, like I drew below.
How would I even start doing this?
MWE:
import numpy as np
from PIL import Image
from glumpy import app, gl, gloo, data, library
from glumpy.geometry import primitives
from glumpy.transforms import Trackball
vertex = """
#include "misc/spatial-filters.frag"
uniform sampler2D data;
uniform vec2 data_shape;
attribute vec3 position;
attribute vec2 texcoord;
varying float zz;
void main()
{
float z = Bicubic(data, data_shape, texcoord).x;
zz = z;
gl_Position = <transform>;
}
"""
fragment = """
#include "misc/spatial-filters.frag"
#include "colormaps/colormaps.glsl"
varying float zz;
void main()
{
vec4 col = vec4(colormap_icefire(zz),1);
gl_FragColor = col;
} """
def func3(x,y,t):
return np.exp(-10*(x-0.5*np.cos(t))**2-10*(y-0.5*np.sin(t))**2)
x = np.linspace(-2.0, 2.0, 64).astype(np.float32)
y = np.linspace(-2.0, 2.0, 64).astype(np.float32)
X,Y = np.meshgrid(x, y)
Z = func3(X,Y,0)
window = app.Window(width=1200, height=800, color = (1,1,1,1))
@window.event
def on_draw(dt):
window.clear()
surface['data'] = Z
surface.draw(gl.GL_TRIANGLES, s_indices)
n = 100
surface = gloo.Program(vertex, fragment)
vertices, s_indices = primitives.plane(2.0, n=n)
surface.bind(vertices)
surface['data_shape'] = Z.shape[1], Z.shape[0]
surface['u_kernel'] = data.get("spatial-filters.npy")
surface['u_kernel'].interpolation = gl.GL_LINEAR
transform = Trackball("vec4(position.xy, 0, 1.0)")
surface['transform'] = transform
window.attach(transform)
app.run()