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

Charlotte Curtis c.f.curtis at gmail.com
Thu Jun 25 12:56:06 EDT 2009


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


More information about the Insight-users mailing list