Re: [MayaVi-users] Newbie
Status: Beta
Brought to you by:
prabhu_r
|
From: Prabhu R. <pr...@ae...> - 2003-02-14 08:36:17
|
Hi, I'm ccing MayaVi-users since the reply might be of some interest there. >>>>> "HJ" == H Jansen <h.jansen at fel.tno.nl> writes: HJ> Thanks for the response. The confusion is mine: I was simply HJ> meaning "three objects" instead of "tree object" --- sorry. No problem. HJ> I'm definitely using Mayavi (not the low level VTK API)! HJ> Meanwhile I've figured out how (and been able) to plot 3D line HJ> data in Mayavi using the VTK format with POLYDATA, LINES, HJ> CELL_DATA objets (JOY). (actually, with Python I'm reading HJ> from a HDF5 file and create a VTK) file.) The only remaining BTW there is a hdf to VTK file converter available here: http://ab-initio.mit.edu/h5utils/ HJ> question now is how I can do animation: the trajectories are HJ> parameterized by time, so it would be nice to see them being HJ> build up gradually when time proceeds. There are two approaches that I've used to do this sort of thing: 1. If you are working at the level of Python scripts and are comfortable with generating VTK files you could investigate how to create VTK data objects directly. In your case vtkPolyData objects. If you know how to do this you can simply modify the points of the polygon directly and then visualize the data. This would take some effort on your part in that you'd need to learn how to create and modify VTK data objects. Its not hard but will take a little while getting right. If you are going to be doing this often perhaps its worth investing time on this. 2. If you are comfortable with just generating VTK data files (and these files are typically reasonably small) and dont want to go through the effort of manipulating data or if you have an external program generating the data to be visualized then you can simply edit the VTK data file each time you want to change the data and make MayaVi re-read the data file to re-render the scene. I have some code that stats the file, checks to see if it has changed and if so re-renders the scene. I've included some sample code below. ########## Code ########## import os from Tkinter import * import mayavi r = Tk() r.withdraw() v = mayavi.Main.MayaViTkGUI(r) # open the data. data = v.open_vtk('data.vtk', 0) # create a visualization f = v.load_filter('PolyDataNormals', 0) f.fil.SetFeatureAngle(45.0) polydata = v.load_module('PolyData', 0) # now stat the data file and poll it to see if it changes. last_stat = os.stat('data.vtk') def anim(): global last_stat s = os.stat('data.vtk') if s[-2] == last_stat[-2]: return last_stat = s data.reader.Modified() data.reader.Update() data.update_references() v.Render() v.start_animation(1500, anim) r.mainloop() ########## Code ########## Basically, this should open a MayaVi window and poll your data file. When the data changes it will re-read the data and re-render the scene. The only trouble with this approach is that it is possible that MayaVi will try to read the file when its only half written. There is a way to get around that but I think you get the basic idea. Hope this helps. cheers, prabhu |