On 2/25/08, <b class="gmail_sendername">Anja Ende</b> &lt;<a href="mailto:anja.ende@googlemail.com">anja.ende@googlemail.com</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br><br>Sorry been bugging this list with questions today but just started out with ITK and am having some troubles...<br><br>I have a class which has a member of itk::ProcessObject::Pointer type (m_extractImageFilter).<br>

<br>Now, at some point it gets set to an itk::ExtractImageFilterType as follows:<br><br>typedef typename itk::ExtractImageFilter&lt;InputImageType, OutputImageType&gt; ExtractImageFilterType;<br>typedef typename ExtractImageFilterType::Pointer ExtractImageFilterTypePointer;<br>

ExtractImageFilterTypePointer extractImageFilter = ExtractImageFilterType::New(); <br>m_extractImageFilter = extractImageFilter;<br><br>Now again, at some point in the code, I want to cast it back and I try to do the following:<br>

<br>typedef typename itk::ExtractImageFilter&lt;InputImageType, OutputImageType&gt; ExtractImageFilterType;<br>typedef typename ExtractImageFilterType::Pointer ExtractImageFilterTypePointer;<br>ExtractImageFilterTypePointer extractImageFilter = dynamic_cast&lt;ExtractImageFilterTypePointer&gt;(m_extractImageFilter);<br>

<br>The last line however fails with the following error:<br><br>error: cannot dynamic_cast &#39;((ITK2VTK*)this)-&gt;ITK2VTK::m_extractImageFilter&#39; (of type &#39;class itk::SmartPointer&lt;itk::ProcessObject&gt;&#39;) to type &#39;class itk::SmartPointer&lt;itk::ExtractImageFilter&lt;itk::Image&lt;double, 4u&gt;, itk::Image&lt;double, 3u&gt; &gt; &gt;&#39; (target is not pointer or reference)</blockquote>
<div><br>You cannot dynamic_cast class A &lt; X &gt; to&nbsp; A &lt; Y &gt; in C++ , even if Y derives from X.&nbsp; However you can certainly downcast X to Y.<br><br>So what you can do is.<br><br>ExtractImageFilterType * e = dynamic_cast&lt; ExtractImageFilterType* &gt;( m_extractImageFilter.GetPointer() );<br>
ExtractImageFilterTypePointer extractImageFilter = e;<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Any ideas how I might safely do this?<br>
<br>Cheers,<br><span class="sg"><br>Anja
</span><br>_______________________________________________<br>
Insight-users mailing list<br>
<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Insight-users@itk.org">Insight-users@itk.org</a><br>
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div>