[Insight-developers] ImageToImageFilter: dimension reduction problem

Luis Ibanez luis.ibanez@kitware.com
Fri, 29 Mar 2002 17:15:06 -0500


Hi Wilson,

The problem does not seem to be related with the
run-time behavior of the virtual functions.

What seems to happen is that regardless of how you overload
the method in your code, the code of ImageToImageFilter<TI,TO>
has to be compiled anyways and since the TInputImage
and TOutputImage that are being used are not compatible
the error will always appear at compilation time.

In fact, the streaming itself is built on the assumption
that dimension match.  (Jim, please correct me if I'm wrong here)
The only way around would be to have a RegionBase class, non
templated from which Region derives, and then do the dimension
checking at run time as opossed to compile time. The drawback
here is the we will lose the performace of inlining Region related
code and got the lower speed of virtual calls...

Another option could be to add another ImageToImageFilter
(with another name...) which just does not have methods
relying on matching dimensions between the input and
output.

This is similar to the problem we encounter when we
generalize the Transforms. Everything was fine until we
got to the Perspective transform where the dimension
of the output points do not match the dimension of the
input points.... The solution taken in that case was to
add the TransformBase (non-templated) class and
afford virtual calls each time a point is transformed.

One very short term solution for you could be to not derive
from ImageToImageFilter but from ProcessObject.....
but that may probably be only a temporary solution.


   Luis

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

Wilson Chang wrote:

> Hi, We have been working on a visualization project with itk and vtk 
> that requires having all of our images in 3-D or less.  Therefore, I 
> have been working on a filter that reduces the number of dimensions of 
> an image.  This filter inherits from the ImageToImageFilter class.  
> The snag that I have run into is the GenerateInputRequestedRegion 
> function in the ImageToImageFilter class:
>
>  
>
>  
>
> template<class TInputImage, class TOutputImage>
> void
> ImageToImageFilter<TInputImage,TOutputImage>
> ::GenerateInputRequestedRegion()
> {
> ...
>
>       input->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
> ...
>
>  
>
> This line of code basicly requires that the input and output image 
> have the same number of dimensions.  When I try to override this 
> GenerateInputRequestedRegion in my filter, I still get a compile error 
> saying:
>
>  
>
> cannot convert from 'const class itk::ImageRegion<2>' to 'const class 
> itk::ImageRegion<3>'
>
>  
>
> Is it possible that the superclass' definition of this function is 
> being called regardless of whether i've redefined this function?
>
>  
>
> ideas?
>
>  
>
> thanks,
>
> wilson
>