[vtkusers] switch between on- and offscreen rendering

Affolter Martin martin.affolter at ntb.ch
Wed Jul 13 10:21:06 EDT 2016


Hi vtkusers

It seems that switching between on- and offscreen is no longer supported in VTK 7.0 on Windows. We used to create images from a view with the code below in VTK 6.1. Switching to offscreen-rendering allowed us to create an image even if the view itself wasn't visible in the UI (e.g. when put in a tab). Can anyone confirm that this is not possible anymore, or is there a build option I am not aware of? I haven't found much information on this in the mailing list, the blog or the changes  listed for migrating from 6.x to 7.0.

Of course, I would also be interested in an alternative solution. Thanks.

The code:

void VTKView::WriteImage( const _TCHAR * fileName, const _TCHAR * imageType, int magnification ){
                std::_tstring extension( imageType );
                std::_tstring fName = CADH_Service::AppendExtension(fileName, extension);

                this->m_RenWin->OffScreenRenderingOn(); // <--- switch to offscreen rendering, since window might be hidden
                vtkRenderLargeImage * renderLarge = vtkRenderLargeImage::New();
                renderLarge->SetInput( m_Renderer );
                renderLarge->SetMagnification( magnification );

                vtkImageWriter * imageWriter = NULL;
                try{
                               if( extension.compare( _T( "bmp" )) == 0 ){
                                               imageWriter = vtkBMPWriter::New();
                               } else if( extension.compare( _T( "png" )) == 0 ){
                                               imageWriter = vtkPNGWriter::New();
                               } else if( extension.compare( _T( "jpeg" )) == 0 || extension.compare( _T( "jpg" )) == 0){
                                               imageWriter = vtkJPEGWriter::New();
                               } else if( extension.compare( _T( "pnm" )) == 0 ){
                                               imageWriter = vtkPNMWriter::New();
                               } else if( extension.compare( _T( "ps" )) == 0 ){
                                               imageWriter = vtkPostScriptWriter::New();
                               } else if( extension.compare( _T( "tif" )) == 0 || extension.compare( _T( "tiff" )) == 0){
                                               imageWriter = vtkTIFFWriter::New();
                               } else {
                                               throw std::_tstring(_T(" Exception in VTKView::WriteImage, picture format not supported."));
                               }
                               if( imageWriter ){
                                               imageWriter->SetInputConnection( renderLarge->GetOutputPort() );
                                               imageWriter->SetFileName( fName.c_str() );
                                               imageWriter->Write();
                                               imageWriter->Delete();
                               }
                } catch( std::_tstring str ){
                               if ( m_RenWin->GetOffScreenRendering() > 0 ){
                                               m_RenWin->OffScreenRenderingOff();
                               }
                               renderLarge->Delete();
                               throw str;
                } catch(...) {
                               if ( m_RenWin->GetOffScreenRendering() > 0 ){
                                               m_RenWin->OffScreenRenderingOff();
                               }
                               renderLarge->Delete();
                               throw std::_tstring(_T(" Exception in VTKView::WriteImage, procedure aborted."));
                }
                renderLarge->Delete();
                this->m_RenWin->OffScreenRenderingOff(); // <--- switch back to onscreen rendering
}

Martin Affolter
MSc FHO in Engineering
Wissenschaftlicher Mitarbeiter
___________________________________________
NTB Interstaatliche Hochschule für Technik Buchs
Institut für Ingenieurinformatik
Schönauweg 4
CH-9013 St. Gallen

Tel:  +41 81 755 32 49
Web: http://www.ntb.ch

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160713/2c920c3f/attachment.html>


More information about the vtkusers mailing list