[Insight-developers] ImageIterators : Suggested Patch: Exception

Luis Ibanez luis.ibanez at kitware.com
Tue May 5 11:07:52 EDT 2009


With Michel Audette we have been tracking the issues related to
aligning physical point coordinates with index coordinates.

In the process we noticed that the ITK image iterators do not
verify at construction time whether the region given as argument
to the iterator constructor,  is inside of the image or not.

The consequence is that a user can provide a region outside
of the image, we compute the offset (that will turn out to be
outside of the image buffer) and then we (incorrectly) provide
access to the pixel location.

This has now been reported as Bug #8960:

     http://public.kitware.com/Bug/view.php?id=8960


We are suggesting the following fix to this problem:

Namely, to check the region argument of the iterator constructor
against the BufferedRegion of the image, and throw an exception
if the region is not fully inside of the image buffered region.


Index: itkImageConstIterator.h
===================================================================
RCS file: /cvsroot/Insight/Insight/Code/Common/itkImageConstIterator.h,v
retrieving revision 1.23
diff -r1.23 itkImageConstIterator.h
175a176,183
>     const RegionType & bufferedRegion = m_Image->GetBufferedRegion();
>
>     if( ! bufferedRegion.IsInside( m_Region ) )
>       {
>       itkGenericExceptionMacro("Region " << m_Region
>         << " is outside of buffered region " << bufferedRegion );
>       }
>
Index: itkImageConstIteratorWithIndex.txx
===================================================================
RCS file: /cvsroot/Insight/Insight/Code/Common/itkImageConstIteratorWithIndex.txx,v
retrieving revision 1.27
diff -r1.27 itkImageConstIteratorWithIndex.txx
84a85,92
>   const RegionType & bufferedRegion = m_Image->GetBufferedRegion();
>
>   if( ! bufferedRegion.IsInside( m_Region ) )
>     {
>     itkGenericExceptionMacro("Region " << m_Region
>       << " is outside of buffered region " << bufferedRegion );
>     }
>


Does anyone see a problem with this patch ?

Any objections ?


   Thanks


        Luis


More information about the Insight-developers mailing list