ITK  6.0.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 * https://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
27namespace itk
28{
51class ITK_TEMPLATE_EXPORT ChainCodePath2D : public ChainCodePath<2>
52{
53public:
54 ITK_DISALLOW_COPY_AND_MOVE(ChainCodePath2D);
55
57 static constexpr unsigned int Dimension = 2;
58
62
65
67 itkOverrideGetNameOfClassMacro(ChainCodePath2D);
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
92 EvaluateToIndex(const InputType & input) const override;
93
99 IncrementInput(InputType & input) const override;
100
101 // Functions specific to ChainCodePath and its descendants
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 }
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 }
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 }
154 std::string
156
157protected:
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
176private:
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
Represent a 2D path as a sequence of connected image index offsets.
Superclass::ChainCodeSizeType ChainCodeSizeType
std::vector< int > ChainCode2DType
void ChangeStep(InputType position, int encodedStep)
OffsetType DecodeOffset(int encodedStep) const
void ChangeStep(InputType position, OffsetType step) override
OffsetType IncrementInput(InputType &input) const override
Superclass::InputType InputType
std::string GetChainCodeAsString() const
Superclass::ChainCodeType ChainCodeType
Superclass::OutputType OutputType
void InsertStep(InputType position, int encodedStep)
~ChainCodePath2D() override
int EncodeOffset(OffsetType step) const
ChainCodeSizeType NumberOfSteps() const override
void InsertStep(InputType position, OffsetType step) override
IndexType EvaluateToIndex(const InputType &input) const override
void PrintSelf(std::ostream &os, Indent indent) const override
OutputType Evaluate(const InputType &input) const override
Represent a path as a sequence of connected image index offsets.
Base class for all data objects in ITK.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....