<!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/PointSet3.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/PointSet3.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: PointSet3.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.14 $</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{PointSet} class was designed to interact with the Image class.</span> <span class="comment">// For this reason it was found convenient to allow the points in the set to</span> <span class="comment">// hold values that could be computed from images. The value associated with</span> <span class="comment">// the point is referred as \code{PixelType} in order to make it consistent</span> <span class="comment">// with image terminology. Users can define the type as they please thanks to</span> <span class="comment">// the flexibility offered by the Generic Programming approach used in the</span> <span class="comment">// toolkit. The \code{PixelType} is the first template parameter of the</span> <span class="comment">// PointSet.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!PixelType}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="preprocessor">#include "<a class="code" href="itkPointSet_8h.html">itkPointSet.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 following code defines a particular type for a pixel type and</span> <span class="comment">// instantiates a PointSet class with it.</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> PixelType; <span class="keyword">typedef</span> <a name="_a1"></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, 3 ></a> PointSetType; <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// A point set is instantiated here</span> <a name="a2"></a><a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">PointSetType::Pointer</a> pointSet = <a name="a3"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#870262f145e0b45206db74df8053b59c">PointSetType::New</a>(); <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Data can be inserted into the PointSet using the \code{SetPointData()}</span> <span class="comment">// method. This method requires the user to provide an identifier. The data</span> <span class="comment">// in question will be associated to the point holding the same identifier.</span> <span class="comment">// It is the user's responsibility to verify the appropriate matching between</span> <span class="comment">// inserted data and inserted points. The following line illustrates the use</span> <span class="comment">// of the \code{SetPointData()} method.</span> <span class="comment">//</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> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> dataId = 0; PixelType value = 79; pointSet->SetPointData( dataId++, value ); <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Data associated with points can be read from the PointSet using the</span> <span class="comment">// \code{GetPointData()} method. This method requires the user to provide</span> <span class="comment">// the identifier to the point and a valid pointer to a location where the</span> <span class="comment">// pixel data can be safely written. In case the identifier does not match</span> <span class="comment">// any existing identifier on the PointSet the method will return</span> <span class="comment">// \code{false} and the pixel value returned will be invalid. It is the</span> <span class="comment">// user's responsibility to check the returned boolean value before</span> <span class="comment">// attempting to use it.</span> <span class="comment">//</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">const</span> <span class="keywordtype">bool</span> found = pointSet->GetPointData( dataId, & value ); <span class="keywordflow">if</span>( found ) { std::cout << <span class="stringliteral">"Pixel value = "</span> << value << std::endl; } <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The \code{SetPointData()} and \code{GetPointData()} methods are not the</span> <span class="comment">// most efficient way to get access to point data. It is far more efficient</span> <span class="comment">// to use the Iterators provided by the \code{PointDataContainer}. </span> <span class="comment">//</span> <span class="comment">// Data associated with points is internally stored in</span> <span class="comment">// \code{PointDataContainer}s. In the same way as with points, the actual</span> <span class="comment">// container type used depend on whether the style of the PointSet is static</span> <span class="comment">// or dynamic. Static point sets will use an \doxygen{VectorContainer} while</span> <span class="comment">// dynamic point sets will use an \doxygen{MapContainer}. The type of the</span> <span class="comment">// data container is defined as one of the traits in the PointSet. The</span> <span class="comment">// following declaration illustrates how the type can be taken from the</span> <span class="comment">// traits and used to conveniently declare a similar type on the global</span> <span class="comment">// namespace.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!PointDataContainer}</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 PointDataContainer; <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Using the type it is now possible to create an instance of the data</span> <span class="comment">// container. This is a standard reference counted object, henceforth it</span> <span class="comment">// uses the \code{New()} method for creation and assigns the newly created</span> <span class="comment">// object to a SmartPointer.</span> <span class="comment">//</span> <span class="comment">// \index{PointDataContainer!New()}</span> <span class="comment">// \index{PointDataContainer!Pointer}</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">PointDataContainer::Pointer</a> pointData = <a class="code" href="namespaceHardConnectedComponentImageFilter.html#870262f145e0b45206db74df8053b59c">PointDataContainer::New</a>(); <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Pixel data can be inserted in the container with the method</span> <span class="comment">// \code{InsertElement()}. This method requires an identified to be provided</span> <span class="comment">// for each point data.</span> <span class="comment">//</span> <span class="comment">// \index{PointDataContainer!InsertElement()}</span> <span class="comment">// \index{itk::VectorContainer!InsertElement()}</span> <span class="comment">// \index{itk::MapContainer!InsertElement()}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pointId = 0; PixelType value0 = 34; PixelType value1 = 67; pointData->InsertElement( pointId++ , value0 ); pointData->InsertElement( pointId++ , value1 ); <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Finally the PointDataContainer can be assigned to the PointSet. This will</span> <span class="comment">// substitute any previously existing PointDataContainer on the PointSet. The</span> <span class="comment">// assignment is done using the \code{SetPointData()} method.</span> <span class="comment">//</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> pointSet->SetPointData( pointData ); <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The PointDataContainer can be obtained from the PointSet using the</span> <span class="comment">// \code{GetPointData()} method. This method returns a pointer (assigned to</span> <span class="comment">// a SmartPointer) to the actual container owned by the PointSet.</span> <span class="comment">//</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> <a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">PointDataContainer::Pointer</a> pointData2 = pointSet->GetPointData(); <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The most efficient way to sequentially visit the data associated with</span> <span class="comment">// points is to use the iterators provided by \code{PointDataContainer}. The</span> <span class="comment">// \code{Iterator} type belongs to the traits of the PointsContainer</span> <span class="comment">// classes. The iterator is not a reference counted class, so it is just</span> <span class="comment">// created directly from the traits without using SmartPointers.</span> <span class="comment">//</span> <span class="comment">// \index{PointDataContainer!Iterator}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> <span class="keyword">typedef</span> PointDataContainer::Iterator PointDataIterator; <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The subsequent use of the iterator follows what you may expect from a STL</span> <span class="comment">// iterator. The iterator to the first point is obtained from the container</span> <span class="comment">// with the \code{Begin()} method and assigned to another iterator.</span> <span class="comment">//</span> <span class="comment">// \index{PointDataContainer!Begin()}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> PointDataIterator pointDataIterator = pointData2->Begin(); <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The \code{++} operator on the iterator can be used to advance from one</span> <span class="comment">// data point to the next. The actual value of the PixelType to which the</span> <span class="comment">// iterator is pointing can be obtained with the \code{Value()}</span> <span class="comment">// method. The loop for walking through all the point data can be</span> <span class="comment">// controlled by comparing the current iterator with the iterator returned</span> <span class="comment">// by the \code{End()} method of the PointsContainer. The following lines</span> <span class="comment">// illustrate the typical loop for walking through the point data.</span> <span class="comment">//</span> <span class="comment">// \index{PointDataContainer!End()}</span> <span class="comment">// \index{PointDataContainer!increment ++}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> PointDataIterator end = pointData2->End(); <span class="keywordflow">while</span>( pointDataIterator != end ) { PixelType p = pointDataIterator.Value(); <span class="comment">// access the pixel data</span> std::cout << p << std::endl; <span class="comment">// print the pixel data</span> ++pointDataIterator; <span class="comment">// advance to next pixel/point</span> } <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Note that as in STL, the iterator returned by the \code{End()} method is</span> <span class="comment">// not a valid iterator. This is called a \emph{past-end} iterator in order</span> <span class="comment">// to indicate that it is the value resulting from advancing one step after</span> <span class="comment">// visiting the last element in the container.</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>