ITK  5.4.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:
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 
161  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
162 
165  bool
166  operator<=(const Self & it) const
167  {
168  // an iterator is "less than" another if it "points to" a lower
169  // memory location
170  return (m_PositionIndex) <= (it.m_PositionIndex);
171  }
172 
175  bool
176  operator<(const Self & it) const
177  {
178  // an iterator is "less than" another if it "points to" a lower
179  // memory location
180  return (m_PositionIndex) < (it.m_PositionIndex);
181  }
182 
185  bool
186  operator>=(const Self & it) const
187  {
188  // an iterator is "greater than" another if it "points to" a higher
189  // memory location
190  return (m_PositionIndex) >= (it.m_PositionIndex);
191  }
192 
195  bool
196  operator>(const Self & it) const
197  {
198  // an iterator is "greater than" another if it "points to" a higher
199  // memory location
200  return (m_PositionIndex) > (it.m_PositionIndex);
201  }
202 
205  const IndexType &
206  GetIndex() const
207  {
208  return m_PositionIndex;
209  }
210 
213  const RegionType &
214  GetRegion() const
215  {
216  return m_Region;
217  }
218 
221  void
222  SetIndex(const IndexType & ind)
223  {
224  m_PositionIndex = ind;
225  }
226 
228  void
229  GoToBegin();
230 
232  void
233  GoToReverseBegin();
234 
236  bool
238  {
239  return !m_Remaining;
240  }
241 
243  bool
244  IsAtEnd() const
245  {
246  return !m_Remaining;
247  }
248 
250  bool
252  {
253  return m_Remaining;
254  }
255 
256 protected: // made protected so other iterators can access
257  typename TImage::ConstPointer m_Image{};
258 
259  IndexType m_PositionIndex{ { 0 } }; // Index where we currently are
260  IndexType m_BeginIndex{ { 0 } }; // Index to start iterating over
261  IndexType m_EndIndex{ { 0 } }; // Index to finish iterating:
262  // one pixel past the end of each
263  // row, col, slice, etc....
264 
265  RegionType m_Region{}; // region to iterate over
266 
267  OffsetValueType m_OffsetTable[ImageDimension + 1]{};
268 
269  bool m_Remaining{ false };
270 };
271 } // end namespace itk
272 
273 #ifndef ITK_MANUAL_INSTANTIATION
274 # include "itkImageConstIteratorWithOnlyIndex.hxx"
275 #endif
276 
277 #endif
itk::ImageConstIteratorWithOnlyIndex::Remaining
bool Remaining()
Definition: itkImageConstIteratorWithOnlyIndex.h:251
itk::ImageConstIteratorWithOnlyIndex::GetImageDimension
static unsigned int GetImageDimension()
Definition: itkImageConstIteratorWithOnlyIndex.h:147
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::ImageConstIteratorWithOnlyIndex::m_PositionIndex
IndexType m_PositionIndex
Definition: itkImageConstIteratorWithOnlyIndex.h:259
itk::ImageConstIteratorWithOnlyIndex::IsAtReverseEnd
bool IsAtReverseEnd() const
Definition: itkImageConstIteratorWithOnlyIndex.h:237
itk::operator<
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:559
itk::operator<=
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:573
itk::ImageConstIteratorWithOnlyIndex::IsAtEnd
bool IsAtEnd() const
Definition: itkImageConstIteratorWithOnlyIndex.h:244
itk::ImageConstIteratorWithOnlyIndex::operator>=
bool operator>=(const Self &it) const
Definition: itkImageConstIteratorWithOnlyIndex.h:186
itk::ImageConstIteratorWithOnlyIndex::SizeType
typename TImage::SizeType SizeType
Definition: itkImageConstIteratorWithOnlyIndex.h:112
itk::ImageConstIteratorWithOnlyIndex::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkImageConstIteratorWithOnlyIndex.h:122
itk::ImageConstIteratorWithOnlyIndex::SetIndex
void SetIndex(const IndexType &ind)
Definition: itkImageConstIteratorWithOnlyIndex.h:222
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:196
itk::ImageConstIteratorWithOnlyIndex::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkImageConstIteratorWithOnlyIndex.h:109
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:90
itk::ImageConstIteratorWithOnlyIndex::GetIndex
const IndexType & GetIndex() const
Definition: itkImageConstIteratorWithOnlyIndex.h:206
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:155
itk::ImageConstIteratorWithOnlyIndex::GetRegion
const RegionType & GetRegion() const
Definition: itkImageConstIteratorWithOnlyIndex.h:214
itk::OffsetValueType
long OffsetValueType
Definition: itkIntTypes.h:94
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:113
AddImageFilter
Definition: itkAddImageFilter.h:81
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