ITK  5.2.0
Insight Toolkit
itkChainCodePath2D.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 {
51 class ITK_TEMPLATE_EXPORT ChainCodePath2D : public ChainCodePath<2>
52 {
53 public:
54  ITK_DISALLOW_COPY_AND_MOVE(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 
88  Evaluate(const InputType & input) const override;
89 
91  IndexType
92  EvaluateToIndex(const InputType & input) const override;
93 
99  IncrementInput(InputType & input) const override;
100 
101  // Functions specific to ChainCodePath and its descendents
102 
104  itkNewMacro(Self);
105 
108  NumberOfSteps() const override
109  {
110  return m_Chain2D.size();
111  }
112 
114  inline void
115  InsertStep(InputType position, int encodedStep)
116  {
117  m_Chain2D.insert(m_Chain2D.begin() + position, encodedStep);
118  this->Modified();
119  }
121 
122  void
123  InsertStep(InputType position, OffsetType step) override
124  {
125  m_Chain2D.insert(m_Chain2D.begin() + position, EncodeOffset(step));
126  this->Modified();
127  }
128 
130  inline void
131  ChangeStep(InputType position, int encodedStep)
132  {
133  m_Chain2D[position] = encodedStep;
134  this->Modified();
135  }
137 
138  void
139  ChangeStep(InputType position, OffsetType step) override
140  {
141  m_Chain2D[position] = EncodeOffset(step);
142  this->Modified();
143  }
144 
146  void
147  Clear() override
148  {
149  m_Chain2D.clear();
150  this->Modified();
151  }
153 
154  std::string
155  GetChainCodeAsString() const;
156 
157 protected:
158  ChainCodePath2D();
159  ~ChainCodePath2D() override;
160  void
161  PrintSelf(std::ostream & os, Indent indent) const override;
162 
164  inline int
166  {
167  return m_FreemanCode[step[0] + 1][step[1] + 1];
168  }
169 
170  inline OffsetType
171  DecodeOffset(int encodedStep) const
172  {
173  return m_ReverseFreemanCode[encodedStep];
174  }
175 
176 private:
177  ChainCode2DType m_Chain2D; // the Freeman-encoded chain code
178 
179  // FreemanCode[][] implements a lookup table for converting offsets to a
180  // Freeman code. Within each dimension, the only allowable offset values are
181  // { -1, 0, 1 }. The y-axis is assumed to point up. It is initialized in the
182  // constructor. Use it as follows:
183  //
184  // encodedValue = m_FreemanCode[ x offset + 1 ][ y offset + 1 ]
185  //
186  int m_FreemanCode[3][3];
187 
188  // m_ReverseFreemanCode[ encodedValue ] implements a lookup table for the
189  // inverse of m_FreemanCode[][]. It is initialized in the constructor.
190  OffsetType m_ReverseFreemanCode[9];
191 };
192 } // end namespace itk
193 
194 #endif
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
itk::ChainCodePath2D
Represent a 2D path as a sequence of connected image index offsets.
Definition: itkChainCodePath2D.h:51
itk::ChainCodePath2D::ChangeStep
void ChangeStep(InputType position, OffsetType step) override
Definition: itkChainCodePath2D.h:139
itk::ChainCodePath2D::InputType
Superclass::InputType InputType
Definition: itkChainCodePath2D.h:71
itk::ChainCodePath2D::OffsetType
OutputType OffsetType
Definition: itkChainCodePath2D.h:74
itk::ChainCodePath2D::Clear
void Clear() override
Definition: itkChainCodePath2D.h:147
itk::ChainCodePath2D::ChainCode2DType
std::vector< int > ChainCode2DType
Definition: itkChainCodePath2D.h:82
itk::ChainCodePath2D::InsertStep
void InsertStep(InputType position, OffsetType step) override
Definition: itkChainCodePath2D.h:123
itk::ChainCodePath2D::OutputType
Superclass::OutputType OutputType
Definition: itkChainCodePath2D.h:70
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkChainCodePath.h
itk::ChainCodePath2D::ChainCodeType
Superclass::ChainCodeType ChainCodeType
Definition: itkChainCodePath2D.h:78
itk::ChainCodePath2D::m_Chain2D
ChainCode2DType m_Chain2D
Definition: itkChainCodePath2D.h:177
itk::ChainCodePath2D::InsertStep
void InsertStep(InputType position, int encodedStep)
Definition: itkChainCodePath2D.h:115
itkIndex.h
itk::ChainCodePath2D::DecodeOffset
OffsetType DecodeOffset(int encodedStep) const
Definition: itkChainCodePath2D.h:171
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::ChainCodePath2D::EncodeOffset
int EncodeOffset(OffsetType step) const
Definition: itkChainCodePath2D.h:165
itk::ChainCodePath
Represent a path as a sequence of connected image index offsets.
Definition: itkChainCodePath.h:50
itk::ChainCodePath2D::NumberOfSteps
ChainCodeSizeType NumberOfSteps() const override
Definition: itkChainCodePath2D.h:108
itk::ChainCodePath2D::ChangeStep
void ChangeStep(InputType position, int encodedStep)
Definition: itkChainCodePath2D.h:131
itk::ChainCodePath2D::ChainCodeSizeType
Superclass::ChainCodeSizeType ChainCodeSizeType
Definition: itkChainCodePath2D.h:79
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293