ITK  4.9.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 #include "ITKPathExport.h"
24 
25 #include <vector>
26 #include <string>
27 
28 namespace itk
29 {
51 class ITKPath_EXPORT ChainCodePath2D:public
52  ChainCodePath< 2 >
53 {
54 public:
56  itkStaticConstMacro(Dimension, unsigned int, 2);
57 
61 
64 
67 
69  typedef Superclass::OutputType OutputType;
70  typedef Superclass::InputType InputType;
71 
75 
77  typedef Superclass::ChainCodeType ChainCodeType;
78  typedef Superclass::ChainCodeSizeType ChainCodeSizeType;
79 
81  typedef std::vector< int > ChainCode2DType;
82 
83  // Functions inherited from Path
84 
86  virtual OutputType Evaluate(const InputType & input) const ITK_OVERRIDE;
87 
89  virtual IndexType EvaluateToIndex(const InputType & input) const ITK_OVERRIDE;
90 
95  virtual OffsetType IncrementInput(InputType & input) const ITK_OVERRIDE;
96 
97  // Functions specific to ChainCodePath and its descendents
98 
100  itkNewMacro(Self);
101 
103  virtual inline ChainCodeSizeType NumberOfSteps() const ITK_OVERRIDE { return m_Chain2D.size(); }
104 
106  inline void InsertStep(InputType position, int encodedStep)
107  {
108  m_Chain2D.insert(m_Chain2D.begin() + position, encodedStep);
109  this->Modified();
110  }
112 
113  virtual inline void InsertStep(InputType position, OffsetType step) ITK_OVERRIDE
114  {
115  m_Chain2D.insert( m_Chain2D.begin() + position, EncodeOffset(step) );
116  this->Modified();
117  }
118 
120  inline void ChangeStep(InputType position, int encodedStep)
121  {
122  m_Chain2D[position] = encodedStep;
123  this->Modified();
124  }
126 
127  virtual inline void ChangeStep(InputType position, OffsetType step) ITK_OVERRIDE
128  {
129  m_Chain2D[position] = EncodeOffset(step);
130  this->Modified();
131  }
132 
134  virtual inline void Clear() ITK_OVERRIDE
135  {
136  m_Chain2D.clear();
137  this->Modified();
138  }
140 
141  std::string GetChainCodeAsString() const;
142 
143 protected:
144  ChainCodePath2D();
145  ~ChainCodePath2D();
146  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
147 
149  inline int EncodeOffset(OffsetType step) const
150  {
151  return m_FreemanCode[step[0] + 1][step[1] + 1];
152  }
153 
154  inline OffsetType DecodeOffset(int encodedStep) const
155  {
156  return m_ReverseFreemanCode[encodedStep];
157  }
158 
159 private:
160  ChainCodePath2D(const Self &) ITK_DELETE_FUNCTION;
161  void operator=(const Self &) ITK_DELETE_FUNCTION;
162 
163  ChainCode2DType m_Chain2D; // the Freeman-encoded chain code
164 
165  // FreemanCode[][] implements a lookup table for converting offsets to a
166  // Freeman code. Within each dimension, the only allowable offset values are
167  // { -1, 0, 1 }. The y-axis is assumed to point up. It is initialized in the
168  // constructor. Use it as follows:
169  //
170  // encodedValue = m_FreemanCode[ x offset + 1 ][ y offset + 1 ]
171  //
172  int m_FreemanCode[3][3];
173 
174  // m_ReverseFreemanCode[ encodedValue ] implements a lookup table for the
175  // inverse of m_FreemanCode[][]. It is initialized in the constructor.
176  OffsetType m_ReverseFreemanCode[9];
177 };
178 } // end namespace itk
179 
180 #endif
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
int EncodeOffset(OffsetType step) const
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:71
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)