<div dir="ltr">Hi All,<br><br>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.<br><br>Like the following code (but it doesn't work (maybe because the iterator's direction can be set only once(?)):<br>
So, what's wrong with the output image of this code ?<br> - the image which had been written at the "switch case" is the same.<br><br> typedef itk::ImageLinearIteratorWithIndex <ImageType> iteratorType;<br>
typedef itk::ImageLinearConstIteratorWithIndex <ImageType> constIteratorType;<br> <br> constIteratorType image_iterator (Image1, Image1->GetRequestedRegion()); <br> iteratorType output_iterator (Image2, Image2->GetRequestedRegion()); <br>
<br><br> for (int idx=0; idx<3; idx++)<br> { <br> output_iterator.SetDirection(idx);<br> image_iterator.SetDirection(idx);<br><br> for( image_iterator.GoToBegin(),output_iterator.GoToBegin()<br>
; !image_iterator.IsAtEnd()<br> ; image_iterator.NextLine(), output_iterator.NextLine()) <br> {<br> //set some pixels values ...<br> }<br><br> Image2->Update();<br>
<br><br> switch (idx)<br> {<br> case 0:<br> writerItk->SetInput(Image2);<br> writerItk->SetFileName("Image2_0.nii");<br> writerItk->Write();<br>
break;<br> case 1:<br> writerItk->SetInput(Image2);<br> writerItk->SetFileName("Image2_1.nii");<br> writerItk->Write();<br> break;<br>
case 2:<br> writerItk->SetInput(Image2);<br> writerItk->SetFileName("Image2_2.nii");<br> writerItk->Write();<br> break; <br>
}<br> }<br></div>