<br>Hi Xiaopeng,<br><br>It is likely that the source of the error is that<br>you are instantiating ITK objects inside your<br>constructor, but not associating them to <br>member variables of the "SimpleView" class.<br>
<br>Therefore, these ITK objects will be destroyed<br>by the time you get to the closing bracket of<br>your class constructor (the end of scope).<br><br><br>The typical solution here,<br>is that you should make:<br><br><p class="MsoNormal" style="">
<span style="font-size: 10pt; font-family: DotumChe;"> ReaderType::Pointer reader;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> FilterType::Pointer connector;</span></p><p class="MsoNormal" style=""><br><span style="font-size: 10pt; font-family: DotumChe;"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;">to be member variables of your class (move them to <br></span></p><p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;">declaration of the SimpleView class in your header file)</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;">and instantiate them in the constructor as</span></p><p class="MsoNormal" style=""><br><span style="font-size: 10pt; font-family: DotumChe;"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> this->reader = ReaderType::New();</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> this->connector = FilterType::New();</span></p><br><br>In this way, they will stay alive for the lifetime<br>of the SimpleView class.<br>
<br><br><br> Regards,<br><br><br> Luis<br><br><br>-----------------------------------------------------------------<br><div class="gmail_quote">On Tue, Jun 15, 2010 at 10:06 AM, Xiaopeng Yang <span dir="ltr"><<a href="mailto:yxp233@postech.ac.kr">yxp233@postech.ac.kr</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;"><div><div></div><div class="h5">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal">Dear VTK users,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> 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?</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;">SimpleView::SimpleView() </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;">{</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> <span style="color: blue;">this</span>->ui = <span style="color: blue;">new</span> Ui_SimpleView;</span></p>
<p class="MsoNormal" style="text-indent: 10.5pt;"><span style="font-size: 10pt; font-family: DotumChe; color: blue;">this</span><span style="font-size: 10pt; font-family: DotumChe;">->ui->setupUi(<span style="color: blue;">this</span>);</span></p>
<p class="MsoNormal" style="text-indent: 10.5pt;"> </p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe; color: green;">//Define ITK DICOM loader</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> <span style="color: blue;">typedef</span> itk::Image
<<span style="color: blue;">unsigned</span> <span style="color: blue;">short</span>,
2> ImageType;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> <span style="color: blue;">typedef</span>
itk::ImageFileReader<ImageType>ReaderType;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> <span style="color: green;">//Connect ITK to VTK</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> <span style="color: blue;">typedef</span>
itk::ImageToVTKImageFilter<ImageType>FilterType;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> ReaderType::Pointer reader = ReaderType::New();</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> FilterType::Pointer connector = FilterType::New();</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> reader->SetFileName(<span style="color: rgb(163, 21, 21);">"C:/Documents
and Settings/edt/Desktop/QT Test3/ImageViewer/DICOM/portal47.dcm"</span>);</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> connector->SetInput(reader->GetOutput());</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> </span></p>
<p class="MsoNormal" style="text-indent: 10.5pt;"><span style="font-size: 10pt; font-family: DotumChe;">vtkImageViewer *viewer = vtkImageViewer::New();</span></p>
<p class="MsoNormal" style="text-indent: 10.5pt;"><span style="font-size: 10pt; font-family: DotumChe;"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe; color: green;"> </span><span style="font-size: 10pt; font-family: DotumChe; color: blue;">this</span><span style="font-size: 10pt; font-family: DotumChe;">->ui->qvtkWidget_2->SetRenderWindow(viewer->GetRenderWindow());</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> viewer->SetupInteractor(<span style="color: blue;">this</span>->ui->qvtkWidget_2->GetRenderWindow()->GetInteractor());</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> viewer->SetInput(connector->GetOutput());</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> viewer->Render();</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> viewer->SetColorLevel(255);</span></p>
<p class="MsoNormal" style="text-indent: 10.5pt;"><span style="font-size: 10pt; font-family: DotumChe;">viewer->SetColorWindow(128);</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> connect(<span style="color: blue;">this</span>->ui->actionOpenFile,
SIGNAL(triggered()), <span style="color: blue;">this</span>,
SLOT(slotOpenFile()));</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> connect(<span style="color: blue;">this</span>->ui->actionExit,
SIGNAL(triggered()), <span style="color: blue;">this</span>, SLOT(slotExit()));</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;">};</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: DotumChe;"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;">Thanks.</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt;">Xiaopeng</span><span></span></p>
</div>
</div>
</div></div><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>
<br></blockquote></div><br>