[Insight-users] VariableLengthVector and ConstIterator

Julien Michel julien.michel at c-s.cnes.fr
Fri Sep 12 05:00:58 EDT 2008


Dear itk users and developpers,

Lets consider the following code :

typedef itk::VectorImage<double> ImageType;
typedef ImageType::PixelType     PixelType;

itk::ImageRegionConstIterator<ImageType> 
it(myImage,myImage->GetLargestPossibleRegion());

for(it.GoToBegin();!it.IsAtEnd();++it)
{
   PixelType v = it.Get();
   v.Fill(0);
   ...
}

I was expecting v to be a local copy of the vector pixel returned by 
it.Get(). But this is not what happens : v will contain a pointer to the 
image internal buffer (due to itk::VariableLengthVector memory 
management), so v.Fill(0) allows me to write into myImage, even if the 
iterator is a ConstIterator. Might also work with an 
ImageType::ConstPointer.

Isn't it some kind of bug ?

Best regards,

Julien
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Julien MICHEL - Ingénieur d'études - Traitement d'images
CS Systèmes d'Information - Division ESPACE
Département Information Géographique & Image
Téléphone : +33 561 17 64 27
Email : julien.michel at c-s.fr

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Insight-users mailing list