ITK  5.2.0
Insight Toolkit
itkImageConstIteratorWithOnlyIndex.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  * 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 itkImageConstIteratorWithOnlyIndex_h
19 #define itkImageConstIteratorWithOnlyIndex_h
20 
21 #include "itkIndex.h"
22 #include "itkImage.h"
23 #include <memory>
24 
25 namespace itk
26 {
94 template <typename TImage>
95 class ITK_TEMPLATE_EXPORT ImageConstIteratorWithOnlyIndex
96 {
97 public:
100 
105  static constexpr unsigned int ImageDimension = TImage::ImageDimension;
106 
108  using IndexType = typename TImage::IndexType;
110 
112  using SizeType = typename TImage::SizeType;
114 
116  using RegionType = typename TImage::RegionType;
117 
119  using ImageType = TImage;
120 
122  using OffsetType = typename TImage::OffsetType;
124 
128 
132 
135  ImageConstIteratorWithOnlyIndex(const TImage * ptr, const RegionType & region);
136 
138  virtual ~ImageConstIteratorWithOnlyIndex() = default;
139 
142  Self &
143  operator=(const Self & it);
144 
146  static unsigned int
148  {
149  return ImageDimension;
150  }
151 
154  bool
155  operator!=(const Self & it) const
156  {
157  // two iterators are the same if they "point to" the same memory location
158  return (m_PositionIndex) != (it.m_PositionIndex);
159  }
160 
163  bool
164  operator==(const Self & it) const
165  {
166  // two iterators are the same if they "point to" the same memory location
167  return (m_PositionIndex) == (it.m_PositionIndex);
168  }
169 
172  bool
173  operator<=(const Self & it) const
174  {
175  // an iterator is "less than" another if it "points to" a lower
176  // memory location
177  return (m_PositionIndex) <= (it.m_PositionIndex);
178  }
179 
182  bool
183  operator<(const Self & it) const
184  {
185  // an iterator is "less than" another if it "points to" a lower
186  // memory location
187  return (m_PositionIndex) < (it.m_PositionIndex);
188  }
189 
192  bool
193  operator>=(const Self & it) const
194  {
195  // an iterator is "greater than" another if it "points to" a higher
196  // memory location
197  return (m_PositionIndex) >= (it.m_PositionIndex);
198  }
199 
202  bool
203  operator>(const Self & it) const
204  {
205  // an iterator is "greater than" another if it "points to" a higher
206  // memory location
207  return (m_PositionIndex) > (it.m_PositionIndex);
208  }
209 
212  const IndexType &
213  GetIndex() const
214  {
215  return m_PositionIndex;
216  }
217 
220  const RegionType &
221  GetRegion() const
222  {
223  return m_Region;
224  }
225 
228  void
229  SetIndex(const IndexType & ind)
230  {
231  m_PositionIndex = ind;
232  }
233 
235  void
236  GoToBegin();
237 
239  void
240  GoToReverseBegin();
241 
243  bool
245  {
246  return !m_Remaining;
247  }
248 
250  bool
251  IsAtEnd() const
252  {
253  return !m_Remaining;
254  }
255 
257  bool
259  {
260  return m_Remaining;
261  }
262 
263 protected: // made protected so other iterators can access
264  typename TImage::ConstPointer m_Image;
265 
266  IndexType m_PositionIndex; // Index where we currently are
267  IndexType m_BeginIndex; // Index to start iterating over
268  IndexType m_EndIndex; // Index to finish iterating:
269  // one pixel past the end of each
270  // row, col, slice, etc....
271 
272  RegionType m_Region; // region to iterate over
273 
274  OffsetValueType m_OffsetTable[ImageDimension + 1];
275 
277 };
278 } // end namespace itk
279 
280 #ifndef ITK_MANUAL_INSTANTIATION
281 # include "itkImageConstIteratorWithOnlyIndex.hxx"
282 #endif
283 
284 #endif
itk::ImageConstIteratorWithOnlyIndex::Remaining
bool Remaining()
Definition: itkImageConstIteratorWithOnlyIndex.h:258
itk::ImageConstIteratorWithOnlyIndex::GetImageDimension
static unsigned int GetImageDimension()
Definition: itkImageConstIteratorWithOnlyIndex.h:147
itk::ImageConstIteratorWithOnlyIndex::m_Image
TImage::ConstPointer m_Image
Definition: itkImageConstIteratorWithOnlyIndex.h:264
itk::ImageConstIteratorWithOnlyIndex::m_PositionIndex
IndexType m_PositionIndex
Definition: itkImageConstIteratorWithOnlyIndex.h:266
itk::ImageConstIteratorWithOnlyIndex::IsAtReverseEnd
bool IsAtReverseEnd() const
Definition: itkImageConstIteratorWithOnlyIndex.h:244
itk::operator<
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:546
itk::operator<=
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:560
itk::ImageConstIteratorWithOnlyIndex::IsAtEnd
bool IsAtEnd() const
Definition: itkImageConstIteratorWithOnlyIndex.h:251
itk::ImageConstIteratorWithOnlyIndex::m_Remaining
bool m_Remaining
Definition: itkImageConstIteratorWithOnlyIndex.h:276
itk::ImageConstIteratorWithOnlyIndex::operator>=
bool operator>=(const Self &it) const
Definition: itkImageConstIteratorWithOnlyIndex.h:193
itk::ImageConstIteratorWithOnlyIndex::SizeType
typename TImage::SizeType SizeType
Definition: itkImageConstIteratorWithOnlyIndex.h:112
itk::ImageConstIteratorWithOnlyIndex::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkImageConstIteratorWithOnlyIndex.h:122
itk::ImageConstIteratorWithOnlyIndex::m_BeginIndex
IndexType m_BeginIndex
Definition: itkImageConstIteratorWithOnlyIndex.h:267
itk::ImageConstIteratorWithOnlyIndex::SetIndex
void SetIndex(const IndexType &ind)
Definition: itkImageConstIteratorWithOnlyIndex.h:229
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itkImage.h
itk::ImageConstIteratorWithOnlyIndex::RegionType
typename TImage::RegionType RegionType
Definition: itkImageConstIteratorWithOnlyIndex.h:116
itk::ImageConstIteratorWithOnlyIndex::operator>
bool operator>(const Self &it) const
Definition: itkImageConstIteratorWithOnlyIndex.h:203
itk::ImageConstIteratorWithOnlyIndex::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkImageConstIteratorWithOnlyIndex.h:109
itk::ImageConstIteratorWithOnlyIndex::GetIndex
const IndexType & GetIndex() const
Definition: itkImageConstIteratorWithOnlyIndex.h:213
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageConstIteratorWithOnlyIndex::ImageType
TImage ImageType
Definition: itkImageConstIteratorWithOnlyIndex.h:119
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageConstIteratorWithOnlyIndex::operator==
bool operator==(const Self &it) const
Definition: itkImageConstIteratorWithOnlyIndex.h:164
itk::ImageConstIteratorWithOnlyIndex::operator!=
bool operator!=(const Self &it) const
Definition: itkImageConstIteratorWithOnlyIndex.h:155
itk::ImageConstIteratorWithOnlyIndex::GetRegion
const RegionType & GetRegion() const
Definition: itkImageConstIteratorWithOnlyIndex.h:221
itk::ImageConstIteratorWithOnlyIndex
A base class for multi-dimensional iterators templated over image type that are designed to provide o...
Definition: itkImageConstIteratorWithOnlyIndex.h:95
itkIndex.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::ImageConstIteratorWithOnlyIndex::SizeValueType
typename SizeType::SizeValueType SizeValueType
Definition: itkImageConstIteratorWithOnlyIndex.h:113
itk::ImageConstIteratorWithOnlyIndex::m_EndIndex
IndexType m_EndIndex
Definition: itkImageConstIteratorWithOnlyIndex.h:268
itk::ImageConstIteratorWithOnlyIndex::IndexType
typename TImage::IndexType IndexType
Definition: itkImageConstIteratorWithOnlyIndex.h:108
itk::ImageConstIteratorWithOnlyIndex::OffsetValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageConstIteratorWithOnlyIndex.h:123
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ImageConstIteratorWithOnlyIndex::m_Region
RegionType m_Region
Definition: itkImageConstIteratorWithOnlyIndex.h:272