<html><head>
<meta name="Generator" content="MS Exchange Server version 6.5.7651.53"><title>RE: [vtkusers] QVTKWidget with vtkImageViewer2 glitch</title></head><body><div><font size="2"></font> Hi,<br>
<br>
A short update: The weird resize problems were caused by the interaction of the QVTKWidget with a
composite window manager (compiz on Ubuntu 8.10). On a regular (or should I say, old fashioned)
window manager the QVTKWidget works all right.<br>
<br>
I have reported this as an issue:<br>
http://public.kitware.com/Bug/view.php?id=8648<br>
<br>
best,<br>
Jeroen<br>
</div><br><div class="OutlookMessageHeader" dir="ltr" align="left" lang="en-us"> <hr tabindex="-1"> <font face="Tahoma" size="2"> <b>From:</b> vtkusers-bounces@vtk.org [mailto:vtkusers-bounces@vtk.org] <b>On Behalf Of </b> J.S.Wijnhout@lumc.nl<br> <b>Sent:</b> Friday, February 27, 2009 1:42 PM<br> <b>To:</b> vtkusers@vtk.org<br> <b>Subject:</b> Re: [vtkusers] QVTKWidget with vtkImageViewer2 glitch<br> </font><br></div><div></div>
<!-- Converted from text/plain format -->
<p><font size="2">Thank for the pointer. Since setting the size of the image viewer is apparently
the problem I created a custom QVTKWidget that embeds an vtkImageViewer2. The<br>
implementation is basically:<br>
<br>
ImageViewerWidget::ImageViewerWidget(QWidget *_parent) : QVTKWidget(_parent)<br>
{<br>
m_imageViewer = vtkImageViewer2::New ();<br>
}<br>
<br>
void ImageViewerWidget::SetInput ( vtkImageData *_image )<br>
{<br>
m_imageViewer->SetInput ( _image );<br>
m_imageViewer->SetupInteractor(GetInteractor()); <br>
m_imageViewer->SetRenderWindow(GetRenderWindow());<br>
m_imageViewer->UpdateDisplayExtent ();<br>
}<br>
<br>
void ImageViewerWidget::resizeEvent ( QResizeEvent * event )<br>
{<br>
QVTKWidget::resizeEvent(event);<br>
m_imageViewer->SetSize(width(),height());<br>
m_imageViewer->SetPosition(x(),y());<br>
m_imageViewer->UpdateDisplayExtent (); <br>
}<br>
<br>
void ImageViewerWidget::showEvent ( QShowEvent * event )<br>
{<br>
QVTKWidget::showEvent(event);<br>
m_imageViewer->SetSize(width(),height());<br>
m_imageViewer->SetPosition(x(),y());<br>
m_imageViewer->UpdateDisplayExtent ();<br>
}<br>
<br>
This gets rid of the problems I mentioned, because the size is set explicitly on a show and resize event.<br>
<br>
However, there is a new problem that occurs only when there are multiple QVTKWidgets around. Upon
starting the application (I have four QVTKWidgets in a grid layout), a random number of widgets
actually show up (sometimes all four, but usually only two or three). After, seemingly, an
arbitrary number of resize actions one or more QVTKWidgets become defunctional (it stops resizing
and does not respond to input any more). When you click on a defunctional QVTKWidget, the whole
desktop screen flickers once. It almost seems as if there can be only on QVTKWidget because the
first QVTKWidget that is initialized always remains working.<br>
<br>
best,<br>
Jeroen<br>
<br>
--<br>
Leiden University Medical Center<br>
Image Processing Division<br>
<br>
<br>
<br>
-----Original Message-----<br>
From: Clinton Stimpson [<a href="mailto:clinton@elemtech.com">mailto:clinton@elemtech.com</a>]<br>
Sent: Wed 2/25/2009 7:06 PM<br>
To: Wijnhout, J.S. (LKEB)<br>
Cc: vtkusers@vtk.org<br>
Subject: Re: [vtkusers] QVTKWidget with vtkImageViewer2 glitch<br>
<br>
<br>
Here's what I understand is happening.<br>
<br>
vtkImageViewer2::Render assumes it can change the size of the window and<br>
places the image accordingly.<br>
When embedded in a GUI, the size of the window can't always be changed,<br>
so the image shows up in the wrong place based on what it thought the<br>
window size was.<br>
Your workaround give vtkImageViewer2 a chance to successfully resize a<br>
window and initialize the camera properly based on that, then you<br>
replaced the window and kept the correctly initialized camera.<br>
<br>
There are probably other workarounds, such as fixing the camera<br>
yourself. I'd file a bug against vtkImageViewer2.<br>
<br>
Clint<br>
<br>
<br>
J.S.Wijnhout@lumc.nl wrote:<br>
> Hi,<br>
><br>
> For starters, I have read the thread on this issue:<br>
> <a href="http://www.vtk.org/pipermail/vtkusers/2008-November/098242.html">http://www.vtk.org/pipermail/vtkusers/2008-November/098242.html</a><br>
><br>
> However I managed to get vtkImageViewer2 working inside a QVTKWidget,<br>
> with one glitch however. The sample code is printed at the bottom of<br>
> the screen.<br>
> The way I got this to work relies on the order in which calls to<br>
> Render and SetRenderWindow are made. First I render the image viewer<br>
> by calling vtkImageViewer2::Render, after that I attach the image<br>
> viewer render window to the QVTKWidget. This works, but because I call<br>
> render first a separate render window is created and then (after the<br>
> call to QVTKWidget::SetRenderWindow) reparented to the QVTKWidget.<br>
> This happens really fast, so I guess I could live with it. But it<br>
> keeps me wondering what I should do to have it functioning properly.<br>
> Any advice on how to circumvent or fix vtkImageViewer2 would be welcome.<br>
><br>
> best,<br>
> Jeroen<br>
><br>
><br>
> #include <vtkRenderer.h><br>
> #include <vtkRenderWindow.h><br>
> #include <vtkImageViewer2.h><br>
> #include <vtkRenderWindowInteractor.h><br>
> #include <vtkPNGReader.h><br>
><br>
> #include <QVTKWidget.h><br>
><br>
> #include <QApplication><br>
> #include <QMainWindow><br>
> #include <QStatusBar><br>
><br>
> int main ( int argc, char **argv )<br>
> {<br>
> QApplication app(argc,argv);<br>
><br>
> const char* fileName = argv[1];<br>
> <br>
> QMainWindow w;<br>
> w.statusBar()->showMessage(fileName);<br>
><br>
> QVTKWidget vtkWidget;<br>
> vtkWidget.setAutomaticImageCacheEnabled(false);<br>
> w.setCentralWidget(&vtkWidget);<br>
><br>
> vtkPNGReader *reader1 = vtkPNGReader::New ();<br>
> reader1->SetFileName(fileName);<br>
> reader1->Update ();<br>
><br>
> vtkImageViewer2 *viewer1 = vtkImageViewer2::New ();<br>
> viewer1->SetInput(reader1->GetOutput());<br>
> viewer1->SetupInteractor(vtkWidget.GetInteractor());<br>
> viewer1->Render ();<br>
> viewer1->SetRenderWindow(vtkWidget.GetRenderWindow());<br>
><br>
> w.show ();<br>
> <br>
> app.exec ();<br>
><br>
> viewer1->Delete ();<br>
> reader1->Delete ();<br>
> }<br>
><br>
><br>
> <br>
> ------------------------------------------------------------------------<br>
><br>
> _______________________________________________<br>
> Powered by www.kitware.com<br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
> <br>
<br>
<br>
<br>
<br>
<br>
</font>
</p>
</body></html>