<div>On Thu, Oct 7, 2010 at 4:42 PM, Jothy <span dir="ltr">&lt;<a href="mailto:jothybasu@gmail.com">jothybasu@gmail.com</a>&gt;</span> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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)">&lt;vtkImageData.h&gt;</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)">&lt;QString&gt;</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">&quot;mydcmimporter.h&quot;</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)">&lt;QFileDialog&gt;</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)">&lt;QString&gt;</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)">&lt;vtkDICOMImageReader.h&gt;</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)">&lt;vtkSmartPointer.h&gt;</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)">&lt;QDebug&gt;</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)">&lt;</span>vtkDICOMImageReader<span style="color:rgb(0, 0, 0)">&gt;</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)">&lt;</span>vtkDICOMImageReader<span style="color:rgb(0, 0, 0)">&gt;::</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)">-&gt;</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)">-&gt;</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)">-&gt;</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)">-&gt;</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)">-&gt;</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-&gt;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)">()&lt;&lt;</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)">]&lt;&lt;</span><span style="color:rgb(0, 128, 0)">&quot;running...&quot;</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>This function is supposed to return a vtkImageData*, but there is no &#39;return&#39; statement!</div>
<div><br></div><div>vtkImageData* myDcmImporter::readImage()</div><div>{</div><div>    QString imageDirName=QFileDialog::getExistingDirectory();</div><div>    vtkSmartPointer &lt;vtkDICOMImageReader&gt; reader=</div><div>
            vtkSmartPointer&lt;vtkDICOMImageReader&gt;::New();</div><div>    reader-&gt;SetDirectoryName(imageDirName.toLatin1());</div><div>    reader-&gt;Update();</div><div>    this-&gt;imageData= reader-&gt;GetOutput();</div>
<div>}</div><div><br></div><div>However, I don&#39;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&lt;vtkImageData&gt; imageData;</div><div><br></div><div>I&#39;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-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; ">
myDcmImporter<span style="color: rgb(0, 0, 0); ">::</span>myDcmImporter<span style="color: rgb(0, 0, 0); ">()</span></pre><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; ">
<span style="color: rgb(0, 0, 0); ">{</span></pre><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; "><span style="color: rgb(0, 0, 0); ">  this-&gt;imageData = vtkImageData::New();</span></pre>
<pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; "><span style="color: rgb(0, 0, 0); ">}</span></pre></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12.5px; border-collapse: collapse; "><pre style="white-space: pre-wrap; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; ">
<span style="color: rgb(0, 0, 0); "><br></span></pre><pre style="white-space: pre-wrap; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; ">
<span style="color: rgb(0, 0, 0); ">Then instead of assigning the pointer:</span></pre><pre style="white-space: pre-wrap; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; ">
<span style="color: rgb(0, 0, 0); "><br></span></pre><pre style="white-space: pre-wrap; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; ">
<span style="color: rgb(0, 0, 0); "><span class="Apple-style-span" style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small; ">    this-&gt;imageData= reader-&gt;GetOutput();</span></span></pre>
<pre style="white-space: pre-wrap; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; "><span style="color: rgb(0, 0, 0); "><span class="Apple-style-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-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; "><span style="color: rgb(0, 0, 0); "><span class="Apple-style-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-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; "><span style="color: rgb(0, 0, 0); "><span class="Apple-style-span" style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12.5px; border-collapse: collapse; "><pre style="white-space: pre-wrap; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; ">
<span style="color: rgb(0, 0, 0); "><span class="Apple-style-span" style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small; ">    this-&gt;imageData-&gt;ShallowCopy(reader-&gt;GetOutput());</span></span></pre>
<pre style="white-space: pre-wrap; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; "><span style="color: rgb(0, 0, 0); "><span class="Apple-style-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-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; ">
<span style="color: rgb(0, 0, 0); "><span class="Apple-style-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-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; font-family: &#39;courier new&#39;, monospace; "><font class="Apple-style-span" face="arial"><span class="Apple-style-span" style="border-collapse: separate; white-space: normal; font-size: small;"><br>
</span></font></pre></span></div><div>David </div></div>