[Insight-developers] iterators in a reverse direction?
Luis Ibanez
ibanez@choroid.cs.unc.edu
Wed, 16 May 2001 10:30:15 -0400 (EDT)
ITK don't have reverse iterators yet,
but nothing prevent them from being implemented.
It is just a matter of volonteers :-)
We implemented a ReflectiveIterator for being
used in the Danielsson distance algorithm.
It is in Code/BasicFilters.
This iterator walks line by line, first forward
and then backwards. The fact is that if you
take its operator++ method, the code on the option
if( ! firstpass )
is what has to be written in the normal operator++
of a reverse iterator.
another option, as you suggest, is to add a operator--,
which could be more intuitive. We are not passing
iterators around, so the common API of ++ used in STL
is less necessary.
---
A word of caution. The notion of Begin() and End()
is a bit ambiguous in reverse iterators... STL
uses rbegin() and rend() to clarify, maybe we should
follow that.
Luis
On Wed, 16 May 2001, Damion Shelton wrote:
> Hi...
>
> Is there an easy way to iterate through an image in the "reverse" of the
> normal direction? The code fragment:
>
> for ( outIt.Begin(); !outIt.IsAtEnd(); ++outIt)
>
> iterates forwards. Prior to looking at the documentation, I assumed that the
> line:
>
> for ( outIt.End(); !outIt.IsAtBegin(); --outIt)
>
> would also be legal; the "--" operator is not defined, though. So, how do I
> go about iterating backwards.
>
> Thanks,
>
> -Damion-
>
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
>
--
Luis Ibanez CB#: 7060
Research Assistan Professor phone: (919) 843 6941
Division of Neurosurgery fax: (919) 966 6627
University of North Carolina at Chapel Hill email: ibanez@cs.unc.edu
Chapel Hill, NC 27599-7060 http://www.cs.unc.edu/~ibanez