[Insight-developers] Downcasting smartpointers

Matthew McCormick (thewtex) matt at mmmccormick.com
Mon Aug 30 14:36:25 EDT 2010


On Mon, Aug 30, 2010 at 1:02 PM, Antonin Perrot-Audet <
antonin07130 at gmail.com> wrote:

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

Oops -- thanks for the correction on changing the type to convert to.


>
> But then, I am not really manipulating a smart pointer, am I ?
>
>
No, as far as I know, the casting operators can only be performed on raw
pointers instead of SmartPointer objects.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20100830/07ca3743/attachment.htm>


More information about the Insight-developers mailing list