[Insight-users] Can't cast RescaleIntensityImageFilter to ImageToImageFilter ?

Luis Ibanez luis.ibanez at kitware.com
Tue Jun 30 13:40:27 EDT 2009


Hi Charlotte,


         Yes, your intuition is right.


    Calling Register() in ITK is a bad idea.


What you want to do is actually a lot simpler.

   A) Use a Raw pointer for doing the casting  and

   B) Just after casting assign the pointer to a
        SmartPointer. The operator assignment
        of the SmartPointer will do the Register
        calls for you.



  Regards,


         Luis


-----------------------------------------------------
On Thu, Jun 25, 2009 at 12:56 PM, Charlotte Curtis <c.f.curtis at gmail.com>wrote:

> On Sat, Jun 20, 2009 at 6:38 PM, motes motes<mort.motes at gmail.com> wrote:
> > cannot convert from 'itk::SmartPointer<TObjectType>' to
> > 'itk::SmartPointer<TObjectType>'
> >
> > But as I understand ImageToImageFilter is a base class for
> > RescaleIntensityImageFilter so I don't see why I get this error, but
> maybe
> > my C++ skills are a bit rusty.
>
> I've also been working on casting to the base class lately and one
> thing that I've discovered is that you need to cast to a raw pointer
> instead of a smart pointer (like Luis said).  Maybe try:
>
> ImageToImageFilterType *pp1 = static_cast<ImageToImageFilterType *>(pp0);
>
> However, if you do that you might get a seg fault from the filter
> going out of scope (assuming pp0 is created in the function as a smart
> pointer and is not a member variable).  The workaround for this that
> I've found (and I'm sure it's a terrible hack) is to artificially
> increase the reference count before casting to the base class by first
> calling:
>
> pp0->Register();
>
> Of course, if there's a better way to be doing this, I'd love to hear
> about it too.
>
> Charlotte
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090630/c9b5fda9/attachment-0001.htm>


More information about the Insight-users mailing list