ITK  6.0.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  * 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 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:
98  ITK_DEFAULT_COPY_AND_MOVE(ImageConstIteratorWithOnlyIndex);
99 
102 
107  static constexpr unsigned int ImageDimension = TImage::ImageDimension;
108 
110  using IndexType = typename TImage::IndexType;
112 
114  using SizeType = typename TImage::SizeType;
116 
118  using RegionType = typename TImage::RegionType;
119 
121  using ImageType = TImage;
122 
124  using OffsetType = typename TImage::OffsetType;
126 
130 
133  ImageConstIteratorWithOnlyIndex(const TImage * ptr, const RegionType & region);
134 
136  virtual ~ImageConstIteratorWithOnlyIndex() = default;
137 
139  static unsigned int
141  {
142  return ImageDimension;
143  }
144 
147  bool
148  operator==(const Self & it) const
149  {
150  // two iterators are the same if they "point to" the same memory location
151  return (m_PositionIndex) == (it.m_PositionIndex);
152  }
153 
154  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
155 
158  bool
159  operator<=(const Self & it) const
160  {
161  // an iterator is "less than" another if it "points to" a lower
162  // memory location
163  return (m_PositionIndex) <= (it.m_PositionIndex);
164  }
165 
168  bool
169  operator<(const Self & it) const
170  {
171  // an iterator is "less than" another if it "points to" a lower
172  // memory location
173  return (m_PositionIndex) < (it.m_PositionIndex);
174  }
175 
178  bool
179  operator>=(const Self & it) const
180  {
181  // an iterator is "greater than" another if it "points to" a higher
182  // memory location
183  return (m_PositionIndex) >= (it.m_PositionIndex);
184  }
185 
188  bool
189  operator>(const Self & it) const
190  {
191  // an iterator is "greater than" another if it "points to" a higher
192  // memory location
193  return (m_PositionIndex) > (it.m_PositionIndex);
194  }
195 
198  const IndexType &
199  GetIndex() const
200  {
201  return m_PositionIndex;
202  }
203 
206  const RegionType &
207  GetRegion() const
208  {
209  return m_Region;
210  }
211 
214  void
215  SetIndex(const IndexType & ind)
216  {
217  m_PositionIndex = ind;
218  }
219 
221  void
222  GoToBegin();
223 
225  void
226  GoToReverseBegin();
227 
229  bool
231  {
232  return !m_Remaining;
233  }
234 
236  bool
237  IsAtEnd() const
238  {
239  return !m_Remaining;
240  }
241 
243  bool
245  {
246  return m_Remaining;
247  }
248 
249 protected: // made protected so other iterators can access
250  typename TImage::ConstPointer m_Image{};
251 
252  IndexType m_PositionIndex{ { 0 } }; // Index where we currently are
253  IndexType m_BeginIndex{ { 0 } }; // Index to start iterating over
254  IndexType m_EndIndex{ { 0 } }; // Index to finish iterating:
255  // one pixel past the end of each
256  // row, col, slice, etc....
257 
258  RegionType m_Region{}; // region to iterate over
259 
260  OffsetValueType m_OffsetTable[ImageDimension + 1]{};
261 
262  bool m_Remaining{ false };
263 };
264 } // end namespace itk
265 
266 #ifndef ITK_MANUAL_INSTANTIATION
267 # include "itkImageConstIteratorWithOnlyIndex.hxx"
268 #endif
269 
270 #endif
itk::ImageConstIteratorWithOnlyIndex::Remaining
bool Remaining()
Definition: itkImageConstIteratorWithOnlyIndex.h:244
itk::ImageConstIteratorWithOnlyIndex::GetImageDimension
static unsigned int GetImageDimension()
Definition: itkImageConstIteratorWithOnlyIndex.h:140
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::ImageConstIteratorWithOnlyIndex::m_PositionIndex
IndexType m_PositionIndex
Definition: itkImageConstIteratorWithOnlyIndex.h:252
itk::ImageConstIteratorWithOnlyIndex::IsAtReverseEnd
bool IsAtReverseEnd() const
Definition: itkImageConstIteratorWithOnlyIndex.h:230
itk::operator<
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:557
itk::operator<=
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:571
itk::ImageConstIteratorWithOnlyIndex::IsAtEnd
bool IsAtEnd() const
Definition: itkImageConstIteratorWithOnlyIndex.h:237
itk::ImageConstIteratorWithOnlyIndex::operator>=
bool operator>=(const Self &it) const
Definition: itkImageConstIteratorWithOnlyIndex.h:179
itk::ImageConstIteratorWithOnlyIndex::SizeType
typename TImage::SizeType SizeType
Definition: itkImageConstIteratorWithOnlyIndex.h:114
itk::ImageConstIteratorWithOnlyIndex::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkImageConstIteratorWithOnlyIndex.h:124
itk::ImageConstIteratorWithOnlyIndex::SetIndex
void SetIndex(const IndexType &ind)
Definition: itkImageConstIteratorWithOnlyIndex.h:215
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itkImage.h
itk::ImageConstIteratorWithOnlyIndex::RegionType
typename TImage::RegionType RegionType
Definition: itkImageConstIteratorWithOnlyIndex.h:118
itk::ImageConstIteratorWithOnlyIndex::operator>
bool operator>(const Self &it) const
Definition: itkImageConstIteratorWithOnlyIndex.h:189
itk::ImageConstIteratorWithOnlyIndex::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkImageConstIteratorWithOnlyIndex.h:111
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:93
itk::ImageConstIteratorWithOnlyIndex::GetIndex
const IndexType & GetIndex() const
Definition: itkImageConstIteratorWithOnlyIndex.h:199
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageConstIteratorWithOnlyIndex::ImageType
TImage ImageType
Definition: itkImageConstIteratorWithOnlyIndex.h:121
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageConstIteratorWithOnlyIndex::operator==
bool operator==(const Self &it) const
Definition: itkImageConstIteratorWithOnlyIndex.h:148
itk::ImageConstIteratorWithOnlyIndex::GetRegion
const RegionType & GetRegion() const
Definition: itkImageConstIteratorWithOnlyIndex.h:207
itk::OffsetValueType
long OffsetValueType
Definition: itkIntTypes.h:97
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::ImageConstIteratorWithOnlyIndex::SizeValueType
typename SizeType::SizeValueType SizeValueType
Definition: itkImageConstIteratorWithOnlyIndex.h:115
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::ImageConstIteratorWithOnlyIndex::IndexType
typename TImage::IndexType IndexType
Definition: itkImageConstIteratorWithOnlyIndex.h:110
itk::ImageConstIteratorWithOnlyIndex::OffsetValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageConstIteratorWithOnlyIndex.h:125
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86