[英]Connect streaming points using VTK
I have a function that is called in a loop, and at each pass it gives (x,y,z) of a 3D point. 我有一个在循环中调用的函数,每次传递时它都会给出(x,y,z)3D点。 I am trying to connect these points in real-time using VTK, but I am unable to get the rendering window to refresh after every frame. 我正在尝试使用VTK实时连接这些点,但无法在每帧后刷新渲染窗口。 I see a bunch of lines if I exit the loop though. 如果退出循环,我会看到很多行。
Basically, this is what I am doing: 基本上,这就是我在做什么:
// 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();
}
If I do renderer->Render()
outside the loop, I am getting all the lines (or at least I think I do). 如果我在循环外执行renderer->Render()
,那么我将得到所有行(或者至少我认为是的)。 Can someone figure out where I am going wrong? 有人可以找出我要去哪里吗?
From these docs , it seems that you shouldn't be directly calling 从这些文档中 ,您似乎不应该直接致电
renderer->Render();
You should only call 你应该只打电话
renderWindow->Render();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.