Sophie

Sophie

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

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: DataRepresentation/Mesh/PointSetWithCovariantVectors.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>DataRepresentation/Mesh/PointSetWithCovariantVectors.cxx</h1><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: PointSetWithCovariantVectors.cxx,v $</span>
<span class="comment">  Language:  C++</span>
<span class="comment">  Date:      $Date: 2008-01-20 21:19:51 $</span>
<span class="comment">  Version:   $Revision: 1.15 $</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">//  It is common to represent geometric object by using points on their surfaces</span>
<span class="comment">//  and normals associated with those points.  This structure can be easily </span>
<span class="comment">//  instantiated with the \doxygen{PointSet} class.</span>
<span class="comment">//</span>
<span class="comment">//  The natural class for representing normals to surfaces and</span>
<span class="comment">//  gradients of functions is the \doxygen{CovariantVector}. A</span>
<span class="comment">//  covariant vector differs from a vector in the way they behave</span>
<span class="comment">//  under affine transforms, in particular under anisotropic</span>
<span class="comment">//  scaling. If a covariant vector represents the gradient of a</span>
<span class="comment">//  function, the transformed covariant vector will still be the valid</span>
<span class="comment">//  gradient of the transformed function, a property which would not</span>
<span class="comment">//  hold with a regular vector.</span>
<span class="comment">// </span>
<span class="comment">//  \index{itk::PointSet!itk::CovariantVector}</span>
<span class="comment">//  \index{itk::CovariantVector!itk::PointSet}</span>
<span class="comment">//</span>
<span class="comment">//  The following code shows how vector values can be used as pixel type on the</span>
<span class="comment">//  PointSet class.  The CovariantVector class is used here as the</span>
<span class="comment">//  pixel type. The example illustrates how a deformable model could move under</span>
<span class="comment">//  the influence of the gradient of potential function.</span>
<span class="comment">//  </span>
<span class="comment">//  In order to use the CovariantVector class it is necessary to</span>
<span class="comment">//  include its header file along with the header of the point set.</span>
<span class="comment">//</span>
<span class="comment">//  \index{itk::CovariantVector!Header}</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="itkCovariantVector_8h.html">itkCovariantVector.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">//  The CovariantVector class is templated over the type used to</span>
  <span class="comment">//  represent the spatial coordinates and over the space dimension.  Since</span>
  <span class="comment">//  the PixelType is independent of the PointType, we are free to select any</span>
  <span class="comment">//  dimension for the covariant vectors to be used as pixel type. However, we</span>
  <span class="comment">//  want to illustrate here the spirit of a deformable model. It is then</span>
  <span class="comment">//  required for the vectors representing gradients to be of the same</span>
  <span class="comment">//  dimension as the points in space.</span>
  <span class="comment">//</span>
  <span class="comment">//  \index{itk::CovariantVector!Instantiation}</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_1CovariantVector.html" title="A templated class holding a n-Dimensional covariant vector.">itk::CovariantVector&lt; float, Dimension &gt;</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 CovariantVectors) to</span>
  <span class="comment">//  instantiate the 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&lt; PixelType, Dimension &gt;</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 generates a sphere and assigns gradient values to</span>
  <span class="comment">//  the points. The components of the CovariantVectors in this example are</span>
  <span class="comment">//  computed to represent the normals to the circle.</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   gradient;
  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&lt;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>
    gradient[0] =  sin(angle);
    gradient[1] =  cos(angle);
    gradient[2] = 0.0;  <span class="comment">// flat on the Z plane</span>
    pointSet-&gt;SetPoint( pointId, point );   
    pointSet-&gt;SetPointData( pointId, gradient );   
    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</span>
  <span class="comment">//  to apply a deformation on the points by following the gradient of the</span>
  <span class="comment">//  function. This is along the spirit of what a deformable model could do</span>
  <span class="comment">//  at each one of its iterations. To be more formal we should use the</span>
  <span class="comment">//  function gradients as forces and multiply them by local stress tensors</span>
  <span class="comment">//  in order to obtain local deformations.  The resulting deformations</span>
  <span class="comment">//  would finally be used to apply displacements on the points.  However,</span>
  <span class="comment">//  to shorten the example, we will ignore this complexity for the moment.</span>
  <span class="comment">//</span>
  <span class="comment">//  \index{itk::PointSet!PointDataIterator}</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-&gt;GetPointData()-&gt;Begin();
  PointDataIterator pixelEnd      = pointSet-&gt;GetPointData()-&gt;End();

  <span class="keyword">typedef</span>  PointSetType::PointsContainer::Iterator     PointIterator;
  PointIterator pointIterator = pointSet-&gt;GetPoints()-&gt;Begin();
  PointIterator pointEnd      = pointSet-&gt;GetPoints()-&gt;End();

  <span class="keywordflow">while</span>( pixelIterator != pixelEnd  &amp;&amp; pointIterator != pointEnd ) 
    {
    point    = pointIterator.Value();
    gradient = pixelIterator.Value();
    <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;Dimension; i++) 
      {
      point[i] += gradient[i];
      } 
    pointIterator.Value() = point;
    ++pixelIterator;
    ++pointIterator;
    }
  <span class="comment">// Software Guide : EndCodeSnippet</span>


  <span class="comment">//  Software Guide : BeginLatex</span>
  <span class="comment">//</span>
  <span class="comment">//  The CovariantVector class does not overload the \code{+}</span>
  <span class="comment">//  operator with the \doxygen{Point}. In other words, CovariantVectors can</span>
  <span class="comment">//  not be added to points in order to get new points. Further, since we</span>
  <span class="comment">//  are ignoring physics in the example, we are also forced to do the</span>
  <span class="comment">//  illegal addition manually between the components of the gradient and</span>
  <span class="comment">//  the coordinates of the points.</span>
  <span class="comment">//</span>
  <span class="comment">//  Note that the absence of some basic operators on the ITK geometry classes</span>
  <span class="comment">//  is completely intentional with the aim of preventing the  incorrect use</span>
  <span class="comment">//  of the mathematical concepts they represent.</span>
  <span class="comment">//</span>
  <span class="comment">//  \index{itk::CovariantVector}</span>
  <span class="comment">//</span>
  <span class="comment">//  Software Guide : EndLatex </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>
  pointIterator = pointSet-&gt;GetPoints()-&gt;Begin();
  pointEnd      = pointSet-&gt;GetPoints()-&gt;End();
  <span class="keywordflow">while</span>( pointIterator != pointEnd ) 
    {
    std::cout &lt;&lt; pointIterator.Value() &lt;&lt; std::endl;
    ++pointIterator;
    }


  <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>,
 &copy;&nbsp;1997-2000</small></address>
</body>
</html>