Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何从vtkWindowToImageFilter中提取前景?_C++_Qt_Vtk_Qvtkwidget - Fatal编程技术网

C++ 如何从vtkWindowToImageFilter中提取前景?

C++ 如何从vtkWindowToImageFilter中提取前景?,c++,qt,vtk,qvtkwidget,C++,Qt,Vtk,Qvtkwidget,我正在将vtk与qt集成,我有vtkWindowToImageFilter,输入设置为vtkgenericopenglerenderwindow,为什么我只提取图像前景 vtkWindowToImageFilter *w2if = vtkWindowToImageFilter::New(); w2if->ReadFrontBufferOff(); w2if->SetInput(renderWindow); w2if->Update(); vtkImageData *img =

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

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

vtkImageData
包含背景,我怎样才能使用它?

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

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();
auto-oldSB=renderWindow->GetSwapBuffers();
renderWindow->SwapBuffersOff();
//隐藏背景(将可见性设置为false或其他值)
...
自动windowToImageFilter=vtkSmartPointer::New();
windowToImageFilter->SetInput(渲染窗口);
windowToImageFilter->SetScale(1);
windowToImageFilter->SetInputBufferTypeToRGBA();
windowToImageFilter->ReadFrontBufferOff();
windowToImageFilter->Update();//根据输入发出渲染
renderWindow->SetSwapBuffers(oldSB);
renderWindow->SwapBuffersOn();
//再次显示背景(将可见性设置为true或其他值)
...
自动img=windowToImageFilter->GetOutput();

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

您好,虽然您的解决方案是合理的,但我已经通过将alpha通道添加到vtkimagedata解决了此问题,并且成功了,我很感激,除非我测试您的解决方案,否则我不会将其标记为已解决。谢谢,这是另一种方法。我在许多情况下使用上述方法,其中我需要在没有光标对象或一些注释的情况下进行屏幕转储。
Update
触发渲染调用,因此不需要额外的渲染调用