[vtkusers] display streaming data in vtk

Avanindra Singh avanindra.singh at gmail.com
Mon Jun 13 13:14:06 EDT 2011


Hi everyone,

I want to display efficiently a streaming data. Every fraction of second, I
get approximately 100 new points with colors, and I want to display the
continuous stream of data.
Here is what I have done,

I have created a vtkPolyData object. Every time I get new set of points I
put them in a cell and dump the cell in the polydata object.

the polydata object is connected to vtkPolyDataMapper . I call
mapper->modified() and mapper->update() method every time I had new data.

This works fine when I don't interact the display window. When I try to
interact the display window with mouse , it gives segmentation fault with
nvidia opengl driver.

Can anyone please guide me to do this task correctly. i am relatively new to
rendering portion of vtk. If there is any reference code for it , do point
it out.



Code------------

code for adding new data:

void update_data(std::vector< double > data_set, std::vector< char > colors)
{
 /* Checks for validity of input data. */
 assert( data_set.size() == colors.size() );

 int _num_pts = data_set.size() / 3;

 display_data->GetVerts()->InsertNextCell( _num_pts );

 double x[3];

 vtkPoints *_points;

 vtkUnsignedCharArray *_colors ;

 vtkCellArray *_verts = display_data->GetVerts();

 _verts->InsertNextCell(_num_pts);

 if( display_data->GetNumberOfPoints() > 0 )
 {
  _points = display_data->GetPoints();

  _colors =  (vtkUnsignedCharArray
*)(display_data->GetPointData()->GetScalars());

 }
 else
 {
   _points = vtkPoints::New();

   _colors = vtkUnsignedCharArray::New();

   _colors->SetName("colors");
   _colors->SetNumberOfComponents(3);

 }

 for( int i = 0; i < _num_pts; i++ )
 {
    x[0] = data_set[ 3 * i ];
    x[1] = data_set[ 3 * i + 1 ];
    x[2] = data_set[ 3 * i + 2 ];

    int _id = _points->InsertNextPoint( x );

    _verts->InsertCellPoint( _id );

    const unsigned char _color[] = { colors[3 * i + 2], colors[3 * i + 1] ,
colors[3 * i ] };

    ( _colors )->InsertNextTupleValue( _color );
 }

}



-------------------------------------------------For
rendering-----------------------------------------------------------


 mapper->Modified();
 mapper->Update();
 renderer->ResetCameraClippingRange();
 rendererWindow->Render();



Thanks

Avanindra Singh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110613/692f4159/attachment.htm>


More information about the vtkusers mailing list