Orfeo Toolbox  4.0
itkImageReverseConstIterator.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 __itkImageReverseConstIterator_h
19 #define __itkImageReverseConstIterator_h
20 
21 #include "itkSize.h"
22 #include "itkImageConstIterator.h"
23 #include <memory>
24 
25 namespace itk
26 {
86 template< typename TImage >
88 {
89 public:
92 
97  itkStaticConstMacro(ImageIteratorDimension, unsigned int,
98  TImage::ImageDimension);
99 
101  typedef typename TImage::IndexType IndexType;
102 
104  typedef typename TImage::SizeType SizeType;
105 
107  typedef typename TImage::OffsetType OffsetType;
108 
110  typedef typename TImage::RegionType RegionType;
111 
113  typedef TImage ImageType;
114 
118  typedef typename TImage::PixelContainer PixelContainer;
119  typedef typename PixelContainer::Pointer PixelContainerPointer;
120 
122  typedef typename TImage::InternalPixelType InternalPixelType;
123 
125  typedef typename TImage::PixelType PixelType;
126 
129  typedef typename TImage::AccessorType AccessorType;
130 
132  typedef typename TImage::AccessorFunctorType AccessorFunctorType;
133 
137  {
138  m_Buffer = 0;
139  m_Offset = 0;
140  m_BeginOffset = 0;
141  m_EndOffset = 0;
143  }
144 
147 
151  {
152  m_Image = it.m_Image; // copy the smart pointer
153 
154  m_Region = it.m_Region;
155 
156  m_Buffer = it.m_Buffer;
157  m_Offset = it.m_Offset;
163  }
164 
167  ImageReverseConstIterator(const ImageType *ptr, const RegionType & region)
168  {
169  SizeValueType offset;
170 
171  m_Image = ptr;
172  m_Buffer = m_Image->GetBufferPointer();
173  m_Region = region;
174 
175  // Compute the end offset, one pixel before the first pixel
176  offset = m_Image->ComputeOffset( m_Region.GetIndex() );
177  m_EndOffset = offset - 1;
178 
179  // Compute the begin offset, the last pixel in the region
180  IndexType ind( m_Region.GetIndex() );
181  SizeType size( m_Region.GetSize() );
182  for ( unsigned int i = 0; i < TImage::ImageDimension; ++i )
183  {
184  ind[i] += ( size[i] - 1 );
185  }
186  m_BeginOffset = m_Image->ComputeOffset(ind);
188 
189  m_PixelAccessor = ptr->GetPixelAccessor();
190  m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
192  }
193 
202  {
203  m_Image = it.GetImage();
204  m_Region = it.GetRegion();
205  m_Buffer = m_Image->GetBufferPointer();
206 
207  IndexType ind = it.GetIndex();
208 
209  m_Offset = m_Image->ComputeOffset(ind);
210 
211  // Compute the end offset, one pixel before the first pixel
212  m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
213 
214  // Compute the begin offset, the last pixel in the region
215  IndexType regInd( m_Region.GetIndex() );
216  SizeType regSize( m_Region.GetSize() );
217  for ( unsigned int i = 0; i < TImage::ImageDimension; ++i )
218  {
219  regInd[i] += ( regSize[i] - 1 );
220  }
221  m_BeginOffset = m_Image->ComputeOffset(regInd);
222 
223  m_PixelAccessor = m_Image->GetPixelAccessor();
224  m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
226  }
227 
230  Self & operator=(const Self & it)
231  {
232  if(this != &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;
242  m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
244  }
245  return *this;
246  }
247 
251  {
252  m_Image = it.GetImage();
253  m_Region = it.GetRegion();
254  m_Buffer = m_Image->GetBufferPointer();
255 
256  IndexType ind = it.GetIndex();
257 
258  m_Offset = m_Image->ComputeOffset(ind);
259 
260  // Compute the end offset, one pixel before the first pixel
261  m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
262 
263  // Compute the begin offset, the last pixel in the region
264  IndexType regInd( m_Region.GetIndex() );
265  SizeType regSize( m_Region.GetSize() );
266  for ( unsigned int i = 0; i < TImage::ImageDimension; ++i )
267  {
268  regInd[i] += ( regSize[i] - 1 );
269  }
270  m_BeginOffset = m_Image->ComputeOffset(regInd);
271 
272  m_PixelAccessor = m_Image->GetPixelAccessor();
273  m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
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 
305  { return m_Image->ComputeIndex(m_Offset); }
306 
309  virtual void SetIndex(const IndexType & ind)
310  { m_Offset = m_Image->ComputeOffset(ind); }
311 
314  const RegionType & GetRegion() const
315  { return m_Region; }
316 
318  const PixelType Get(void) const
319  { return m_PixelAccessorFunctor.Get( *( m_Buffer + m_Offset ) ); }
320 
322  void Set(const PixelType & value) const
323  {
324  this->m_PixelAccessorFunctor.Set(*( const_cast< InternalPixelType * >(
325  this->m_Buffer + this->m_Offset ) ), value);
326  }
327 
331  const PixelType & Value(void) const
332  { return *( m_Buffer + m_Offset ); }
333 
337  const PixelType & Value(void)
338  { return *( m_Buffer + m_Offset ); }
339 
343  itkLegacyMacro(Self Begin() const);
344 
347  void GoToBegin()
348  {
350  }
351 
355  itkLegacyMacro(Self End() const);
356 
359  void GoToEnd()
360  {
362  }
363 
366  bool IsAtBegin()
367  {
368  return ( m_Offset == m_BeginOffset );
369  }
370 
373  bool IsAtEnd()
374  {
375  return ( m_Offset == m_EndOffset );
376  }
377 
378 protected: //made protected so other iterators can access
379  typename ImageType::ConstWeakPointer m_Image;
380 
381  RegionType m_Region; // region to iterate over
382 
384  SizeValueType m_BeginOffset; // offset to last pixel in region
385  SizeValueType m_EndOffset; // offset to one pixel before first pixel
386 
388 
391 };
392 } // end namespace itk
393 
394 #ifndef ITK_MANUAL_INSTANTIATION
396 #endif
397 
398 #endif

Generated at Sat Mar 8 2014 14:53:30 for Orfeo Toolbox with doxygen 1.8.3.1