ITK  5.1.0
Insight Toolkit
itkImageConstIteratorWithIndex.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 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;
122  using PixelContainerPointer = typename PixelContainer::Pointer;
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 
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 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 
177  bool
178  operator==(const Self & it) const
179  {
180  // two iterators are the same if they "point to" the same memory location
181  return (m_Position) == (it.m_Position);
182  }
183 
186  bool
187  operator<=(const Self & it) const
188  {
189  // an iterator is "less than" another if it "points to" a lower
190  // memory location
191  return (m_Position) <= (it.m_Position);
192  }
193 
196  bool
197  operator<(const Self & it) const
198  {
199  // an iterator is "less than" another if it "points to" a lower
200  // memory location
201  return (m_Position) < (it.m_Position);
202  }
203 
206  bool
207  operator>=(const Self & it) const
208  {
209  // an iterator is "greater than" another if it "points to" a higher
210  // memory location
211  return (m_Position) >= (it.m_Position);
212  }
213 
216  bool
217  operator>(const Self & it) const
218  {
219  // an iterator is "greater than" another if it "points to" a higher
220  // memory location
221  return (m_Position) > (it.m_Position);
222  }
223 
226  const IndexType &
227  GetIndex() const
228  {
229  return m_PositionIndex;
230  }
231 
234  const RegionType &
235  GetRegion() const
236  {
237  return m_Region;
238  }
239 
242  void
243  SetIndex(const IndexType & ind)
244  {
245  m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset(ind);
246  m_PositionIndex = ind;
247  }
249 
251  PixelType
252  Get() const
253  {
254  return m_PixelAccessorFunctor.Get(*m_Position);
255  }
256 
260  const PixelType &
261  Value() const
262  {
263  return *m_Position;
264  }
265 
267  void
268  GoToBegin();
269 
271  void
272  GoToReverseBegin();
273 
275  bool
277  {
278  return !m_Remaining;
279  }
280 
282  bool
283  IsAtEnd() const
284  {
285  return !m_Remaining;
286  }
287 
289  bool
291  {
292  return m_Remaining;
293  }
294 
295 protected: // made protected so other iterators can access
296  typename TImage::ConstWeakPointer m_Image;
297 
298  IndexType m_PositionIndex; // Index where we currently are
299  IndexType m_BeginIndex; // Index to start iterating over
300  IndexType m_EndIndex; // Index to finish iterating:
301  // one pixel past the end of each
302  // row, col, slice, etc....
303 
304  RegionType m_Region; // region to iterate over
305 
306  OffsetValueType m_OffsetTable[ImageDimension + 1];
307 
311 
313 
314  AccessorType m_PixelAccessor;
315  AccessorFunctorType m_PixelAccessorFunctor;
316 };
317 } // end namespace itk
318 
319 #ifndef ITK_MANUAL_INSTANTIATION
320 # include "itkImageConstIteratorWithIndex.hxx"
321 #endif
322 
323 #endif
itk::ImageConstIteratorWithIndex::operator>
bool operator>(const Self &it) const
Definition: itkImageConstIteratorWithIndex.h:217
itk::ImageConstIteratorWithIndex::m_PixelAccessorFunctor
AccessorFunctorType m_PixelAccessorFunctor
Definition: itkImageConstIteratorWithIndex.h:315
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:546
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:560
itk::ImageConstIteratorWithIndex::m_Region
RegionType m_Region
Definition: itkImageConstIteratorWithIndex.h:304
itk::ImageConstIteratorWithIndex::GetRegion
const RegionType & GetRegion() const
Definition: itkImageConstIteratorWithIndex.h:235
itk::ImageConstIteratorWithIndex::m_BeginIndex
IndexType m_BeginIndex
Definition: itkImageConstIteratorWithIndex.h:299
itk::ImageConstIteratorWithIndex::m_Image
TImage::ConstWeakPointer m_Image
Definition: itkImageConstIteratorWithIndex.h:296
itk::ImageConstIteratorWithIndex::GetImageDimension
static unsigned int GetImageDimension()
Definition: itkImageConstIteratorWithIndex.h:161
itk::ImageConstIteratorWithIndex< TImageType >::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkImageConstIteratorWithIndex.h:122
itk::ImageConstIteratorWithIndex::m_PixelAccessor
AccessorType m_PixelAccessor
Definition: itkImageConstIteratorWithIndex.h:314
itk::ImageConstIteratorWithIndex::operator!=
bool operator!=(const Self &it) const
Definition: itkImageConstIteratorWithIndex.h:169
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:261
itkImage.h
itk::ImageConstIteratorWithIndex::Get
PixelType Get() const
Definition: itkImageConstIteratorWithIndex.h:252
itk::ImageConstIteratorWithIndex::GetIndex
const IndexType & GetIndex() const
Definition: itkImageConstIteratorWithIndex.h:227
itk::ImageConstIteratorWithIndex< TImageType >::PixelType
typename TImageType ::PixelType PixelType
Definition: itkImageConstIteratorWithIndex.h:128
itk::ImageConstIteratorWithIndex::m_EndIndex
IndexType m_EndIndex
Definition: itkImageConstIteratorWithIndex.h:300
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:243
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageConstIteratorWithIndex::operator>=
bool operator>=(const Self &it) const
Definition: itkImageConstIteratorWithIndex.h:207
itk::ImageConstIteratorWithIndex::m_Remaining
bool m_Remaining
Definition: itkImageConstIteratorWithIndex.h:312
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageConstIteratorWithIndex::m_Position
const InternalPixelType * m_Position
Definition: itkImageConstIteratorWithIndex.h:308
itk::ImageConstIteratorWithIndex
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
Definition: itkImageConstIteratorWithIndex.h:92
itkIndex.h
itk::ImageConstIteratorWithIndex::IsAtReverseEnd
bool IsAtReverseEnd() const
Definition: itkImageConstIteratorWithIndex.h:276
itk::ImageConstIteratorWithIndex::IsAtEnd
bool IsAtEnd() const
Definition: itkImageConstIteratorWithIndex.h:283
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::ImageConstIteratorWithIndex::m_End
const InternalPixelType * m_End
Definition: itkImageConstIteratorWithIndex.h:310
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::ImageConstIteratorWithIndex::m_Begin
const InternalPixelType * m_Begin
Definition: itkImageConstIteratorWithIndex.h:309
itk::ImageConstIteratorWithIndex::m_PositionIndex
IndexType m_PositionIndex
Definition: itkImageConstIteratorWithIndex.h:298
itk::ImageConstIteratorWithIndex::operator==
bool operator==(const Self &it) const
Definition: itkImageConstIteratorWithIndex.h:178
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:290
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ImageConstIteratorWithIndex< TImageType >::OffsetType
typename TImageType ::OffsetType OffsetType
Definition: itkImageConstIteratorWithIndex.h:136