Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > d5e74628f0e673bb8680aebce32b2c04 > files > 29

itk-doc-3.12.0-1mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>ITK: Examples/Iterators/ImageLinearIteratorWithIndex.cxx</title>
<link href="DoxygenStyle.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">


<!--  Section customized for INSIGHT : Tue Jul 17 01:02:45 2001 -->
<center>
<a href="index.html" class="qindex">Main Page</a>&nbsp;&nbsp; 
<a href="modules.html" class="qindex">Groups</a>&nbsp;&nbsp;
<a href="namespaces.html" class="qindex">Namespace List</a>&nbsp;&nbsp;
<a href="hierarchy.html" class="qindex">Class Hierarchy</a>&nbsp;&nbsp;
<a href="classes.html" class="qindex">Alphabetical List</a>&nbsp;&nbsp;
<a href="annotated.html" class="qindex">Compound List</a>&nbsp;&nbsp; 
<a href="files.html" class="qindex">File
List</a>&nbsp;&nbsp; 
<a href="namespacemembers.html" class="qindex">Namespace Members</a>&nbsp;&nbsp; 
<a href="functions.html" class="qindex">Compound Members</a>&nbsp;&nbsp; 
<a href="globals.html" class="qindex">File Members</a>&nbsp;&nbsp;
<a href="pages.html" class="qindex">Concepts</a></center>


<!-- Generated by Doxygen 1.5.9 -->
<div class="contents">
<h1>Examples/Iterators/ImageLinearIteratorWithIndex.cxx</h1><dl class="user" compact><dt><b>MORE INFORMATION</b></dt><dd>For a complete description of the ITK Image Iterators and their API, please see the Iterators chapter in the ITK Software Guide. The ITK Software Guide is available in print and as a free .pdf download from <a href="http://www.itk.org.">http://www.itk.org.</a></dd></dl>
<dl class="see" compact><dt><b>See also:</b></dt><dd>ImageConstIterator <p>
ConditionalConstIterator <p>
ConstNeighborhoodIterator <p>
ConstShapedNeighborhoodIterator <p>
ConstSliceIterator <p>
CorrespondenceDataStructureIterator <p>
FloodFilledFunctionConditionalConstIterator <p>
FloodFilledImageFunctionConditionalConstIterator <p>
FloodFilledImageFunctionConditionalIterator <p>
FloodFilledSpatialFunctionConditionalConstIterator <p>
FloodFilledSpatialFunctionConditionalIterator <p>
ImageConstIterator <p>
ImageConstIteratorWithIndex <p>
ImageIterator <p>
ImageIteratorWithIndex <p>
ImageLinearConstIteratorWithIndex <p>
ImageLinearIteratorWithIndex <p>
ImageRandomConstIteratorWithIndex <p>
ImageRandomIteratorWithIndex <p>
ImageRegionConstIterator <p>
ImageRegionConstIteratorWithIndex <p>
ImageRegionExclusionConstIteratorWithIndex <p>
ImageRegionExclusionIteratorWithIndex <p>
ImageRegionIterator <p>
ImageRegionIteratorWithIndex <p>
ImageRegionReverseConstIterator <p>
ImageRegionReverseIterator <p>
ImageReverseConstIterator <p>
ImageReverseIterator <p>
ImageSliceConstIteratorWithIndex <p>
ImageSliceIteratorWithIndex <p>
NeighborhoodIterator <p>
PathConstIterator <p>
PathIterator <p>
ShapedNeighborhoodIterator <p>
SliceIterator <p>
ImageConstIteratorWithIndex</dd></dl>
<div class="fragment"><pre class="fragment"><span class="comment">/*=========================================================================</span>
<span class="comment"></span>
<span class="comment">  Program:   Insight Segmentation &amp; Registration Toolkit</span>
<span class="comment">  Module:    $RCSfile: ImageLinearIteratorWithIndex.cxx,v $</span>
<span class="comment">  Language:  C++</span>
<span class="comment">  Date:      $Date: 2008-01-23 16:43:05 $</span>
<span class="comment">  Version:   $Revision: 1.23 $</span>
<span class="comment"></span>
<span class="comment">  Copyright (c) Insight Software Consortium. All rights reserved.</span>
<span class="comment">  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.</span>
<span class="comment"></span>
<span class="comment">     This software is distributed WITHOUT ANY WARRANTY; without even </span>
<span class="comment">     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR </span>
<span class="comment">     PURPOSE.  See the above copyright notices for more information.</span>
<span class="comment"></span>
<span class="comment">=========================================================================*/</span>
<span class="preprocessor">#if defined(_MSC_VER)</span>
<span class="preprocessor"></span><span class="preprocessor">#pragma warning ( disable : 4786 )</span>
<span class="preprocessor"></span><span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="comment">// Software Guide : BeginLatex</span>
<span class="comment">//</span>
<span class="comment">// The \doxygen{ImageLinearIteratorWithIndex} is designed for line-by-line</span>
<span class="comment">// processing of an image.  It walks a linear path along a selected image</span>
<span class="comment">// direction parallel to one of the coordinate axes of the image. This</span>
<span class="comment">// iterator conceptually breaks an image into a set of parallel lines</span>
<span class="comment">// that span the selected image dimension.</span>
<span class="comment">//</span>
<span class="comment">// \index{Iterators!and image lines}</span>
<span class="comment">//</span>
<span class="comment">// Like all image iterators, movement of the</span>
<span class="comment">// ImageLinearIteratorWithIndex is constrained within an</span>
<span class="comment">// image region $R$.  The line $\ell$ through which the iterator moves is</span>
<span class="comment">// defined by selecting a direction and an origin.   The line $\ell$</span>
<span class="comment">// extends from the origin to the upper boundary of $R$. The origin can be</span>
<span class="comment">// moved to any position along the lower boundary of $R$. </span>
<span class="comment">//    </span>
<span class="comment">// Several additional methods are defined for this iterator to control movement</span>
<span class="comment">// of the iterator along the line $\ell$ and movement of the origin of $\ell$.</span>
<span class="comment">//</span>
<span class="comment">// %Might need a figure here to describe this iterator.</span>
<span class="comment">//</span>
<span class="comment">// \begin{itemize}</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageLinearIteratorWithIndex!NextLine()}</span>
<span class="comment">//</span>
<span class="comment">// \item \textbf{\code{NextLine()}} Moves the iterator to the beginning pixel</span>
<span class="comment">// location of the next line in the image.  The origin of the next line is</span>
<span class="comment">// determined by incrementing the current origin along the fastest increasing</span>
<span class="comment">// dimension of the subspace of the image that excludes the selected dimension.</span>
<span class="comment">//</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageLinearIteratorWithIndex!PreviousLine()}</span>
<span class="comment">//</span>
<span class="comment">// \item \textbf{\code{PreviousLine()}} Moves the iterator to the \emph{last valid</span>
<span class="comment">// pixel location} in the previous line. The origin of the previous line is</span>
<span class="comment">// determined by decrementing the current origin along the fastest increasing</span>
<span class="comment">// dimension of the subspace of the image that excludes the selected dimension.</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageLinearIteratorWithIndex!GoToBeginOfLine()}</span>
<span class="comment">//</span>
<span class="comment">// \item \textbf{\code{GoToBeginOfLine()}} Moves the iterator to the beginning</span>
<span class="comment">// pixel of the current line.</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageLinearIteratorWithIndex!GoToEndOfLine()}</span>
<span class="comment">//</span>
<span class="comment">// \item \textbf{\code{GoToEndOfLine()}}  Move the iterator to </span>
<span class="comment">// \emph{one past} the last valid pixel of the current line.</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageLinearIteratorWithIndex!GoToReverseBeginOfLine()}</span>
<span class="comment">//</span>
<span class="comment">// \item \textbf{\code{GoToReverseBeginOfLine()}}  Move the iterator</span>
<span class="comment">// to \emph{the last valid pixel} of the current line.</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageLinearIteratorWithIndex!IsAtReverseEndOfLine()}</span>
<span class="comment">//</span>
<span class="comment">// \item \textbf{\code{IsAtReverseEndOfLine()}} </span>
<span class="comment">// Returns true if the iterator points</span>
<span class="comment">// to \emph{one position before} the beginning pixel of the current line.</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageLinearIteratorWithIndex!IsAtEndOfLine()}</span>
<span class="comment">//</span>
<span class="comment">// \item \textbf{\code{IsAtEndOfLine()}}  </span>
<span class="comment">// Returns true if the iterator points to</span>
<span class="comment">// \emph{one position past} the last valid pixel of the current line.</span>
<span class="comment">// \end{itemize}</span>
<span class="comment">//</span>
<span class="comment">// The following code example shows how to use the</span>
<span class="comment">// ImageLinearIteratorWithIndex.  It implements the same algorithm as</span>
<span class="comment">// in the previous example, flipping an image across its $x$-axis.  Two line</span>
<span class="comment">// iterators are iterated in opposite directions across the $x$-axis.  </span>
<span class="comment">// After each line is traversed, the iterator origins are stepped along </span>
<span class="comment">// the $y$-axis to the</span>
<span class="comment">// next line.</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageLinearIteratorWithIndex!example of using|(}</span>
<span class="comment">//</span>
<span class="comment">// Headers for both the const and non-const versions are needed.</span>
<span class="comment">//</span>
<span class="comment">// Software Guide : EndLatex</span>

<span class="preprocessor">#include "<a class="code" href="itkImage_8h.html">itkImage.h</a>"</span>
<span class="preprocessor">#include "<a class="code" href="itkRGBPixel_8h.html">itkRGBPixel.h</a>"</span>
<span class="comment">// Software Guide : BeginCodeSnippet</span>
<span class="preprocessor">#include "<a class="code" href="itkImageLinearConstIteratorWithIndex_8h.html">itkImageLinearConstIteratorWithIndex.h</a>"</span>
<span class="preprocessor">#include "<a class="code" href="itkImageLinearIteratorWithIndex_8h.html">itkImageLinearIteratorWithIndex.h</a>"</span>
<span class="comment">// Software Guide : EndCodeSnippet</span>
<span class="preprocessor">#include "<a class="code" href="itkImageFileReader_8h.html">itkImageFileReader.h</a>"</span>
<span class="preprocessor">#include "<a class="code" href="itkImageFileWriter_8h.html">itkImageFileWriter.h</a>"</span>

<span class="keywordtype">int</span> <a name="a0"></a><a class="code" href="itkTestMain_8h.html#dacbe0175a79dff748855d8c9839f82b">main</a>( <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[] )
{
  <span class="comment">// Verify the number of parameters on the command line.</span>
  <span class="keywordflow">if</span> ( argc &lt; 3 )
    {
    std::cerr &lt;&lt; <span class="stringliteral">"Missing parameters. "</span> &lt;&lt; std::endl;
    std::cerr &lt;&lt; <span class="stringliteral">"Usage: "</span> &lt;&lt; std::endl;
    std::cerr &lt;&lt; argv[0]
              &lt;&lt; <span class="stringliteral">" inputImageFile outputImageFile"</span>
              &lt;&lt; std::endl;
    <span class="keywordflow">return</span> -1;
    }

<span class="comment">// Software Guide : BeginLatex</span>
<span class="comment">//</span>
<span class="comment">// The RGB image and pixel types are defined as in the previous example.  The </span>
<span class="comment">// ImageLinearIteratorWithIndex class and its const version each have</span>
<span class="comment">// single template parameters, the image type.</span>
<span class="comment">//</span>
<span class="comment">// Software Guide : EndLatex</span>

  <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Dimension = 2;
  
  <span class="keyword">typedef</span> <a name="_a1"></a><a class="code" href="classitk_1_1RGBPixel.html" title="Represent Red, Green and Blue component for color images.">itk::RGBPixel&lt; unsigned char &gt;</a> RGBPixelType;
  <span class="keyword">typedef</span> <a name="_a2"></a><a class="code" href="classitk_1_1Image.html" title="Templated n-dimensional image class.">itk::Image&lt; RGBPixelType, Dimension &gt;</a>  ImageType;

<span class="comment">// Software Guide : BeginCodeSnippet</span>
  <span class="keyword">typedef</span> <a name="_a3"></a><a class="code" href="classitk_1_1ImageLinearIteratorWithIndex.html" title="A multi-dimensional image iterator that visits image pixels within a region in a...">itk::ImageLinearIteratorWithIndex&lt; ImageType &gt;</a>       IteratorType;
  <span class="keyword">typedef</span> <a name="_a4"></a><a class="code" href="classitk_1_1ImageLinearConstIteratorWithIndex.html" title="A multi-dimensional image iterator that visits image pixels within a region in a...">itk::ImageLinearConstIteratorWithIndex&lt; ImageType &gt;</a>  ConstIteratorType;
<span class="comment">// Software Guide : EndCodeSnippet</span>
  
  <span class="keyword">typedef</span> <a name="_a5"></a><a class="code" href="classitk_1_1ImageFileReader.html" title="Data source that reads image data from a single file.">itk::ImageFileReader&lt; ImageType &gt;</a> ReaderType;
  <span class="keyword">typedef</span> <a name="_a6"></a><a class="code" href="classitk_1_1ImageFileWriter.html" title="Writes image data to a single file.">itk::ImageFileWriter&lt; ImageType &gt;</a> WriterType;

  <a name="a7"></a><a class="code" href="itkFEMMacro_8h.html#68fafcc6909430ccd70cbc4aeee0107c">ImageType::ConstPointer</a> inputImage;
  <a name="a8"></a><a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">ReaderType::Pointer</a> reader = <a name="a9"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#870262f145e0b45206db74df8053b59c">ReaderType::New</a>();
  reader-&gt;SetFileName( argv[1] );
  <span class="keywordflow">try</span>
    {
    reader-&gt;Update();
    inputImage = reader-&gt;GetOutput();
    }
  <span class="keywordflow">catch</span> ( itk::ExceptionObject &amp;err)
    {
    std::cout &lt;&lt; <span class="stringliteral">"ExceptionObject caught a !"</span> &lt;&lt; std::endl; 
    std::cout &lt;&lt; err &lt;&lt; std::endl; 
    <span class="keywordflow">return</span> -1;
    }

<span class="comment">// Software Guide : BeginLatex</span>
<span class="comment">//</span>
<span class="comment">// After reading the input image, we allocate an output image that of the same</span>
<span class="comment">// size, spacing, and origin.</span>
<span class="comment">//</span>
<span class="comment">// Software Guide : EndLatex</span>

<span class="comment">// Software Guide : BeginCodeSnippet</span>
  <a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">ImageType::Pointer</a> outputImage = <a class="code" href="namespaceHardConnectedComponentImageFilter.html#870262f145e0b45206db74df8053b59c">ImageType::New</a>();
  outputImage-&gt;SetRegions( inputImage-&gt;GetRequestedRegion() );
  outputImage-&gt;CopyInformation( inputImage );
  outputImage-&gt;Allocate();
<span class="comment">// Software Guide : EndCodeSnippet</span>

<span class="comment">// Software Guide : BeginLatex</span>
<span class="comment">//</span>
<span class="comment">// Next we create the two iterators.  The const iterator walks the input image,</span>
<span class="comment">// and the non-const iterator walks the output image.  The iterators are</span>
<span class="comment">// initialized over the same region.  The direction of iteration is set to 0,</span>
<span class="comment">// the $x$ dimension.</span>
<span class="comment">//</span>
<span class="comment">// Software Guide : EndLatex</span>

<span class="comment">// Software Guide : BeginCodeSnippet</span>
  ConstIteratorType inputIt( inputImage, inputImage-&gt;GetRequestedRegion() );
  IteratorType outputIt( outputImage, inputImage-&gt;GetRequestedRegion() );

  inputIt.SetDirection(0);
  outputIt.SetDirection(0);
<span class="comment">// Software Guide : EndCodeSnippet</span>

<span class="comment">// Software Guide: BeginLatex</span>
<span class="comment">//</span>
<span class="comment">// Each line in the input is copied to the output.  The input iterator moves</span>
<span class="comment">// forward across columns while the output iterator moves backwards.</span>
<span class="comment">//</span>
<span class="comment">// Software Guide : EndLatex</span>

<span class="comment">// Software Guide : BeginCodeSnippet</span>
  <span class="keywordflow">for</span> ( inputIt.GoToBegin(),  outputIt.GoToBegin(); ! inputIt.IsAtEnd();
        outputIt.NextLine(),  inputIt.NextLine())
    {
    inputIt.GoToBeginOfLine();
    outputIt.GoToEndOfLine();
    <span class="keywordflow">while</span> ( ! inputIt.IsAtEndOfLine() )
      {
      --outputIt;
      outputIt.Set( inputIt.Get() );
      ++inputIt;
      }
    }
<span class="comment">// Software Guide : EndCodeSnippet</span>

  <a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">WriterType::Pointer</a> writer = <a class="code" href="namespaceHardConnectedComponentImageFilter.html#870262f145e0b45206db74df8053b59c">WriterType::New</a>();
  writer-&gt;SetFileName( argv[2] );
  writer-&gt;SetInput(outputImage);
  <span class="keywordflow">try</span>
    {
    writer-&gt;Update();
    }
  <span class="keywordflow">catch</span> ( itk::ExceptionObject &amp;err)
    {
    std::cout &lt;&lt; <span class="stringliteral">"ExceptionObject caught !"</span> &lt;&lt; std::endl; 
    std::cout &lt;&lt; err &lt;&lt; std::endl; 
    <span class="keywordflow">return</span> -1;   
    }

<span class="comment">// Software Guide : BeginLatex</span>
<span class="comment">//</span>
<span class="comment">// Running this example on \code{VisibleWomanEyeSlice.png} produces</span>
<span class="comment">// the same output image shown in</span>
<span class="comment">// Figure~\ref{fig:ImageRegionIteratorWithIndexExample}.</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageLinearIteratorWithIndex!example of using|)}</span>
<span class="comment">// Software Guide : EndLatex</span>
  
  <span class="keywordflow">return</span> 0;
}

</pre></div> </div>
<hr><address><small>
Generated at Thu May 7 22:04:09 2009 for ITK  by <a href="http://www.stack.nl/~dimitri/doxygen/index.html"> <img 
src="http://www.stack.nl/~dimitri/doxygen/doxygen.png" alt="doxygen"
align="middle" border=0 width=110 height=53>
</a> 1.5.9 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2000</small></address>
</body>
</html>