[vtkusers] QVTKWidget with vtkImageViewer2 glitch

Clinton Stimpson clinton at elemtech.com
Wed Feb 25 13:06:31 EST 2009


Here's what I understand is happening.

vtkImageViewer2::Render assumes it can change the size of the window and 
places the image accordingly.
When embedded in a GUI, the size of the window can't always be changed, 
so the image shows up in the wrong place based on what it thought the 
window size was.
Your workaround give vtkImageViewer2 a chance to successfully resize a 
window and initialize the camera properly based on that, then you 
replaced the window and kept the correctly initialized camera.

There are probably other workarounds, such as fixing the camera 
yourself.  I'd file a bug against vtkImageViewer2.

Clint


J.S.Wijnhout at lumc.nl wrote:
> Hi,
>
> For starters, I have read the thread on this issue:
> http://www.vtk.org/pipermail/vtkusers/2008-November/098242.html
>
> However I managed to get vtkImageViewer2 working inside a QVTKWidget, 
> with one glitch however. The sample code is printed at the bottom of 
> the screen.
> The way I got this to work relies on the order in which calls to 
> Render and SetRenderWindow are made. First I render the image viewer 
> by calling vtkImageViewer2::Render, after that I attach the image 
> viewer render window to the QVTKWidget. This works, but because I call 
> render first a separate render window is created and then (after the 
> call to QVTKWidget::SetRenderWindow) reparented to the QVTKWidget. 
> This happens really fast, so I guess I could live with it. But it 
> keeps me wondering what I should do to have it functioning properly. 
> Any advice on how to circumvent or fix vtkImageViewer2 would be welcome.
>
> best,
> Jeroen
>
>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> #include <vtkImageViewer2.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkPNGReader.h>
>
> #include <QVTKWidget.h>
>
> #include <QApplication>
> #include <QMainWindow>
> #include <QStatusBar>
>
> int main ( int argc, char **argv )
> {
>     QApplication app(argc,argv);
>
>     const char* fileName = argv[1];
>    
>     QMainWindow w;
>     w.statusBar()->showMessage(fileName);
>
>     QVTKWidget vtkWidget;
>     vtkWidget.setAutomaticImageCacheEnabled(false);
>     w.setCentralWidget(&vtkWidget);
>
>     vtkPNGReader *reader1 = vtkPNGReader::New ();
>     reader1->SetFileName(fileName);
>     reader1->Update ();
>
>     vtkImageViewer2 *viewer1 = vtkImageViewer2::New ();
>     viewer1->SetInput(reader1->GetOutput());
>     viewer1->SetupInteractor(vtkWidget.GetInteractor());
>     viewer1->Render ();
>     viewer1->SetRenderWindow(vtkWidget.GetRenderWindow());
>
>     w.show ();
>      
>     app.exec ();
>
>     viewer1->Delete ();
>     reader1->Delete ();
> }
>
>
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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