[vtkusers] animate actors by iterating through a list of points with vtk timer callback function - causing huge slow down during rendering

Thangam Natarajan thangam at mie.utoronto.ca
Mon Jan 1 15:25:42 EST 2018


Hi all,

I have a file (pandas + hdf --> final.h5) that contains positions of "seed points" over time. It is of the format (tuple with x,y,z positions):

              t = 0\                 t =  1\                    t = 2\
0   (33.8 18.0 36.6)        0   (35.7 17.9 37.1)        0   (33.3 17.9 39.4)
1   (32.3 18.0 38.5)        1   (33.8 18.0 36.6)        1   (35.7 17.9 37.1)
2   (34.8 17.9 40.1)        2   (32.3 18.0 38.5)        2   (33.8 18.0 36.6)
3   (32.2 18.0 38.8)        3   (34.8 17.9 40.1)        3   (32.3 18.0 38.5)
4   (35.3 18.0 39.9)        4   (32.2 18.0 38.8)        4   (34.8 17.9 40.1)
5   (34.4 17.9 37.0)        5   (35.3 18.0 39.9)        5   (32.2 18.0 38.8)
I am trying to animate the path these 6 "seed points" inside a 3d pipe model by iterating them over time(t). I used the sphere animation example and wrote the following code:

import vtk
import os #needed for directory listing & sorting
import numpy as np
import pandas as pd

seeds = 6
timeS = 3

class vtkTimerCallback():
    def __init__(self):
        self.i = 0

    def execute(self, obj, event):
        for i in range(len(timeS)-1):
            for sd in range(len(seeds)):                  
              self.sphereActor[sd].SetPosition(finalMatrixh5[i][sd])            
              iren = obj
              iren.GetRenderWindow().Render()


finalMatrixh5 = pd.read_hdf('final.h5', 'endFrame', mode='r')   

def main():
    # Create a sphere
    sphere = vtk.vtkSphereSource()
    sphere.SetRadius(0.25)
    sphere.SetThetaResolution(4)
    sphere.SetPhiResolution(4) 

    sphereMapper = vtk.vtkPolyDataMapper()
    sphereMapper.SetInputConnection(sphere.GetOutputPort())

    actorlist = list()
    ren1 = vtk.vtkRenderer()

    sphereActor = [vtk.vtkActor() for i in range(len(seeds))]
    for obj in sphereActor:
        actorlist.append(obj)

    for sd in range(len(seeds)):
        sphereActor[sd].SetMapper(sphereMapper)
        ren1.AddActor(sphereActor[sd])     

    ren1.SetBackground(0.1, 0.2, 0.4)
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)
    renWin.SetSize(1600, 1600)
    iren = vtk.vtkRenderWindowInteractor() 
    iren.SetRenderWindow(renWin)
    style = vtk.vtkInteractorStyleTrackballCamera() 
    iren.SetInteractorStyle(style)

    renWin.Render() #
# Sign up to receive TimerEvent
    iren.Initialize() #initialize the rendering process   
    cb = vtkTimerCallback()
    cb.sphereActor = sphereActor
    iren.AddObserver('TimerEvent', cb.execute)
    iren.CreateRepeatingTimer(200)   


    iren.Start()



if __name__ == '__main__':
    main()
This does the job in creating spheres for the number of "seed points" and moves the spheres in the correct manner. However, the movement of these spheres are so slow and the window freezes such that no interaction is possible or super slow (zoom in, rotation etc.). Instead of 6 seed points even if I try to iterate a single seed through the points, it is so memory hogging and terribly slow. I am not sure where I am going wrong as this should be a straight forward animation with vtk where a few spheres move through their respective positions over time. Something wrong with the way I am adding actors or iterating? Any pointers? I am happy to try any other method to do this as well (perhaps, with Qt?)

Thanks a lot.

regards
Thangam.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180101/c2f50436/attachment.html>


More information about the vtkusers mailing list