[Insight-users] [vtkusers] About DICOM loading with VTK, ITK and QT

Luis Ibanez luis.ibanez at kitware.com
Tue Jul 13 18:35:51 EDT 2010


Hi Xiaopeng,

Please post some of the error messages
to the mailing list.

We can't help you much if we can't see the
error messages...


    Thanks


          Luis


-----------------------------------------------------------
2010/7/12 Xiaopeng Yang <yxp233 at postech.ac.kr>

>  Hi Luis,
>
>
>
> Thanks very much for your help. I tried again according to your suggestion,
> but I met many errors. Attached is my header file of SimpleView, where shall
> I modify? And at the main code, what I need to do is that just changing them
> to
>
>   this->reader = ReaderType::New();
>
> this->connector = FilterType::New();
>
> Is there anything else I shall modify in the main code?
>
>
>
>
>
> Attached is the header file:
>
>
>
> #ifndef SimpleView_H
>
> #define SimpleView_H
>
>
>
> #include "vtkSmartPointer.h"    // Required for smart pointer internal
> ivars.
>
> #include <QMainWindow>
>
>
>
> QT_BEGIN_NAMESPACE
>
> class QAction;
>
> class QLabel;
>
> class QMenu;
>
> class QScrollArea;
>
> class QScrollBar;
>
>
>
> QT_END_NAMESPACE
>
>
>
> // Forward Qt class declarations
>
> class Ui_SimpleView;
>
>
>
> // Forward VTK class declarations
>
> class vtkQtTableView;
>
>
>
>
>
> class SimpleView : public QMainWindow
>
> {
>
>   Q_OBJECT
>
>
>
> public:
>
>
>
>   // Constructor/Destructor
>
>   SimpleView();
>
>   ~SimpleView();
>
>
>
> public slots:
>
>
>
>   virtual void slotOpenFile();
>
>   virtual void slotExit();
>
>
>
> protected:
>
>
>
>
>
> protected slots:
>
>
>
> private:
>
>
>
>   vtkSmartPointer<vtkQtTableView>         TableView;
>
>
>
>   // Designer form
>
>   Ui_SimpleView *ui;
>
> };
>
>
>
> #endif // SimpleView_H
>
>
>
>
>
>
>
> *发件人**:* Luis Ibanez [mailto:luis.ibanez at kitware.com]
> *发送时间:* Thursday, June 17, 2010 11:53 PM
> *收件人:* Xiaopeng Yang
> *抄送:* vtkusers at vtk.org; itk
> *主题:* Re: [vtkusers] About DICOM loading with VTK, ITK and QT
>
>
>
>
> Hi Xiaopeng,
>
> It is likely that the source of the error is that
> you are instantiating ITK objects inside your
> constructor, but not associating them to
> member variables of the "SimpleView" class.
>
> Therefore, these ITK objects will be destroyed
> by the time you get to the closing bracket of
> your class constructor (the end of scope).
>
>
> The typical solution here,
> is that you should make:
>
>   ReaderType::Pointer reader;
>
>   FilterType::Pointer connector;
>
>
>
> to be member variables of your class (move them to
>
> declaration of the SimpleView class in your header file)
>
> and instantiate them in the constructor as
>
>
>
>   this->reader = ReaderType::New();
>
>   this->connector = FilterType::New();
>
>
>
> In this way, they will stay alive for the lifetime
> of the SimpleView class.
>
>
>
>      Regards,
>
>
>           Luis
>
>
> -----------------------------------------------------------------
>
> On Tue, Jun 15, 2010 at 10:06 AM, Xiaopeng Yang <yxp233 at postech.ac.kr>
> wrote:
>
> Dear VTK users,
>
>
>
>  I made a simple UI with QT for loading a DICOM image by ITK and visualize
> it by VTK. Even I successfully debugged the code, but when I ran the
> executable file, errors occurred: “An unhandled win32 exception occurred in
> SimpleView.exe [448]”. Could you help me to check whether there is any
> problem in my code?
>
>
>
> SimpleView::SimpleView()
>
> {
>
>   this->ui = new Ui_SimpleView;
>
> this->ui->setupUi(this);
>
>
>
> //Define ITK DICOM loader
>
>   typedef itk::Image <unsigned short, 2> ImageType;
>
>   typedef itk::ImageFileReader<ImageType>ReaderType;
>
>
>
>   //Connect ITK to VTK
>
>   typedef itk::ImageToVTKImageFilter<ImageType>FilterType;
>
>
>
>   ReaderType::Pointer reader = ReaderType::New();
>
>   FilterType::Pointer connector = FilterType::New();
>
>   reader->SetFileName("C:/Documents and Settings/edt/Desktop/QT
> Test3/ImageViewer/DICOM/portal47.dcm");
>
>   connector->SetInput(reader->GetOutput());
>
>
>
> vtkImageViewer *viewer = vtkImageViewer::New();
>
>
>
>   this->ui->qvtkWidget_2->SetRenderWindow(viewer->GetRenderWindow());
>
>   viewer->SetupInteractor(this
> ->ui->qvtkWidget_2->GetRenderWindow()->GetInteractor());
>
>   viewer->SetInput(connector->GetOutput());
>
>   viewer->Render();
>
>   viewer->SetColorLevel(255);
>
> viewer->SetColorWindow(128);
>
>
>
>   connect(this->ui->actionOpenFile, SIGNAL(triggered()), this,
> SLOT(slotOpenFile()));
>
>   connect(this->ui->actionExit, SIGNAL(triggered()), this,
> SLOT(slotExit()));
>
> };
>
>
>
>
>
> Thanks.
>
>
>
> Xiaopeng
>
>
> _______________________________________________
> 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100713/ffa39536/attachment-0001.htm>


More information about the Insight-users mailing list