OTB  7.1.0
Orfeo Toolbox
otbSubsampledImageRegionConstIterator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 
23 #ifndef otbSubsampledImageRegionConstIterator_h
24 #define otbSubsampledImageRegionConstIterator_h
25 
26 #include "itkImageRegionConstIterator.h"
27 
28 namespace otb
29 {
30 
43 template <class TImage>
44 class ITK_EXPORT SubsampledImageRegionConstIterator : public itk::ImageRegionConstIterator<TImage>
45 {
46 public:
47 
50  typedef itk::ImageRegionConstIterator<TImage> Superclass;
51 
53  itkTypeMacro(SubsampledImageRegionConstIterator, ImageRegionConstIterator);
54 
59  itkStaticConstMacro(ImageIteratorDimension, unsigned int, Superclass::ImageIteratorDimension);
60 
63  typedef typename Superclass::IndexType IndexType;
64 
67  typedef typename Superclass::SizeType SizeType;
68 
70  typedef typename Superclass::RegionType RegionType;
71 
74  typedef typename Superclass::ImageType ImageType;
75 
78  // typedef typename Superclass::OffsetType OffsetType;
79  typedef unsigned long OffsetType;
80 
84  typedef typename Superclass::PixelContainer PixelContainer;
85  typedef typename Superclass::PixelContainerPointer PixelContainerPointer;
86 
88  typedef typename Superclass::InternalPixelType InternalPixelType;
89 
91  typedef typename Superclass::PixelType PixelType;
92 
95  typedef typename Superclass::AccessorType AccessorType;
96 
98  // typedef typename Superclass::IndexValueType IndexValueType;
99  typedef typename IndexType::IndexValueType IndexValueType;
100 
103 
106  SubsampledImageRegionConstIterator(const ImageType* ptr, const RegionType& region);
107 
114  SubsampledImageRegionConstIterator(const itk::ImageIterator<TImage>& it);
115 
122  SubsampledImageRegionConstIterator(const itk::ImageConstIterator<TImage>& it);
123 
125  void SetSubsampleFactor(IndexValueType factor);
126 
128  void SetSubsampleFactor(const IndexType& factor);
129 
130  const IndexType& GetSubsampleFactor() const
131  {
132  return this->m_SubsampleFactor;
133  }
134 
137  void GoToBegin();
138 
141  void GoToEnd();
142 
149  bool IsAtBegin(void) const
150  {
151  return (this->m_Offset <= m_SubSampledBeginOffset);
152  }
153 
161  bool IsAtEnd(void) const
162  {
163  return (this->m_Offset >= m_SubSampledEndOffset);
164  }
165 
169  void SetIndex(const IndexType& ind) override;
170 
172  IndexType GetIndex() const
173  {
174  return Superclass::GetIndex();
175  }
176 
184  Self& operator++()
185  {
186  // On the contrary to itk::ImageRegionConstIterator, m_Offset to
187  // not incremented before the test
188  if (this->m_Offset + m_SubsampleFactor[0] >= this->m_SpanEndOffset)
189  {
190  this->Increment();
191  }
192  else
193  {
194  // Now, the increment is performed
195  this->m_Offset += m_SubsampleFactor[0];
196  }
197  return *this;
198  }
200 
208  Self& operator--()
209  {
210  // On the contrary to itk::ImageRegionConstIterator, m_Offset
211  // is not decremented here (it may become negative!)
212  if (this->m_Offset < this->m_SpanBeginOffset + m_SubsampleFactor[0])
213  {
214  this->Decrement();
215  }
216  else
217  {
218  // Now we can
219  this->m_Offset -= m_SubsampleFactor[0];
220  }
221  return *this;
222  }
224 
228  void SetOffset(const OffsetType& offset);
229  OffsetType GetOffset() const
230  {
231  return this->m_Offset;
232  }
234 
238  RegionType GenerateOutputInformation() const;
239 
240 protected:
241  IndexType m_SubsampleFactor;
242  unsigned long m_SubSampledBeginOffset;
243  // unsigned long m_SubSampledReverseEndOffset;
246  IndexType m_LastUsableIndex;
247 
248 private:
249  void Increment(); // jump in a direction other than the fastest moving
250  void Decrement(); // go back in a direction other than the fastest moving
251 };
252 
253 } // end of namespace otb
254 
255 #ifndef OTB_MANUAL_INSTANTIATION
257 #endif
258 
259 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
itk::ImageRegionConstIterator< TImage > Superclass
Regular subsample iterator over an image.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.