The Initialize function in the VTK vtkrenderwindowinteractor initializes the interactive window, but the actual project often requires the window to be displayed on other pages, such as PNG images and so on. The concrete method can see Vtkrenderwindow class introduction.
This article mainly describes how to capture the screen of the current window.
//renWin:当前活动窗口;//pdata:后返回的数据指针,RGBA,32位,存储格式为RGBARGBA....//maxlen: 防止pdata开辟的空间不够bool GetOutput(vtkRenderWindow *renWin,unsigned char* pdata, int maxlen){ int w = renWin->GetSize()[0]; int h = renWin->GetSize()[1]; if (maxlen<w*h * 4) return false; vtkSmartPointer<vtkUnsignedCharArray> pixels = vtkSmartPointer<vtkUnsignedCharArray>::New(); pixels->SetArray(pdata, w*h * 4, 1); renWin->GetRGBACharPixelData(0, 0, h - 1, w - 1, 1, pixels); return true;}
The above code can be used to intercept the current scene of the desired window, in addition to this way, can also be saved in PNG format just call the VTK PNG class.
How to intercept the scene of window in VTK