[Insight-developers] Downcasting smartpointers

Antonin Perrot-Audet antonin07130 at gmail.com
Mon Aug 30 14:02:33 EDT 2010


  Hello Matt,

On 8/30/10 1:45 PM, Matthew McCormick (thewtex) wrote:
> Hey Antonin
>
> On Mon, Aug 30, 2010 at 12:33 PM, Antonin Perrot-Audet 
> <antonin07130 at gmail.com <mailto:antonin07130 at gmail.com>> wrote:
>
>     Hello,
>     I am trying to cast a processObject to an itkfilter, and couldn't
>     manage to, here is the type of conversion I try to perform :
>
>     typedef itk::ImageToVTKImageFilter<InputImageType>::Pointer 
>     itkFilterPointerType;
>     typedef itk::ProcessObject::Pointer itkProcessObjectPointerType;
>
>     itkProcessObjectPointerType m_filter = itkFilterPointerType::New();
>
>     ( dynamic_cast<itkFilterPointerType>(itkFilterPointerType)
>     )->SetInput(..etc...etc...
>
>
> How about this:
>  ( dynamic_cast<itkFilterPointerType>(m_filter.GetPointer()) 
> )->SetInput(..etc...etc...

thanks for your answer,
but m_filter.GetPointer() returns an 
itk::ImageToVTKImageFilter<InputImageType>* and not a 
itk::ImageToVTKImageFilter<InputImageType>::Pointer ,
so that I still get a cast error (cant cast from smart pointer to 
pointer), but,
that works :

typedef itk::ImageToVTKImageFilter<InputImageType> itkFilterType;
( dynamic_cast<itkFilterType*>(m_filter.GetPointer()) 
)->SetInput(..etc...etc...

But then, I am not really manipulating a smart pointer, am I ?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20100830/b91b0f46/attachment.htm>


More information about the Insight-developers mailing list