On 2/25/08, <b class="gmail_sendername">Anja Ende</b> <<a href="mailto:anja.ende@googlemail.com">anja.ende@googlemail.com</a>> 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<InputImageType, OutputImageType> 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<InputImageType, OutputImageType> ExtractImageFilterType;<br>typedef typename ExtractImageFilterType::Pointer ExtractImageFilterTypePointer;<br>ExtractImageFilterTypePointer extractImageFilter = dynamic_cast<ExtractImageFilterTypePointer>(m_extractImageFilter);<br>
<br>The last line however fails with the following error:<br><br>error: cannot dynamic_cast '((ITK2VTK*)this)->ITK2VTK::m_extractImageFilter' (of type 'class itk::SmartPointer<itk::ProcessObject>') to type 'class itk::SmartPointer<itk::ExtractImageFilter<itk::Image<double, 4u>, itk::Image<double, 3u> > >' (target is not pointer or reference)</blockquote>
<div><br>You cannot dynamic_cast class A < X > to A < Y > in C++ , even if Y derives from X. However you can certainly downcast X to Y.<br><br>So what you can do is.<br><br>ExtractImageFilterType * e = dynamic_cast< ExtractImageFilterType* >( 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>