title: update live pointcloud data in vtk python
body: <p>I have a basic question as i am new to VTK. I have to draw live point cloud data in VTK. I have modified the code given in <a href="https://stackoverflow.com/questions/7591204/how-to-display-point-cloud-in-vtk-in-different-colors">How to display point cloud in vtk in different colors?</a>. </p>
  
  <p>The pointcloud should update for number of times given in iterations(here 30). I have used Initialize() to avoid blocking control flow as mentioned in some solutions, in every iteration the point cloud is updated, and render() is called so that it can update the window with new data.</p>
  
  <p>I cannot figure out why this is blocking the control flow, and the data is not updated. Only once the iterations are over, after <strong>renderWindowInteractor.Start()</strong> is called, the interaction is enabled.</p>
  
  <pre><code>import vtk
  from numpy import random
  
  class VtkPointCloud:
  
      def __init__(self, zMin=-10.0, zMax=10.0, maxNumPoints=1e6):
          self.maxNumPoints = maxNumPoints
          self.vtkPolyData = vtk.vtkPolyData()
          self.clearPoints()
          mapper = vtk.vtkPolyDataMapper()
          mapper.SetInputData(self.vtkPolyData)
          mapper.SetColorModeToDefault()
          mapper.SetScalarRange(zMin, zMax)
          mapper.SetScalarVisibility(1)
          self.vtkActor = vtk.vtkActor()
          self.vtkActor.SetMapper(mapper)
  
      def addPoint(self, point):
          if self.vtkPoints.GetNumberOfPoints() &lt; self.maxNumPoints:
              pointId = self.vtkPoints.InsertNextPoint(point[:])
              self.vtkDepth.InsertNextValue(point[2])
              self.vtkCells.InsertNextCell(1)
              self.vtkCells.InsertCellPoint(pointId)
          else:
              r = random.randint(0, self.maxNumPoints)
              self.vtkPoints.SetPoint(r, point[:])
          self.vtkCells.Modified()
          self.vtkPoints.Modified()
          self.vtkDepth.Modified()
  
      def clearPoints(self):
          self.vtkPoints = vtk.vtkPoints()
          self.vtkCells = vtk.vtkCellArray()
          self.vtkDepth = vtk.vtkDoubleArray()
          self.vtkDepth.SetName('DepthArray')
          self.vtkPolyData.SetPoints(self.vtkPoints)
          self.vtkPolyData.SetVerts(self.vtkCells)
          self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth)
          self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray')
  
  def func(pointCloud):
      # Renderer
      renderer = vtk.vtkRenderer()
      renderer.AddActor(pointCloud.vtkActor)
      renderer.SetBackground(.2, .3, .4)
      renderer.ResetCamera()
  
      # Render Window
      renderWindow = vtk.vtkRenderWindow()
  
      renderWindow.AddRenderer(renderer)
  
      # Interactor
      renderWindowInteractor = vtk.vtkRenderWindowInteractor()
      renderWindowInteractor.SetRenderWindow(renderWindow)
  
      # Begin Interaction
      renderWindow.Render()
      renderWindowInteractor.Initialize()
      return renderWindow,renderWindowInteractor
  
  def main(iter):
      while iter &gt; 0:
          pointCloud = VtkPointCloud()
          for k in xrange(10000):
              point = 20*(random.rand(3)-0.5)
              pointCloud.addPoint(point)
          pointCloud.addPoint([0,0,0])
          pointCloud.addPoint([0,0,0])
          pointCloud.addPoint([0,0,0])
          pointCloud.addPoint([0,0,0])
          if iter == 30:
              renderWindow,renderWindowInteractor = func(pointCloud)
          else:
              #pointCloud.vtkPolyData.Modified()
              renderWindow.Render()
          iter -= 1
      renderWindowInteractor.Start()
  
  main(30)
  </code></pre>