<!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/PointSet1.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/PointSet1.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: PointSet1.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.16 $</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 \code{itk::PointSet} is a basic class intended to represent geometry</span> <span class="comment">// in the form of a set of points in n-dimensional space. It is the base</span> <span class="comment">// class for the \code{itk::Mesh} providing the methods necessary to</span> <span class="comment">// manipulate sets of point. Points can have values associated with</span> <span class="comment">// them. The type of such values is defined by a template parameter of the</span> <span class="comment">// \code{itk::PointSet} class (i.e., \code{TPixelType}. Two basic</span> <span class="comment">// interaction styles of PointSets are available in ITK. These styles are</span> <span class="comment">// referred to as \emph{static} and \emph{dynamic}. The first style is used</span> <span class="comment">// when the number of points in the set is known in advance and is not</span> <span class="comment">// expected to change as a consequence of the manipulations performed on the</span> <span class="comment">// set. The dynamic style, on the other hand, is intended to support</span> <span class="comment">// insertion and removal of points in an efficient manner. Distinguishing</span> <span class="comment">// between the two styles is meant to facilitate the fine tuning of a</span> <span class="comment">// \code{PointSet}'s behavior while optimizing performance and memory</span> <span class="comment">// management.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet}</span> <span class="comment">// \index{itk::PointSet!Static}</span> <span class="comment">// \index{itk::PointSet!Dynamic}</span> <span class="comment">//</span> <span class="comment">// In order to use the PointSet class, its header file should be included.</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="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">// Then we must decide what type of value to associate with the</span> <span class="comment">// points. This is generally called the \code{PixelType} in order to make the</span> <span class="comment">// terminology consistent with the \code{itk::Image}. The PointSet is also </span> <span class="comment">// templated over the dimension of the space in which the points are</span> <span class="comment">// represented. The following declaration illustrates a typical</span> <span class="comment">// instantiation of the PointSet class.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!Instantiation}</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_1PointSet.html" title="A superclass of the N-dimensional mesh structure; supports point (geometric coordinate...">itk::PointSet< unsigned short, 3 ></a> PointSetType; <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// A \code{PointSet} object is created by invoking the \code{New()} method</span> <span class="comment">// on its type. The resulting object must be assigned to a</span> <span class="comment">// \code{SmartPointer}. The PointSet is then reference-counted and can be</span> <span class="comment">// shared by multiple objects. The memory allocated for the PointSet will</span> <span class="comment">// be released when the number of references to the object is reduced to</span> <span class="comment">// zero. This simply means that the user does not need to be concerned</span> <span class="comment">// with invoking the \code{Delete()} method on this class. In fact, the</span> <span class="comment">// \code{Delete()} method should \textbf{never} be called directly within</span> <span class="comment">// any of the reference-counted ITK classes.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!New()}</span> <span class="comment">// \index{itk::PointSet!Pointer}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> <a name="a2"></a><a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">PointSetType::Pointer</a> pointsSet = <a name="a3"></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">// Following the principles of Generic Programming, the \code{PointSet} class has a</span> <span class="comment">// set of associated defined types to ensure that interacting objects can be</span> <span class="comment">// declared with compatible types. This set of type definitions is</span> <span class="comment">// commonly known as a set of \emph{traits}. Among them we can find the</span> <span class="comment">// \code{PointType} type, for example. This is the type used by the point set to</span> <span class="comment">// represent points in space. The following declaration takes the point</span> <span class="comment">// type as defined in the \code{PointSet} traits and renames it to be conveniently</span> <span class="comment">// used in the global namespace.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!PointType}</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::PointType PointType; <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The \code{PointType} can now be used to declare point objects to be</span> <span class="comment">// inserted in the \code{PointSet}. Points are fairly small objects, so</span> <span class="comment">// it is inconvenient to manage them with reference counting and smart</span> <span class="comment">// pointers. They are simply instantiated as typical C++ classes. The Point</span> <span class="comment">// class inherits the \code{[]} operator from the \code{itk::Array} class.</span> <span class="comment">// This makes it possible to access its components using index notation. For</span> <span class="comment">// efficiency's sake no bounds checking is performed during index access. It is</span> <span class="comment">// the user's responsibility to ensure that the index used is in the range</span> <span class="comment">// $\{0,Dimension-1\}$. Each of the components in the point is associated</span> <span class="comment">// with space coordinates. The following code illustrates how to instantiate</span> <span class="comment">// a point and initialize its components.</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> PointType p0; p0[0] = -1.0; <span class="comment">// x coordinate</span> p0[1] = -1.0; <span class="comment">// y coordinate</span> p0[2] = 0.0; <span class="comment">// z coordinate</span> <span class="comment">// Software Guide : EndCodeSnippet</span> PointType p1; p1[0] = 1.0; <span class="comment">// Point 1 = { 1,-1,0 } </span> p1[1] = -1.0; p1[2] = 0.0; PointType p2; <span class="comment">// Point 2 = { 1,1,0 }</span> p2[0] = 1.0; p2[1] = 1.0; p2[2] = 0.0; <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Points are inserted in the PointSet by using the \code{SetPoint()} method.</span> <span class="comment">// This method requires the user to provide a unique identifier for the</span> <span class="comment">// point. The identifier is typically an unsigned integer that will enumerate</span> <span class="comment">// the points as they are being inserted. The following code shows how three</span> <span class="comment">// points are inserted into the PointSet.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!SetPoint()}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> pointsSet->SetPoint( 0, p0 ); pointsSet->SetPoint( 1, p1 ); pointsSet->SetPoint( 2, p2 ); <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// It is possible to query the PointSet in order to determine how many points</span> <span class="comment">// have been inserted into it. This is done with the \code{GetNumberOfPoints()}</span> <span class="comment">// method as illustrated below.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!GetNumberOfPoints()}</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> numberOfPoints = pointsSet->GetNumberOfPoints(); std::cout << numberOfPoints << std::endl; <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Points can be read from the PointSet by using the \code{GetPoint()} method</span> <span class="comment">// and the integer identifier. The point is stored in a pointer provided by</span> <span class="comment">// the user. If the identifier provided does not match an</span> <span class="comment">// existing point, the method will return \code{false} and the contents of the</span> <span class="comment">// point will be invalid. The following code illustrates point access</span> <span class="comment">// using defensive programming.</span> <span class="comment">//</span> <span class="comment">// \index{itk::PointSet!GetPoint()}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> PointType pp; <span class="keywordtype">bool</span> pointExists = pointsSet->GetPoint( 1, & pp ); <span class="keywordflow">if</span>( pointExists ) { std::cout << <span class="stringliteral">"Point is = "</span> << pp << std::endl; } <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// \code{GetPoint()} and \code{SetPoint()} are not the most efficient methods</span> <span class="comment">// to access points in the PointSet. It is preferable to get direct access</span> <span class="comment">// to the internal point container defined by the \emph{traits} and use</span> <span class="comment">// iterators to walk sequentially over the list of points (as shown in</span> <span class="comment">// the following example).</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: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>