<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.E-MailFormatvorlage17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE-CH" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hi vtkusers<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Of course, I would also be interested in an alternative solution. Thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The code:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">void VTKView::WriteImage( const _TCHAR * fileName, const _TCHAR * imageType, int magnification ){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> std::_tstring extension( imageType );<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> std::_tstring fName = CADH_Service::AppendExtension(fileName, extension);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> this->m_RenWin->OffScreenRenderingOn(); // <--- switch to offscreen rendering, since window might be hidden<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> </span>vtkRenderLargeImage * renderLarge = vtkRenderLargeImage::New();<o:p></o:p></p>
<p class="MsoNormal"> renderLarge->SetInput( m_Renderer );<o:p></o:p></p>
<p class="MsoNormal"> <span lang="EN-US">renderLarge->SetMagnification( magnification );<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> vtkImageWriter * imageWriter = NULL;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> try{<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> if( extension.compare( _T( "bmp" )) == 0 ){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> imageWriter = vtkBMPWriter::New();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> } else if( extension.compare( _T( "png" )) == 0 ){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> imageWriter = vtkPNGWriter::New();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> } else if( extension.compare( _T( "jpeg" )) == 0 || extension.compare( _T( "jpg" )) == 0){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> imageWriter = vtkJPEGWriter::New();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> } else if( extension.compare( _T( "pnm" )) == 0 ){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> imageWriter = vtkPNMWriter::New();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> } else if( extension.compare( _T( "ps" )) == 0 ){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> imageWriter = vtkPostScriptWriter::New();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> } else if( extension.compare( _T( "tif" )) == 0 || extension.compare( _T( "tiff" )) == 0){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> imageWriter = vtkTIFFWriter::New();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> } else {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> throw std::_tstring(_T(" Exception in VTKView::WriteImage, picture format not supported."));<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> if( imageWriter ){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> imageWriter->SetInputConnection( renderLarge->GetOutputPort() );<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> imageWriter->SetFileName( fName.c_str() );<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> imageWriter->Write();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> imageWriter->Delete();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> } catch( std::_tstring str ){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> if ( m_RenWin->GetOffScreenRendering() > 0 ){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> m_RenWin->OffScreenRenderingOff();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> renderLarge->Delete();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> throw str;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> } catch(...) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> if ( m_RenWin->GetOffScreenRendering() > 0 ){<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> m_RenWin->OffScreenRenderingOff();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> renderLarge->Delete();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> throw std::_tstring(_T(" Exception in VTKView::WriteImage, procedure aborted."));<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> renderLarge->Delete();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> this->m_RenWin->OffScreenRenderingOff(); // <--- switch back to onscreen rendering<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;mso-fareast-language:DE-CH">Martin Affolter<br>
MSc FHO in Engineering<br>
Wissenschaftlicher Mitarbeiter<br>
<span style="color:#999999">___________________________________________<br>
</span><span style="color:gray">NTB Interstaatliche Hochschule für Technik Buchs <br>
Institut für Ingenieurinformatik<br>
Schönauweg 4<br>
CH-9013 St. Gallen<br>
<br>
Tel: +41 81 755 32 49</span><span style="color:#999999"><br>
</span><span style="color:gray">Web:</span><span style="color:#999999"> <u><a href="http://www.ntb.ch"><span style="color:#0563C1">http://www.ntb.ch</span></a></u></span></span><span style="mso-fareast-language:DE-CH"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>