<!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/Mesh/PointSetWithVectors.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/Mesh/PointSetWithVectors.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: PointSetWithVectors.cxx,v $</span> <span class="comment"> Language: C++</span> <span class="comment"> Date: $Date: 2005-11-19 16:31:49 $</span> <span class="comment"> Version: $Revision: 1.17 $</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">// This example illustrates how a point set can be parameterized to manage a</span> <span class="comment">// particular pixel type. It is quite common to associate vector values with</span> <span class="comment">// points for producing geometric representations. The following code shows</span> <span class="comment">// how vector values can be used as pixel type on the PointSet class. The</span> <span class="comment">// \doxygen{Vector} class is used here as the pixel type. This class is</span> <span class="comment">// appropriate for representing the relative position between two points. It</span> <span class="comment">// could then be used to manage displacements, for example.</span> <span class="comment">// </span> <span class="comment">// \index{itk::PointSet!Vector pixels}</span> <span class="comment">// </span> <span class="comment">// In order to use the vector class it is necessary to include its header file</span> <span class="comment">// along with the header of the point set.</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="preprocessor">#include "<a class="code" href="itkPointSet_8h.html">itkPointSet.h</a>"</span> <span class="comment">// Software Guide : EndCodeSnippet</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">// \itkpiccaption[PointSet with Vectors as PixelType]{Vectors as PixelType.\label{fig:PointSetWithVectors}}</span> <span class="comment">// \parpic(6cm,4cm)[r]{\includegraphics[width=4cm]{PointSetWithVectors.eps}}</span> <span class="comment">//</span> <span class="comment">// The Vector class is templated over the type used to represent</span> <span class="comment">// the spatial coordinates and over the space dimension. Since the</span> <span class="comment">// PixelType is independent of the PointType, we are free to select any</span> <span class="comment">// dimension for the vectors to be used as pixel type. However, for the</span> <span class="comment">// sake of producing an interesting example, we will use vectors that </span> <span class="comment">// represent displacements of the points in the PointSet. Those vectors</span> <span class="comment">// are then selected to be of the same dimension as the PointSet.</span> <span class="comment">//</span> <span class="comment">// \index{itk::Vector!itk::PointSet}</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 = 3; <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, Dimension ></a> PixelType; <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Then we use the PixelType (which are actually Vectors) to instantiate the</span> <span class="comment">// PointSet type and subsequently create a PointSet object.</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="_a2"></a><a class="code" href="classitk_1_1PointSet.html" title="A superclass of the N-dimensional mesh structure; supports point (geometric coordinate...">itk::PointSet< PixelType, Dimension ></a> PointSetType; <a name="a3"></a><a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">PointSetType::Pointer</a> pointSet = <a name="a4"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#870262f145e0b45206db74df8053b59c">PointSetType::New</a>(); <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The following code is generating a sphere and assigning vector values</span> <span class="comment">// to the points. The components of the vectors in this example are</span> <span class="comment">// computed to represent the tangents to the circle as shown in</span> <span class="comment">// Figure~\ref{fig:PointSetWithVectors}.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!SetPoint()}</span> <span class="comment">// \index{itk::PointSet!SetPointData()}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> PointSetType::PixelType tangent; PointSetType::PointType point; <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pointId = 0; <span class="keyword">const</span> <span class="keywordtype">double</span> radius = 300.0; <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i<360; i++) { <span class="keyword">const</span> <span class="keywordtype">double</span> angle = i * atan(1.0) / 45.0; point[0] = radius * sin( angle ); point[1] = radius * cos( angle ); point[2] = 1.0; <span class="comment">// flat on the Z plane</span> tangent[0] = cos(angle); tangent[1] = -sin(angle); tangent[2] = 0.0; <span class="comment">// flat on the Z plane</span> pointSet->SetPoint( pointId, point ); pointSet->SetPointData( pointId, tangent ); pointId++; } <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// We can now visit all the points and use the vector on the pixel values to</span> <span class="comment">// apply a displacement on the points. This is along the spirit of what a</span> <span class="comment">// deformable model could do at each one of its iterations. </span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!PointIterator}</span> <span class="comment">// \index{itk::PointSet!GetPoints()}</span> <span class="comment">// \index{itk::PointSet!GetPointData()}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> <span class="keyword">typedef</span> PointSetType::PointDataContainer::ConstIterator PointDataIterator; PointDataIterator pixelIterator = pointSet->GetPointData()->Begin(); PointDataIterator pixelEnd = pointSet->GetPointData()->End(); <span class="keyword">typedef</span> PointSetType::PointsContainer::Iterator PointIterator; PointIterator pointIterator = pointSet->GetPoints()->Begin(); PointIterator pointEnd = pointSet->GetPoints()->End(); <span class="keywordflow">while</span>( pixelIterator != pixelEnd && pointIterator != pointEnd ) { pointIterator.Value() = pointIterator.Value() + pixelIterator.Value(); ++pixelIterator; ++pointIterator; } <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Note that the \code{ConstIterator} was used here instead of the normal</span> <span class="comment">// \code{Iterator} since the pixel values are only intended to be read and</span> <span class="comment">// not modified. ITK supports const-correctness at the API level.</span> <span class="comment">//</span> <span class="comment">// \index{ConstIterator}</span> <span class="comment">// \index{const-correctness}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The \doxygen{Vector} class has overloaded the \code{+} operator with</span> <span class="comment">// the \doxygen{Point}. In other words, vectors can be added to points in</span> <span class="comment">// order to produce new points. This property is exploited in the center</span> <span class="comment">// of the loop in order to update the points positions with a single</span> <span class="comment">// statement.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!PointIterator}</span> <span class="comment">//</span> <span class="comment">// We can finally visit all the points and print out the new values</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> pointIterator = pointSet->GetPoints()->Begin(); pointEnd = pointSet->GetPoints()->End(); <span class="keywordflow">while</span>( pointIterator != pointEnd ) { std::cout << pointIterator.Value() << std::endl; ++pointIterator; } <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Note that \doxygen{Vector} is not the appropriate class for</span> <span class="comment">// representing normals to surfaces and gradients of functions. This is due</span> <span class="comment">// to the way in which vectors behave under affine transforms. ITK has a</span> <span class="comment">// specific class for representing normals and function gradients. This is</span> <span class="comment">// the \doxygen{CovariantVector} class.</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:08 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>