[Insight-developers] ImageRegionIteratorWithIndex

Miller, James V (CRD) millerjv@crd.ge.com
Wed, 18 Jul 2001 17:32:15 -0400


I checked in a fix to the ImageIteratorWithIndex class.  The constructor was not positioning the
iterator at the beginning of the region.

You used to have code that read:	

 itk::ImageRegionIteratorWithIndex <UShortImage2D> it(inputimg, region);
 it.Begin();
 while( !it.IsAtEnd()) {}

But now, Begin() returns an iterator and does not reset the current iterator.  The current behavior
is the desired behavior.

Your code can now read:

 itk::ImageRegionIteratorWithIndex <UShortImage2D> it(inputimg, region);
 while( !it.IsAtEnd()) {}

or 

 itk::ImageRegionIteratorWithIndex <UShortImage2D> it(inputimg, region);
 it.GoToBegin();
 while( !it.IsAtEnd()) {}

Note that anywhere in itk code where we used to have a single statement like

it.Begin();

or 

it.End();

and "it" is a instance of an ImageIteratorWithIndex (or one of its subclasses) then we need to change
that code. The change is either:

1) Remove the line of code if the iterator was just created.
2) Replace the line of code with it.GoToBegin() or it.GoToEnd()

Pretty much all the tests that are crashing today are candidates for this change.  Note that many of
the crashes were because the constructor was not setting the initial position (which I just fixed).
So these tests will probably not crash anymore.  However, they will probably produce the wrong
results.

I will try to make a pass at cleaning up this code this evening.



-----Original Message-----
From: Miller, James V (CRD) 
Sent: Wednesday, July 18, 2001 5:14 PM
To: 'Yinpeng Jin'; insight-developers@public.kitware.com
Subject: RE: [Insight-developers] ImageRegionIteratorWithIndex


It looks like the Begin()/End() definitions now perform like ImageIterator and ImageRegionIterator.

That is Begin()/End() return an iterator that points to the beginning or end of a region where they
used to reposition the current iterator.

That is the only change that I can see.

So the line

it.Begin() should change to it.GoToBegin()

Jim

-----Original Message-----
From: Yinpeng Jin [mailto:yj76@columbia.edu]
Sent: Wednesday, July 18, 2001 4:24 PM
To: insight-developers@public.kitware.com
Subject: [Insight-developers] ImageRegionIteratorWithIndex


What is the difference in terms of usage between
ImageRegionIteratorWithIndex and the old version of
ImageSimpleRegionIterator?
Suddently found that the below codes begin to crash on it.Set() Method. It
used to work for SimpleRegionIterator.
Yinpeng


 itk::ImageRegionIteratorWithIndex <UShortImage2D> it(inputimg, region);
 it.Begin();
 int k=0;
 while( !it.IsAtEnd()) {
  it.Set(TestingImage[k]);
  k++;
  ++it;
 }



_______________________________________________
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