Orfeo Toolbox  3.16
itkImageReverseConstIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkImageReverseConstIterator.h,v $
5  Language: C++
6  Date: $Date: 2008-10-18 21:13:25 $
7  Version: $Revision: 1.10 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkImageReverseConstIterator_h
18 #define __itkImageReverseConstIterator_h
19 
20 #include "itkIndex.h"
21 #include "itkSize.h"
22 #include "itkImage.h"
23 #include "itkImageConstIterator.h"
24 #include <memory>
25 
26 namespace itk
27 {
28 
86 template<typename TImage>
88 {
89 public:
92 
97  itkStaticConstMacro(ImageIteratorDimension, unsigned int,
98  TImage::ImageDimension);
99 
101  typedef typename TImage::IndexType IndexType;
102  typedef typename TImage::IndexValueType IndexValueType;
103 
105  typedef typename TImage::SizeType SizeType;
106  typedef typename TImage::SizeValueType SizeValueType;
107 
109  typedef typename TImage::OffsetType OffsetType;
110  typedef typename TImage::OffsetValueType OffsetValueType;
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 
135  typedef typename TImage::AccessorFunctorType AccessorFunctorType;
136 
139  ImageReverseConstIterator() :m_PixelAccessor(), m_PixelAccessorFunctor()
140  {
141  m_Buffer = 0;
142  m_Offset = 0;
143  m_BeginOffset = 0;
144  m_EndOffset = 0;
145  m_PixelAccessorFunctor.SetBegin( m_Buffer );
146  }
147 
150 
154  {
155  m_Image = it.m_Image; // copy the smart pointer
156 
157  m_Region = it.m_Region;
158 
159  m_Buffer = it.m_Buffer;
160  m_Offset = it.m_Offset;
161  m_BeginOffset = it.m_BeginOffset;
162  m_EndOffset = it.m_EndOffset;
163  m_PixelAccessor = it.m_PixelAccessor;
164  m_PixelAccessorFunctor = it.m_PixelAccessorFunctor;
165  m_PixelAccessorFunctor.SetBegin( m_Buffer );
166  }
167 
171  {
172  unsigned long offset;
173  m_Image = ptr;
174  m_Buffer = m_Image->GetBufferPointer();
175  m_Region = region;
176 
177  // Compute the end offset, one pixel before the first pixel
178  offset = m_Image->ComputeOffset( m_Region.GetIndex() );
179  m_EndOffset = offset-1;
180 
181  // Compute the begin offset, the last pixel in the region
182  IndexType ind(m_Region.GetIndex());
183  SizeType size(m_Region.GetSize());
184  for (unsigned int i=0; i < TImage::ImageDimension; ++i)
185  {
186  ind[i] += (size[i] - 1);
187  }
188  m_BeginOffset = m_Image->ComputeOffset( ind );
189  m_Offset = m_BeginOffset;
190 
191  m_PixelAccessor = ptr->GetPixelAccessor();
192  m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
193  m_PixelAccessorFunctor.SetBegin( m_Buffer );
194  }
195 
204  {
205  m_Image = it.GetImage();
206  m_Region = it.GetRegion();
207  m_Buffer = m_Image->GetBufferPointer();
208 
209  IndexType ind = it.GetIndex();
210 
211  m_Offset = m_Image->ComputeOffset( ind );
212 
213  // Compute the end offset, one pixel before the first pixel
214  m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
215 
216  // Compute the begin offset, the last pixel in the region
217  IndexType regInd(m_Region.GetIndex());
218  SizeType regSize(m_Region.GetSize());
219  for (unsigned int i=0; i < TImage::ImageDimension; ++i)
220  {
221  regInd[i] += (regSize[i] - 1);
222  }
223  m_BeginOffset = m_Image->ComputeOffset( regInd );
224 
225  m_PixelAccessor = m_Image->GetPixelAccessor();
226  m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
227  m_PixelAccessorFunctor.SetBegin( m_Buffer );
228  }
229 
232  Self &operator=(const Self& it)
233  {
234  m_Image = it.m_Image; // copy the smart pointer
235  m_Region = it.m_Region;
236 
237  m_Buffer = it.m_Buffer;
238  m_Offset = it.m_Offset;
239  m_BeginOffset = it.m_BeginOffset;
240  m_EndOffset = it.m_EndOffset;
241  m_PixelAccessor = it.m_PixelAccessor;
242  m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
243  m_PixelAccessorFunctor.SetBegin( m_Buffer );
244  return *this;
245  }
246 
249  Self &operator=(const ImageConstIterator<TImage>& it)
250  {
251  m_Image = it.GetImage();
252  m_Region = it.GetRegion();
253  m_Buffer = m_Image->GetBufferPointer();
254 
255  IndexType ind = it.GetIndex();
256 
257  m_Offset = m_Image->ComputeOffset( ind );
258 
259  // Compute the end offset, one pixel before the first pixel
260  m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
261 
262  // Compute the begin offset, the last pixel in the region
263  IndexType regInd(m_Region.GetIndex());
264  SizeType regSize(m_Region.GetSize());
265  for (unsigned int i=0; i < TImage::ImageDimension; ++i)
266  {
267  regInd[i] += (regSize[i] - 1);
268  }
269  m_BeginOffset = m_Image->ComputeOffset( regInd );
270 
271  m_PixelAccessor = m_Image->GetPixelAccessor();
272  m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
273  m_PixelAccessorFunctor.SetBegin( m_Buffer );
274 
275  return *this;
276  }
277 
279  static unsigned int GetImageIteratorDimension()
280  {return TImage::ImageDimension;}
281 
284  bool
285  operator!=(const Self &it) const
286  {
287  // two iterators are the same if they "point to" the same memory location
288  return (m_Buffer + m_Offset) != (it.m_Buffer + it.m_Offset);
289  }
290 
293  bool
294  operator==(const Self &it) const
295  {
296  // two iterators are the same if they "point to" the same memory location
297  return (m_Buffer + m_Offset) == (it.m_Buffer + it.m_Offset);
298  }
299 
304  const IndexType GetIndex()
305  { return m_Image->ComputeIndex( m_Offset ); }
306 
309  virtual void SetIndex(const IndexType &ind)
310  { m_Offset = m_Image->ComputeOffset( ind ); }
311 
312 
315  const RegionType& GetRegion() const
316  { return m_Region; }
317 
319  const PixelType Get(void) const
320  { return m_PixelAccessorFunctor.Get(*(m_Buffer+m_Offset)); }
321 
323  void Set( const PixelType & value) const
324  {
325  this->m_PixelAccessorFunctor.Set(*(const_cast<InternalPixelType *>(
326  this->m_Buffer+this->m_Offset)),value);
327  }
328 
332  const PixelType & Value(void) const
333  { return *(m_Buffer+m_Offset); }
334 
338  const PixelType & Value(void)
339  { return *(m_Buffer+m_Offset); }
340 
344  Self Begin() const;
345 
348  void GoToBegin()
349  {
350  m_Offset = m_BeginOffset;
351  }
352 
356  Self End() const;
357 
360  void GoToEnd()
361  {
362  m_Offset = m_EndOffset;
363  }
364 
367  bool IsAtBegin()
368  {
369  return (m_Offset == m_BeginOffset);
370  }
371 
374  bool IsAtEnd()
375  {
376  return (m_Offset == m_EndOffset);
377  }
378 
379 protected: //made protected so other iterators can access
380  typename ImageType::ConstWeakPointer m_Image;
381  RegionType m_Region; // region to iterate over
382 
383  unsigned long m_Offset;
384  unsigned long m_BeginOffset; // offset to last pixel in region
385  unsigned long m_EndOffset; // offset to one pixel before first pixel
386 
388 
391 };
392 
393 } // end namespace itk
394 
395 // Define instantiation macro for this template.
396 #define ITK_TEMPLATE_ImageReverseConstIterator(_, EXPORT, x, y) namespace itk { \
397  _(1(class EXPORT ImageReverseConstIterator< ITK_TEMPLATE_1 x >)) \
398  namespace Templates { typedef ImageReverseConstIterator< ITK_TEMPLATE_1 x > ImageReverseConstIterator##y; } \
399  }
400 
401 #if ITK_TEMPLATE_EXPLICIT
402 # include "Templates/itkImageReverseConstIterator+-.h"
403 #endif
404 
405 #if ITK_TEMPLATE_TXX
407 #endif
408 
409 #endif

Generated at Sat Feb 2 2013 23:44:29 for Orfeo Toolbox with doxygen 1.8.1.1