[vtkusers] QVTK issue with vtkImageViewer2
Ashish Singh
asinghmlists at gmail.com
Fri Nov 20 15:12:53 EST 2009
Hi Clint,
Thanks for replying. I did the modifications you suggested. But the problem
still exists. I can load the data first time. But after I unload this data
and try to browse and load a new dataset, I don't see anything in the
QVTKwidget. What might be going wrong here?
Thanks,
Ashish
On Fri, Nov 20, 2009 at 12:53 PM, Clinton Stimpson <clinton at elemtech.com>wrote:
>
> A quick glance at the code shows you're not hooking up the QVTKWIdget with
> the
> vtkImageViewer2 correctly.
>
> One way to do it:
> vtkwidget = new QVTKWidget(centralwidget);
> imgview->SetupInteractor(vtkwidget->GetInteractor());
> imgview->SetRenderWindow(vtkwidget->GetRenderWindow());
>
> Clint
>
> On Friday 20 November 2009 11:21:27 am Ashish Singh wrote:
> > any suggestions on this?
> >
> > ---------- Forwarded message ----------
> > From: Ashish Singh <asinghmlists at gmail.com>
> > Date: Thu, Nov 19, 2009 at 10:59 AM
> > Subject: QVTK issue with vtkImageViewer2
> > To: vtkusers at vtk.org
> >
> >
> > 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();
> >
> > }
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091120/1a3aa710/attachment.htm>
More information about the vtkusers
mailing list