[Insight-developers] ImageToImageFilter: dimension reductionproblem

Wilson Chang wmcst6+@pitt.edu
Tue, 23 Apr 2002 17:37:43 -0400


hi,
I havent been able to figure out how to use the SetRegionCopier() in the
context of ExtractImageFilter.  Specifically, how do i instantiate a
subclass of the ImageToImageFilterDetail::RegionCopier function object to
pass to SetRegionCopier()?

This function object would be a function within ExtractImageFilter, and
everytime a call to CopyRegion is made, it will dispatch to the function I
passed to SetRegionCopier, right?

thanks,
wilson



----- Original Message -----
From: "Miller, James V (Research)" <millerjv@crd.ge.com>
To: "'Wilson Chang'" <wmcst6@pitt.edu>; "Insight-developers (E-mail)"
<Insight-developers@public.kitware.com>
Sent: Thursday, April 18, 2002 2:42 PM
Subject: RE: [Insight-developers] ImageToImageFilter: dimension
reductionproblem


> I just checked in a series of changes to the architecture that allow
> the output of a filter to be a different dimension than the input.
> The difficulty in supporting this is that
>
> ImageToImageFilter::GenerateInputRequestedRegion()
>
> needs to be able to compile regardless of whether the input and output
> dimensions match. The default implementation of this routine tries to
> call
>
> input->SetRequestedRegion( output->GetRequestedRegion() );
>
> This line of code will not compile if the input region and the output
> region are not the same dimension.
>
> In the new model, the line above is now
>
> InputImageRegionType inputRegion;
> m_RegionCopier(inputRegion, output->GetRequestedRegion() );
> input->SetRequestedRegion( inputRegion );
>
> m_RegionCopier is an ivar that is a function object. The call operator
> dispatches to an overloaded function that is in NOT a member function
> of ImageToImageFilter but rather is a standard function in a separate
> namespace (thanks Brad!).  Thus, the RegionCopier dispatches to one
routine
> if the input dimension matches the output dimension, another if the input
> dimension is less than the output dimension, and a third if the input
> dimension is greater than the output dimension.  The default
implementations
> are rather simplistic.  If the input dimension is greater than the output
> dimension, the output region information is copied to the first part of
the
> input region.  Zeros fill the remainder of the StartIndex and Size.  If
the
> input dimension is less than the output dimension, the first part of the
> output region is copied to the input region.
>
> If a filter needs a behavior different from this (for instance the
> ExtractImageFilter should support a different behavior), the filter can
> pass a different function object to ImageToImageFilter.  This would
> probably be done in the constructor of the filter.  It would call the
protected
> method SetRegionCopier().
>
> The function object would have to provide the call operator and dispatch
> to a different set of routines to handle the different behavior.
>
> To support these operations, there is a new file called
> itkImageToImageFilterDetail.h that has a series of types defined to
facilitate
> dispatching to different routines based on dimensions.
>
> Brad also pointed out that the dispatch pattern currently deployed in ITK
> in a few places will have a problem with explicit instantiation.  I'll be
> converting the current dispatch implementations to this new model.
>
> Wilson, you should be able to implement your filter to remove an image
dimension.
> I would suggest that functionality be placed in the ExtractImageFilter.
>
>
>
>
>
> -----Original Message-----
> From: Wilson Chang [mailto:wmcst6+@pitt.edu]
> Sent: Thursday, April 04, 2002 4:21 PM
> To: Miller, James V (CRD)
> Subject: Re: [Insight-developers] ImageToImageFilter: dimension
> reductionproblem
>
>
> Does it look like a fix to the base classes will be doable?  If it isnt, I
> could do what luis was suggesting by having the dimension reduction filter
> inherit from process object.
>
> thanks,
> wilson
>
>
> ----- Original Message -----
> From: "Miller, James V (CRD)" <millerjv@crd.ge.com>
> To: "'Luis Ibanez'" <luis.ibanez@kitware.com>; "Wilson Chang"
> <wmcst6@pitt.edu>
> Cc: "Insight Developers" <Insight-developers@public.kitware.com>
> Sent: Monday, April 01, 2002 8:36 AM
> Subject: RE: [Insight-developers] ImageToImageFilter: dimension
> reductionproblem
>
>
> > I think there are a few ways that we can handle this.
> >
> > There already is a non-templated Region base class so that
> > may be an avenue.  Another option is to function overloading
> > to force a default implementation when the dimensions
> > match and require subclasses provided a method when the
> > the dimensions do not.
> >
> > I'll put together a fix.  Wilson, could you send me the
> > snippet of your test program (or check in the test without
> > putting it in the TestDriver yest) that is causing this
> > error (just to save me from reinventing the wheel).
> >
> >
> >
> > -----Original Message-----
> > From: Luis Ibanez [mailto:luis.ibanez@kitware.com]
> > Sent: Friday, March 29, 2002 5:15 PM
> > To: Wilson Chang
> > Cc: Insight Developers; Miller, James V (CRD)
> > Subject: Re: [Insight-developers] ImageToImageFilter: dimension
> > reduction problem
> >
> >
> >
> > 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
> > >
> >
> >
> > _______________________________________________
> > Insight-developers mailing list
> > Insight-developers@public.kitware.com
> > http://public.kitware.com/mailman/listinfo/insight-developers
> >
>