[Insight-developers] extra iteration in FloodFilledSpatialFunctionConditionalIterator

Wilson Chang wmcst6+ at pitt . edu
Fri, 12 Jul 2002 13:00:37 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_00B9_01C229A4.1DCC0340
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

hi
     I think we have found a "feature" of the =
FloodFilledSpatialFunctionConditionalIterator.  If you recall, it =
iterates within some spatial function via a flood fill, beginning at =
some seed point that is fed to the iterator.  Well, what seems to happen =
to that seed point is that it is visited twice.  Here is an example code =
snipped (from itkFloodFillIteratorTest.cxx) for filling a sphere with =
radius 2 centered at (10,10,10) with a seed point of (9,10,10)

---------------------------------------------------
  typedef itk::SphereSpatialFunction<dim> TFunctionType;
  typedef TFunctionType::InputType TFunctionPositionType;

  // Create and initialize a new sphere function

  TFunctionType::Pointer spatialFunc =3D TFunctionType::New();
  spatialFunc->SetRadius( 2 );

  TFunctionPositionType center;
  center[0]=3D10;
  center[1]=3D10;
  center[2]=3D10;
  spatialFunc->SetCenter(center);

  std::cout << "Sphere spatial function created" << std::endl;

  //---------Create and initialize a spatial function =
iterator-----------
  TImageType::IndexType seedPos;
  const TImageType::IndexValueType pos[] =3D {9,10,10};
  seedPos.SetIndex(pos);

  typedef itk::FloodFilledSpatialFunctionConditionalIterator
    <TImageType, TFunctionType> TItType;
  TItType sfi =3D TItType(sourceImage, spatialFunc, seedPos);

  // Iterate through the entire image and set interior pixels to 255
  for( ; !( sfi.IsAtEnd() );++sfi)
    {
    std::cout << sfi.GetIndex() << ": " << sfi.Get() << std::endl;
    sfi.Set(255);
    }

-------------------------------------------------

and the output listing the pixel indices (and their values) as they are =
visited by the iterator:

[9, 10, 10]: 0
[9, 10, 10]: 255
[8, 10, 10]: 0
[8, 9, 10]: 0
[9, 9, 10]: 0
[10, 9, 10]: 0
[11, 10, 10]: 0
[10, 11, 10]: 0
[9, 11, 10]: 0
[9, 11, 9]: 0
[10, 11, 9]: 0
[10, 10, 9]: 0
[9, 10, 9]: 0
[8, 10, 9]: 0
[8, 9, 9]: 0
[9, 9, 9]: 0
[10, 9, 9]: 0
[11, 10, 9]: 0
[11, 9, 10]: 0
[11, 9, 9]: 0
[10, 8, 10]: 0
[9, 8, 10]: 0
[9, 8, 9]: 0
[10, 8, 9]: 0
[10, 9, 8]: 0
[9, 10, 8]: 0
[10, 10, 8]: 0
[9, 9, 8]: 0
[10, 10, 10]: 0
[10, 10, 11]: 0
[9, 10, 11]: 0
[9, 9, 11]: 0
[10, 9, 11]: 0


As you might notice, the first index [9,10,10] is repeated.  This is the =
seed point.  Currently, to get around this bug, we increment the =
iterator before it is used the first time.  Of course, this hack is not =
a fix.

Has anybody else noticed this bug? =20

wilson


------=_NextPart_000_00B9_01C229A4.1DCC0340
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.2716.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>hi</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp; I think we =
have found a=20
"feature" of the FloodFilledSpatialFunctionConditionalIterator.&nbsp; If =
you=20
recall, it iterates within some spatial function via a flood fill, =
beginning at=20
some seed point that is fed to the iterator.&nbsp; Well, what seems to =
happen to=20
that seed point is that it is visited twice.&nbsp; Here is an example =
code=20
snipped (from itkFloodFillIteratorTest.cxx)&nbsp;for filling a sphere =
with=20
radius&nbsp;2 centered at (10,10,10) with a seed point of =
(9,10,10)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>---------------------------------------------------</FONT></DIV>=

<DIV><FONT face=3DArial size=3D2>&nbsp; typedef=20
itk::SphereSpatialFunction&lt;dim&gt; TFunctionType;<BR>&nbsp; typedef=20
TFunctionType::InputType TFunctionPositionType;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; // Create and initialize a new =
sphere=20
function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; TFunctionType::Pointer =
spatialFunc =3D=20
TFunctionType::New();<BR>&nbsp; spatialFunc-&gt;SetRadius( 2 =
);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; TFunctionPositionType =
center;<BR>&nbsp;=20
center[0]=3D10;<BR>&nbsp; center[1]=3D10;<BR>&nbsp; =
center[2]=3D10;<BR>&nbsp;=20
spatialFunc-&gt;SetCenter(center);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; std::cout &lt;&lt; "Sphere =
spatial function=20
created" &lt;&lt; std::endl;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; //---------Create and initialize =
a spatial=20
function iterator-----------<BR>&nbsp; TImageType::IndexType =
seedPos;<BR>&nbsp;=20
const TImageType::IndexValueType pos[] =3D {9,10,10};<BR>&nbsp;=20
seedPos.SetIndex(pos);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; typedef=20
itk::FloodFilledSpatialFunctionConditionalIterator<BR>&nbsp;&nbsp;&nbsp; =

&lt;TImageType, TFunctionType&gt; TItType;<BR>&nbsp; TItType sfi =3D=20
TItType(sourceImage, spatialFunc, seedPos);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; // Iterate through the entire =
image and set=20
interior pixels to 255<BR>&nbsp; for( ; !( sfi.IsAtEnd()=20
);++sfi)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; std::cout =
&lt;&lt;=20
sfi.GetIndex() &lt;&lt; ": " &lt;&lt; sfi.Get() &lt;&lt;=20
std::endl;<BR>&nbsp;&nbsp;&nbsp; sfi.Set(255);<BR>&nbsp;&nbsp;&nbsp;=20
}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>-------------------------------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>and the output listing the pixel =
indices (and their=20
values) as they are visited by the iterator:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>[9, 10, 10]: 0<BR>[9, 10, 10]: =
255<BR>[8, 10, 10]:=20
0<BR>[8, 9, 10]: 0<BR>[9, 9, 10]: 0<BR>[10, 9, 10]: 0<BR>[11, 10, 10]: =
0<BR>[10,=20
11, 10]: 0<BR>[9, 11, 10]: 0<BR>[9, 11, 9]: 0<BR>[10, 11, 9]: 0<BR>[10, =
10, 9]:=20
0<BR>[9, 10, 9]: 0<BR>[8, 10, 9]: 0<BR>[8, 9, 9]: 0<BR>[9, 9, 9]: =
0<BR>[10, 9,=20
9]: 0<BR>[11, 10, 9]: 0<BR>[11, 9, 10]: 0<BR>[11, 9, 9]: 0<BR>[10, 8, =
10]:=20
0<BR>[9, 8, 10]: 0<BR>[9, 8, 9]: 0<BR>[10, 8, 9]: 0<BR>[10, 9, 8]: =
0<BR>[9, 10,=20
8]: 0<BR>[10, 10, 8]: 0<BR>[9, 9, 8]: 0<BR>[10, 10, 10]: 0<BR>[10, 10, =
11]:=20
0<BR>[9, 10, 11]: 0<BR>[9, 9, 11]: 0<BR>[10, 9, 11]: 0</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>As you might notice, the first index =
[9,10,10] is=20
repeated.&nbsp; This is the seed point.&nbsp; Currently, to get around =
this bug,=20
we increment the iterator before it is used the first time.&nbsp; Of =
course,=20
this hack is not a fix.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Has anybody else noticed this =
bug?&nbsp;=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>wilson</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_00B9_01C229A4.1DCC0340--