OTB  7.1.0
Orfeo Toolbox
otbImageRegionAdaptativeSplitter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 
22 #ifndef otbImageRegionAdaptativeSplitter_h
23 #define otbImageRegionAdaptativeSplitter_h
24 
25 #include "itkRegion.h"
26 #include "itkImageRegionSplitter.h"
27 #include "itkIndex.h"
28 #include "itkSize.h"
29 #include "itkFastMutexLock.h"
30 
31 namespace otb
32 {
33 
64 template <unsigned int VImageDimension>
65 class ITK_EXPORT ImageRegionAdaptativeSplitter : public itk::ImageRegionSplitter<VImageDimension>
66 {
67 public:
70  typedef itk::ImageRegionSplitter<VImageDimension> Superclass;
71  typedef itk::SmartPointer<Self> Pointer;
72  typedef itk::SmartPointer<const Self> ConstPointer;
73 
75  itkNewMacro(Self);
76 
78  itkTypeMacro(ImageRegionAdaptativeSplitter, itk::Object);
79 
81  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
82 
84  static unsigned int GetImageDimension()
85  {
86  return VImageDimension;
87  }
88 
90  typedef itk::Index<VImageDimension> IndexType;
91  typedef typename IndexType::IndexValueType IndexValueType;
92 
94  typedef itk::Size<VImageDimension> SizeType;
95  typedef typename SizeType::SizeValueType SizeValueType;
96 
98  typedef itk::ImageRegion<VImageDimension> RegionType;
99 
100  typedef std::vector<RegionType> StreamVectorType;
101 
103  itkSetMacro(TileHint, SizeType);
104 
106  itkGetConstReferenceMacro(TileHint, SizeType);
107 
109  itkSetMacro(ImageRegion, RegionType);
110 
112  itkGetConstReferenceMacro(ImageRegion, RegionType);
113 
115  itkSetMacro(RequestedNumberOfSplits, unsigned int);
116 
118  itkGetConstReferenceMacro(RequestedNumberOfSplits, unsigned int);
119 
125  unsigned int GetNumberOfSplits(const RegionType& region, unsigned int requestedNumber) override;
126 
130  RegionType GetSplit(unsigned int i, unsigned int numberOfPieces, const RegionType& region) override;
131 
133  void Modified() const override
134  {
135  // Call superclass implementation
136  Superclass::Modified();
137 
138  // Invalidate up-to-date
139  m_IsUpToDate = false;
140  }
141 
142 protected:
143  ImageRegionAdaptativeSplitter() : m_TileHint(), m_ImageRegion(), m_RequestedNumberOfSplits(0), m_StreamVector(), m_IsUpToDate(false)
144  {
145  }
146 
148  {
149  }
150  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
151 
152 private:
155  void EstimateSplitMap();
156 
158  void operator=(const ImageRegionAdaptativeSplitter&) = delete;
159 
160  // This reflects the input image tiling
161  SizeType m_TileHint;
162 
163  // This contains the ImageRegion that is currently being split
164  RegionType m_ImageRegion;
165 
166  // This contains the requested number of splits
168 
169  // This is a vector of all regions which will be split
170  StreamVectorType m_StreamVector;
171 
172  // Is the splitter up-to-date ?
173  mutable bool m_IsUpToDate;
174 
175  // Lock to ensure thread-safety
176  itk::SimpleFastMutexLock m_Lock;
177 };
178 
179 } // end namespace otb
180 
181 #ifndef OTB_MANUAL_INSTANTIATION
183 #endif
184 
185 #endif
itk::ImageRegion< VImageDimension > RegionType
itk::ImageRegionSplitter< VImageDimension > Superclass
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.