[vtkusers] vtkPlot SetInput
Marc Ferland
ferlandm at sonatest.com
Mon Mar 5 10:39:34 EST 2012
Hi,
I'd like to automatically update the content of a vtkPlot but the
current behavior of the SetInput function does not seem to handle
this. Am I right? If so, how can I emulate this behavior?
Here's a sample application:
#include <vtkChartXY.h>
#include <vtkContextScene.h>
#include <vtkContextView.h>
#include <vtkDataObjectToTable.h>
#include <vtkFloatArray.h>
#include <vtkPen.h>
#include <vtkPlot.h>
#include <vtkPolyData.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkTable.h>
int main()
{
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
vtkSmartPointer<vtkDataObjectToTable> dataObjectToTable =
vtkSmartPointer<vtkDataObjectToTable>::New();
dataObjectToTable->SetInputConnection(sphereSource->GetOutputPort());
dataObjectToTable->SetFieldType(vtkDataObjectToTable::POINT_DATA);
// Have to manually update this object before setting it to the vtkPlot
dataObjectToTable->Update();
vtkSmartPointer<vtkContextView> view =
vtkSmartPointer<vtkContextView>::New();
view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
vtkSmartPointer<vtkChartXY> chart =
vtkSmartPointer<vtkChartXY>::New();
view->GetScene()->AddItem(chart);
vtkPlot *line = chart->AddPlot(vtkChart::LINE);
line->SetUseIndexForXSeries(true);
line->SetInput(dataObjectToTable->GetOutput(), 0, 0);
line->SetColor(0, 255, 0, 255);
line->SetWidth(1.0);
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
Basically, what I'd like to do is remove the call to
dataObjectToTable->Update() and let the pipeline update itself when the
view is rendered. I guess what I'm looking for is a function equivalent
to SetInputConnection but from the vtkPlot interface.
Regards,
Marc
More information about the vtkusers
mailing list