ConditionalConstIterator
ConstNeighborhoodIterator
ConstShapedNeighborhoodIterator
ConstSliceIterator
CorrespondenceDataStructureIterator
FloodFilledFunctionConditionalConstIterator
FloodFilledImageFunctionConditionalConstIterator
FloodFilledImageFunctionConditionalIterator
FloodFilledSpatialFunctionConditionalConstIterator
FloodFilledSpatialFunctionConditionalIterator
ImageConstIterator
ImageConstIteratorWithIndex
ImageIterator
ImageIteratorWithIndex
ImageLinearConstIteratorWithIndex
ImageLinearIteratorWithIndex
ImageRandomConstIteratorWithIndex
ImageRandomIteratorWithIndex
ImageRegionConstIterator
ImageRegionConstIteratorWithIndex
ImageRegionExclusionConstIteratorWithIndex
ImageRegionExclusionIteratorWithIndex
ImageRegionIterator
ImageRegionIteratorWithIndex
ImageRegionReverseConstIterator
ImageRegionReverseIterator
ImageReverseConstIterator
ImageReverseIterator
ImageSliceConstIteratorWithIndex
ImageSliceIteratorWithIndex
NeighborhoodIterator
PathConstIterator
PathIterator
ShapedNeighborhoodIterator
SliceIterator
ImageConstIteratorWithIndex
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: ImageLinearIteratorWithIndex.cxx,v $ 00005 Language: C++ 00006 Date: $Date: 2005/02/08 03:59:00 $ 00007 Version: $Revision: 1.21 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #if defined(_MSC_VER) 00018 #pragma warning ( disable : 4786 ) 00019 #endif 00020 00021 // Software Guide : BeginLatex 00022 // 00023 // The \doxygen{ImageLinearIteratorWithIndex} is designed for line-by-line 00024 // processing of an image. It walks a linear path along a selected image 00025 // direction parallel to one of the coordinate axes of the image. This 00026 // iterator conceptually breaks an image into a set of parallel lines 00027 // that span the selected image dimension. 00028 // 00029 // \index{Iterators!and image lines} 00030 // 00031 // Like all image iterators, movement of the 00032 // ImageLinearIteratorWithIndex is constrained within an 00033 // image region $R$. The line $\ell$ through which the iterator moves is 00034 // defined by selecting a direction and an origin. The line $\ell$ 00035 // extends from the origin to the upper boundary of $R$. The origin can be 00036 // moved to any position along the lower boundary of $R$. 00037 // 00038 // Several additional methods are defined for this iterator to control movement 00039 // of the iterator along the line $\ell$ and movement of the origin of $\ell$. 00040 // 00041 // %Might need a figure here to describe this iterator. 00042 // 00043 // \begin{itemize} 00044 // 00045 // \index{itk::ImageLinearIteratorWithIndex!NextLine()} 00046 // 00047 // \item \textbf{\code{NextLine()}} Moves the iterator to the beginning pixel 00048 // location of the next line in the image. The origin of the next line is 00049 // determined by incrementing the current origin along the fastest increasing 00050 // dimension of the subspace of the image that excludes the selected dimension. 00051 // 00052 // 00053 // \index{itk::ImageLinearIteratorWithIndex!PreviousLine()} 00054 // 00055 // \item \textbf{\code{PreviousLine()}} Moves the iterator to the \emph{last valid 00056 // pixel location} in the previous line. The origin of the previous line is 00057 // determined by decrementing the current origin along the fastest increasing 00058 // dimension of the subspace of the image that excludes the selected dimension. 00059 // 00060 // \index{itk::ImageLinearIteratorWithIndex!GoToBeginOfLine()} 00061 // \index{itk::ImageLinearIteratorWithIndex!GoToReverseBeginOfLine()} 00062 // 00063 // \item \textbf{\code{GoToBeginOfLine()}} Moves the iterator to the beginning 00064 // pixel of the current line. 00065 // 00066 // \item \textbf{\code{GoToEndOfLine()}} Move the iterator to 00067 // \emph{one past} the last valid pixel of the current line. 00068 // 00069 // 00070 // \index{itk::ImageLinearIteratorWithIndex!IsAtReverseEndOfLine()} 00071 // \index{itk::ImageLinearIteratorWithIndex!IsAtEndOfLine()} 00072 // 00073 // \item \textbf{\code{IsAtReverseEndOfLine()}} 00074 // Returns true if the iterator points 00075 // to \emph{one position before} the beginning pixel of the current line. 00076 // 00077 // \item \textbf{\code{IsAtEndOfLine()}} 00078 // Returns true if the iterator points to 00079 // \emph{one position past} the last valid pixel of the current line. 00080 // \end{itemize} 00081 // 00082 // The following code example shows how to use the 00083 // ImageLinearIteratorWithIndex. It implements the same algorithm as 00084 // in the previous example, flipping an image across its $x$-axis. Two line 00085 // iterators are iterated in opposite directions across the $x$-axis. 00086 // After each line is traversed, the iterator origins are stepped along 00087 // the $y$-axis to the 00088 // next line. 00089 // 00090 // \index{itk::ImageLinearIteratorWithIndex!example of using|(} 00091 // 00092 // Headers for both the const and non-const versions are needed. 00093 // 00094 // Software Guide : EndLatex 00095 00096 #include "itkImage.h" 00097 #include "itkRGBPixel.h" 00098 // Software Guide : BeginCodeSnippet 00099 #include "itkImageLinearConstIteratorWithIndex.h" 00100 #include "itkImageLinearIteratorWithIndex.h" 00101 // Software Guide : EndCodeSnippet 00102 #include "itkImageFileReader.h" 00103 #include "itkImageFileWriter.h" 00104 00105 int main( int argc, char *argv[] ) 00106 { 00107 // Verify the number of parameters on the command line. 00108 if ( argc < 3 ) 00109 { 00110 std::cerr << "Missing parameters. " << std::endl; 00111 std::cerr << "Usage: " << std::endl; 00112 std::cerr << argv[0] 00113 << " inputImageFile outputImageFile" 00114 << std::endl; 00115 return -1; 00116 } 00117 00118 // Software Guide : BeginLatex 00119 // 00120 // The RGB image and pixel types are defined as in the previous example. The 00121 // ImageLinearIteratorWithIndex class and its const version each have 00122 // single template parameters, the image type. 00123 // 00124 // Software Guide : EndLatex 00125 00126 const unsigned int Dimension = 2; 00127 00128 typedef itk::RGBPixel< unsigned char > RGBPixelType; 00129 typedef itk::Image< RGBPixelType, Dimension > ImageType; 00130 00131 // Software Guide : BeginCodeSnippet 00132 typedef itk::ImageLinearIteratorWithIndex< ImageType > IteratorType; 00133 typedef itk::ImageLinearConstIteratorWithIndex< ImageType > ConstIteratorType; 00134 // Software Guide : EndCodeSnippet 00135 00136 typedef itk::ImageFileReader< ImageType > ReaderType; 00137 typedef itk::ImageFileWriter< ImageType > WriterType; 00138 00139 ImageType::ConstPointer inputImage; 00140 ReaderType::Pointer reader = ReaderType::New(); 00141 reader->SetFileName( argv[1] ); 00142 try 00143 { 00144 reader->Update(); 00145 inputImage = reader->GetOutput(); 00146 } 00147 catch ( itk::ExceptionObject &err) 00148 { 00149 std::cout << "ExceptionObject caught a !" << std::endl; 00150 std::cout << err << std::endl; 00151 return -1; 00152 } 00153 00154 // Software Guide : BeginLatex 00155 // 00156 // After reading the input image, we allocate an output image that of the same 00157 // size, spacing, and origin. 00158 // 00159 // Software Guide : EndLatex 00160 00161 // Software Guide : BeginCodeSnippet 00162 ImageType::Pointer outputImage = ImageType::New(); 00163 outputImage->SetRegions( inputImage->GetRequestedRegion() ); 00164 outputImage->CopyInformation( inputImage ); 00165 outputImage->Allocate(); 00166 // Software Guide : EndCodeSnippet 00167 00168 // Software Guide : BeginLatex 00169 // 00170 // Next we create the two iterators. The const iterator walks the input image, 00171 // and the non-const iterator walks the output image. The iterators are 00172 // initialized over the same region. The direction of iteration is set to 0, 00173 // the $x$ dimension. 00174 // 00175 // Software Guide : EndLatex 00176 00177 // Software Guide : BeginCodeSnippet 00178 ConstIteratorType inputIt( inputImage, inputImage->GetRequestedRegion() ); 00179 IteratorType outputIt( outputImage, inputImage->GetRequestedRegion() ); 00180 00181 inputIt.SetDirection(0); 00182 outputIt.SetDirection(0); 00183 // Software Guide : EndCodeSnippet 00184 00185 // Software Guide: BeginLatex 00186 // 00187 // Each line in the input is copied to the output. The input iterator moves 00188 // forward across columns while the output iterator moves backwards. 00189 // 00190 // Software Guide : EndLatex 00191 00192 // Software Guide : BeginCodeSnippet 00193 for ( inputIt.GoToBegin(), outputIt.GoToBegin(); ! inputIt.IsAtEnd(); 00194 outputIt.NextLine(), inputIt.NextLine()) 00195 { 00196 inputIt.GoToBeginOfLine(); 00197 outputIt.GoToEndOfLine(); 00198 --outputIt; 00199 while ( ! inputIt.IsAtEndOfLine() ) 00200 { 00201 outputIt.Set( inputIt.Get() ); 00202 ++inputIt; 00203 --outputIt; 00204 } 00205 } 00206 // Software Guide : EndCodeSnippet 00207 00208 WriterType::Pointer writer = WriterType::New(); 00209 writer->SetFileName( argv[2] ); 00210 writer->SetInput(outputImage); 00211 try 00212 { 00213 writer->Update(); 00214 } 00215 catch ( itk::ExceptionObject &err) 00216 { 00217 std::cout << "ExceptionObject caught !" << std::endl; 00218 std::cout << err << std::endl; 00219 return -1; 00220 } 00221 00222 // Software Guide : BeginLatex 00223 // 00224 // Running this example on \code{VisibleWomanEyeSlice.png} produces 00225 // the same output image shown in 00226 // Figure~\ref{fig:ImageRegionIteratorWithIndexExample}. 00227 // 00228 // \index{itk::ImageLinearIteratorWithIndex!example of using|)} 00229 // Software Guide : EndLatex 00230 00231 return 0; 00232 }