<div dir="ltr">Excellent!<br><br>vtkSmartPointer<vtkImageData> imageData; is working.<br><br>Thank you<br><br>Jothy<br><br><div class="gmail_quote">On Fri, Oct 8, 2010 at 3:25 AM, David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com">daviddoria@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div class="h5"><div>On Thu, Oct 7, 2010 at 4:42 PM, Jothy <span dir="ltr"><<a href="mailto:jothybasu@gmail.com" target="_blank">jothybasu@gmail.com</a>></span> wrote:</div>
</div></div><div class="gmail_quote"><div><div></div><div class="h5"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div dir="ltr">Hi Guys,<br><br>I am trying to create a c++ class to read a dicom image set. But,my app is crashing with out any errors during building.<br><br>here is the header and source of that class, I am using Qt creator.<br>
<br>Header:<br><br><span style="color: rgb(0, 0, 128); font-family: courier new,monospace;">#ifndef</span><span style="color: rgb(192, 192, 192); font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;">MYDCMIMPORTER_H
</span><pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 128);">#define</span><span style="color: rgb(192, 192, 192);"> </span>MYDCMIMPORTER_H</pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 128);">#include</span><span style="color: rgb(0, 128, 0);"><vtkImageData.h></span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 128);">#include</span><span style="color: rgb(0, 128, 0);"><QString></span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(128, 128, 0);">class</span><span style="color: rgb(192, 192, 192);"> </span>myDcmImporter</pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 0);">{</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(128, 128, 0);">public</span><span style="color: rgb(0, 0, 0);">:</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span>myDcmImporter<span style="color: rgb(0, 0, 0);">();</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span>vtkImageData<span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(192, 192, 192);"> </span>imageData<span style="color: rgb(0, 0, 0);">;</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span>vtkImageData<span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(192, 192, 192);"> </span>readImage<span style="color: rgb(0, 0, 0);">();</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 0);">};</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 128);">#endif</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">MYDCMIMPORTER_H</span></pre>
<pre style="margin: 0px; text-indent: 0px;"><br></pre>Source:<br><span style="color: rgb(0, 0, 128); font-family: courier new,monospace;">#include</span><span style="color: rgb(192, 192, 192); font-family: courier new,monospace;"> </span><span style="color: rgb(0, 128, 0); font-family: courier new,monospace;">"mydcmimporter.h"</span>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 128);">#include</span><span style="color: rgb(0, 128, 0);"><QFileDialog></span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 128);">#include</span><span style="color: rgb(0, 128, 0);"><QString></span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 128);">#include</span><span style="color: rgb(0, 128, 0);"><vtkDICOMImageReader.h></span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 128);">#include</span><span style="color: rgb(0, 128, 0);"><vtkSmartPointer.h></span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 128);">#include</span><span style="color: rgb(0, 128, 0);"><QDebug></span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;">myDcmImporter<span style="color: rgb(0, 0, 0);">::</span>myDcmImporter<span style="color: rgb(0, 0, 0);">()</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 0);">{</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 0);">}</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;">vtkImageData<span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(192, 192, 192);"> </span>myDcmImporter<span style="color: rgb(0, 0, 0);">::</span>readImage<span style="color: rgb(0, 0, 0);">()</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 0);">{</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(128, 0, 128);">QString</span><span style="color: rgb(192, 192, 192);"> </span>imageDirName<span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(128, 0, 128);">QFileDialog</span><span style="color: rgb(0, 0, 0);">::</span>getExistingDirectory<span style="color: rgb(0, 0, 0);">();</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span>vtkSmartPointer<span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 0, 0);"><</span>vtkDICOMImageReader<span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(192, 192, 192);"> </span>reader<span style="color: rgb(0, 0, 0);">=</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span>vtkSmartPointer<span style="color: rgb(0, 0, 0);"><</span>vtkDICOMImageReader<span style="color: rgb(0, 0, 0);">>::</span>New<span style="color: rgb(0, 0, 0);">();</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span>reader<span style="color: rgb(0, 0, 0);">-></span>SetDirectoryName<span style="color: rgb(0, 0, 0);">(</span>imageDirName<span style="color: rgb(0, 0, 0);">.</span>toLatin1<span style="color: rgb(0, 0, 0);">());</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span>reader<span style="color: rgb(0, 0, 0);">-></span>Update<span style="color: rgb(0, 0, 0);">();</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(128, 128, 0);">this</span><span style="color: rgb(0, 0, 0);">-></span>imageData<span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(192, 192, 192);"> </span>reader<span style="color: rgb(0, 0, 0);">-></span>GetOutput<span style="color: rgb(0, 0, 0);">();</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 0, 0);">}</span></pre>
<pre style="margin: 0px; text-indent: 0px;"><br></pre>App crashes only while executing <br><br><span style="font-family: courier new,monospace;">myDcmImporter</span><span style="color: rgb(192, 192, 192); font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;">dcmImporter</span><span style="color: rgb(0, 0, 0); font-family: courier new,monospace;">;</span>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span>dcmImporter<span style="color: rgb(0, 0, 0);">.</span>readImage<span style="color: rgb(0, 0, 0);">();</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">vtkImageData</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">*img=dcmImporter.imageData;</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(128, 128, 0);">int</span><span style="color: rgb(192, 192, 192);"> </span>dims<span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 128);">3</span><span style="color: rgb(0, 0, 0);">];</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span>dcmImporter<span style="color: rgb(0, 0, 0);">.</span>imageData<span style="color: rgb(0, 0, 0);">-></span>GetDimensions<span style="color: rgb(0, 0, 0);">(</span>dims<span style="color: rgb(0, 0, 0);">);</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">dcmImporter.imageData->GetDimensions(dims);</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: courier new,monospace;"><span style="color: rgb(192, 192, 192);"> </span>qDebug<span style="color: rgb(0, 0, 0);">()<<</span>dims<span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 128);">0</span><span style="color: rgb(0, 0, 0);">]<<</span><span style="color: rgb(0, 128, 0);">"running..."</span><span style="color: rgb(0, 0, 0);">;</span></pre>
<br clear="all">Since I am new to c++, could be a silly mistake somewhere.<br><br>Thank you<br><br>Jothy<br></div><div dir="ltr"><br></div></blockquote><div><br></div></div></div><div>This function is supposed to return a vtkImageData*, but there is no 'return' statement!</div>
<div class="im">
<div><br></div><div>vtkImageData* myDcmImporter::readImage()</div><div>{</div><div> QString imageDirName=QFileDialog::getExistingDirectory();</div><div> vtkSmartPointer <vtkDICOMImageReader> reader=</div><div>
vtkSmartPointer<vtkDICOMImageReader>::New();</div><div> reader->SetDirectoryName(imageDirName.toLatin1());</div><div> reader->Update();</div><div> this->imageData= reader->GetOutput();</div>
<div>}</div><div><br></div></div><div>However, I don't think this is the problem because you call the function without asking for its return value anyway.</div><div><br></div><div>What may be happening is that the reader smart pointer is going out of scope. I think you could fix this in two ways</div>
<div><br></div><div>1) Change the member</div><div>vtkImageData* imageData;</div><div>to</div><div>vtkSmartPointer<vtkImageData> imageData;</div><div><br></div><div>I'm not sure, but that might make the reader pointer hang around longer.</div>
<div><br></div><div>2) (this will definitely work)</div><div>Create the imageData object in the constructor:</div><div><br></div><div><pre style="margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;">
myDcmImporter<span style="color: rgb(0, 0, 0);">::</span>myDcmImporter<span style="color: rgb(0, 0, 0);">()</span></pre><pre style="margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><span style="color: rgb(0, 0, 0);">{</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><span style="color: rgb(0, 0, 0);"> this->imageData = vtkImageData::New();</span></pre>
<pre style="margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><span style="color: rgb(0, 0, 0);">}</span></pre></div><div><span style="font-family: arial,sans-serif; font-size: 12.5px; border-collapse: collapse;"><pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;">
<span style="color: rgb(0, 0, 0);"><br></span></pre><pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><span style="color: rgb(0, 0, 0);">Then instead of assigning the pointer:</span></pre>
<pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><span style="color: rgb(0, 0, 0);"><br></span></pre><pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;">
<span style="color: rgb(0, 0, 0);"><span style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small;"> this->imageData= reader->GetOutput();</span></span></pre>
<pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><span style="color: rgb(0, 0, 0);"><span style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small;"><br>
</span></span></pre><pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><span style="color: rgb(0, 0, 0);"><span style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small;">actually copy the output of the filter:</span></span></pre>
<pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><span style="color: rgb(0, 0, 0);"><span style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small;"><span style="font-family: arial,sans-serif; font-size: 12.5px; border-collapse: collapse;"><pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;">
<span style="color: rgb(0, 0, 0);"><span style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small;"> this->imageData->ShallowCopy(reader->GetOutput());</span></span></pre>
<pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><span style="color: rgb(0, 0, 0);"><span style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small;"><br>
</span></span></pre></span></span></span></pre><pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><span style="color: rgb(0, 0, 0);"><span style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small;">Give those a shot and let us know if you have any luck.</span></span></pre>
<pre style="white-space: pre-wrap; margin: 0px; text-indent: 0px; font-family: 'courier new',monospace;"><font face="arial"><span style="border-collapse: separate; white-space: normal; font-size: small;"><br>
</span></font></pre></span></div><div>David </div></div>
</blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr">Research Scholar<br>Dept. of Medical Physics<br>Clatterbridge Centre for Oncology<br>UK<br></div><br>
</div>