[ITK] ITK-4.6 problem - OffsetValueType
Matt McCormick
matt.mccormick at kitware.com
Wed Sep 17 11:48:13 EDT 2014
Hi Gib,
OffsetValueType is defined here [1].
HTH,
Matt
[1] http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Core/Common/include/itkIntTypes.h;h=c7fe398a593c79367631719e75104983efb27335;hb=HEAD#l137
On Tue, Sep 16, 2014 at 9:12 PM, Gib Bogle <g.bogle at auckland.ac.nz> wrote:
> Hi,
>
> I've been digging into the code, and trying to track down where the memory access problem occurs. By putting some printf statements in itkImage.hxx and itkImageBase.h I think I've got close to the source. As I suspected it is in the Image::Allocate() function. As the program output below shows, with N=1625 GetOffsetTable() returns the correct size of the image, but with N=1626 it returns 1626^3 - 2^32. The problem is that OffsetValueType is only 4 bytes. I'm reluctant to go further with this because I don't want to risk breaking something, but somebody should know why OffsetValueType has this size and how to increase it to 8 bytes in the case of ITK_USE_64BITS_IDS on.
>
> itkImage.hxx:
>
> void
> Image< TPixel, VImageDimension >
> ::Allocate(bool initializePixels)
> {
> SizeValueType num;
>
> this->ComputeOffsetTable();
> num = static_cast<SizeValueType>(this->GetOffsetTable()[VImageDimension]);
> printf("Image::Allocate: GetOffsetTable(): %lld\n",this->GetOffsetTable()[VImageDimension]); //Gib
> printf("Image::Allocate: num: %lld\n",num); //Gib
> m_Buffer->Reserve(num, initializePixels);
> }
>
> itkImageBase.h:
>
> const OffsetValueType * GetOffsetTable() const {
> printf("Image::Allocate: sizeof(OffsetValueType): %d\n",sizeof(OffsetValueType)); //Gib
> return m_OffsetTable; }
>
>
> D:\testing\ITK\bigtiff>Release\makebig.exe zzz-4.6.tif 1625 1
> Output image file: zzz-4.6.tif
> Desired image dimensions: width, height, depth: 1625 1625 1625
> Image::Allocate: sizeof(OffsetValueType): 4
> Image::Allocate: sizeof(OffsetValueType): 4
> Image::Allocate: GetOffsetTable(): 4291015625
> Image::Allocate: num: 4291015625
> Requested image dimensions: width, height, depth: 1625 1625 1625
> imregion size(0): 1625
> imregion size(1): 1625
> imregion size(2): 1625
> Image::FillBuffer: numberOfPixels: 4291015625
>
> D:\testing\ITK\bigtiff>Release\makebig.exe zzz-4.6.tif 1626 1
> Output image file: zzz-4.6.tif
> Desired image dimensions: width, height, depth: 1626 1626 1626
> Image::Allocate: sizeof(OffsetValueType): 4
> Image::Allocate: sizeof(OffsetValueType): 4
> Image::Allocate: GetOffsetTable(): 3975080
> Image::Allocate: num: 3975080
> Requested image dimensions: width, height, depth: 1626 1626 1626
> imregion size(0): 1626
> imregion size(1): 1626
> imregion size(2): 1626
> Image::FillBuffer: numberOfPixels: 3975080
> ________________________________________
> From: Community [community-bounces at itk.org] on behalf of Gib Bogle [g.bogle at auckland.ac.nz]
> Sent: Wednesday, 17 September 2014 10:39 a.m.
> To: Matt McCormick
> Cc: community at itk.org
> Subject: Re: [ITK] ITK-4.6 problem
>
> Update on the bug in the version of ITK-4.6 installed by Slicer:
>
> What can we make of this:
>
> ImageType::Pointer im = ImageType::New();
> ImageType::SizeType imsize;
> imsize[0] = width;
> imsize[1] = height;
> imsize[2] = depth;
> ImageType::IndexType imstart;
> imstart[0] = 0;
> imstart[1] = 0;
> imstart[2] = 0;
> ImageType::RegionType imregion;
> imregion.SetSize(imsize);
> imregion.SetIndex(imstart);
> im->SetRegions(imregion);
> im->Allocate();
> p = (unsigned char *)(im->GetBufferPointer());
>
> width = im->GetLargestPossibleRegion().GetSize()[0];
> height = im->GetLargestPossibleRegion().GetSize()[1];
> depth = im->GetLargestPossibleRegion().GetSize()[2];
> printf("Requested image dimensions: width, height, depth: %d %d %d\n",width,height,depth);
>
> printf("imregion size(0): %d\n",imregion.GetSize(0));
> printf("imregion size(1): %d\n",imregion.GetSize(1));
> printf("imregion size(2): %d\n",imregion.GetSize(2));
>
> int i = 195000000;
> for (int i=197160890; i<200000000;i++) {
> printf("offset: %d\n",i);
> p[i] = 0;
> }
>
> yields (reproducibly):
>
> D:\testing\ITK\bigtiff>Release\makebig.exe big1650c-4.6.tif 1650 0
> ...
> Requested image dimensions: width, height, depth: 1650 1650 1650
> imregion size(0): 1650
> imregion size(1): 1650
> imregion size(2): 1650
> offset: 197160890
> offset: 197160891
> offset: 197160892
> offset: 197160893
> offset: 197160894
> offset: 197160895
> offset: 197160896
> <crash>
>
> (If instead of writing to the image buffer I do this: im->FillBuffer(0) the program crashes when it attempts writer->Update().)
>
> Varying the size of the image (NxNxN) I find that N = 1625 is OK, N = 1626 crashes at z=2, buffer offset = 5287752 (clearly the offset index is insignificant). 1626^3 is slightly bigger than 2^32.
>
> I checked that the ITK build definitely had ITKV3_COMPATIBILITY off and therefore ITK_USE_64BITS_IDS on.
>
> I'm wondering if the image buffer allocation im->Allocate() is successful in the cases that crash. How can I check that?
>
> I'd appreciate some pointers.
>
> Thanks
> Gib
>
> ________________________________________
> From: Matt McCormick [matt.mccormick at kitware.com]
> Sent: Wednesday, 17 September 2014 1:48 a.m.
> To: Gib Bogle
> Cc: community at itk.org
> Subject: Re: [ITK] ITK-4.6 problem
>
> Hi Gib,
>
>>
>> There is something a bit funny about the installed ITK-4.6, in that the
>> compiler complained about some missing include files, vnl_*.h and others,
>> which are in my ITK-4.0 installation but not in 4.6. I just copied them
>> across - I hope this is not a problem.
>>
>
> This is probably a problem. Did the ITK 4.6 build complete
> successfully and the install complete successfully?
>
> Thanks,
> Matt
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
More information about the Community
mailing list