Created
September 2, 2013 17:16
-
-
Save oesteban/6415156 to your computer and use it in GitHub Desktop.
A short file to load an vtk and show a surface in iPython notebooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mayavi import mlab | |
from tvtk.api import tvtk | |
import numpy as np | |
surfname = os.path.join( model_path, 'fixed.csf.vtk' ) | |
reader =tvtk.PolyDataReader( file_name=surfname ) | |
mesh = reader.get_output() | |
reader.update() | |
### DATA | |
#data = array([[0,0,0,10], | |
# [1,0,0,20], | |
# [0,1,0,20], | |
# [0,0,1,30]], 'f') | |
#triangles = array([[0,1,3], | |
# [0,3,2], | |
# [1,2,3], | |
# [0,2,1]]) | |
#points = data[:,:3] | |
#temperature = data[:,-1] | |
#mesh = tvtk.PolyData(points=points, polys=triangles) | |
#mesh.point_data.scalars = temperature | |
nodes = np.array( mesh.points ) | |
x = nodes[:,0] | |
y = nodes[:,1] | |
z = nodes[:,2] | |
triangles = np.array( mesh.polys.to_array() ) | |
triangles = triangles.reshape( (-1,4) )[:,1:4] | |
print np.shape( triangles ) | |
s = mlab.triangular_mesh( x, y, z, triangles ) | |
mlab.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment