Description
The Get function of an iterator on an itk::Image of itk::VariableLengthVector returns an itk::VariableLengthVector which data points to a pixel of the itk::Image. This is because the DefaultVectorPixelAccessor::Get calls the VariableLengthVector constructor parameterized by a const pointer. This leads to an unexpected behavior for the user.
Steps to Reproduce
This is a minimal example reproducing the issue:
#include <itkVectorImage.h>
#include <itkImageRegionIterator.h>
int
main(int argc, char * argv[])
{
using ImageType = itk::VectorImage<float,2>;
auto img = ImageType::New();
img->SetVectorLength(3);
ImageType::SizeType size = { { 2, 2 } };
img->SetRegions(size);
img->AllocateInitialized();
itk::ImageRegionIterator<ImageType> it(img, img->GetLargestPossibleRegion());
auto v { it.Get() };
float c = 0.;
while(!it.IsAtEnd())
{
v.Fill(c++);
it.Set(v);
++it;
}
it.GoToBegin();
while(!it.IsAtEnd())
{
std::cout << it.Get() << std::endl;
++it;
}
return EXIT_SUCCESS;
}
Expected behavior
It should display
[0, 0, 0]
[1, 1, 1]
[2, 2, 2]
[3, 3, 3]
Actual behavior
It actually displays
[3, 3, 3]
[1, 1, 1]
[2, 2, 2]
[3, 3, 3]
Reproducibility
100%
Versions
All versions since 6a60327.
Environment
All OSs.
Additional Information
Description
The
Getfunction of an iterator on anitk::Imageofitk::VariableLengthVectorreturns anitk::VariableLengthVectorwhich data points to a pixel of theitk::Image. This is because theDefaultVectorPixelAccessor::Getcalls theVariableLengthVectorconstructor parameterized by aconst pointer. This leads to an unexpected behavior for the user.Steps to Reproduce
This is a minimal example reproducing the issue:
Expected behavior
It should display
Actual behavior
It actually displays
Reproducibility
100%
Versions
All versions since 6a60327.
Environment
All OSs.
Additional Information