0

我正在将 vtk 与 qt 集成,我将vtkWindowToImageFilter输入设置为vtkGenericOpenGLRenderWindow,我怎么只提取图像前景?

vtkWindowToImageFilter *w2if = vtkWindowToImageFilter::New();
w2if->ReadFrontBufferOff();
w2if->SetInput(renderWindow);
w2if->Update();
vtkImageData *img = w2if->GetOutput();

包括vtkImageData背景我怎么能骑它?

4

1 回答 1

1

我的建议是重新渲染除背景之外的所有内容。类似于以下内容

auto oldSB = renderWindow->GetSwapBuffers();
renderWindow->SwapBuffersOff();

// Hide the background (set visibility to false or whatever)
...
auto windowToImageFilter = vtkSmartPointer<vtkWindowToImageFilter>::New();
windowToImageFilter->SetInput(renderWindow);

windowToImageFilter->SetScale(1);
windowToImageFilter->SetInputBufferTypeToRGBA();

windowToImageFilter->ReadFrontBufferOff();
windowToImageFilter->Update(); // Issues a render on input

renderWindow->SetSwapBuffers(oldSB);
renderWindow->SwapBuffersOn();

// Show background again (set visibility to true or whatever)
...

auto img = windowToImageFilter->GetOutput();

下面的渲染调用将再次显示背景。

于 2021-05-28T12:39:05.107 回答