[Insight-users] Dynamic casting between itk smart pointers

Anja Ende anja.ende at googlemail.com
Mon Feb 25 11:49:34 EST 2008


Thanks guys!

On 25/02/2008, Tomáš Kazmar <Tomash.Kazmar at seznam.cz> wrote:
>
> 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
>
> #
> #
> #
>



-- 
Cheers,

Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20080225/243db11d/attachment.html


More information about the Insight-users mailing list