Hi,<br><br>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. <br>
<br>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?<br>
<br>My development environment is:<br>Windows XP Pro x64<br>Visual Studio 2005<br>VTK 5.4.2<br>Qt 4.5.0<br><br>Thanks,<br>Ashish<br><br>Here's the code that I use:<br>----Header file: test.h-----<br>#include <QObject><br>
#include <QPushButton><br>#include <QLabel><br>#include <QHBoxLayout><br>#include <QVBoxLayout><br>#include <QMainWindow><br>#include <QVTKWidget.h><br>#include <QWidget><br>#include <QString><br>
#include <QFileDialog><br>#include <QDir><br>#include <qapplication.h><br>#include <qobject.h><br>#include <QtGui><br><br>#include <vtkDICOMImageReader.h><br>#include <vtkImageViewer2.h><br>
#include <vtkRenderWindow.h><br>#include "vtkRenderer.h"<br>#include "vtkCornerAnnotation.h"<br>#include "vtkImageData.h"<br><br><br>using namespace std;<br><br>class test : public QObject<br>
{<br> Q_OBJECT<br><br>public:<br> string dirname;<br> vtkDICOMImageReader *reader;<br> vtkImageViewer2 *imgview;<br> vtkImageData *blank;<br><br> QMainWindow *mymainwindow;<br> QWidget *centralwidget;<br>
QLabel *mylabel;<br> QPushButton *mypbutton;<br> QPushButton *myloadbutton;<br> QPushButton *myunloadbutton;<br> QVTKWidget *vtkwidget;<br> QHBoxLayout *myhlayout;<br> QVBoxLayout *myvlayout;<br> test(QObject* parent = 0);<br>
~test();<br><br> public slots:<br> void OnLoad();<br> void OnBrowse();<br> void OnUnLoad();<br><br>};<br><br>-----cpp file: test.cpp-------<br>#include "test.h"<br><br>test::test(QObject * parent):QObject(parent)<br>
{<br> reader = vtkDICOMImageReader::New();<br> imgview = vtkImageViewer2::New();<br> <br> //create dummy data to create start up blank image<br> blank = vtkImageData::New();<br> blank->SetDimensions(10, 10, 1);<br>
blank->AllocateScalars();<br> for (int i = 0; i < 10; i++)<br> for (int j = 0; j < 10; j++)<br> blank->SetScalarComponentFromDouble(i, j, 0, 0, 0);<br> blank->Update();<br> imgview->SetInput(blank);<br>
imgview->SetInput(blank);<br> //create dummy data to create start up blank image<br><br> mymainwindow = new QMainWindow();<br> centralwidget = new QWidget(mymainwindow);<br><br> mylabel = new QLabel(centralwidget);<br>
mypbutton = new QPushButton(centralwidget);<br> myloadbutton = new QPushButton(centralwidget);<br> myunloadbutton = new QPushButton(centralwidget);<br><br> vtkwidget = new QVTKWidget(centralwidget);<br> vtkwidget->GetRenderWindow()->AddRenderer(imgview->GetRenderer());<br>
vtkwidget->setFixedSize(512,512);<br><br> myhlayout = new QHBoxLayout();<br> myvlayout = new QVBoxLayout();<br><br> //setup UI<br> mylabel->setText("Select Dicom Dir");<br> mypbutton->setText("Browse");<br>
this->connect(this->mypbutton,SIGNAL(clicked()),this, SLOT(OnBrowse()));<br><br> myloadbutton->setText("Load");<br> this->connect(this->myloadbutton,SIGNAL(clicked()),this, SLOT(OnLoad()));<br>
<br> myunloadbutton->setText("Unload");<br> this->connect(this->myunloadbutton,SIGNAL(clicked()),this,SLOT(OnUnLoad()));<br><br> myhlayout->addWidget(mylabel);<br> myhlayout->addWidget(mypbutton);<br>
myhlayout->addWidget(myloadbutton);<br> myhlayout->addWidget(myunloadbutton);<br><br> myvlayout->addLayout(myhlayout);<br> myvlayout->addWidget(vtkwidget);<br><br> centralwidget->setLayout(myvlayout);<br>
mymainwindow->setCentralWidget(centralwidget);<br> mymainwindow->show();<br>}<br><br>test::~test()<br>{<br> reader->Delete();<br> imgview->Delete();<br> blank->Delete();<br>}<br><br>void test::OnLoad()<br>
{<br> reader->SetDirectoryName(dirname.c_str());<br> reader->Update();<br> imgview->SetInput(reader->GetOutput());<br> imgview->GetRenderer()->ResetCamera();<br> vtkwidget->update();<br>
}<br><br>void test::OnUnLoad()<br>{<br> imgview->GetRenderer()->RemoveAllViewProps();<br> imgview->GetRenderer()->ResetCamera();<br> vtkwidget->update();<br>}<br><br>void test::OnBrowse()<br>{<br> QString indirectory = QFileDialog::getExistingDirectory(this->centralwidget,tr("Select Input Directory"), QDir::currentPath());<br>
dirname = indirectory.toStdString();<br>}<br><br>-----main.cpp---------<br>#include "test.h"<br>void main(int argc, char *argv[])<br>{<br> QApplication app(argc, argv);<br> test *mywin = new test;<br> app.exec();<br>
<br>}<br><br>