[vtkusers] Updating points of a structured grid
Heath Johnson
heathbjohnson at gmail.com
Fri Jan 22 18:52:45 EST 2010
I am very new to this so please excuse me if I don't have all the
terminology right yet. I am using tvtk.StructuredGrid to visualize a grid,
and I want to be able to modify the dataset and have the figure update.
Here is a sample code:
-----------------------------
-----------------------
#!/usr/bin/python
# -*- coding: utf-8 -*-
from numpy import empty
from enthought.tvtk.api import tvtk
from enthought.mayavi import mlab
import numpy
import time
# Create the points array
def xyzToPts(x,y,z):
# Reform into 2D array
pts = empty(z.shape + (3,), dtype=float)
pts[...,0] = x
pts[...,1] = y
pts[...,2] = z
pts.shape = pts.size/3, 3
return(x.shape,pts)
# -- Set initial mesh
x, y = numpy.mgrid[0:3:1,0:3:1]
x.shape= x.shape + (1,)
y.shape= y.shape + (1,)
z= x*0.0
# Create the 2D points array
(xsh,pts)= xyzToPts(x,y,z)
# Create the structured grid dataset
sg = tvtk.StructuredGrid(dimensions=xsh, points=pts)
d = mlab.pipeline.add_dataset(sg)
gx = mlab.pipeline.grid_plane(d)
# Iterate on performing smoothing passes and displaying the updated mesh
for i in range(4):
time.sleep(1)
print "-- Iterating, i= ",i
x= x*0.75
y= y*0.75
z= z*0.75
(xsh,pts)= xyzToPts(x,y,z)
# How to have the plot onscreen update? This doesn't work!
#sg.point_data.set(scalars=pts)
#sg.modified()
# Creates a new dataset. Not what we want!
sg = tvtk.StructuredGrid(dimensions=xsh, points=pts)
d = mlab.pipeline.add_dataset(sg)
gx = mlab.pipeline.grid_plane(d)
# Launch the interactive viewer
mlab.show()
exit()
----------------------------------------------------
The above code displays a new dataset each time the x,y,z points are
changed. Instead I would like to modify the values of the current dataset
and have the figure update to reflect the new values. I just can't get this
to work. Can somebody please help?
Thanks,
Heath
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100122/091bf42e/attachment.htm>
More information about the vtkusers
mailing list