[Insight-developers] ImageRandomConstIteratorWithIndex
Joshua Cates
cates@sci.utah.edu
Thu, 20 Feb 2003 15:21:14 -0700 (MST)
Hi,
> So I don't mind the change. Just make sure the documentation say that
> the above scenario does not work.
Both of these scenarios should continue to work with the minor
modification of
it.GoToEnd();
--it; // because end is defined as one past the last valid sample
while(!it.IsAtBegin())
{
--it;
}
In addition, the code would correctly interpret situations like:
it.GoToBegin()
while (!it.IsAtEnd())
{
if (it.Get() < someValue) // throw out values in a range
{
--it;
continue;
}
...
++it;
}
It doesn't really seem that critical, but as I was writing some
documentation, I noted that the current implementation will not be
correct if you try to iterate backwards and forwards in the same
loop.
Josh.
______________________________
Josh Cates
School of Computer Science
University of Utah
Email: cates@sci.utah.edu
Phone: (801) 587-7697
URL: http://www.sci.utah.edu/~cates
On Thu, 20 Feb 2003, Lydia Ng wrote:
> Dear Josh and Luis,
>
> For the metric I only have use:
>
> it.GoToBegin();
> while(!it.IsAtEnd())
> {
> ++it;
> }
>
> I remember went Luis made this we weren't quite sure as to how to treat
> the operator--. For consistency we went something that works properly
> for
>
> it.GoToEnd();
> while (!it.IsAtBegin() )
> {
> --it;
> }
>
>
> Making operator-- decrement the m_NumberOfSamplesDone would be a good
> tool.
> So I don't mind the change. Just make sure the documentation say that
> the above scenario does not work.
>
> - Lydia
>
> > -----Original Message-----
> > From: Joshua Cates [mailto:cates@sci.utah.edu]
> > Sent: Thursday, February 20, 2003 2:01 PM
> > To: Luis Ibanez
> > Cc: Insight-Developers; Lydia Ng
> > Subject: Re: [Insight-developers] ImageRandomConstIteratorWithIndex
> >
> > Hi Luis,
> >
> > We could still use it as a reverse iterator as long as SetToEnd()
> > and IsAtBegin() were modified. I think all that needs doing is
> >
> > void SetToEnd()
> > {
> > m_NumberOfSamplesDone = m_NumberOfSamplesRequested +1;
> > }
> > bool IsAtBegin()
> > {
> > return (m_NumberOfSamplesDone == 0);
> > }
> > void operator--()
> > {
> > m_NumberOfSamplesDone -= 2;
> > return ++(*this);
> > }
> >
> > Josh.
> > ______________________________
> > Josh Cates
> > School of Computer Science
> > University of Utah
> > Email: cates@sci.utah.edu
> > Phone: (801) 587-7697
> > URL: http://www.sci.utah.edu/~cates
> >
> >
> > On Thu, 20 Feb 2003, Luis Ibanez wrote:
> >
> > >
> > > Hi Josh,
> > >
> > > We can probably go either way,
> > > and it will be more a matter of convention.
> > >
> > > Actually, some weeks ago a user suggested that
> > > we modify the MutualInformation metric to keep
> > > generating samples until all of them where
> > > inside the overlap region.
> > >
> > > It happens that this behaviour could be easily
> > > implemented with the ++ and -- operators iff
> > > the numberOfSamples where decremented as you
> > > just suggested.
> > >
> > > The original reason for incrementing samples in
> > > the -- operator was to make possible for the
> > > iterator to behave like a reverse iterator, but...
> > > probably nobody is in need of such functionality
> > > at this point.
> > >
> > > I'm ok with changing the behavior on the operator--.
> > >
> > > Lydia may have a deeper insight on this issue
> > > since this will affect mostly the MutualInformation
> > > metric.
> > >
> > >
> > > Luis
> > >
> > >
> > > ----------------------------------
> > > Joshua Cates wrote:
> > > > Hi,
> > > >
> > > > In the implementation of ImageRandomConstIteratorWithIndex, the
> member
> > > > variable m_NumerOfSamplesDone is incremented in both operator++
> and
> > > > operator--. This works fine for common cases of iteratation in
> one
> > > > "direction" through the whole random sample set because IsAtBegin,
> > > > IsAtEnd are defined appropriately.
> > > >
> > > > But for cases where you might want to reverse iteration direction
> in a
> > > > loop, or go back a few random samples, (for example, an it++
> followed
> > by a
> > > > conditional it--), this implementation will fail. Is there any
> reason
> > not
> > > > to modify this class so that operator-- decrements
> > m_NumberOfSamplesDone?
> > > >
> > > > Josh.
> > > > ______________________________
> > > > Josh Cates
> > > > School of Computer Science
> > > > University of Utah
> > > > Email: cates@sci.utah.edu
> > > > Phone: (801) 587-7697
> > > > URL: http://www.sci.utah.edu/~cates
> > > >
> > > >
> > > > _______________________________________________
> > > > 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
> > >
>
>