Re: [Insight-users] Dynamic casting between itk smart pointers

Tomáš Kazmar Tomash.Kazmar at seznam.cz
Mon Feb 25 10:29:39 EST 2008


Hi,

  try to cast the actual pointer (not the smart pointer), like this:

ExtractImageFilterTypePointer extractImageFilter
 = dynamic_cast<ExtractImageFilterType *>(m_extractImageFilter.GetPointer());

Tomas

# 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
# 
# 
# 


More information about the Insight-users mailing list