Sophie

Sophie

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

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: Iterators/ImageRegionIteratorWithIndex.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>Iterators/ImageRegionIteratorWithIndex.cxx</h1>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><p>
<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: ImageRegionIteratorWithIndex.cxx,v $</span>
<span class="comment">  Language:  C++</span>
<span class="comment">  Date:      $Date: 2005-02-08 03:59:00 $</span>
<span class="comment">  Version:   $Revision: 1.25 $</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 : BeginCommandLineArgs</span>
<span class="comment">//     INPUTS: {VisibleWomanEyeSlice.png} </span>
<span class="comment">//     OUTPUTS: {ImageRegionIteratorWithIndexOutput.png}</span>
<span class="comment">//  Software Guide : EndCommandLineArgs</span>

<span class="comment">// Software Guide : BeginLatex</span>
<span class="comment">//</span>
<span class="comment">// \index{Iterators!speed}</span>
<span class="comment">// The ``WithIndex'' family of iterators was designed for algorithms that</span>
<span class="comment">// use both the value and the location of image pixels in calculations.  Unlike</span>
<span class="comment">// \doxygen{ImageRegionIterator}, which calculates an index only when</span>
<span class="comment">// asked for, \doxygen{ImageRegionIteratorWithIndex} maintains its</span>
<span class="comment">// index location as a member variable that is updated during the increment or</span>
<span class="comment">// decrement process. Iteration speed is penalized, but the index queries are</span>
<span class="comment">// more efficient.</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageRegionIteratorWithIndex!example of using|(}</span>
<span class="comment">//</span>
<span class="comment">// The following example illustrates the use of</span>
<span class="comment">// ImageRegionIteratorWithIndex.  The algorithm mirrors</span>
<span class="comment">// a 2D image across its $x$-axis (see \doxygen{FlipImageFilter} for an ND</span>
<span class="comment">// version).  The algorithm makes extensive use of the \code{GetIndex()}</span>
<span class="comment">// method.</span>
<span class="comment">//</span>
<span class="comment">// We start by including the proper header file.</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="itkImageRegionIteratorWithIndex_8h.html">itkImageRegionIteratorWithIndex.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">// For this example, we will use an RGB pixel type so that we can process color</span>
<span class="comment">// images. Like most other ITK image iterator,</span>
<span class="comment">// ImageRegionIteratorWithIndex class expects the image type as its</span>
<span class="comment">// single template parameter.</span>
<span class="comment">//</span>
<span class="comment">// Software Guide : EndLatex</span>

<span class="comment">// Software Guide : BeginCodeSnippet</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="keyword">typedef</span> <a name="_a3"></a><a class="code" href="classitk_1_1ImageRegionIteratorWithIndex.html" title="A multi-dimensional iterator templated over image type that walks pixels within a...">itk::ImageRegionIteratorWithIndex&lt; ImageType &gt;</a> IteratorType;
<span class="comment">// Software Guide : EndCodeSnippet</span>
  
  <span class="keyword">typedef</span> <a name="_a4"></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="_a5"></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="a6"></a><a class="code" href="itkFEMMacro_8h.html#68fafcc6909430ccd70cbc4aeee0107c">ImageType::ConstPointer</a> inputImage;
  <a name="a7"></a><a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">ReaderType::Pointer</a> reader = <a name="a8"></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 !"</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">// An \code{ImageType} smart pointer called \code{inputImage} points to the</span>
<span class="comment">// output of the image reader.  After updating the image reader, we can</span>
<span class="comment">// allocate an output image of the same size, spacing, and origin as the</span>
<span class="comment">// input image.</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 iterator that walks the output image.  This algorithm</span>
<span class="comment">// requires no iterator for the input image.</span>
<span class="comment">//</span>
<span class="comment">// Software Guide : EndLatex</span>

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

<span class="comment">// Software Guide: BeginLatex</span>
<span class="comment">//</span>
<span class="comment">// This axis flipping algorithm works by iterating through the output image,</span>
<span class="comment">// querying the iterator for its index, and copying the value from the input</span>
<span class="comment">// at an index mirrored across the $x$-axis.</span>
<span class="comment">//</span>
<span class="comment">// Software Guide : EndLatex</span>

<span class="comment">// Software Guide : BeginCodeSnippet</span>
  <a name="a9"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#be32dc19e71d40322ad9828b9ab40853">ImageType::IndexType</a> requestedIndex =
                outputImage-&gt;GetRequestedRegion().GetIndex();
  <a name="a10"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#5bf82236e1e50e653de84c8ead448599">ImageType::SizeType</a> requestedSize =
                outputImage-&gt;GetRequestedRegion().GetSize();

  <span class="keywordflow">for</span> ( outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt)
    {
    <a class="code" href="namespaceHardConnectedComponentImageFilter.html#be32dc19e71d40322ad9828b9ab40853">ImageType::IndexType</a> idx = outputIt.GetIndex();
    idx[0] =  requestedIndex[0] + requestedSize[0] - 1 - idx[0];
    outputIt.Set( inputImage-&gt;GetPixel(idx) );
    }
<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">// Let's run this example on the image \code{VisibleWomanEyeSlice.png} found in</span>
<span class="comment">// the \code{Examples/Data} directory.</span>
<span class="comment">// Figure~\ref{fig:ImageRegionIteratorWithIndexExample} shows how the original</span>
<span class="comment">// image has been mirrored across its $x$-axis in the output.</span>
<span class="comment">//</span>
<span class="comment">// \begin{figure} \center</span>
<span class="comment">// \includegraphics[width=0.44\textwidth]{VisibleWomanEyeSlice.eps}</span>
<span class="comment">// \includegraphics[width=0.44\textwidth]{ImageRegionIteratorWithIndexOutput.eps}</span>
<span class="comment">// \itkcaption[Using the ImageRegionIteratorWithIndex]{Results of using</span>
<span class="comment">// ImageRegionIteratorWithIndex to mirror an image across an axis. The original</span>
<span class="comment">// image is shown at left.  The mirrored output is shown at right.}</span>
<span class="comment">// \label{fig:ImageRegionIteratorWithIndexExample}</span>
<span class="comment">// \end{figure}</span>
<span class="comment">//</span>
<span class="comment">// \index{itk::ImageRegionIteratorWithIndex!example of using|)}</span>
<span class="comment">//</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>