[Insight-users] Dynamic casting between itk smart pointers

Anja Ende anja.ende at googlemail.com
Mon Feb 25 09:41:10 EST 2008


Hi all,

Sorry been bugging this list with questions today but just started out with
ITK and am having some troubles...

I have a class which has a member of itk::ProcessObject::Pointer type
(m_extractImageFilter).

Now, at some point it gets set to an itk::ExtractImageFilterType as follows:

typedef typename itk::ExtractImageFilter<InputImageType, OutputImageType>
ExtractImageFilterType;
typedef typename ExtractImageFilterType::Pointer
ExtractImageFilterTypePointer;
ExtractImageFilterTypePointer extractImageFilter =
ExtractImageFilterType::New();
m_extractImageFilter = extractImageFilter;

Now again, at some point in the code, I want to cast it back and I try to do
the following:

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

The last line however fails with the following error:

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)

Any ideas how I might safely do this?

Cheers,

Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20080225/1ed4c027/attachment.htm


More information about the Insight-users mailing list