[Insight-developers] fast image allocation

Damion Shelton dmshelto@andrew.cmu.edu
Wed, 06 Mar 2002 15:58:51 -0500


Hi...

Any objections to adding a FastAllocate(unsigned long* size) method to 
itk::Image?

The idea is to reduce the following block of code:

  unsigned long sourceImageSize[]  = { 20,20,20 };

  // Image typedef
  typedef itk::Image< unsigned char, dim > TImageType;

  // Creates the sourceImage (but doesn't set the size or allocate memory)
  TImageType::Pointer sourceImage = TImageType::New();
  // Create a size object native to the sourceImage type
  TImageType::SizeType sourceImageSizeObject;
  // Set the size object to the array defined earlier
  sourceImageSizeObject.SetSize( sourceImageSize );
  // Create a region object native to the sourceImage type
  TImageType::RegionType largestPossibleRegion;
  // Resize the region
  largestPossibleRegion.SetSize( sourceImageSizeObject );
  // Set the largest legal region size (i.e. the size of the whole 
sourceImage) to what we just defined
  sourceImage->SetLargestPossibleRegion( largestPossibleRegion );
  // Set the buffered region
  sourceImage->SetBufferedRegion( largestPossibleRegion );
  // Set the requested region
  sourceImage->SetRequestedRegion( largestPossibleRegion );
  // Now allocate memory for the sourceImage
  sourceImage->Allocate();

To:

  unsigned long sourceImageSize[]  = { 20,20,20 };

  // Image typedef
  typedef itk::Image< unsigned char, dim > TImageType;

  // Creates the sourceImage (but doesn't set the size or allocate memory)
  TImageType::Pointer sourceImage = TImageType::New();

  sourceImage->FastAllocate(sourceImageSize);

Comments?

-Damion-