[Insight-users] Iterator moving in reverse

Radhika Sivaramakrishna Radhika Sivaramakrishna" <radshashi at earthlink . net
Thu, 18 Dec 2003 15:54:07 -0800


This is a multi-part message in MIME format.

------=_NextPart_000_00BA_01C3C57F.2B754510
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Luis,

1)I was trying to write a simple iterator loop to find the starting and =
ending non-zero slices of a given binary image. Here is part of the code =
for that. It worked correctly for identifying the starting slice but not =
the ending slice, though I cannot figure out why.

#include "itkImageRegionIterator.h"

const unsigned int Dimension =3D 3;

 typedef unsigned char   PixelType;
=20
 typedef itk::Image< PixelType,  Dimension >  ImageType;
typedef itk::ImageRegionIterator< ImageType > IteratorType3D;

IteratorType3D =
startandendit(readermask->GetOutput(),readermask->GetOutput()->GetBuffere=
dRegion());
  startandendit.GoToBegin();
  while (startandendit.Get() =3D=3D 0 && !startandendit.IsAtEnd())
  ++startandendit;
  if (!startandendit.IsAtEnd())
  {
 sstart =3D startandendit.GetIndex()[2];
 startandendit.GoToEnd();
 while (startandendit.Get() =3D=3D 0 && !startandendit.IsAtBegin())
  --startandendit;
 send =3D startandendit.GetIndex()[2];
  }
  else
  {
   std::cout << " Empty image " << std::endl;
   exit(1);
  }
  std::cout << " Start and end slices " << sstart << " " << send << =
std::endl;=20

2) Also, I found I could not use ImageRegionIteratorwithIndex for this =
since it did not have the functions IsAtBegin and GoToEnd. Why is that.
------=_NextPart_000_00BA_01C3C57F.2B754510
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1276" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi Luis,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>1)I was trying to write a simple =
iterator loop to=20
find the starting and ending non-zero slices of a given binary =
</FONT><FONT=20
face=3DArial size=3D2>image. Here is&nbsp;part of the&nbsp;code for =
that. It worked=20
correctly for identifying the starting slice but not the ending slice, =
though I=20
cannot figure out why.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#include =
"itkImageRegionIterator.h"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>const unsigned int Dimension =3D =
3;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;typedef unsigned char&nbsp;&nbsp; =

PixelType;<BR>&nbsp;</FONT><FONT face=3DArial size=3D2><BR>&nbsp;typedef =

itk::Image&lt; PixelType,&nbsp; Dimension &gt;&nbsp; =
ImageType;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>typedef itk::ImageRegionIterator&lt; =
ImageType &gt;=20
IteratorType3D;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>IteratorType3D=20
startandendit(readermask-&gt;GetOutput(),readermask-&gt;GetOutput()-&gt;G=
etBufferedRegion());<BR>&nbsp;=20
startandendit.GoToBegin();<BR>&nbsp; while (startandendit.Get() =3D=3D 0 =
&amp;&amp;=20
!startandendit.IsAtEnd())<BR>&nbsp;&nbsp;++startandendit;<BR>&nbsp; if=20
(!startandendit.IsAtEnd())<BR>&nbsp; {<BR>&nbsp;sstart =3D=20
startandendit.GetIndex()[2];<BR>&nbsp;startandendit.GoToEnd();<BR>&nbsp;w=
hile=20
(startandendit.Get() =3D=3D 0 &amp;&amp;=20
!startandendit.IsAtBegin())<BR>&nbsp;&nbsp;--startandendit;<BR>&nbsp;send=
 =3D=20
startandendit.GetIndex()[2];<BR>&nbsp; }<BR>&nbsp; else<BR>&nbsp;=20
{<BR>&nbsp;&nbsp; std::cout &lt;&lt; " Empty image " &lt;&lt;=20
std::endl;<BR>&nbsp;&nbsp; exit(1);<BR>&nbsp; }<BR>&nbsp; std::cout =
&lt;&lt; "=20
Start and end slices " &lt;&lt; sstart &lt;&lt; " " &lt;&lt; send =
&lt;&lt;=20
std::endl; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>2) Also, I found I could not use=20
ImageRegionIteratorwithIndex for this since it did not have the =
functions=20
IsAtBegin and GoToEnd. Why is that.</FONT></DIV></BODY></HTML>

------=_NextPart_000_00BA_01C3C57F.2B754510--