[Insight-developers] writing an ImageToImageFilter, problem with Requested Region...

Bradley Lowekamp blowekamp at mail.nih.gov
Mon Jul 27 09:59:29 EDT 2009


Hello,

I agree that this situation is not good, and can be rather confusing  
to users to know what method to call. To further complicate things,  
with the writer does not have the UpdateLargestPossibleRegion method.

In case you are curious this oddity is the result of code in  
ImageBase::UpdateOutputInformation:

   // Now we should know what our largest possible region is. If our
   // requested region was not set yet, (or has been set to something
   // invalid - with no data in it ) then set it to the largest possible
   // region.
   if ( this->GetRequestedRegion().GetNumberOfPixels() == 0)
     {
     this->SetRequestedRegionToLargestPossibleRegion();
     }


I bet it would be possible to add a member variable to indicate that  
the requested region had been set automagically. Then when this part  
of the code is encountered again, it could set the appropriate  
requested region again.... But this is so deep in the pipeline  
architecture, it's unlikely that it would be side- effect free. I  
think it'd work though :)

Brad

On Jul 24, 2009, at 5:51 PM, kent williams wrote:

> The problem lies, actually, before my filter's GenerateData is called.
>
> The abort happens in itk::DataObject::PropogateRequestedRegion(),  
> where it
> calls itk::ProcessObject::PropogateRequestedRegion, which then calls
> itk::DataObject::PropogateRequestedRegion, which calls
> itk::DataObject::VerifyRequestedRegion, which returns false.  At  
> that point,
> an exception is thrown.
>
> The problem is that calling SetInput a second time doesn't update the
> requested region, so if the region doesn't fit in the input region, an
> exception is thrown.  If the input region coincidentally happens to  
> contain
> the requested region, it's even worse, because the filter would  
> succeed but
> not process the entire input region.
>
> So as far as I can tell, a program should do one of two things:
>
> 1. Never re-use a filter on different sized inputs, always  
> instantiate a
> fresh instance of the filter.
>
> 2. Always call UpdateLargestPossibleRegion() instead of Update(), if  
> you
> want to re-use a filter.
>
> On 7/24/09 4:11 PM, "Gaëtan Lehmann" <gaetan.lehmann at jouy.inra.fr>  
> wrote:
>>>
>>
>> You have to call UpdateLargestPossibleRegion() inside GenerateData(),
>> instead of Update(). Note that if the filter is not enlarging the
>> requested region to the largest one, you may have some problem with
>> that code. I may be better to force the requested region of the
>> internal filter to the requested region of the output image of your
>> custom filter.
>>
>> Do you still have this kind of exception if you use the double
>> GraftOutput()? I think that the region are copied properly by
>> GraftOutput(). If your internal code fits entirely in the pipeline
>> model, it may be enough to make your code work properly.
>>
>> Gaëtan
>>
>>
>

========================================================
Bradley Lowekamp
Lockheed Martin Contractor for
Office of High Performance Computing and Communications
National Library of Medicine
blowekamp at mail.nih.gov


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20090727/0798418e/attachment.htm>


More information about the Insight-developers mailing list