[Insight-developers] iterators in a reverse direction?

Joshua Cates cates@cs.utah.edu
Thu, 17 May 2001 11:16:17 -0600 (MDT)


Hello,

When I "bidirectionalized" the NeighborhoodIterators I stuck operator--
within the existing classes.  The only awkwardness in this approach is
that the user must remember that *(it.end()) is undefined.  So reverse
iteration looks something like:

BidirectionalIterator it;
it = it.end();
for (--it; it >= it.begin(); --it) {}


To convert this API to itk iterator (aka "image walker") style we might do
something like:

BidirectionalIterator it;
it.End();
--it;
while (! it.IsLessThanBegin())
{
 --it;
}

In the interest of reducing complexity, my feeling is that if there is no
implementational reason that existing ImageIterators cannot be made
bidirectional, they should be made bidirectional (and not broken apart
into forward and reverse iterators).  Same functionality at a reduced code
volume requiring fewer itk objects.  This approach also offers a bit more
flexibility to the user.

Josh.
______________________________
 Josh Cates			
 School of Computer Science	
 University of Utah
 Email: cates@cs.utah.edu
 Phone: (801) 587-7697
 URL:   www.cs.utk.edu/~cates


On Fri, 18 May 2001, Damion Shelton wrote:

> Hi...
> 
> I played with ReflectiveImageRegionIterator and although it appears to be
> working correctly, I don't know the behavior is exactly what I'm looking for
> though. In the case of a 2D image, ReflectiveImageRegionIterator seems to
> proceed by:
> 
> walk x forwards and back, next y, walk x forwards and back, next y, etc.
> 
> while what I'm looking for is:
> 
> walk x forwards, next y, walk x forwards, next y, walk x back, previous y,
> etc.
> 
> I would volunteer to implement this but I'm not comfortable playing in the
> guts of iterators just yet. I like the idea of an iterator that iterates
> both forwards and back in a manner transparent to the user, though. I don't
> know whether this should be a separate implementation or a modification of
> the existing ImageRegionIterator (i.e. support the -- operator).
> 
> -Damion-
> 
> ----- Original Message -----
> From: "Luis Ibanez" <ibanez@choroid.cs.unc.edu>
> Subject: Re: [Insight-developers] iterators in a reverse direction?
> 
> > 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
> >
> >
> >
> > _______________________________________________
> > Insight-developers mailing list
> > Insight-developers@public.kitware.com
> > http://public.kitware.com/mailman/listinfo/insight-developers
> >
> 
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
>