OTB  9.0.0
Orfeo Toolbox
otbImageRegionAdaptativeSplitter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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{0,0};
162 
163  // This contains the ImageRegion that is currently being split
165 
166  // This contains the requested number of splits
168 
169  // This is a vector of all regions which will be split
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
otb::ImageRegionAdaptativeSplitter
Definition: otbImageRegionAdaptativeSplitter.h:65
otb::ImageRegionAdaptativeSplitter::StreamVectorType
std::vector< RegionType > StreamVectorType
Definition: otbImageRegionAdaptativeSplitter.h:100
otb::ImageRegionAdaptativeSplitter::~ImageRegionAdaptativeSplitter
~ImageRegionAdaptativeSplitter() override
Definition: otbImageRegionAdaptativeSplitter.h:147
otb::ImageRegionAdaptativeSplitter::IndexValueType
IndexType::IndexValueType IndexValueType
Definition: otbImageRegionAdaptativeSplitter.h:91
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ImageRegionAdaptativeSplitter::GetImageDimension
static unsigned int GetImageDimension()
Definition: otbImageRegionAdaptativeSplitter.h:84
otb::ImageRegionAdaptativeSplitter::IndexType
itk::Index< VImageDimension > IndexType
Definition: otbImageRegionAdaptativeSplitter.h:90
otb::ImageRegionAdaptativeSplitter::RegionType
itk::ImageRegion< VImageDimension > RegionType
Definition: otbImageRegionAdaptativeSplitter.h:98
otb::ImageRegionAdaptativeSplitter::Modified
void Modified() const override
Definition: otbImageRegionAdaptativeSplitter.h:133
otb::ImageRegionAdaptativeSplitter::m_IsUpToDate
bool m_IsUpToDate
Definition: otbImageRegionAdaptativeSplitter.h:173
otb::ImageRegionAdaptativeSplitter::SizeValueType
SizeType::SizeValueType SizeValueType
Definition: otbImageRegionAdaptativeSplitter.h:95
otb::ImageRegionAdaptativeSplitter::m_RequestedNumberOfSplits
unsigned int m_RequestedNumberOfSplits
Definition: otbImageRegionAdaptativeSplitter.h:167
otb::ImageRegionAdaptativeSplitter::Superclass
itk::ImageRegionSplitter< VImageDimension > Superclass
Definition: otbImageRegionAdaptativeSplitter.h:70
otbImageRegionAdaptativeSplitter.hxx
otb::ImageRegionAdaptativeSplitter::m_ImageRegion
RegionType m_ImageRegion
Definition: otbImageRegionAdaptativeSplitter.h:164
otb::ImageRegionAdaptativeSplitter::m_Lock
itk::SimpleFastMutexLock m_Lock
Definition: otbImageRegionAdaptativeSplitter.h:176
otb::ImageRegionAdaptativeSplitter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbImageRegionAdaptativeSplitter.h:72
otb::ImageRegionAdaptativeSplitter::Self
ImageRegionAdaptativeSplitter Self
Definition: otbImageRegionAdaptativeSplitter.h:69
otb::ImageRegionAdaptativeSplitter::ImageRegionAdaptativeSplitter
ImageRegionAdaptativeSplitter()
Definition: otbImageRegionAdaptativeSplitter.h:143
otb::ImageRegionAdaptativeSplitter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageRegionAdaptativeSplitter.h:71
otb::ImageRegionAdaptativeSplitter::m_StreamVector
StreamVectorType m_StreamVector
Definition: otbImageRegionAdaptativeSplitter.h:170
otb::ImageRegionAdaptativeSplitter::SizeType
itk::Size< VImageDimension > SizeType
Definition: otbImageRegionAdaptativeSplitter.h:94