ITK  5.4.0
Insight Toolkit
itkLineConstIterator.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 itkLineConstIterator_h
19 #define itkLineConstIterator_h
20 
21 #include "itkIndex.h"
22 #include "itkImage.h"
23 
24 namespace itk
25 {
55 template <typename TImage>
56 class ITK_TEMPLATE_EXPORT LineConstIterator
57 {
58 public:
59 
62 
67  static constexpr unsigned int ImageIteratorDimension = TImage::ImageDimension;
68 
70  using IndexType = typename TImage::IndexType;
71 
73  using OffsetType = typename TImage::OffsetType;
74 
76  using SizeType = typename TImage::SizeType;
77 
79  using RegionType = typename TImage::RegionType;
80 
82  using SpacingType = typename TImage::SpacingType;
83 
85  using PointType = typename TImage::PointType;
86 
88  using ImageType = TImage;
89 
93  using PixelContainer = typename TImage::PixelContainer;
95 
97  using InternalPixelType = typename TImage::InternalPixelType;
98 
100  using PixelType = typename TImage::PixelType;
101 
104  using AccessorType = typename TImage::AccessorType;
105 
107  itkVirtualGetNameOfClassMacro(LineConstIterator);
108 
110  static unsigned int
112  {
113  return TImage::ImageDimension;
114  }
115 
117  const IndexType
119  {
120  return m_CurrentImageIndex;
121  }
122 
124  const PixelType
125  Get() const
126  {
127  return m_Image->GetPixel(m_CurrentImageIndex);
128  }
129 
131  bool
132  IsAtEnd() const
133  {
134  return m_IsAtEnd;
135  }
136 
138  void
139  GoToBegin();
140 
142  void
143  operator++();
144 
147  Self &
148  operator=(const Self & it);
149 
151  LineConstIterator(const ImageType * imagePtr, const IndexType & firstIndex, const IndexType & lastIndex);
152 
154  virtual ~LineConstIterator() = default;
155 
156 protected: // made protected so other iterators can access
158  typename ImageType::ConstWeakPointer m_Image{};
159 
161  RegionType m_Region{};
162 
164  bool m_IsAtEnd{};
165 
167  IndexType m_CurrentImageIndex{};
168  IndexType m_StartIndex{};
169  IndexType m_LastIndex{};
170  IndexType m_EndIndex{}; // one past the end of the line in the m_MainDirection
171 
173  // The dimension with the largest difference between start and end
174  unsigned int m_MainDirection{};
175 
176  // Accumulated error for the other dimensions
177  IndexType m_AccumulateError{};
178 
179  // Increment for the error for each step. Two times the difference between
180  // start and end
181  IndexType m_IncrementError{};
182 
183  // If enough is accumulated for a dimension, the index has to be
184  // incremented. Will be the number of pixels in the line
185  IndexType m_MaximalError{};
186 
187  // Direction of increment. -1 or 1
188  IndexType m_OverflowIncrement{};
189 
190  // After an overflow, the accumulated error is reduced again. Will be
191  // two times the number of pixels in the line
192  IndexType m_ReduceErrorAfterIncrement{};
193 };
194 } // end namespace itk
195 
196 #ifndef ITK_MANUAL_INSTANTIATION
197 # include "itkLineConstIterator.hxx"
198 #endif
199 
200 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::LineConstIterator::SizeType
typename TImage::SizeType SizeType
Definition: itkLineConstIterator.h:76
itk::LineConstIterator::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkLineConstIterator.h:94
itk::LineConstIterator::IsAtEnd
bool IsAtEnd() const
Definition: itkLineConstIterator.h:132
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::LineConstIterator::PixelType
typename TImage::PixelType PixelType
Definition: itkLineConstIterator.h:100
itk::LineConstIterator::PointType
typename TImage::PointType PointType
Definition: itkLineConstIterator.h:85
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::LineConstIterator::GetImageIteratorDimension
static unsigned int GetImageIteratorDimension()
Definition: itkLineConstIterator.h:111
itkImage.h
itk::LineConstIterator::SpacingType
typename TImage::SpacingType SpacingType
Definition: itkLineConstIterator.h:82
itk::LineConstIterator
An iterator that walks a Bresenham line through an ND image with read-only access to pixels.
Definition: itkLineConstIterator.h:56
itk::LineConstIterator::GetIndex
const IndexType GetIndex()
Definition: itkLineConstIterator.h:118
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::LineConstIterator::RegionType
typename TImage::RegionType RegionType
Definition: itkLineConstIterator.h:79
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::LineConstIterator::Get
const PixelType Get() const
Definition: itkLineConstIterator.h:125
itk::LineConstIterator::PixelContainer
typename TImage::PixelContainer PixelContainer
Definition: itkLineConstIterator.h:93
itk::LineConstIterator::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkLineConstIterator.h:73
itk::LineConstIterator::AccessorType
typename TImage::AccessorType AccessorType
Definition: itkLineConstIterator.h:104
itkIndex.h
itk::LineConstIterator::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkLineConstIterator.h:97
itk::LineConstIterator::ImageType
TImage ImageType
Definition: itkLineConstIterator.h:88
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::LineConstIterator::IndexType
typename TImage::IndexType IndexType
Definition: itkLineConstIterator.h:70