[vtkusers] QVTK issue with vtkImageViewer2

lars-friedrich lars-friedrich at gmx.net
Sat Nov 21 01:46:40 EST 2009


Hi Ashish,


I think I can suggest some possible solutions to your problem with
vtkImageViewer2-handling:


1. the easiest thing may be to use your 'blank'-image instead of removing
the view-props of the renderer; I mean, you did already implement it in
order to overcome the broken pipeline problem vtkImageViewer2 usually causes
at situations when its input is NULL ...; e.g. do this in the unload-slot:
{
    //imgview->GetRenderer()->RemoveAllViewProps(); // forget about that
    imgview->SetInput(blank); // simply set the blank input again
    imgview->GetRenderer()->ResetCamera();
    vtkwidget->update();
}


2. the problem with removing the renderer's view props is that
vtkImageViewer2 does not automatically add the view props again - you must
either do this (a) manually or (b) re-trigger the internal
InstallPipeline-method

(a)
load-slot:
{
    reader->SetDirectoryName(dirname.c_str());
    reader->Update();
    imgview->SetInput(reader->GetOutput());
    if (!imgview->GetRenderer()->HasViewProp(imgview->GetImageActor())) //
manually check whether we've to re-add the actor
      imgview->GetRenderer()->AddViewProp(imgview->GetImageActor());
    imgview->GetRenderer()->ResetCamera();
    vtkwidget->update();
}
unload-slot:
{
    //imgview->GetRenderer()->RemoveAllViewProps();
    imgview->GetRenderer()->RemoveViewProp(imgview->GetImageActor()); //
remove vtkImageViewer's specific actor
    imgview->GetRenderer()->ResetCamera();
    vtkwidget->update();
}


(b)
load-slot:
{
    reader->SetDirectoryName(dirname.c_str());
    reader->Update();
    imgview->SetInput(reader->GetOutput());

    imgview->SetRenderWindow(NULL); // internal call of UninstallPipeline()
is for example triggered by re-setting render window ... 
    imgview->SetRenderWindow(vtkwidget->GetRenderWindow());

    imgview->GetRenderer()->ResetCamera();
    vtkwidget->update();
}
unload-slot:
{
    //imgview->GetRenderer()->RemoveAllViewProps();
    imgview->GetRenderer()->RemoveViewProp(imgview->GetImageActor()); //
remove vtkImageViewer's specific actor
    imgview->GetRenderer()->ResetCamera();
    vtkwidget->update();
}




HTH,

lars




Ashish Singh-4 wrote:
> 
> Hi,
> 
> I am trying to display each slice from a series of CT scans in a
> QVTKwidget.
> The QVTKWidget itself is in a QMainWindow with 3 other widgets to browse,
> load and unload the data. I want to be able to display the data in
> QVTKwidget as soon as I hit the load button. I also want to be able to
> unload the data and clear the QVTKwidget as soon as I hit the unload
> button
> so that I can load a new dataset afterwards.
> 
> I can read and display the data fine only the first time. I can also
> unload
> the data, but after unload when I try to load new data it doesn't show up
> in
> my QVTKwidget. Can anyone please tell me what am I missing or doing wrong
> here and how to correct it?
> 
> My development environment is:
> Windows XP Pro x64
> Visual Studio 2005
> VTK 5.4.2
> Qt 4.5.0
> 
> Thanks,
> Ashish
> 
> Here's the code that I use:
> ----Header file: test.h-----
> #include <QObject>
> #include <QPushButton>
> #include <QLabel>
> #include <QHBoxLayout>
> #include <QVBoxLayout>
> #include <QMainWindow>
> #include <QVTKWidget.h>
> #include <QWidget>
> #include <QString>
> #include <QFileDialog>
> #include <QDir>
> #include <qapplication.h>
> #include <qobject.h>
> #include <QtGui>
> 
> #include <vtkDICOMImageReader.h>
> #include <vtkImageViewer2.h>
> #include <vtkRenderWindow.h>
> #include "vtkRenderer.h"
> #include "vtkCornerAnnotation.h"
> #include "vtkImageData.h"
> 
> 
> using namespace std;
> 
> class test : public QObject
> {
>     Q_OBJECT
> 
> public:
>     string dirname;
>     vtkDICOMImageReader *reader;
>     vtkImageViewer2 *imgview;
>     vtkImageData *blank;
> 
>     QMainWindow *mymainwindow;
>     QWidget *centralwidget;
>     QLabel *mylabel;
>     QPushButton *mypbutton;
>     QPushButton *myloadbutton;
>     QPushButton *myunloadbutton;
>     QVTKWidget *vtkwidget;
>     QHBoxLayout *myhlayout;
>     QVBoxLayout *myvlayout;
>     test(QObject* parent = 0);
>     ~test();
> 
>     public slots:
>         void OnLoad();
>         void OnBrowse();
>         void OnUnLoad();
> 
> };
> 
> -----cpp file: test.cpp-------
> #include "test.h"
> 
> test::test(QObject * parent):QObject(parent)
> {
>     reader = vtkDICOMImageReader::New();
>     imgview = vtkImageViewer2::New();
> 
>     //create dummy data to create start up blank image
>     blank = vtkImageData::New();
>     blank->SetDimensions(10, 10, 1);
>     blank->AllocateScalars();
>     for (int i = 0; i < 10; i++)
>         for (int j = 0; j < 10; j++)
>             blank->SetScalarComponentFromDouble(i, j, 0, 0, 0);
>     blank->Update();
>     imgview->SetInput(blank);
>     imgview->SetInput(blank);
>     //create dummy data to create start up blank image
> 
>     mymainwindow = new QMainWindow();
>     centralwidget = new QWidget(mymainwindow);
> 
>     mylabel = new QLabel(centralwidget);
>     mypbutton = new QPushButton(centralwidget);
>     myloadbutton = new QPushButton(centralwidget);
>     myunloadbutton = new QPushButton(centralwidget);
> 
>     vtkwidget = new QVTKWidget(centralwidget);
>     vtkwidget->GetRenderWindow()->AddRenderer(imgview->GetRenderer());
>     vtkwidget->setFixedSize(512,512);
> 
>     myhlayout = new QHBoxLayout();
>     myvlayout = new QVBoxLayout();
> 
>     //setup UI
>     mylabel->setText("Select Dicom Dir");
>     mypbutton->setText("Browse");
>     this->connect(this->mypbutton,SIGNAL(clicked()),this,
> SLOT(OnBrowse()));
> 
>     myloadbutton->setText("Load");
>     this->connect(this->myloadbutton,SIGNAL(clicked()),this,
> SLOT(OnLoad()));
> 
>     myunloadbutton->setText("Unload");
> 
> this->connect(this->myunloadbutton,SIGNAL(clicked()),this,SLOT(OnUnLoad()));
> 
>     myhlayout->addWidget(mylabel);
>     myhlayout->addWidget(mypbutton);
>     myhlayout->addWidget(myloadbutton);
>     myhlayout->addWidget(myunloadbutton);
> 
>     myvlayout->addLayout(myhlayout);
>     myvlayout->addWidget(vtkwidget);
> 
>     centralwidget->setLayout(myvlayout);
>     mymainwindow->setCentralWidget(centralwidget);
>     mymainwindow->show();
> }
> 
> test::~test()
> {
>     reader->Delete();
>     imgview->Delete();
>     blank->Delete();
> }
> 
> void test::OnLoad()
> {
>     reader->SetDirectoryName(dirname.c_str());
>     reader->Update();
>     imgview->SetInput(reader->GetOutput());
>     imgview->GetRenderer()->ResetCamera();
>     vtkwidget->update();
> }
> 
> void test::OnUnLoad()
> {
>     imgview->GetRenderer()->RemoveAllViewProps();
>     imgview->GetRenderer()->ResetCamera();
>     vtkwidget->update();
> }
> 
> void test::OnBrowse()
> {
>     QString indirectory =
> QFileDialog::getExistingDirectory(this->centralwidget,tr("Select Input
> Directory"), QDir::currentPath());
>     dirname = indirectory.toStdString();
> }
> 
> -----main.cpp---------
> #include "test.h"
> void main(int argc, char *argv[])
> {
>     QApplication app(argc, argv);
>     test *mywin = new test;
>     app.exec();
> 
> }
> 
> _______________________________________________
> 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
> 
> 

-- 
View this message in context: http://old.nabble.com/QVTK-issue-with-vtkImageViewer2-tp26429989p26454127.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list