ITK  4.13.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 ITK_TEMPLATE_EXPORT ChainCodePath2D:public
51  ChainCodePath< 2 >
52 {
53 public:
55  itkStaticConstMacro(Dimension, unsigned int, 2);
56 
60 
63 
66 
68  typedef Superclass::OutputType OutputType;
69  typedef Superclass::InputType InputType;
70 
74 
76  typedef Superclass::ChainCodeType ChainCodeType;
77  typedef Superclass::ChainCodeSizeType ChainCodeSizeType;
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 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 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 void ChangeStep(InputType position, OffsetType step) ITK_OVERRIDE
127  {
128  m_Chain2D[position] = EncodeOffset(step);
129  this->Modified();
130  }
131 
133  virtual void Clear() ITK_OVERRIDE
134  {
135  m_Chain2D.clear();
136  this->Modified();
137  }
139 
140  std::string GetChainCodeAsString() const;
141 
142 protected:
143  ChainCodePath2D();
144  ~ChainCodePath2D() ITK_OVERRIDE;
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  ITK_DISALLOW_COPY_AND_ASSIGN(ChainCodePath2D);
160 
161  ChainCode2DType m_Chain2D; // the Freeman-encoded chain code
162 
163  // FreemanCode[][] implements a lookup table for converting offsets to a
164  // Freeman code. Within each dimension, the only allowable offset values are
165  // { -1, 0, 1 }. The y-axis is assumed to point up. It is initialized in the
166  // constructor. Use it as follows:
167  //
168  // encodedValue = m_FreemanCode[ x offset + 1 ][ y offset + 1 ]
169  //
170  int m_FreemanCode[3][3];
171 
172  // m_ReverseFreemanCode[ encodedValue ] implements a lookup table for the
173  // inverse of m_FreemanCode[][]. It is initialized in the constructor.
174  OffsetType m_ReverseFreemanCode[9];
175 };
176 } // end namespace itk
177 
178 #endif
ChainCode2DType m_Chain2D
std::vector< int > ChainCode2DType
OffsetType DecodeOffset(int encodedStep) const
Superclass::ChainCodeType ChainCodeType
Represent a path as a sequence of connected image index offsets.
Superclass::InputType InputType
ChainCodePath< 2 > Superclass
Superclass::OutputType OutputType
SmartPointer< const Self > ConstPointer
void ChangeStep(InputType position, int encodedStep)
virtual void InsertStep(InputType position, OffsetType step) override
virtual void Clear() override
virtual ChainCodeSizeType NumberOfSteps() const override
Superclass::ChainCodeSizeType ChainCodeSizeType
virtual void ChangeStep(InputType position, OffsetType step) override
Control indentation during Print() invocation.
Definition: itkIndent.h:49
SmartPointer< Self > Pointer
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:72
Base class for all data objects in ITK.
Represent a 2D path as a sequence of connected image index offsets.
void InsertStep(InputType position, int encodedStep)