I need to plot data that is living in Python (or some file that I read from python) and not living in a VTK file. I would like to achieve the equivalent of this simple matplotlib script using VTK with vectorized input (preferably numpy arrays). I would like to be able to update this directly from the application in a responsive manner (i.e. the pattern changing in response to some parameter on the UI)
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# make some interesting data
theta = np.linspace(-np.pi/2, np.pi/2, 181)
phi = np.arange(np.pi, -np.pi, -np.pi/180)[::-1]
r = np.outer(np.sin(2*phi), np.sin(2*theta))
# xyz it
x = r * np.outer(np.cos(phi), np.sin(theta))
y = r * np.outer(np.sin(phi), np.sin(theta))
z = r * np.outer(np.ones(np.size(phi)), np.cos(theta))
# plot the surface
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, color='b')
plt.show()
I have found plenty of examples showing how to get data out of VTK structures into Python, but my requirement is the other way around. I have also found examples of how to build up VTK arrays element by element, but this is Python; I need it vectorized as I want it to be updated responsively. I also haven't been able to figure out how to get from a 2D StructuredGrid to a spherical plot.