[vtkusers] Rendering QVTKWidget into QPixmap

Clinton Stimpson clinton at elemtech.com
Wed Feb 8 09:52:53 EST 2012


Have you tried using QPixmap::grabWidget() instead?  QVTKWidget already implements redirected painting and uses vtkRenderWindow::GetRGBACharPixelData to get the pixel data.  So I don't see how calling GetRGBAPixelData() yourself is going to fix this.  This method also works if grabbing a main window that contains multiple QVTKWidget's and other widgets.  As a side note, if I look in QVTKWidget::paintEvent(), it looks like turning the image cache on disables the redirected painting code so you wouldn't get anything by calling grabWidget().

If you want it to work with other windows overlapping, then you can set the offscreen flag before calling grabWidget().

Clint

On Feb 8, 2012, at 5:16 AM, Christian Lackas wrote:

> Hi Everybody,
> 
> we are using VTK in a Qt-based application of ours and employ QVTKWidget
> for this. To allow the user to store rendered data as images, we use
> code such as:
> 
>    class VRenderer: public QVTKWidget {
>        Q_OBJECT
>        public:
>            ...
>            QPixmap grabImage() {
>                QPixmap pixmap( size() );
>                render( &pixmap );
>                return pixmap;
>            }
>        ...
>    };
> 
> and then use the QPixmap object to produce an image file (which aligns
> well with our non-VTK-based rendering widgets).
> On Mac OS X, as well as Linux and many Windows systems this does work
> pretty well. Unfortunately, we do have a couple of Windows system
> (Vista, 7, 32- and 64-bit, but not consistently on one platform) where
> above code produces merely an all-black image.
> I assume this has something to do with how the graphic card driver
> handles the OpenGL drawing (or something along this line, e.g.
> asynchronous processing, where we grab the image to early, etc...).
> 
> I already tried using functions such as vtkRenderWindow::WaitForCompletion(),
> however, as the documentation suggest that was not useful here, calling
> vtkRenderWindow::Render() explicitly myself, etc...
> 
> Is there a way to make sure that a QVTKWidget renders and actual image
> into my pixmap?
> 
> Or should I start using vtkRenderWindow::GetRGBAPixelData() instead?
> 
> Thanks for any hints.
> Christian
> 
> -- 
> http://www.invicro.com/  http://www.spect-ct.com/
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list