<!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: itkContourExtractor2DImageFilter.h Source File</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="navpath"><a class="el" href="dir_02e23d841c198393a6e961e9a0678fff.html">Code</a> » <a class="el" href="dir_dd352b1cbb04f9ff09fa5f33693fed9f.html">Review</a> </div> <div class="contents"> <h1>itkContourExtractor2DImageFilter.h</h1><a href="itkContourExtractor2DImageFilter_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*=========================================================================</span> <a name="l00002"></a>00002 <span class="comment"></span> <a name="l00003"></a>00003 <span class="comment"> Program: Insight Segmentation & Registration Toolkit</span> <a name="l00004"></a>00004 <span class="comment"> Module: $RCSfile: itkContourExtractor2DImageFilter.h,v $</span> <a name="l00005"></a>00005 <span class="comment"> Language: C++</span> <a name="l00006"></a>00006 <span class="comment"> Date: $Date: 2008-12-06 13:28:10 $</span> <a name="l00007"></a>00007 <span class="comment"> Version: $Revision: 1.10 $</span> <a name="l00008"></a>00008 <span class="comment"></span> <a name="l00009"></a>00009 <span class="comment"> Copyright (c) Insight Software Consortium. All rights reserved.</span> <a name="l00010"></a>00010 <span class="comment"> See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.</span> <a name="l00011"></a>00011 <span class="comment"></span> <a name="l00012"></a>00012 <span class="comment"> This software is distributed WITHOUT ANY WARRANTY; without even </span> <a name="l00013"></a>00013 <span class="comment"> the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR </span> <a name="l00014"></a>00014 <span class="comment"> PURPOSE. See the above copyright notices for more information.</span> <a name="l00015"></a>00015 <span class="comment"></span> <a name="l00016"></a>00016 <span class="comment">=========================================================================*/</span> <a name="l00017"></a>00017 <a name="l00018"></a>00018 <span class="preprocessor">#ifndef __itkContourExtractor2DImageFilter_h</span> <a name="l00019"></a>00019 <span class="preprocessor"></span><span class="preprocessor">#define __itkContourExtractor2DImageFilter_h</span> <a name="l00020"></a>00020 <span class="preprocessor"></span> <a name="l00021"></a>00021 <span class="preprocessor">#include "<a class="code" href="itkImageToPathFilter_8h.html">itkImageToPathFilter.h</a>"</span> <a name="l00022"></a>00022 <span class="preprocessor">#include "itkNumericTraits.h"</span> <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="itkPolyLineParametricPath_8h.html">itkPolyLineParametricPath.h</a>"</span> <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="itkConceptChecking_8h.html">itkConceptChecking.h</a>"</span> <a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="itk__hash__map_8h.html">itk_hash_map.h</a>"</span> <a name="l00026"></a>00026 <span class="preprocessor">#include "vcl_deque.h"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "vcl_list.h"</span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="keyword">namespace </span>itk <a name="l00030"></a>00030 { <a name="l00091"></a>00091 <span class="keyword">template</span> <<span class="keyword">class</span> TInputImage> <a name="l00092"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html">00092</a> <span class="keyword">class </span><a class="code" href="itkWin32Header_8h.html#7d4384322557205d75f0719c012dded6">ITK_EXPORT</a> <a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html" title="Computes a list of PolyLineParametricPath objects from the contours in a 2D image...">ContourExtractor2DImageFilter</a> : <a name="l00093"></a>00093 <span class="keyword">public</span> <a class="code" href="classitk_1_1ImageToPathFilter.html" title="Base class for filters that take an image as input and produce an path as output...">ImageToPathFilter</a>< TInputImage, PolyLineParametricPath<2> > <a name="l00094"></a>00094 { <a name="l00095"></a>00095 <span class="keyword">public</span>: <a name="l00097"></a>00097 <a class="code" href="itkMacro_8h.html#1905cf6b2e88235996fa7ff73b2fb0eb">itkStaticConstMacro</a>(InputImageDimension, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>, <a name="l00098"></a>00098 TInputImage::ImageDimension); <a name="l00099"></a>00099 <a name="l00101"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#401cec8ee539591c6053ce41493d8eaa">00101</a> <span class="keyword">typedef</span> TInputImage <a class="code" href="namespaceHardConnectedComponentImageFilter.html#3742cbac150bee74daa9aab85ed80623">InputImageType</a>; <a name="l00102"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#2c5d5cc7d9d0b6faf434c1e981e74642">00102</a> <span class="keyword">typedef</span> <a class="code" href="classitk_1_1PolyLineParametricPath.html" title="Represent a path of line segments through ND Space.">PolyLineParametricPath<2></a> <a class="code" href="classitk_1_1PolyLineParametricPath.html" title="Represent a path of line segments through ND Space.">OutputPathType</a>; <a name="l00103"></a>00103 <a name="l00105"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#67cd4decad6d409b649c5810afee0184">00105</a> <span class="keyword">typedef</span> <a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html" title="Computes a list of PolyLineParametricPath objects from the contours in a 2D image...">ContourExtractor2DImageFilter</a> <a class="code" href="classitk_1_1LightObject.html" title="Light weight base class for most itk classes.">Self</a>; <a name="l00106"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#c1efac1d57b11b1d1ab2772ca6d89fbc">00106</a> <span class="keyword">typedef</span> <a class="code" href="classitk_1_1ImageToPathFilter.html" title="Base class for filters that take an image as input and produce an path as output...">ImageToPathFilter<InputImageType, OutputPathType></a> <a class="code" href="classitk_1_1LightObject.html" title="Light weight base class for most itk classes.">Superclass</a>; <a name="l00107"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#c4e2a4370d47f2181fc72afc24ac6f29">00107</a> <span class="keyword">typedef</span> <a class="code" href="classitk_1_1SmartPointer.html">SmartPointer<Self></a> <a class="code" href="classitk_1_1SmartPointer.html">Pointer</a>; <a name="l00108"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#1af6a0893377cef8da9e02ff6c7e251a">00108</a> <span class="keyword">typedef</span> <a class="code" href="classitk_1_1SmartPointer.html">SmartPointer<const Self></a> <a class="code" href="classitk_1_1SmartPointer.html">ConstPointer</a>; <a name="l00109"></a>00109 <a name="l00111"></a>00111 <a class="code" href="itkMacro_8h.html#0fdc15685afa271857c57e7cd482f30c">itkNewMacro</a>(<a class="code" href="classitk_1_1LightObject.html" title="Light weight base class for most itk classes.">Self</a>); <a name="l00112"></a>00112 <a name="l00114"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#53c7369f796dfb0ec29b6122ee65a518">00114</a> <a class="code" href="itkMacro_8h.html#574c1f86661d409dd32c742307a0e96a">itkTypeMacro</a>(<a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html" title="Computes a list of PolyLineParametricPath objects from the contours in a 2D image...">ContourExtractor2DImageFilter</a>, <a class="code" href="classitk_1_1ImageToPathFilter.html" title="Base class for filters that take an image as input and produce an path as output...">ImageToPathFilter</a>); <a name="l00115"></a>00115 <a name="l00117"></a>00117 <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">InputImageType::Pointer</a> InputImagePointer; <a name="l00118"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#29a5528653b4b357034505acdf2e771d">00118</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> InputImageType::PixelType <a class="code" href="namespaceHardConnectedComponentImageFilter.html#6e44b89d73d576fe68c175566a634ab8">InputPixelType</a>; <a name="l00119"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#b3ab2fa8394ae8594b8ca7f2f43e0661">00119</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="namespaceHardConnectedComponentImageFilter.html#be32dc19e71d40322ad9828b9ab40853">InputImageType::IndexType</a> InputIndexType; <a name="l00120"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#2d4b3850f15dca6b5026b68f0f157cb3">00120</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> InputImageType::OffsetType InputOffsetType; <a name="l00121"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#8f0e7d00c98e74aeed61ae478609d0aa">00121</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="namespaceHardConnectedComponentImageFilter.html#ed8c4a40607d317c666eb96ea265e126">InputImageType::RegionType</a> InputRegionType; <a name="l00122"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#b669058c70396f850577a8d46c7427f0">00122</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="classitk_1_1SmartPointer.html">OutputPathType::Pointer</a> <a class="code" href="classitk_1_1SmartPointer.html">OutputPathPointer</a>; <a name="l00123"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#d19b7c1bae55d5783a88d7f7c870fd67">00123</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="classitk_1_1ContinuousIndex.html" title="A templated class holding a point in n-Dimensional image space.">OutputPathType::VertexType</a> <a class="code" href="classitk_1_1ContinuousIndex.html" title="A templated class holding a point in n-Dimensional image space.">VertexType</a>; <a name="l00124"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#8d74c1cdf5c5af352cba3b49137e2a34">00124</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="classitk_1_1VectorContainer.html">OutputPathType::VertexListType</a> <a class="code" href="classitk_1_1VectorContainer.html">VertexListType</a>; <a name="l00125"></a>00125 <a name="l00127"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#eb180fdacaeecc08d391497dd230be7d">00127</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> NumericTraits<InputPixelType>::RealType InputRealType; <a name="l00128"></a>00128 <a name="l00129"></a>00129 <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="classitk_1_1SmartPointer.html">VertexListType::ConstPointer</a> <a name="l00130"></a><a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html#c15d7d6b686aa4ebe1807a3d027047d8">00130</a> <a class="code" href="classitk_1_1SmartPointer.html">VertexListConstPointer</a>; <a name="l00133"></a>00133 <a class="code" href="itkMacro_8h.html#7ebdd33cc5e7d74720ced9099c034faa">itkSetMacro</a>(ReverseContourOrientation, <span class="keywordtype">bool</span>); <a name="l00134"></a>00134 <a class="code" href="itkMacro_8h.html#7d989c13a1a213168db99ae0f84185d4">itkGetConstReferenceMacro</a>(ReverseContourOrientation, <span class="keywordtype">bool</span>); <a name="l00135"></a>00135 <a class="code" href="itkMacro_8h.html#9e7d129ffebb09fd28bc213e02d87248">itkBooleanMacro</a>(ReverseContourOrientation); <a name="l00137"></a>00137 <a name="l00141"></a>00141 <a class="code" href="itkMacro_8h.html#7ebdd33cc5e7d74720ced9099c034faa">itkSetMacro</a>(VertexConnectHighPixels, <span class="keywordtype">bool</span>); <a name="l00142"></a>00142 <a class="code" href="itkMacro_8h.html#7d989c13a1a213168db99ae0f84185d4">itkGetConstReferenceMacro</a>(VertexConnectHighPixels, <span class="keywordtype">bool</span>); <a name="l00143"></a>00143 <a class="code" href="itkMacro_8h.html#9e7d129ffebb09fd28bc213e02d87248">itkBooleanMacro</a>(VertexConnectHighPixels); <a name="l00145"></a>00145 <a name="l00148"></a>00148 <span class="keywordtype">void</span> SetRequestedRegion(<span class="keyword">const</span> InputRegionType region); <a name="l00149"></a>00149 <a class="code" href="itkMacro_8h.html#7d989c13a1a213168db99ae0f84185d4">itkGetConstReferenceMacro</a>(RequestedRegion, InputRegionType); <a name="l00150"></a>00150 <span class="keywordtype">void</span> ClearRequestedRegion(); <a name="l00152"></a>00152 <a name="l00155"></a>00155 <a class="code" href="itkMacro_8h.html#7ebdd33cc5e7d74720ced9099c034faa">itkSetMacro</a>(ContourValue,InputRealType); <a name="l00156"></a>00156 <a class="code" href="itkMacro_8h.html#7d989c13a1a213168db99ae0f84185d4">itkGetConstReferenceMacro</a>(ContourValue, InputRealType); <a name="l00158"></a>00158 <a name="l00159"></a>00159 <a name="l00160"></a>00160 <span class="preprocessor">#ifdef ITK_USE_CONCEPT_CHECKING</span> <a name="l00161"></a>00161 <span class="preprocessor"></span> <a name="l00162"></a>00162 <a class="code" href="itkConceptChecking_8h.html#009eae6c305d9c390972159815e6a710">itkConceptMacro</a>(DimensionShouldBe2, <a name="l00163"></a>00163 (<a class="code" href="structitk_1_1Concept_1_1SameDimension.html">Concept::SameDimension</a><<a class="code" href="itkMacro_8h.html#94ef2dc11d52c8ef0a78e34558feb8cb">itkGetStaticConstMacro</a>(InputImageDimension),2>)); <a name="l00164"></a>00164 <a class="code" href="itkConceptChecking_8h.html#009eae6c305d9c390972159815e6a710">itkConceptMacro</a>(InputPixelTypeComparable, <a name="l00165"></a>00165 (<a class="code" href="structitk_1_1Concept_1_1Comparable.html">Concept::Comparable<InputPixelType></a>)); <a name="l00166"></a>00166 <a class="code" href="itkConceptChecking_8h.html#009eae6c305d9c390972159815e6a710">itkConceptMacro</a>(InputHasPixelTraitsCheck, <a name="l00167"></a>00167 (<a class="code" href="structitk_1_1Concept_1_1HasPixelTraits.html">Concept::HasPixelTraits<InputPixelType></a>)); <a name="l00168"></a>00168 <a class="code" href="itkConceptChecking_8h.html#009eae6c305d9c390972159815e6a710">itkConceptMacro</a>(InputHasNumericTraitsCheck, <a name="l00169"></a>00169 (<a class="code" href="structitk_1_1Concept_1_1HasNumericTraits.html">Concept::HasNumericTraits<InputPixelType></a>)); <a name="l00170"></a>00170 <a name="l00172"></a>00172 <span class="preprocessor">#endif</span> <a name="l00173"></a>00173 <span class="preprocessor"></span> <a name="l00174"></a>00174 <span class="keyword">protected</span>: <a name="l00175"></a>00175 <a name="l00176"></a>00176 <a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html" title="Computes a list of PolyLineParametricPath objects from the contours in a 2D image...">ContourExtractor2DImageFilter</a>(); <a name="l00177"></a>00177 <span class="keyword">virtual</span> ~<a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html" title="Computes a list of PolyLineParametricPath objects from the contours in a 2D image...">ContourExtractor2DImageFilter</a>(); <a name="l00178"></a>00178 <span class="keywordtype">void</span> <a class="code" href="namespaceHardConnectedComponentImageFilter.html#920ae03048a5ad715d803ca2e92b52de">PrintSelf</a>(std::ostream& os, <a class="code" href="classitk_1_1Indent.html" title="Control indentation during Print() invocation.">Indent</a> indent) <span class="keyword">const</span>; <a name="l00179"></a>00179 <a name="l00180"></a>00180 <span class="keywordtype">void</span> <a class="code" href="namespaceHardConnectedComponentImageFilter.html#f75a5945cdd8315676941024a0b8c1e9">GenerateData</a>(); <a name="l00181"></a>00181 <a name="l00185"></a>00185 <span class="keyword">virtual</span> <span class="keywordtype">void</span> GenerateInputRequestedRegion() <a name="l00186"></a>00186 throw(<a class="code" href="classitk_1_1InvalidRequestedRegionError.html">InvalidRequestedRegionError</a>); <a name="l00187"></a>00187 <a name="l00188"></a>00188 private: <a name="l00189"></a>00189 <a class="code" href="classitk_1_1ContinuousIndex.html" title="A templated class holding a point in n-Dimensional image space.">VertexType</a> InterpolateContourPosition(<a class="code" href="namespaceHardConnectedComponentImageFilter.html#6e44b89d73d576fe68c175566a634ab8">InputPixelType</a> fromValue, <a name="l00190"></a>00190 <a class="code" href="namespaceHardConnectedComponentImageFilter.html#6e44b89d73d576fe68c175566a634ab8">InputPixelType</a> toValue, <a name="l00191"></a>00191 InputIndexType fromIndex, <a name="l00192"></a>00192 InputOffsetType toOffset); <a name="l00193"></a>00193 <span class="keywordtype">void</span> AddSegment(const <a class="code" href="classitk_1_1ContinuousIndex.html" title="A templated class holding a point in n-Dimensional image space.">VertexType</a> from, const <a class="code" href="classitk_1_1ContinuousIndex.html" title="A templated class holding a point in n-Dimensional image space.">VertexType</a> to); <a name="l00194"></a>00194 <span class="keywordtype">void</span> FillOutputs(); <a name="l00195"></a>00195 <a class="code" href="classitk_1_1ContourExtractor2DImageFilter.html" title="Computes a list of PolyLineParametricPath objects from the contours in a 2D image...">ContourExtractor2DImageFilter</a>(const <a class="code" href="classitk_1_1LightObject.html" title="Light weight base class for most itk classes.">Self</a>&); <span class="comment">//purposely not implemented</span> <a name="l00196"></a>00196 <span class="keywordtype">void</span> operator=(const Self&); <span class="comment">//purposely not implemented</span> <a name="l00197"></a>00197 <a name="l00198"></a>00198 InputRealType m_ContourValue; <a name="l00199"></a>00199 <span class="keywordtype">bool</span> m_ReverseContourOrientation; <a name="l00200"></a>00200 <span class="keywordtype">bool</span> m_VertexConnectHighPixels; <a name="l00201"></a>00201 <span class="keywordtype">bool</span> m_UseCustomRegion; <a name="l00202"></a>00202 InputRegionType m_RequestedRegion; <a name="l00203"></a>00203 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m_NumberOfContoursCreated; <a name="l00204"></a>00204 <a name="l00205"></a>00205 <span class="comment">// Represent each contour as deque of vertices to facilitate addition of</span> <a name="l00206"></a>00206 <span class="comment">// nodes at beginning or end. At the end of the processing, we will copy </span> <a name="l00207"></a>00207 <span class="comment">// the contour into a PolyLineParametricPath.</span> <a name="l00208"></a>00208 <span class="comment">// We subclass the deque to store an additional bit of information: an </span> <a name="l00209"></a>00209 <span class="comment">// identification number for each growing contour. We use this number so</span> <a name="l00210"></a>00210 <span class="comment">// that when it becomes necessary to merge two growing contours, we can </span> <a name="l00211"></a>00211 <span class="comment">// merge the newer one into the older one. This helps because then we can</span> <a name="l00212"></a>00212 <span class="comment">// guarantee that the output contour list is ordered from left to right,</span> <a name="l00213"></a>00213 <span class="comment">// top to bottom (in terms of the first pixel of the contour encountered</span> <a name="l00214"></a>00214 <span class="comment">// by the marching squares). Currently we make no guarantees that this </span> <a name="l00215"></a>00215 <span class="comment">// pixel is the first pixel in the contour list, just that the contours </span> <a name="l00216"></a>00216 <span class="comment">// are so ordered in the output. Ensuring this latter condition (first </span> <a name="l00217"></a>00217 <span class="comment">// pixel traversed = first pixel in contour) would be possible by either </span> <a name="l00218"></a>00218 <span class="comment">// changing the merging rules, which would make the contouring operation </span> <a name="l00219"></a>00219 <span class="comment">//slower, or by storing additional data as to which pixel was first.</span> <a name="l00220"></a>00220 class ContourType : public vcl_deque<<a class="code" href="classitk_1_1ContinuousIndex.html" title="A templated class holding a point in n-Dimensional image space.">VertexType</a>> <a name="l00221"></a>00221 { <a name="l00222"></a>00222 <span class="keyword">public</span>: <a name="l00223"></a>00223 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m_ContourNumber; <a name="l00224"></a>00224 }; <a name="l00225"></a>00225 <a name="l00226"></a>00226 <span class="comment">// Store all the growing contours in a list. We may need to delete contours</span> <a name="l00227"></a>00227 <span class="comment">// from anywhere in the sequence (when we merge them together), so we need to</span> <a name="l00228"></a>00228 <span class="comment">// use a list instead of a vector or similar.</span> <a name="l00229"></a>00229 <span class="keyword">typedef</span> vcl_list<ContourType> ContourContainer; <a name="l00230"></a>00230 <span class="keyword">typedef</span> <span class="keyword">typename</span> ContourContainer::iterator ContourRef; <a name="l00231"></a>00231 <a name="l00232"></a>00232 <span class="comment">// declare the hash function we are using for the hash_map.</span> <a name="l00233"></a>00233 <span class="keyword">struct </span>VertexHash <a name="l00234"></a>00234 { <a name="l00235"></a>00235 <span class="keyword">typedef</span> <span class="keyword">typename</span> VertexType::CoordRepType CoordinateType; <a name="l00236"></a>00236 <span class="keyword">inline</span> <span class="keywordtype">size_t</span> operator()(<span class="keyword">const</span> VertexType& k)<span class="keyword"> const </span> <a name="l00237"></a>00237 <span class="keyword"> </span>{ <a name="l00238"></a>00238 <span class="comment">// Xor the hashes of the vertices together, after multiplying the </span> <a name="l00239"></a>00239 <span class="comment">// first by some number, so that identical (x,y) vertex indices </span> <a name="l00240"></a>00240 <span class="comment">// don't all hash to the same bucket. This is a decent if not </span> <a name="l00241"></a>00241 <span class="comment">// optimal hash. </span> <a name="l00242"></a>00242 <span class="keyword">const</span> <span class="keywordtype">size_t</span> hashVertex1 = this->float_hash(k[0] * 0xbeef); <a name="l00243"></a>00243 <span class="keyword">const</span> <span class="keywordtype">size_t</span> hashVertex2 = this->float_hash(k[1]); <a name="l00244"></a>00244 <span class="keyword">const</span> <span class="keywordtype">size_t</span> hashValue = hashVertex1 ^ hashVertex2; <a name="l00245"></a>00245 <span class="keywordflow">return</span> hashValue; <a name="l00246"></a>00246 } <a name="l00247"></a>00247 <a name="l00248"></a>00248 <span class="comment">// Define hash function for floats. Based on method from</span> <a name="l00249"></a>00249 <span class="comment">// http://www.brpreiss.com/books/opus4/html/page217.html</span> <a name="l00250"></a>00250 <span class="keyword">inline</span> <span class="keywordtype">size_t</span> float_hash(<span class="keyword">const</span> CoordinateType &k)<span class="keyword"> const </span> <a name="l00251"></a>00251 <span class="keyword"> </span>{ <a name="l00252"></a>00252 <span class="keywordflow">if</span> (k == 0) <a name="l00253"></a>00253 { <a name="l00254"></a>00254 <span class="keywordflow">return</span> 0; <a name="l00255"></a>00255 } <a name="l00256"></a>00256 <span class="keywordtype">int</span> exponent; <a name="l00257"></a>00257 CoordinateType mantissa = vcl_frexp(k, &exponent); <a name="l00258"></a>00258 <span class="keywordtype">size_t</span> value = <span class="keyword">static_cast<</span><span class="keywordtype">size_t</span><span class="keyword">></span>(vcl_fabs(mantissa)); <a name="l00259"></a>00259 value = ( 2 * value - 1 ) * ~0U; <a name="l00260"></a>00260 <span class="keywordflow">return</span> value; <a name="l00261"></a>00261 } <a name="l00262"></a>00262 }; <a name="l00263"></a>00263 <a name="l00264"></a>00264 <span class="comment">// We use a hash to associate the endpoints of each contour with the </span> <a name="l00265"></a>00265 <span class="comment">// contour itself. This makes it easy to look up which contour we should add</span> <a name="l00266"></a>00266 <span class="comment">// a new arc to.</span> <a name="l00267"></a>00267 <span class="comment">// We can't store the contours themselves in the hashtable because we</span> <a name="l00268"></a>00268 <span class="comment">// need to have two tables (one to hash from beginpoint -> contour and one </span> <a name="l00269"></a>00269 <span class="comment">// for endpoint -> contour), and sometimes will remove a contour from the </span> <a name="l00270"></a>00270 <span class="comment">// tables (if it has been closed or merged with another contour). So in the</span> <a name="l00271"></a>00271 <span class="comment">// hash table we store a reference to the contour. Because sometimes we will</span> <a name="l00272"></a>00272 <span class="comment">// need to merge contours, we need to be able to quickly remove contours </span> <a name="l00273"></a>00273 <span class="comment">// from our list when they have been merged into another. Thus, we store </span> <a name="l00274"></a>00274 <span class="comment">// an iterator pointing to the contour in the list.</span> <a name="l00275"></a>00275 <a name="l00276"></a>00276 <span class="keyword">typedef</span> hash_map<VertexType, ContourRef, VertexHash> VertexToContourMap; <a name="l00277"></a>00277 <span class="keyword">typedef</span> <span class="keyword">typename</span> VertexToContourMap::iterator VertexMapIterator; <a name="l00278"></a>00278 <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="namespaceitk.html#87ac35b82c3f0b7231a21eda576557d1">VertexToContourMap::value_type</a> VertexContourRefPair; <a name="l00279"></a>00279 <a name="l00280"></a>00280 <span class="comment">// The contours we find in the image are stored here</span> <a name="l00281"></a>00281 ContourContainer m_Contours; <a name="l00282"></a>00282 <a name="l00283"></a>00283 <span class="comment">// And indexed by their beginning and ending points here</span> <a name="l00284"></a>00284 VertexToContourMap m_ContourStarts; <a name="l00285"></a>00285 VertexToContourMap m_ContourEnds; <a name="l00286"></a>00286 <a name="l00287"></a>00287 }; <a name="l00288"></a>00288 <a name="l00289"></a>00289 } <span class="comment">// end namespace itk</span> <a name="l00290"></a>00290 <a name="l00291"></a>00291 <span class="preprocessor">#ifndef ITK_MANUAL_INSTANTIATION</span> <a name="l00292"></a>00292 <span class="preprocessor"></span><span class="preprocessor">#include "itkContourExtractor2DImageFilter.txx"</span> <a name="l00293"></a>00293 <span class="preprocessor">#endif</span> <a name="l00294"></a>00294 <span class="preprocessor"></span> <a name="l00295"></a>00295 <span class="preprocessor">#endif</span> <a name="l00296"></a>00296 <span class="preprocessor"></span> </pre></div></div> <hr><address><small> Generated at Thu May 7 22:29:33 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>