[Insight-users] multiple iterator's direction

Miri Trope miritrope at gmail.com
Fri Jan 27 17:16:21 EST 2012


Hi All,

I'd like to set values on an image by an iterator. The catch is that I want
to set the iterator by a different direction each time.

Like the following code (but it doesn't work (maybe because the iterator's
direction can be set only once(?)):
So, what's wrong with the output image of this code ?
 - the image which had been written at the "switch case" is the same.

    typedef itk::ImageLinearIteratorWithIndex             <ImageType>
iteratorType;
    typedef itk::ImageLinearConstIteratorWithIndex     <ImageType>
constIteratorType;

    constIteratorType     image_iterator     (Image1,
Image1->GetRequestedRegion());
    iteratorType             output_iterator     (Image2,
Image2->GetRequestedRegion());


    for (int idx=0; idx<3; idx++)
        {
            output_iterator.SetDirection(idx);
            image_iterator.SetDirection(idx);

            for( image_iterator.GoToBegin(),output_iterator.GoToBegin()
            ;   !image_iterator.IsAtEnd()
            ;    image_iterator.NextLine(), output_iterator.NextLine())
            {
                //set some pixels values ...
            }

            Image2->Update();


        switch (idx)
        {
            case 0:
                writerItk->SetInput(Image2);
                writerItk->SetFileName("Image2_0.nii");
                writerItk->Write();
                break;
            case 1:
                writerItk->SetInput(Image2);
                writerItk->SetFileName("Image2_1.nii");
                writerItk->Write();
                break;
            case 2:
                writerItk->SetInput(Image2);
                writerItk->SetFileName("Image2_2.nii");
                writerItk->Write();
                break;
            }
        }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120128/9f2002bc/attachment.htm>


More information about the Insight-users mailing list