ITK  4.2.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 >
93 {
94 public:
97 
102  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
103 
105  typedef typename TImage::IndexType IndexType;
107 
109  typedef typename TImage::SizeType SizeType;
111 
113  typedef typename TImage::RegionType RegionType;
114 
116  typedef TImage ImageType;
117 
121  typedef typename TImage::PixelContainer PixelContainer;
122  typedef typename PixelContainer::Pointer PixelContainerPointer;
123 
125  typedef typename TImage::InternalPixelType InternalPixelType;
126 
128  typedef typename TImage::PixelType PixelType;
129 
132  typedef typename TImage::AccessorType AccessorType;
133  typedef typename TImage::AccessorFunctorType AccessorFunctorType;
134 
136  typedef typename TImage::OffsetType OffsetType;
138 
142 
145  ImageConstIteratorWithIndex(const Self & it);
146 
149  ImageConstIteratorWithIndex(const TImage *ptr,
150  const RegionType & region);
151 
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(void) const
248  {
249  return m_PixelAccessorFunctor.Get(*m_Position);
250  }
251 
255  const PixelType & Value(void) const
256  {
257  return *m_Position;
258  }
259 
262  itkLegacyMacro(Self Begin(void) const);
263 
265  void GoToBegin(void);
266 
269  itkLegacyMacro(Self End(void) const);
270 
272  void GoToReverseBegin(void);
273 
275  bool IsAtReverseEnd(void) const
276  {
277  return !m_Remaining;
278  }
279 
281  bool IsAtEnd(void) const
282  {
283  return !m_Remaining;
284  }
285 
287  bool Remaining()
288  {
289  return m_Remaining;
290  }
291 
292 protected: //made protected so other iterators can access
293  typename TImage::ConstWeakPointer m_Image;
294 
295  IndexType m_PositionIndex; // Index where we currently are
296  IndexType m_BeginIndex; // Index to start iterating over
297  IndexType m_EndIndex; // Index to finish iterating:
298  // one pixel past the end of each
299  // row, col, slice, etc....
300 
301  RegionType m_Region; // region to iterate over
302 
303  OffsetValueType m_OffsetTable[ImageDimension + 1];
304 
305  const InternalPixelType *m_Position;
306  const InternalPixelType *m_Begin;
307  const InternalPixelType *m_End;
308 
310 
311  AccessorType m_PixelAccessor;
312  AccessorFunctorType m_PixelAccessorFunctor;
313 };
314 } // end namespace itk
315 
316 // Define instantiation macro for this template.
317 #define ITK_TEMPLATE_ImageConstIteratorWithIndex(_, EXPORT, TypeX, TypeY) \
318  namespace itk \
319  { \
320  _( 1 ( class EXPORT ImageConstIteratorWithIndex< ITK_TEMPLATE_1 TypeX > ) ) \
321  namespace Templates \
322  { \
323  typedef ImageConstIteratorWithIndex< ITK_TEMPLATE_1 TypeX > ImageConstIteratorWithIndex##TypeY; \
324  } \
325  }
326 
327 #if ITK_TEMPLATE_EXPLICIT
328 //template<typename TImage> const unsigned int itk::ImageConstIteratorWithIndex<
329 // TImage>::ImageDimension;
330 #include "Templates/itkImageConstIteratorWithIndex+-.h"
331 #endif
332 
333 #if ITK_TEMPLATE_TXX
334 #include "itkImageConstIteratorWithIndex.hxx"
335 #endif
336 
337 #endif
338