[vtkusers] vtkqt and vtkWindowToImageFilter

Zisik, Herbert Herbert.Zisik at muc.mtu.de
Tue Jun 29 06:08:44 EDT 2004


Hi All,

I use vtkqt and vtk 4.2 on Windows. Everything works fine, but using
vtkWindowToImageFilter, the mouse is flickering and the response time at
mouse movement ist very slow.

Here my example code:

#include "qvExample.h"

#include "vtkWindowToImageFilter.h"
#include "vtkJPEGWriter.h"
#include "vtkTIFFWriter.h"
#include "vtkRenderWindow.h"

QVExample::QVExample() {
    setCaption("Another Example for Qt and VTK together");

    QPopupMenu *popup = new QPopupMenu;
    popup->insertItem("Save", this, SLOT(saveFrame()));
    popup->insertItem("Exit", qApp, SLOT(quit()));
    
    QMenuBar *menuBar = new QMenuBar(this);
    menuBar->insertItem("File", popup);

    renderWindowLeft = new vtkQtRenderWindow(this);
    interactorLeft = vtkQtRenderWindowInteractor::New();
    interactorLeft->SetRenderWindow(renderWindowLeft);
    renderWindowLeft->show();

    interactorLeft->SetDesiredUpdateRate(3.0);
    interactorLeft->SetStillUpdateRate(0.1);

    leftRenderer = NULL;

    QHBoxLayout *layTop = new QHBoxLayout(this);
    layTop->addWidget(renderWindowLeft);
}

void QVExample::setLeftRenderer(vtkRenderer *renderer) {
    if (!renderer)
	return;
    if (leftRenderer)
	renderWindowLeft->RemoveRenderer(leftRenderer);
    leftRenderer = renderer;
    renderWindowLeft->AddRenderer(renderer);
}

void QVExample::saveFrame()
{
	renderWindowLeft->OffScreenRenderingOn();

	vtkWindowToImageFilter* w2i = vtkWindowToImageFilter::New();
	w2i->SetInput( renderWindowLeft );
//	w2i->Update();

	vtkJPEGWriter* jpegw = vtkJPEGWriter::New();
	jpegw->SetInput( w2i->GetOutput() );
	jpegw->SetFileName("whatever.jpg" );
	jpegw->ProgressiveOn();
	jpegw->SetQuality( 100 );
//	jpegw->Write();

	vtkTIFFWriter* tiffw = vtkTIFFWriter::New();
	tiffw->SetInput( w2i->GetOutput() );
	tiffw->SetFileName("whatever.tif" );
//	tiffw->Write();

	tiffw->Delete();
	jpegw->Delete();

	w2i->Delete();

	renderWindowLeft->OffScreenRenderingOff();
}

The red code lines marked as comment, causes the effect.

Mit freundlichen Grüßen / Best Regards

Herbert Zisik
MTU Aero Engines GmbH
Zerstörungsfreie Prüfverfahren (TEFP)
Advanced Non-Destructive Testing (TEFP)
Dachauer Str. 665
80995 München
Germany

Tel  +49 (0)89 14 89-42 91
Fax +49 (0)89 14 89-96283
mailto:Herbert.Zisik at muc.mtu.de
http://www.mtu.de




More information about the vtkusers mailing list