使用VTK连接流式传输点



我有一个在循环中调用的函数,每次调用时都会给出一个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(),那么我得到了所有的行(或者至少我认为我得到了)。有人能找出我哪里出了问题吗?

从这些文档来看,似乎不应该直接调用

renderer->Render();

你应该只打

renderWindow->Render();

相关内容

  • 没有找到相关文章

最新更新