[Insight-users] Iterators ??
Karthik Krishnan
Karthik.Krishnan at kitware.com
Sun Feb 5 13:54:14 EST 2006
You cannot use a linear iterator without checking if it is at the end of
the line and restarting its pointer on the next line. You cannot do with
just the IsAtEnd() check. See
Examples/Iterators/ImageLinearIteratorWithIndex for an example. BTW for
this simple case, you would not need a LinearIteratorWithIndex, a
ImageRegionIterator would suffice.
-karthik
On Sun, 2006-02-05 at 11:02 +0100, Lagaffe wrote:
> Hi all,
>
> Just because I am curious ;-), I would like to
> understand why the method2 below doesn't works ??
>
> I Have a vectorial Image, and I would like to
> "extract" an image from this vectorial image (the
> simple code below is simple to understand ;-)...
>
> OutputImageType aPixelType
> ImageType a vectorial image (vector< aPixelType,3>
> for example)
>
>
> // METHOD 1 => OK
> typedef typename
> itk::ImageLinearConstIteratorWithIndex< ImageType >
> ConstIteratorType;
>
> for (inputIt.GoToBegin (); !inputIt.IsAtEnd ();
> inputIt.NextLine ())
> {
> inputIt.GoToBeginOfLine ();
> while (!inputIt.IsAtEndOfLine ())
> {
> index=inputIt.GetIndex ();
> vectorPixel=outputImage->GetPixel(index);
> vectorPixel[i]=inputIt.Get(); // i, the slice I
> want to extract from my vectorial image
> outputImage->SetPixel(index,vectorPixel);
> ++inputIt;
> }
> }
>
>
> // METHOD 2 => Failed, the for loop goes far from my
> image length ??, I added a simple cpt inside the loop
> and find values of cpt > of sizeX*sizeY
>
> typedef typename
> itk::ImageLinearIteratorWithIndex< OutputImageType >
> IteratorType;
> typedef typename
> itk::ImageLinearConstIteratorWithIndex< ImageType >
> ConstIteratorType;
>
>
> ConstIteratorType in( temp,
> temp->GetRequestedRegion() );
> IteratorType out( outputImage,
> inputImage->GetRequestedRegion() );
> for ( in.GoToBegin(), out.GoToBegin();
> !in.IsAtEnd(); ++in, ++out )
> {
> vectorPixel=out.Get();
> vectorPixel[i]=in.Get();
> out.Set( vectorPixel);
> }
>
>
> thanks
>
> Arnaud
>
>
>
>
>
>
> ___________________________________________________________________________
> Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international.
> Téléchargez sur http://fr.messenger.yahoo.com
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list