title: Connect streaming points using VTK
body: <p>I have a function that is called in a loop, and at each pass it gives (x,y,z) of a 3D point. I am trying to connect these points in real-time using VTK, but I am unable to get the rendering window to refresh after every frame. I see a bunch of lines if I exit the loop though.</p>
  
  <p>Basically, this is what I am doing:</p>
  
  <pre><code>// Create a vtkPoints object to store the points in it
  vtkSmartPointer&lt;vtkPoints&gt; points = vtkSmartPointer&lt;vtkPoints&gt;::New();
  
  vtkSmartPointer&lt;vtkPolyLine&gt; polyLine = vtkSmartPointer&lt;vtkPolyLine&gt;::New();
  
  // Create a cell array to store the lines in   
  vtkSmartPointer&lt;vtkCellArray&gt; lines = vtkSmartPointer&lt;vtkCellArray&gt;::New();
  
  // Create a polydata to store everything in
  vtkSmartPointer&lt;vtkPolyData&gt; linesPolyData = vtkSmartPointer&lt;vtkPolyData&gt;::New();
  
  // Setup actor and mapper
  vtkSmartPointer&lt;vtkPolyDataMapper&gt; mapper = vtkSmartPointer&lt;vtkPolyDataMapper&gt;::New();
  
  vtkSmartPointer&lt;vtkActor&gt; actor = vtkSmartPointer&lt;vtkActor&gt;::New();
  actor-&gt;SetMapper(mapper);
  
  // Setup render window, renderer, and interactor
  vtkSmartPointer&lt;vtkRenderer&gt; renderer =  vtkSmartPointer&lt;vtkRenderer&gt;::New();
  vtkSmartPointer&lt;vtkRenderWindow&gt; renderWindow =       vtkSmartPointer&lt;vtkRenderWindow&gt;::New();
  renderWindow-&gt;AddRenderer(renderer);
  vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; renderWindowInteractor =   vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();
  renderWindowInteractor-&gt;SetRenderWindow(renderWindow);
  
  renderer-&gt;AddActor(actor);
  renderWindow-&gt;Render();
  renderer-&gt;Render();
  
  int numpoints = 0;
  
  while(some_condition)
  {
    call_function(&amp;x,&amp;y,&amp;z);
    double point[3] = {0.0, 0.0, 0.0};
    point[0] = (float)x;
    point[1] = (float)y;
    point[2] = (float)z;
  
    numpoints++;
    points-&gt;InsertNextPoint(point);
  
    polyLine-&gt;GetPointIds()-&gt;SetNumberOfIds(numpoints);
    for(unsigned int i = 0; i &lt; num_points; i++)
  {
      polyLine-&gt;GetPointIds()-&gt;SetId(i,i);                        
  }
  
    lines-&gt;InsertNextCell(polyLine);
  
  // Add the points to the dataset
  linesPolyData-&gt;SetPoints(points);
  
  // Add the lines to the dataset
  linesPolyData-&gt;SetLines(lines);
  
  #if VTK_MAJOR_VERSION &lt;= 5
  mapper-&gt;SetInput(linesPolyData);
  #else
  mapper-&gt;SetInputData(linesPolyData);
  #endif
  
  linesPolyData-&gt;Modified();
  linesPolyData-&gt;Update();
  
  renderWindow-&gt;Render();
  renderer-&gt;Render();
  
  renderWindowInteractor-&gt;Enable();
  
  check_loop_exit_condition(); 
  }
  </code></pre>
  
  <p>If I do <code>renderer-&gt;Render()</code> outside the loop, I am getting all the lines (or at least I think I do). Can someone figure out where I am going wrong?</p>