ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkChainCodePath2D.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkChainCodePath2D_h
19 #define __itkChainCodePath2D_h
20 
21 #include "itkChainCodePath.h"
22 #include "itkIndex.h"
23 
24 #include <vector>
25 #include <string>
26 
27 namespace itk
28 {
50 class ChainCodePath2D:public
51  ChainCodePath< 2 >
52 {
53 public:
55  itkStaticConstMacro(Dimension, unsigned int, 2);
56 
60 
63 
66 
70 
74 
78 
80  typedef std::vector< int > ChainCode2DType;
81 
82  // Functions inherited from Path
83 
85  virtual OutputType Evaluate(const InputType & input) const ITK_OVERRIDE;
86 
88  virtual IndexType EvaluateToIndex(const InputType & input) const ITK_OVERRIDE;
89 
94  virtual OffsetType IncrementInput(InputType & input) const ITK_OVERRIDE;
95 
96  // Functions specific to ChainCodePath and its descendents
97 
99  itkNewMacro(Self);
100 
102  virtual inline ChainCodeSizeType NumberOfSteps() const ITK_OVERRIDE { return m_Chain2D.size(); }
103 
105  inline void InsertStep(InputType position, int encodedStep)
106  {
107  m_Chain2D.insert(m_Chain2D.begin() + position, encodedStep);
108  this->Modified();
109  }
111 
112  virtual inline void InsertStep(InputType position, OffsetType step) ITK_OVERRIDE
113  {
114  m_Chain2D.insert( m_Chain2D.begin() + position, EncodeOffset(step) );
115  this->Modified();
116  }
117 
119  inline void ChangeStep(InputType position, int encodedStep)
120  {
121  m_Chain2D[position] = encodedStep;
122  this->Modified();
123  }
125 
126  virtual inline void ChangeStep(InputType position, OffsetType step) ITK_OVERRIDE
127  {
128  m_Chain2D[position] = EncodeOffset(step);
129  this->Modified();
130  }
131 
133  virtual inline void Clear() ITK_OVERRIDE
134  {
135  m_Chain2D.clear();
136  this->Modified();
137  }
139 
140  std::string GetChainCodeAsString(void) const;
141 
142 protected:
143  ChainCodePath2D();
145  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
146 
148  inline int EncodeOffset(OffsetType step) const
149  {
150  return m_FreemanCode[step[0] + 1][step[1] + 1];
151  }
152 
153  inline OffsetType DecodeOffset(int encodedStep) const
154  {
155  return m_ReverseFreemanCode[encodedStep];
156  }
157 
158 private:
159  ChainCodePath2D(const Self &); //purposely not implemented
160  void operator=(const Self &); //purposely not implemented
161 
162  ChainCode2DType m_Chain2D; // the Freeman-encoded chain code
163 
164  // FreemanCode[][] implements a lookup table for converting offsets to a
165  // Freeman code. Within each dimension, the only allowable offset values are
166  // { -1, 0, 1 }. The y-axis is assumed to point up. It is initialized in the
167  // constructor. Use it as follows:
168  //
169  // encodedValue = m_FreemanCode[ x offset + 1 ][ y offset + 1 ]
170  //
171  int m_FreemanCode[3][3];
172 
173  // m_ReverseFreemanCode[ encodedValue ] implements a lookup table for the
174  // inverse of m_FreemanCode[][]. It is initialized in the constructor.
176 };
177 } // end namespace itk
178 
179 #endif
ChainCode2DType m_Chain2D
virtual ChainCodeSizeType NumberOfSteps() const ITK_OVERRIDE
std::vector< int > ChainCode2DType
OffsetType DecodeOffset(int encodedStep) const
Superclass::ChainCodeType ChainCodeType
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
Represent a path as a sequence of connected image index offsets.
virtual OutputType Evaluate(const InputType &input) const ITK_OVERRIDE
Superclass::OutputType OutputType
virtual void InsertStep(InputType position, OffsetType step) ITK_OVERRIDE
Superclass::InputType InputType
ChainCodePath< 2 > Superclass
Superclass::OutputType OutputType
Superclass::InputType InputType
std::vector< OffsetType > ChainCodeType
std::string GetChainCodeAsString(void) const
SmartPointer< const Self > ConstPointer
virtual IndexType EvaluateToIndex(const InputType &input) const ITK_OVERRIDE
void ChangeStep(InputType position, int encodedStep)
virtual void Clear() ITK_OVERRIDE
virtual void ChangeStep(InputType position, OffsetType step) ITK_OVERRIDE
ChainCodeType::size_type ChainCodeSizeType
Superclass::ChainCodeSizeType ChainCodeSizeType
virtual void Modified() const
int EncodeOffset(OffsetType step) const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
static const unsigned int Dimension
SmartPointer< Self > Pointer
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:71
virtual OffsetType IncrementInput(InputType &input) const ITK_OVERRIDE
Base class for all data objects in ITK.
Represent a 2D path as a sequence of connected image index offsets.
void operator=(const Self &)
void InsertStep(InputType position, int encodedStep)
OffsetType m_ReverseFreemanCode[9]