ITK  5.0.0
Insight Segmentation and Registration 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,
150  const RegionType & region);
151 
153  virtual ~ImageConstIteratorWithIndex() = default;
154 
157  Self & operator=(const Self & it);
158 
160  static unsigned int GetImageDimension()
161  {
162  return ImageDimension;
163  }
164 
167  bool
168  operator!=(const Self & it) const
169  {
170  // two iterators are the same if they "point to" the same memory location
171  return ( m_Position ) != ( it.m_Position );
172  }
173 
176  bool
177  operator==(const Self & it) const
178  {
179  // two iterators are the same if they "point to" the same memory location
180  return ( m_Position ) == ( it.m_Position );
181  }
182 
185  bool
186  operator<=(const Self & it) const
187  {
188  // an iterator is "less than" another if it "points to" a lower
189  // memory location
190  return ( m_Position ) <= ( it.m_Position );
191  }
192 
195  bool
196  operator<(const Self & it) const
197  {
198  // an iterator is "less than" another if it "points to" a lower
199  // memory location
200  return ( m_Position ) < ( it.m_Position );
201  }
202 
205  bool
206  operator>=(const Self & it) const
207  {
208  // an iterator is "greater than" another if it "points to" a higher
209  // memory location
210  return ( m_Position ) >= ( it.m_Position );
211  }
212 
215  bool
216  operator>(const Self & it) const
217  {
218  // an iterator is "greater than" another if it "points to" a higher
219  // memory location
220  return ( m_Position ) > ( it.m_Position );
221  }
222 
225  const IndexType & GetIndex() const
226  {
227  return m_PositionIndex;
228  }
229 
232  const RegionType & GetRegion() const
233  {
234  return m_Region;
235  }
236 
239  void SetIndex(const IndexType & ind)
240  {
241  m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset(ind);
242  m_PositionIndex = ind;
243  }
245 
247  PixelType Get() const
248  {
249  return m_PixelAccessorFunctor.Get(*m_Position);
250  }
251 
255  const PixelType & Value() const
256  {
257  return *m_Position;
258  }
259 
261  void GoToBegin();
262 
264  void GoToReverseBegin();
265 
267  bool IsAtReverseEnd() const
268  {
269  return !m_Remaining;
270  }
271 
273  bool IsAtEnd() const
274  {
275  return !m_Remaining;
276  }
277 
279  bool Remaining()
280  {
281  return m_Remaining;
282  }
283 
284 protected: //made protected so other iterators can access
285  typename TImage::ConstWeakPointer m_Image;
286 
287  IndexType m_PositionIndex; // Index where we currently are
288  IndexType m_BeginIndex; // Index to start iterating over
289  IndexType m_EndIndex; // Index to finish iterating:
290  // one pixel past the end of each
291  // row, col, slice, etc....
292 
293  RegionType m_Region; // region to iterate over
294 
295  OffsetValueType m_OffsetTable[ImageDimension + 1];
296 
300 
302 
303  AccessorType m_PixelAccessor;
304  AccessorFunctorType m_PixelAccessorFunctor;
305 };
306 } // end namespace itk
307 
308 #ifndef ITK_MANUAL_INSTANTIATION
309 #include "itkImageConstIteratorWithIndex.hxx"
310 #endif
311 
312 #endif
unsigned long SizeValueType
Definition: itkIntTypes.h:83
typename TImageType::InternalPixelType InternalPixelType
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:514
signed long IndexValueType
Definition: itkIntTypes.h:90
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:499
signed long OffsetValueType
Definition: itkIntTypes.h:94