<!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: DataRepresentation/Image/VectorImage.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> <a href="modules.html" class="qindex">Groups</a> <a href="namespaces.html" class="qindex">Namespace List</a> <a href="hierarchy.html" class="qindex">Class Hierarchy</a> <a href="classes.html" class="qindex">Alphabetical List</a> <a href="annotated.html" class="qindex">Compound List</a> <a href="files.html" class="qindex">File List</a> <a href="namespacemembers.html" class="qindex">Namespace Members</a> <a href="functions.html" class="qindex">Compound Members</a> <a href="globals.html" class="qindex">File Members</a> <a href="pages.html" class="qindex">Concepts</a></center> <!-- Generated by Doxygen 1.5.9 --> <div class="contents"> <h1>DataRepresentation/Image/VectorImage.cxx</h1><div class="fragment"><pre class="fragment"><span class="comment">/*=========================================================================</span> <span class="comment"></span> <span class="comment"> Program: Insight Segmentation & Registration Toolkit</span> <span class="comment"> Module: $RCSfile: VectorImage.cxx,v $</span> <span class="comment"> Language: C++</span> <span class="comment"> Date: $Date: 2005-02-08 03:51:53 $</span> <span class="comment"> Version: $Revision: 1.12 $</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">// Many image processing tasks require images of non-scalar pixel type. A</span> <span class="comment">// typical example is an image of vectors. This is the image type required to</span> <span class="comment">// represent the gradient of a scalar image. The following code illustrates</span> <span class="comment">// how to instantiate and use an image whose pixels are of vector type.</span> <span class="comment">//</span> <span class="comment">// For convenience we use the \doxygen{Vector} class to define the pixel</span> <span class="comment">// type. The Vector class is intended to represent a geometrical vector in</span> <span class="comment">// space. It is not intended to be used as an array container like the</span> <span class="comment">// \href{http://www.sgi.com/tech/stl/Vector.html}{\code{std::vector}} in</span> <span class="comment">// \href{http://www.sgi.com/tech/stl/}{STL}. If you are interested in</span> <span class="comment">// containers, the \doxygen{VectorContainer} class may provide the</span> <span class="comment">// functionality you want.</span> <span class="comment">//</span> <span class="comment">// \index{itk::Vector}</span> <span class="comment">// \index{itk::Vector!header}</span> <span class="comment">//</span> <span class="comment">//</span> <span class="comment">// The first step is to include the header file of the Vector class.</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> <span class="preprocessor">#include "<a class="code" href="itkVector_8h.html">itkVector.h</a>"</span> <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="preprocessor">#include "<a class="code" href="itkImage_8h.html">itkImage.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>, <span class="keywordtype">char</span> *[]) { <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">// </span> <span class="comment">// The Vector class is templated over the type used to represent</span> <span class="comment">// the coordinate in space and over the dimension of the space. In this example,</span> <span class="comment">// we want the vector dimension to match the image dimension, but this is by</span> <span class="comment">// no means a requirement. We could have defined a four-dimensional image</span> <span class="comment">// with three-dimensional vectors as pixels.</span> <span class="comment">//</span> <span class="comment">// \index{itk::Vector!Instantiation}</span> <span class="comment">// \index{itk::Vector!itk::Image}</span> <span class="comment">// \index{itk::Image!Vector pixel}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> <span class="keyword">typedef</span> <a name="_a1"></a><a class="code" href="classitk_1_1Vector.html" title="A templated class holding a n-Dimensional vector.">itk::Vector< float, 3 ></a> PixelType; <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< PixelType, 3 ></a> ImageType; <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Then the image object can be created</span> <a name="a3"></a><a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">ImageType::Pointer</a> image = <a name="a4"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#870262f145e0b45206db74df8053b59c">ImageType::New</a>(); <span class="comment">// The image region should be initialized</span> <a name="a5"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#be32dc19e71d40322ad9828b9ab40853">ImageType::IndexType</a> start; <a name="a6"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#5bf82236e1e50e653de84c8ead448599">ImageType::SizeType</a> size; size[0] = 200; <span class="comment">// size along X</span> size[1] = 200; <span class="comment">// size along Y</span> size[2] = 200; <span class="comment">// size along Z</span> start[0] = 0; <span class="comment">// first index on X</span> start[1] = 0; <span class="comment">// first index on Y</span> start[2] = 0; <span class="comment">// first index on Z</span> <a name="a7"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#ed8c4a40607d317c666eb96ea265e126">ImageType::RegionType</a> region; region.SetSize( size ); region.SetIndex( start ); <span class="comment">// Pixel data is allocated</span> image->SetRegions( region ); image->Allocate(); <span class="comment">// The image buffer is initialized to a particular value</span> ImageType::PixelType initialValue; <span class="comment">// A vector can initialize all its components to the</span> <span class="comment">// same value by using the Fill() method.</span> initialValue.Fill( 0.0 ); <span class="comment">// Now the image buffer can be initialized with this</span> <span class="comment">// vector value.</span> image->FillBuffer( initialValue ); <a class="code" href="namespaceHardConnectedComponentImageFilter.html#be32dc19e71d40322ad9828b9ab40853">ImageType::IndexType</a> pixelIndex; pixelIndex[0] = 27; <span class="comment">// x position</span> pixelIndex[1] = 29; <span class="comment">// y position</span> pixelIndex[2] = 37; <span class="comment">// z position</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The Vector class inherits the operator \code{[]} from the</span> <span class="comment">// \doxygen{FixedArray} class. This makes it possible to access the</span> <span class="comment">// Vector's components using index notation.</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> ImageType::PixelType pixelValue; pixelValue[0] = 1.345; <span class="comment">// x component</span> pixelValue[1] = 6.841; <span class="comment">// y component</span> pixelValue[2] = 3.295; <span class="comment">// x component</span> <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// We can now store this vector in one of the image pixels by defining an</span> <span class="comment">// index and invoking the \code{SetPixel()} method.</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> image->SetPixel( pixelIndex, pixelValue ); <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// The GetPixel method can also be used to read Vectors </span> <span class="comment">// pixels from the image</span> ImageType::PixelType value = image->GetPixel( pixelIndex ); <span class="comment">// Lets repeat that both \code{SetPixel()} and \code{GetPixel()} are</span> <span class="comment">// inefficient and should only be used for debugging purposes or for</span> <span class="comment">// implementing interactions with a graphical user interface such as</span> <span class="comment">// querying pixel value by clicking with the mouse.</span> <span class="keywordflow">return</span> 0; } </pre></div> </div> <hr><address><small> Generated at Thu May 7 22:04:07 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>, © 1997-2000</small></address> </body> </html>