[ITK] 3D iterator goes out of bounds but still works

Matt McCormick matt.mccormick at kitware.com
Mon Apr 24 13:37:54 EDT 2017


Hi Nirvedh,

For performance reasons, the iterators do not do bounds-checking.

HTH,
Matt

On Fri, Apr 21, 2017 at 9:49 PM, Nirvedh Meshram <nmeshram at wisc.edu> wrote:

> Hello All,
>
>
> I am working on a Code which is using an iterator which access pixels
> beyond the region boundary. However, this is not causing an error as I
> would expect it to. I need to use version 4.0  for legacy reasons. I am
> attaching a verifiable code and its output with this issue. Let me know if
> this is a bug in my ITK version or I am missing something and this is
> correct behavior.
>
>
> #include "itkImage.h"
> #include "itkImageRegionIterator.h"
> #include "itkVersion.h"
> int main( int argc, char * argv[] )
> {
>         typedef    float    InputPixelType;
>         typedef itk::Image< InputPixelType,  3 >   InputImageType;
>
>         InputImageType::Pointer ip=InputImageType::New();
>         InputPixelType *input;
>         InputImageType::RegionType region,region1;
>         InputImageType::SizeType size,size1;
>         InputImageType::IndexType index,index1;
>         size[0]=5;
>         size[1]=5;
>         size[2]=5;
>         index[0]=0;
>         index[1]=0;
>         index[2]=0;
>
>         region.SetSize(size);
>         region.SetIndex(index);
>         std::cout<<region;
>         ip->SetRegions(region);
>         ip->Allocate();
>         size[2]=1;
>         region.SetSize(size);
>         std::cout<<region;
>         typedef itk::ImageRegionIterator<InputImageType> Iteratortype;
>         Iteratortype It(ip,region);
>         int count=0;
>         for(It.GoToBegin();count<25*5;count++,++It)
>         {
>                 It.Set(27);
>         }
>         input=ip->GetBufferPointer();
>         for(int k=0;k<5;k++)
>         {
>                 for(int i=0;i<5;i++)
>                 {
>                         for(int j=0;j<5;j++)
>                         {
>                                 std::cout<<input[k*25+j+5*i]<<" ";
>                         }
>                         std::cout<<"\n";
>
>                 }
>                 std::cout<<"\n";
>         }
>         itk::Version *Ver=itk::Version::New();
>         std::cout<<Ver->GetITKMajorVersion()<<"."<<
> Ver->GetITKMinorVersion()<<"\n";
>
>
>
>         return EXIT_SUCCESS;
> }
>
> Output:
>
>
> ImageRegion (0x7ffcfc489560)
>   Dimension: 3
>   Index: [0, 0, 0]
>   Size: [5, 5, 5]
> ImageRegion (0x7ffcfc489560)
>   Dimension: 3
>   Index: [0, 0, 0]
>   Size: [5, 5, 1]
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
>
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
>
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
>
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
>
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
> 27 27 27 27 27
>
> 4.0
>
>
>
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20170424/de2a330a/attachment.html>


More information about the Community mailing list