ITK  5.0.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:
54  ITK_DISALLOW_COPY_AND_ASSIGN(ChainCodePath2D);
55 
57  static constexpr unsigned int Dimension = 2;
58 
62 
65 
67  itkTypeMacro(ChainCodePath2D, ChainCodePath);
68 
70  using OutputType = Superclass::OutputType;
71  using InputType = Superclass::InputType;
72 
76 
78  using ChainCodeType = Superclass::ChainCodeType;
79  using ChainCodeSizeType = Superclass::ChainCodeSizeType;
80 
82  using ChainCode2DType = std::vector< int >;
83 
84  // Functions inherited from Path
85 
87  OutputType Evaluate(const InputType & input) const override;
88 
90  IndexType EvaluateToIndex(const InputType & input) const override;
91 
96  OffsetType IncrementInput(InputType & input) const override;
97 
98  // Functions specific to ChainCodePath and its descendents
99 
101  itkNewMacro(Self);
102 
104  ChainCodeSizeType NumberOfSteps() const override { return m_Chain2D.size(); }
105 
107  inline void InsertStep(InputType position, int encodedStep)
108  {
109  m_Chain2D.insert(m_Chain2D.begin() + position, encodedStep);
110  this->Modified();
111  }
113 
114  void InsertStep(InputType position, OffsetType step) override
115  {
116  m_Chain2D.insert( m_Chain2D.begin() + position, EncodeOffset(step) );
117  this->Modified();
118  }
119 
121  inline void ChangeStep(InputType position, int encodedStep)
122  {
123  m_Chain2D[position] = encodedStep;
124  this->Modified();
125  }
127 
128  void ChangeStep(InputType position, OffsetType step) override
129  {
130  m_Chain2D[position] = EncodeOffset(step);
131  this->Modified();
132  }
133 
135  void Clear() override
136  {
137  m_Chain2D.clear();
138  this->Modified();
139  }
141 
142  std::string GetChainCodeAsString() const;
143 
144 protected:
145  ChainCodePath2D();
146  ~ChainCodePath2D() override;
147  void PrintSelf(std::ostream & os, Indent indent) const override;
148 
150  inline int EncodeOffset(OffsetType step) const
151  {
152  return m_FreemanCode[step[0] + 1][step[1] + 1];
153  }
154 
155  inline OffsetType DecodeOffset(int encodedStep) const
156  {
157  return m_ReverseFreemanCode[encodedStep];
158  }
159 
160 private:
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
OffsetType DecodeOffset(int encodedStep) const
Represent a path as a sequence of connected image index offsets.
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
ChainCodeSizeType NumberOfSteps() const override
std::vector< int > ChainCode2DType
void ChangeStep(InputType position, int encodedStep)
Superclass::ChainCodeSizeType ChainCodeSizeType
void ChangeStep(InputType position, OffsetType step) override
Superclass::InputType InputType
int EncodeOffset(OffsetType step) const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void InsertStep(InputType position, OffsetType step) override
Superclass::OutputType OutputType
Superclass::ChainCodeType ChainCodeType
Base class for most ITK classes.
Definition: itkObject.h:60
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)