KWStyle - itkChainCodePath2D.cxx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkChainCodePath2D.cxx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:33 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 DEF =========================================================================*/
17 #include "itkChainCodePath2D.h"
18 #include "itkNumericTraits.h"
19 #include <string>
20
21 namespace itk
22 {
23
24 ChainCodePath2D::OutputType
25 ChainCodePath2D
26 ::Evaluate( const InputType & input ) const
27 {
28   return DecodeOffset( m_Chain2D[input] );
29 }
30
31
32 EML
33 ChainCodePath2D::IndexType
34 ChainCodePath2D
35 ::EvaluateToIndex( const InputType & input ) const
36 {
37   IndexType index = GetStart();
38   
39   // Iterate through the chaincode, summing the offsets as we go.
40   for(InputType i=0; i<input; i++)
41     {
42     index += DecodeOffset( m_Chain2D[i] );
43     }
44   
45   return index;
46 }
47
48
49 EML
50 ChainCodePath2D::OffsetType
51 ChainCodePath2D
52 ::IncrementInput( InputType & input ) const
53 {
54   if( input < NumberOfSteps() )
55     {
56     return DecodeOffset( m_Chain2D[input++] );
57     }
58   else
59     {
60     return this->GetZeroOffset();
61     }
62 }
63
64
65 EML
66 std::string
67 ChainCodePath2D
68 ::GetChainCodeAsString(void) const
69 {
70   
71   std::string printableChain;
72   
73   for(unsigned int i=0; i<m_Chain2D.size(); i++)
74     {
75     // Make a single char string out of the current step 
76     OStringStream printableStep;
77     printableStep << m_Chain2D[i];
78     
79     // Append the new step (in string form) to the main string of steps
80     printableChain.insert( i, printableStep.str() );
81     }
82   
83   return printableChain;
84 }
85
86
87 EML
88 /**
89  * Constructor
90  */
91 ChainCodePath2D
92 ::ChainCodePath2D()
93 {
94   // Most of the work is done in the parent constructor.
95   
96   OffsetType  offset;
97   
98   // Initialize the lookup tables m_FreemanCode and m_ReverseFreemanCode:
99   offset[0]=0;
100   offset[1]=0;
101   m_FreemanCode[ offset[0] + 1 ][ offset[1] + 1 ] = 0;
102   m_ReverseFreemanCode[ 0 ] = offset;
103
104   offset[0]=0;
105   offset[1]=1;
106   m_FreemanCode[ offset[0] + 1 ][ offset[1] + 1 ] = 1;
107   m_ReverseFreemanCode[ 1 ] = offset;
108
109   offset[0]=1;
110   offset[1]=1;
111   m_FreemanCode[ offset[0] + 1 ][ offset[1] + 1 ] = 2;
112   m_ReverseFreemanCode[ 2 ] = offset;
113
114   offset[0]=1;
115   offset[1]=0;
116   m_FreemanCode[ offset[0] + 1 ][ offset[1] + 1 ] = 3;
117   m_ReverseFreemanCode[ 3 ] = offset;
118
119   offset[0]=1;
120   offset[1]=-1;
121   m_FreemanCode[ offset[0] + 1 ][ offset[1] + 1 ] = 4;
122   m_ReverseFreemanCode[ 4 ] = offset;
123
124   offset[0]=0;
125   offset[1]=-1;
126   m_FreemanCode[ offset[0] + 1 ][ offset[1] + 1 ] = 5;
127   m_ReverseFreemanCode[ 5 ] = offset;
128
129   offset[0]=-1;
130   offset[1]=-1;
131   m_FreemanCode[ offset[0] + 1 ][ offset[1] + 1 ] = 6;
132   m_ReverseFreemanCode[ 6 ] = offset;
133
134   offset[0]=-1;
135   offset[1]=0;
136   m_FreemanCode[ offset[0] + 1 ][ offset[1] + 1 ] = 7;
137   m_ReverseFreemanCode[ 7 ] = offset;
138
139   offset[0]=-1;
140   offset[1]=1;
141   m_FreemanCode[ offset[0] + 1 ][ offset[1] + 1 ] = 8;
142   m_ReverseFreemanCode[ 8 ] = offset;
143 }
144
145 ChainCodePath2D::~ChainCodePath2D()
146 {
147 }
148
149 /**
150  * Standard "PrintSelf" method
151  */
152 void
153 ChainCodePath2D
154 ::PrintSelf( std::ostream& os, Indent indent) const
155 {
156   Superclass::PrintSelf( os, indent );
157   os << indent << "Chain code 2D:  " << GetChainCodeAsString() << std::endl;
158 }
159
160
161 EML
162 // end namespace itk
163

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:02PM
© Kitware Inc.