[vtkusers] Data format for XYPlot

James Turner zakalawe at mac.com
Mon Sep 24 07:42:05 EDT 2007


I'm attempting to insert some data from a non-VTK, realtime source  
into the right kind of structure such that it appears on an vtkXYPlot.

=================
Setup code:

m_graphData = vtkPolyData::New();
m_graphData->Allocate();
vtkPoints* points = vtkPoints::New();
m_graphData->SetPoints(points);


m_xyPlot = vtkXYPlotActor::New();
m_xyPlot->AddInput(m_graphData);
  .. setup some other cosmetics of the graphic, eg position  
coordinates, labels, titles, etc ...

Code for each (x,y) sample I receive:

double x,y .... from my data source.
vtkIdType id = m_graphData->GetPoints()->InsertNextPoint(x, y, 0.0);
m_graphData->InsertNextCell(VTK_VERTEX, 1, &id);

================

This doesn't work, so I tried adding the Y-values as scalar data  
attached to each cell (based on the documentation for XYPlot):

(additional setup code)

m_scalars = vtkFloatArray::New();
m_scalars->Allocate(100, 100);
m_graphData->GetCellData()->SetScalars(m_scalars);

(additional update code)

m_scalars->InsertNextValue(y);

====================

But still no luck. Can someone please enlighten me as to the simplest  
way to do this (I'm aware there are probably several, due to the  
flexibility of the XYPlot)

Regards,
James Turner



More information about the vtkusers mailing list