ITK  6.0.0
Insight Toolkit
itkImageConstIteratorWithIndex.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 itkImageConstIteratorWithIndex_h
19 #define itkImageConstIteratorWithIndex_h
20 
21 #include "itkIndex.h"
22 #include "itkImage.h"
23 #include <memory>
24 
25 namespace itk
26 {
91 template <typename TImage>
92 class ITK_TEMPLATE_EXPORT ImageConstIteratorWithIndex
93 {
94 public:
97 
102  static constexpr unsigned int ImageDimension = TImage::ImageDimension;
103 
105  using IndexType = typename TImage::IndexType;
107 
109  using SizeType = typename TImage::SizeType;
111 
113  using RegionType = typename TImage::RegionType;
114 
116  using ImageType = TImage;
117 
121  using PixelContainer = typename TImage::PixelContainer;
123 
125  using InternalPixelType = typename TImage::InternalPixelType;
126 
128  using PixelType = typename TImage::PixelType;
129 
132  using AccessorType = typename TImage::AccessorType;
133  using AccessorFunctorType = typename TImage::AccessorFunctorType;
134 
136  using OffsetType = typename TImage::OffsetType;
138 
141  ImageConstIteratorWithIndex() = default;
142 
145  ImageConstIteratorWithIndex(const Self & it);
146 
149  ImageConstIteratorWithIndex(const TImage * ptr, const RegionType & region);
150 
152  virtual ~ImageConstIteratorWithIndex() = default;
153 
156  Self &
157  operator=(const Self & it);
158 
160  static constexpr unsigned int
162  {
163  return ImageDimension;
164  }
165 
168  bool
169  operator==(const Self & it) const
170  {
171  // two iterators are the same if they "point to" the same memory location
172  return (m_Position) == (it.m_Position);
173  }
174 
175  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
176 
179  bool
180  operator<=(const Self & it) const
181  {
182  // an iterator is "less than" another if it "points to" a lower
183  // memory location
184  return (m_Position) <= (it.m_Position);
185  }
186 
189  bool
190  operator<(const Self & it) const
191  {
192  // an iterator is "less than" another if it "points to" a lower
193  // memory location
194  return (m_Position) < (it.m_Position);
195  }
196 
199  bool
200  operator>=(const Self & it) const
201  {
202  // an iterator is "greater than" another if it "points to" a higher
203  // memory location
204  return (m_Position) >= (it.m_Position);
205  }
206 
209  bool
210  operator>(const Self & it) const
211  {
212  // an iterator is "greater than" another if it "points to" a higher
213  // memory location
214  return (m_Position) > (it.m_Position);
215  }
216 
219  const IndexType &
220  GetIndex() const
221  {
222  return m_PositionIndex;
223  }
224 
227  const RegionType &
228  GetRegion() const
229  {
230  return m_Region;
231  }
232 
235  void
236  SetIndex(const IndexType & ind)
237  {
238  m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset(ind);
239  m_PositionIndex = ind;
240  }
244  PixelType
245  Get() const
246  {
247  return m_PixelAccessorFunctor.Get(*m_Position);
248  }
249 
253  const PixelType &
254  Value() const
255  {
256  return *m_Position;
257  }
258 
260  void
261  GoToBegin();
262 
264  void
265  GoToReverseBegin();
266 
268  bool
270  {
271  return !m_Remaining;
272  }
273 
275  bool
276  IsAtEnd() const
277  {
278  return !m_Remaining;
279  }
280 
282  bool
284  {
285  return m_Remaining;
286  }
287 
288 protected: // made protected so other iterators can access
289  typename TImage::ConstWeakPointer m_Image{};
290 
291  IndexType m_PositionIndex{ { 0 } }; // Index where we currently are
292  IndexType m_BeginIndex{ { 0 } }; // Index to start iterating over
293  IndexType m_EndIndex{ { 0 } }; // Index to finish iterating:
294  // one pixel past the end of each
295  // row, col, slice, etc....
296 
297  RegionType m_Region{}; // region to iterate over
298 
299  OffsetValueType m_OffsetTable[ImageDimension + 1]{};
300 
301  const InternalPixelType * m_Position{ nullptr };
302  const InternalPixelType * m_Begin{ nullptr };
303  const InternalPixelType * m_End{ nullptr };
304 
305  bool m_Remaining{ false };
306 
307  AccessorType m_PixelAccessor{};
308  AccessorFunctorType m_PixelAccessorFunctor{};
309 };
310 } // end namespace itk
311 
312 #ifndef ITK_MANUAL_INSTANTIATION
313 # include "itkImageConstIteratorWithIndex.hxx"
314 #endif
315 
316 #endif
itk::ImageConstIteratorWithIndex::operator>
bool operator>(const Self &it) const
Definition: itkImageConstIteratorWithIndex.h:210
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::ImageConstIteratorWithIndex< TImageType >::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkImageConstIteratorWithIndex.h:106
itk::operator<
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:557
itk::ImageConstIteratorWithIndex< TImageType >::SizeType
typename TImageType ::SizeType SizeType
Definition: itkImageConstIteratorWithIndex.h:109
itk::operator<=
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:571
itk::ImageConstIteratorWithIndex::GetImageDimension
static constexpr unsigned int GetImageDimension()
Definition: itkImageConstIteratorWithIndex.h:161
itk::ImageConstIteratorWithIndex::GetRegion
const RegionType & GetRegion() const
Definition: itkImageConstIteratorWithIndex.h:228
itk::ImageConstIteratorWithIndex< TImageType >::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkImageConstIteratorWithIndex.h:122
itk::ImageConstIteratorWithIndex< TImageType >::OffsetValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageConstIteratorWithIndex.h:137
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ImageConstIteratorWithIndex::Value
const PixelType & Value() const
Definition: itkImageConstIteratorWithIndex.h:254
itkImage.h
itk::ImageConstIteratorWithIndex::Get
PixelType Get() const
Definition: itkImageConstIteratorWithIndex.h:245
itk::ImageConstIteratorWithIndex::GetIndex
const IndexType & GetIndex() const
Definition: itkImageConstIteratorWithIndex.h:220
itk::ImageConstIteratorWithIndex< TImageType >::PixelType
typename TImageType ::PixelType PixelType
Definition: itkImageConstIteratorWithIndex.h:128
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:93
itk::ImageConstIteratorWithIndex< TImageType >::IndexType
typename TImageType ::IndexType IndexType
Definition: itkImageConstIteratorWithIndex.h:105
itk::ImageConstIteratorWithIndex< TImageType >::InternalPixelType
typename TImageType ::InternalPixelType InternalPixelType
Definition: itkImageConstIteratorWithIndex.h:125
itk::ImageConstIteratorWithIndex::SetIndex
void SetIndex(const IndexType &ind)
Definition: itkImageConstIteratorWithIndex.h:236
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageConstIteratorWithIndex::operator>=
bool operator>=(const Self &it) const
Definition: itkImageConstIteratorWithIndex.h:200
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageConstIteratorWithIndex::m_Position
const InternalPixelType * m_Position
Definition: itkImageConstIteratorWithIndex.h:301
itk::ImageConstIteratorWithIndex< TImageType >::AccessorType
typename TImageType ::AccessorType AccessorType
Definition: itkImageConstIteratorWithIndex.h:132
itk::ImageConstIteratorWithIndex
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
Definition: itkImageConstIteratorWithIndex.h:92
itk::OffsetValueType
long OffsetValueType
Definition: itkIntTypes.h:97
itkIndex.h
itk::ImageConstIteratorWithIndex::IsAtReverseEnd
bool IsAtReverseEnd() const
Definition: itkImageConstIteratorWithIndex.h:269
itk::ImageConstIteratorWithIndex::IsAtEnd
bool IsAtEnd() const
Definition: itkImageConstIteratorWithIndex.h:276
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ImageConstIteratorWithIndex< TImageType >::RegionType
typename TImageType ::RegionType RegionType
Definition: itkImageConstIteratorWithIndex.h:113
itk::ImageConstIteratorWithIndex::operator==
bool operator==(const Self &it) const
Definition: itkImageConstIteratorWithIndex.h:169
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::ImageConstIteratorWithIndex< TImageType >::ImageType
TImageType ImageType
Definition: itkImageConstIteratorWithIndex.h:116
itk::ImageConstIteratorWithIndex< TImageType >::PixelContainer
typename TImageType ::PixelContainer PixelContainer
Definition: itkImageConstIteratorWithIndex.h:121
itk::ImageConstIteratorWithIndex< TImageType >::SizeValueType
typename SizeType::SizeValueType SizeValueType
Definition: itkImageConstIteratorWithIndex.h:110
itk::ImageConstIteratorWithIndex::Remaining
bool Remaining()
Definition: itkImageConstIteratorWithIndex.h:283
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::ImageConstIteratorWithIndex< TImageType >::OffsetType
typename TImageType ::OffsetType OffsetType
Definition: itkImageConstIteratorWithIndex.h:136