[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> </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 part of the 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> </DIV>
<DIV><FONT face=3DArial size=3D2>#include =
"itkImageRegionIterator.h"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>const unsigned int Dimension =3D =
3;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> typedef unsigned char =
PixelType;<BR> </FONT><FONT face=3DArial size=3D2><BR> typedef =
itk::Image< PixelType, Dimension > =
ImageType;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>typedef itk::ImageRegionIterator< =
ImageType >=20
IteratorType3D;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>IteratorType3D=20
startandendit(readermask->GetOutput(),readermask->GetOutput()->G=
etBufferedRegion());<BR> =20
startandendit.GoToBegin();<BR> while (startandendit.Get() =3D=3D 0 =
&&=20
!startandendit.IsAtEnd())<BR> ++startandendit;<BR> if=20
(!startandendit.IsAtEnd())<BR> {<BR> sstart =3D=20
startandendit.GetIndex()[2];<BR> startandendit.GoToEnd();<BR> w=
hile=20
(startandendit.Get() =3D=3D 0 &&=20
!startandendit.IsAtBegin())<BR> --startandendit;<BR> send=
=3D=20
startandendit.GetIndex()[2];<BR> }<BR> else<BR> =20
{<BR> std::cout << " Empty image " <<=20
std::endl;<BR> exit(1);<BR> }<BR> std::cout =
<< "=20
Start and end slices " << sstart << " " << send =
<<=20
std::endl; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </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--