[vtkusers] QVTKwidget issue

Clinton Stimpson clinton at elemtech.com
Fri Mar 13 16:57:57 EDT 2009


You need to update the view when you change the data.
You can add a call to  vtkRenderWindow::Render() or preferably a call to 
QVTKWidget::update() in your OnLoad().

Clint

Ashish Singh 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 2 other 
> widgets to browse and load the data. I want to be able to display the 
> data in QVTKwidget as soon as I hit the load button. I can read the 
> data fine, but it doesn't display in QVTKwidget until I click or 
> interact with QVTKwidget using mouse. Can anyone please tell me what 
> am I missing here?
>
> I am working on a Windows system and using VTK version 5.2.1 with 
> Visual Studio 2005 and Qt 4.5
>
> Thanks,
> Ashish
>
> Here's my code:
> ------header file----
> #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"
>
> using namespace std;
>
> class test : public QObject
> {
>     Q_OBJECT
>
> public:
>     string dirname;
>     vtkDICOMImageReader *reader;
>     vtkImageViewer2 *imgview;
>
>     QMainWindow *mymainwindow;
>     QWidget *centralwidget;
>     QLabel *mylabel;
>     QPushButton *mypbutton;
>     QPushButton *myloadbutton;
>     QVTKWidget *vtkwidget;
>     QHBoxLayout *myhlayout;
>     QVBoxLayout *myvlayout;
>     test(QObject* parent = 0);
>     ~test();
>
>
>     public slots:
>         void OnLoad();
>         void OnBrowse();
>
> };
> ------cpp file------
> #include "test.h"
> test::test(QObject * parent):QObject(parent)
> {
>     reader = vtkDICOMImageReader::New();
>     imgview = vtkImageViewer2::New();
>
>     mymainwindow = new QMainWindow();
>     centralwidget = new QWidget(mymainwindow);
>
>     mylabel = new QLabel(centralwidget);
>     mypbutton = new QPushButton(centralwidget);
>     myloadbutton = 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->mypbutton,SIGNAL(clicked()),this, SLOT(OnLoad()));
>
>     myhlayout->addWidget(mylabel);
>     myhlayout->addWidget(mypbutton);
>     myhlayout->addWidget(myloadbutton);
>
>     myvlayout->addLayout(myhlayout);
>     myvlayout->addWidget(vtkwidget);
>
>     centralwidget->setLayout(myvlayout);
>     mymainwindow->setCentralWidget(centralwidget);
>     mymainwindow->show();
> }
>
> test::~test()
> {
>     reader->Delete();
>     imgview->Delete();
> }
>
> void test::OnLoad()
> {
>     reader->SetDirectoryName("D:\\testimages\\dicomset\\test");
>     reader->Update();
>
>     imgview->SetInput(reader->GetOutput());
>     imgview->GetRenderer()->ResetCamera();
>
> }
>
> 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
>   




More information about the vtkusers mailing list