[vtkusers] Rendering a scene in which actors move
Gib Bogle
g.bogle at auckland.ac.nz
Thu Mar 11 00:05:29 EST 2010
I wish to repeatedly render a scene with many actors (cones for now) that may
change their positions as time progresses (i.e. I am creating a movie). I can
render the scene OK, but I see that the way I'm doing it is just adding actors
each time step, whereas I want to redraw all the actors each time (or possibly,
if I get clever, only those that have moved). This what I'm doing in Python:
def QVTKRenderWidgetCones(self,page_VTK):
"""A simple example that uses the QVTKRenderWindowInteractor class."""
if self.first_VTK:
self.first_VTK = False
layout = QtGui.QVBoxLayout(page_VTK)
# create the widget
self.VTKscene = QVTKRenderWindowInteractor(page_VTK)
self.VTKscene.Initialize()
self.VTKscene.Start()
renWin = self.VTKscene.GetRenderWindow()
layout.addWidget(self.VTKscene)
self.ren = vtk.vtkRenderer()
renWin.AddRenderer(self.ren)
cone = vtk.vtkConeSource()
cone.SetResolution(8)
self.coneMapper = vtk.vtkPolyDataMapper()
self.coneMapper.SetInput(cone.GetOutput())
# self.ren.Clear()
# for actor in self.ren.GetActors():
# self.ren.RemoveActor(actor)
print self.ren.GetActors()
n = self.ncells
coneActor = [0]*n
for i in range(0,n):
coneActor[i] = vtk.vtkActor()
coneActor[i].SetMapper(self.coneMapper)
self.ren.AddActor(coneActor[i])
cp = self.cellpos[i]
x = int(cp[2])
y = int(cp[3])
z = int(cp[4])
coneActor[i].SetPosition(x, y, z)
# show the widget
self.VTKscene.show()
self.VTKscene.Render()
I tried to use ren.Clear(), but that obviously clears everything, and I
discovered that a collection is not a list and therefore my attempt to use
ren.RemoveActor() failed. What is the right (i.e. fast) way to do this?
Thanks
Gib
More information about the vtkusers
mailing list