[Insight-developers] Smart Pointer (continue)

Luis Ibanez luis.ibanez@kitware.com
Thu, 25 Apr 2002 11:27:30 -0400


Hi Yinpeng

The input to the filters should be
of type:

      const ImageType *

So the signature of your SetInput()
function should be:

  void SetInput( const ImageType * )

The reason for the "const" is that a
filter should not modify its input.

The two main reasons for using a
raw pointer instead of the smart
pointer are:

1) It allows polymorphism, so you can
pass an image that derives from ImageType
and that will be accepted. (SmartPointers
don't allow polymorphism directly)

2) Passing a SmartPointer will produce
an extra construction of the smartpointer
which implies a Mutex on the way. It is
not a big performance concern since SetInput()
should be called initially while the pipeline
is set up but nevertheless is an unecessary
operation.



So, the SetInput() method should look like:


void SetInput( const InputImageType * input)
{
   Superclass::SetInput(input);

   // Note that the "Const" iterator must be used here
   itk::ImageRegionConstIteratorWithIndex <InputImageType>
        iit(this->GetInput(),region);
  ....
}


Please let us know if that helps.


Thanks

  Luis



==================================================

Yinpeng Jin wrote:
> I think I should also give the "background":
> I overwrited the SetInput()
> 
> 
> SetInput(InputImagePointer input)
> {
>   Superclass::SetInput(input);
> .......
>   itk::ImageRegionIteratorWithIndex <InputImageType> iit(this->GetInput(),
> region);
>   // compiler error here
> 
> }
> 
> 
> and typedefs in .h:
>   typedef TInputImage InputImageType;
>   typedef typename TInputImage::Pointer InputImagePointer;
> 
> 
> here is the error message again:
> error C2664: '__thiscall itk::ImageRegionIteratorWithIndex<class
> itk::Image<class itk::Vector<unsigned char,3>,2>
> 
>>::itk::ImageRegionIteratorWithIndex<class itk::Image<cl
>>
> ass itk::Vector<unsigned char,3>,2> >(class itk::Image<class
> itk::Vector<unsigned char,3>,2> *,const class itk::ImageRegion<2> &)' :
> cannot convert parameter 1 from 'class itk::SmartPointer<class
> itk::Image<class itk::Vector<unsigned char,3>,2> cons
> t >' to 'class itk::Image<class itk::Vector<unsigned char,3>,2> *'
>         No user-defined-conversion operator available that can perform this
> conversion, or the operator cannot be called
>         C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xtree(552) :
> while compiling class-template member function 'void __thiscall
> itk::VoronoiSegmentationRGBImageFilter<class itk::Image<class
> itk::Vector<unsigned char,3>,2>,class itk::Image
> <bool,2> >::SetInput(class itk::SmartPointer<class itk::Image<class
> itk::Vector<unsigned char,3>,2> >)'
> 
> so, how to fix it?
> 
> thanks.
> 
> Yinpeng.
> 
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
> 
>