gpt4 book ai didi

c++ - 使用 VTK 连接流媒体点

转载 作者:太空宇宙 更新时间:2023-11-04 12:05:24 26 4
gpt4 key购买 nike

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

最佳答案

来自 these docs , 看来你不应该直接打电话

renderer->Render();

你应该只调用

renderWindow->Render();

关于c++ - 使用 VTK 连接流媒体点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12375662/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com