[Insight-users] VariableLengthVector and ConstIterator
Karthik Krishnan
karthik.krishnan at kitware.com
Fri Sep 12 12:11:13 EDT 2008
Yes, I am aware of it.
It is a speed tradeoff here. The PixelAccessor constructs the pixel,
with a pointer to the actual data in the image instead of copying it
every time. Unfortunately that leaves room for modifying the
underlying data.
The fix is remarkably simple, it will slow down things slightly though...
In itkDefaultVectorPixelAccessor.h, use the assignment operator
instead of the copy constructor. Please let us know if things are fine
with this change.
inline ExternalType Get( const InternalType & input, const unsigned
long offset ) const
{
ExternalType output = ExternalType(
(&input)+(offset*m_OffsetMultiplier) , m_VectorLength );
}
to
inline ExternalType Get( const InternalType & input, const unsigned
long offset ) const
{
ExternalType output;
output = ExternalType( (&input)+(offset*m_OffsetMultiplier) ,
m_VectorLength );
return output;
}
----------
I'll profile it and (probably) commit it to the repository. Its the
same reason why
PixelType v = it.Get();
is different from
PixelType v; v = it.Get();
The former invokes the copy constructor. The latter invokes the
assignment operator.
Thanks
--
karthik
On Fri, Sep 12, 2008 at 5:00 AM, Julien Michel
<julien.michel at c-s.cnes.fr> wrote:
> 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
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
--
Karthik Krishnan
R&D Engineer,
Kitware Inc.
Ph: 518 371 3971 x119
Fax: 518 371 3971
More information about the Insight-users
mailing list