Hi Lars,<br><br>Thanks a lot. All of the solutions that you suggested worked. Is any one approach faster than the other?<br><br>Thanks again.<br>Ashish<br><br><div class="gmail_quote">On Sat, Nov 21, 2009 at 12:46 AM, lars-friedrich <span dir="ltr"><<a href="mailto:lars-friedrich@gmx.net" target="_blank">lars-friedrich@gmx.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Hi Ashish,<br>
<br>
<br>
I think I can suggest some possible solutions to your problem with<br>
vtkImageViewer2-handling:<br>
<br>
<br>
1. the easiest thing may be to use your 'blank'-image instead of removing<br>
the view-props of the renderer; I mean, you did already implement it in<br>
order to overcome the broken pipeline problem vtkImageViewer2 usually causes<br>
at situations when its input is NULL ...; e.g. do this in the unload-slot:<br>
{<br>
//imgview->GetRenderer()->RemoveAllViewProps(); // forget about that<br>
imgview->SetInput(blank); // simply set the blank input again<br>
<div> imgview->GetRenderer()->ResetCamera();<br>
vtkwidget->update();<br>
}<br>
<br>
<br>
</div>2. the problem with removing the renderer's view props is that<br>
vtkImageViewer2 does not automatically add the view props again - you must<br>
either do this (a) manually or (b) re-trigger the internal<br>
InstallPipeline-method<br>
<br>
(a)<br>
load-slot:<br>
<div>{<br>
reader->SetDirectoryName(dirname.c_str());<br>
reader->Update();<br>
imgview->SetInput(reader->GetOutput());<br>
</div> if (!imgview->GetRenderer()->HasViewProp(imgview->GetImageActor())) //<br>
manually check whether we've to re-add the actor<br>
imgview->GetRenderer()->AddViewProp(imgview->GetImageActor());<br>
<div> imgview->GetRenderer()->ResetCamera();<br>
vtkwidget->update();<br>
}<br>
</div>unload-slot:<br>
{<br>
//imgview->GetRenderer()->RemoveAllViewProps();<br>
imgview->GetRenderer()->RemoveViewProp(imgview->GetImageActor()); //<br>
remove vtkImageViewer's specific actor<br>
<div> imgview->GetRenderer()->ResetCamera();<br>
vtkwidget->update();<br>
}<br>
<br>
<br>
</div>(b)<br>
load-slot:<br>
<div>{<br>
reader->SetDirectoryName(dirname.c_str());<br>
reader->Update();<br>
imgview->SetInput(reader->GetOutput());<br>
<br>
</div> imgview->SetRenderWindow(NULL); // internal call of UninstallPipeline()<br>
is for example triggered by re-setting render window ...<br>
imgview->SetRenderWindow(vtkwidget->GetRenderWindow());<br>
<div><br>
imgview->GetRenderer()->ResetCamera();<br>
vtkwidget->update();<br>
}<br>
</div>unload-slot:<br>
{<br>
//imgview->GetRenderer()->RemoveAllViewProps();<br>
imgview->GetRenderer()->RemoveViewProp(imgview->GetImageActor()); //<br>
remove vtkImageViewer's specific actor<br>
<div> imgview->GetRenderer()->ResetCamera();<br>
vtkwidget->update();<br>
}<br>
<br>
<br>
<br>
<br>
</div>HTH,<br>
<br>
lars<br>
<div><div></div><div><br>
<br>
<br>
<br>
Ashish Singh-4 wrote:<br>
><br>
> Hi,<br>
><br>
> I am trying to display each slice from a series of CT scans in a<br>
> QVTKwidget.<br>
> The QVTKWidget itself is in a QMainWindow with 3 other widgets to browse,<br>
> load and unload the data. I want to be able to display the data in<br>
> QVTKwidget as soon as I hit the load button. I also want to be able to<br>
> unload the data and clear the QVTKwidget as soon as I hit the unload<br>
> button<br>
> 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<br>
> unload<br>
> the data, but after unload when I try to load new data it doesn't show up<br>
> in<br>
> my QVTKwidget. Can anyone please tell me what am I missing or doing wrong<br>
> 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,<br>
> SLOT(OnBrowse()));<br>
><br>
> myloadbutton->setText("Load");<br>
> this->connect(this->myloadbutton,SIGNAL(clicked()),this,<br>
> SLOT(OnLoad()));<br>
><br>
> myunloadbutton->setText("Unload");<br>
><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 =<br>
> QFileDialog::getExistingDirectory(this->centralwidget,tr("Select Input<br>
> 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>
</div></div><div>> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at:<br>
> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>
><br>
<br>
</div><font color="#888888">--<br>
View this message in context: <a href="http://old.nabble.com/QVTK-issue-with-vtkImageViewer2-tp26429989p26454127.html" target="_blank">http://old.nabble.com/QVTK-issue-with-vtkImageViewer2-tp26429989p26454127.html</a><br>
</font><div><div></div><div>Sent from the VTK - Users mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br>