我有一个在循环中调用的函数,并且在每次传递时它给出了3D点的(x,y,z)。我试图使用VTK实时连接这些点,但我无法在每帧后刷新渲染窗口。如果我退出循环,我会看到一堆行。
基本上,这就是我在做的事情:
// Create a vtkPoints object to store the points in it
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New();
// Create a cell array to store the lines in
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
// Create a polydata to store everything in
vtkSmartPointer<vtkPolyData> linesPolyData = vtkSmartPointer<vtkPolyData>::New();
// Setup actor and mapper
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// Setup render window, renderer, and interactor
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderWindow->Render();
renderer->Render();
int numpoints = 0;
while(some_condition)
{
call_function(&x,&y,&z);
double point[3] = {0.0, 0.0, 0.0};
point[0] = (float)x;
point[1] = (float)y;
point[2] = (float)z;
numpoints++;
points->InsertNextPoint(point);
polyLine->GetPointIds()->SetNumberOfIds(numpoints);
for(unsigned int i = 0; i < num_points; i++)
{
polyLine->GetPointIds()->SetId(i,i);
}
lines->InsertNextCell(polyLine);
// Add the points to the dataset
linesPolyData->SetPoints(points);
// Add the lines to the dataset
linesPolyData->SetLines(lines);
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(linesPolyData);
#else
mapper->SetInputData(linesPolyData);
#endif
linesPolyData->Modified();
linesPolyData->Update();
renderWindow->Render();
renderer->Render();
renderWindowInteractor->Enable();
check_loop_exit_condition();
}
如果我在循环之外renderer->Render()
,我会得到所有的行(或者至少我认为我这样做)。有人能弄明白我哪里错了吗?