Python VTK polydata not updating -


i'm trying use vtk plot points, interactively update locations given set of point locations.

i can interactively use polydata object plot points, not update when call self.polydata.update(). points update when call self.polydata.getcelldata().setscalars(somechararray)

is bug in vtk, or not updating point coordinates correctly?

i have included example script. if comment out self.polydata.getcelldata().setscalars(somechararray) in slidercallback, plot not update point's coordinates when use slider. update if leave line in.

thanks!

import numpy np import vtk vtk.qt4.qvtkrenderwindowinteractor import qvtkrenderwindowinteractor pyqt4 import qtgui import sys  class viewerwithscrollbar(qtgui.qmainwindow):     def __init__(self, parent=none):         super(viewerwithscrollbar, self).__init__(parent)         # define renderer , qt window ------------------------         self.frame = qtgui.qframe()          self.hl = qtgui.qhboxlayout()         self.vtkwidget = qvtkrenderwindowinteractor(self.frame)         self.hl.addwidget(self.vtkwidget)          self.ren = vtk.vtkrenderer()         self.vtkwidget.getrenderwindow().addrenderer(self.ren)         self.iren = self.vtkwidget.getrenderwindow().getinteractor()         self.iren.setinteractorstyle(vtk.vtkinteractorstyletrackballcamera())         self.ren.resetcamera()          self.frame.setlayout(self.hl)         self.setcentralwidget(self.frame)          # point coordinate data ---------------------------------         self.coorddata = {}         self.coorddata[0] = np.array([[0,0,0], [1,0,0], [1,1,0]])         self.coorddata[1] = self.coorddata[0] + np.array([[0.2, 0.1, -0.05], [0,0,0], [0,0,0]])         self.coorddata[2] = self.coorddata[1] + np.array([[0.2, 0.1, -0.05], [0,0,0], [0,0,0]])          # define slider bar , add window ---------------         slider = qtgui.qslider()         slider.setaccessiblename('time index')         slider.setrange(0, len(self.coorddata)-1)         slider.valuechanged.connect(self.slidercallback)          self.hl.addwidget(slider)          # create polydata object -----------------------------         points = vtk.vtkpoints()         points.setnumberofpoints(len(self.coorddata[0]))         self.polydata = vtk.vtkpolydata()          in range(len(self.coorddata[0])):             points.setpoint(i, self.coorddata[0][i])         self.polydata.setpoints(points)          ptsfilter = vtk.vtkvertexglyphfilter()         ptsfilter.setinputconnection(self.polydata.getproducerport())         ptsmapper = vtk.vtkpolydatamapper()         ptsmapper.setinputconnection(ptsfilter.getoutputport())         ptsactor = vtk.vtkactor()         ptsactor.setmapper(ptsmapper)         ptsactor.getproperty().setpointsize(10)          self.ren.addactor(ptsactor)          self.show()         self.iren.initialize()      def slidercallback(self):         index = self.sender().value() # index slider bar on         somechararray = vtk.vtkunsignedchararray()         points = self.polydata.getpoints()         in range(len(self.coorddata[index])):             points.setpoint(i, self.coorddata[index][i])         self.polydata.getcelldata().setscalars(somechararray) # reason polydata won't update unless called.         # self.polydata.update()         self.iren.render()         return  if __name__ == "__main__":      app = qtgui.qapplication(sys.argv)      window = viewerwithscrollbar()      sys.exit(app.exec_()) 

with lib's advice, modified code. calling self.polydata.modified() in slidercallback method fixed problem

import numpy np import vtk vtk.qt4.qvtkrenderwindowinteractor import qvtkrenderwindowinteractor pyqt4 import qtgui import sys  class viewerwithscrollbar(qtgui.qmainwindow):     def __init__(self, parent=none):         super(viewerwithscrollbar, self).__init__(parent)         # define renderer , qt window ------------------------         self.frame = qtgui.qframe()          self.hl = qtgui.qhboxlayout()         self.vtkwidget = qvtkrenderwindowinteractor(self.frame)         self.hl.addwidget(self.vtkwidget)          self.ren = vtk.vtkrenderer()         self.vtkwidget.getrenderwindow().addrenderer(self.ren)         self.iren = self.vtkwidget.getrenderwindow().getinteractor()         self.iren.setinteractorstyle(vtk.vtkinteractorstyletrackballcamera())         self.ren.resetcamera()          self.frame.setlayout(self.hl)         self.setcentralwidget(self.frame)          # point coordinate data ---------------------------------         self.coorddata = {}         self.coorddata[0] = np.array([[0,0,0], [1,0,0], [1,1,0]])         self.coorddata[1] = self.coorddata[0] + np.array([[0.2, 0.1, -0.05], [0,0,0], [0,0,0]])         self.coorddata[2] = self.coorddata[1] + np.array([[0.2, 0.1, -0.05], [0,0,0], [0,0,0]])          # define slider bar , add window ---------------         slider = qtgui.qslider()         slider.setaccessiblename('time index')         slider.setrange(0, len(self.coorddata)-1)         slider.valuechanged.connect(self.slidercallback)          self.hl.addwidget(slider)          # create polydata object -----------------------------         points = vtk.vtkpoints()         points.setnumberofpoints(len(self.coorddata[0]))         self.polydata = vtk.vtkpolydata()          in range(len(self.coorddata[0])):             points.setpoint(i, self.coorddata[0][i])         self.polydata.setpoints(points)          ptsfilter = vtk.vtkvertexglyphfilter()         ptsfilter.setinputdata(self.polydata)         ptsmapper = vtk.vtkpolydatamapper()         ptsmapper.setinputconnection(ptsfilter.getoutputport())         ptsactor = vtk.vtkactor()         ptsactor.setmapper(ptsmapper)         ptsactor.getproperty().setpointsize(10)          self.ren.addactor(ptsactor)          self.show()         self.iren.initialize()      def slidercallback(self):         index = self.sender().value() # index slider bar on         points = self.polydata.getpoints()         in range(len(self.coorddata[index])):             points.setpoint(i, self.coorddata[index][i])         self.polydata.modified()         self.iren.render()         return  if __name__ == "__main__":      app = qtgui.qapplication(sys.argv)      window = viewerwithscrollbar()      sys.exit(app.exec_()) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -