OTB  9.0.0
Orfeo Toolbox
otbStreamingShrinkImageFilter.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 #ifndef otbStreamingShrinkImageFilter_h
22 #define otbStreamingShrinkImageFilter_h
23 
24 
27 
28 #include "otbStreamingManager.h"
29 #include "otbMacro.h"
30 
31 namespace otb
32 {
33 
34 class ITK_EXPORT StreamingShrinkImageRegionSplitter : public itk::ImageRegionSplitter<2>
35 {
36 public:
39  typedef itk::ImageRegionSplitter<2> Superclass;
40  typedef itk::SmartPointer<Self> Pointer;
41  typedef itk::SmartPointer<const Self> ConstPointer;
42 
44  itkNewMacro(Self);
45 
47  itkTypeMacro(StreamingShrinkImageRegionSplitter, itk::Object);
48 
50  itkStaticConstMacro(ImageDimension, unsigned int, 2);
51 
53  static unsigned int GetImageDimension()
54  {
55  return ImageDimension;
56  }
57 
59  typedef itk::Index<ImageDimension> IndexType;
60  typedef IndexType::IndexValueType IndexValueType;
61 
63  typedef itk::Size<ImageDimension> SizeType;
64  typedef SizeType::SizeValueType SizeValueType;
65 
67  typedef itk::ImageRegion<ImageDimension> RegionType;
68 
74  unsigned int GetNumberOfSplits(const RegionType& region, unsigned int requestedNumber) override;
75 
79  RegionType GetSplit(unsigned int i, unsigned int numberOfPieces, const RegionType& region) override;
80 
81  itkGetMacro(TileSizeAlignment, unsigned int);
82 
83  itkGetMacro(TileDimension, unsigned int);
84 
85  itkSetMacro(ShrinkFactor, unsigned int);
86  itkGetMacro(ShrinkFactor, unsigned int);
87 
88 protected:
89  StreamingShrinkImageRegionSplitter() : m_SplitsPerDimension(0U), m_TileDimension(0), m_TileSizeAlignment(0), m_ShrinkFactor(10)
90  {
91  }
93  {
94  }
95  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
96 
97 private:
99  void operator=(const StreamingShrinkImageRegionSplitter&) = delete;
100 
101  itk::FixedArray<unsigned int, ImageDimension> m_SplitsPerDimension;
102  unsigned int m_TileDimension;
103  unsigned int m_TileSizeAlignment;
104  unsigned int m_ShrinkFactor;
105 };
106 
107 
108 template <class TInputImage>
109 class ITK_EXPORT StreamingShrinkStreamingManager : public StreamingManager<TInputImage>
110 {
111 public:
115  typedef itk::SmartPointer<Self> Pointer;
116  typedef itk::SmartPointer<const Self> ConstPointer;
117 
119  itkNewMacro(Self);
120 
123 
124  typedef TInputImage ImageType;
125  typedef typename ImageType::Pointer ImagePointerType;
126  typedef typename ImageType::RegionType RegionType;
127  typedef typename RegionType::IndexType IndexType;
128  typedef typename RegionType::SizeType SizeType;
129  typedef typename ImageType::InternalPixelType PixelType;
130 
131  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
132 
135  void PrepareStreaming(itk::DataObject* input, const RegionType& region) override;
136 
137  void SetShrinkFactor(unsigned int val)
138  {
139  m_ShrinkFactor = val;
140  }
141 
142  unsigned int GetShrinkFactor() const
143  {
144  return m_ShrinkFactor;
145  }
146 
147 protected:
150 
151 private:
153  void operator=(const StreamingShrinkStreamingManager&) = delete;
154 
155  unsigned int m_ShrinkFactor;
156 };
157 
158 
169 template <class TInputImage, class TOutputImage = TInputImage>
170 class ITK_EXPORT PersistentShrinkImageFilter : public PersistentImageFilter<TInputImage, TOutputImage>
171 {
172 public:
176  typedef itk::SmartPointer<Self> Pointer;
177  typedef itk::SmartPointer<const Self> ConstPointer;
178 
180  itkNewMacro(Self);
181 
184 
186  typedef TInputImage InputImageType;
187  typedef typename TInputImage::Pointer InputImagePointer;
188  typedef typename TInputImage::RegionType RegionType;
189  typedef typename TInputImage::SizeType SizeType;
190  typedef typename TInputImage::IndexType IndexType;
191  typedef typename TInputImage::PixelType PixelType;
192 
194  typedef TOutputImage OutputImageType;
195  typedef typename TOutputImage::Pointer OutputImagePointer;
196 
197  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
198 
200  typedef typename itk::DataObject::Pointer DataObjectPointer;
201 
203  {
204  return m_ShrunkOutput;
205  }
206 
207  void Synthetize(void) override;
208 
209  void Reset(void) override;
210 
211  itkSetMacro(ShrinkFactor, unsigned int);
212  itkGetMacro(ShrinkFactor, unsigned int);
213 
214 protected:
216 
217  ~PersistentShrinkImageFilter() override;
218 
219  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
220 
221  void BeforeThreadedGenerateData() override;
222 
224  void ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
225 
226  void AfterThreadedGenerateData() override;
227 
231  void AllocateOutputs() override;
232 
233  void GenerateOutputInformation() override;
234 
235 
236 private:
237  PersistentShrinkImageFilter(const Self&) = delete;
238  void operator=(const Self&) = delete;
239 
240  /* the output shrunk image */
242 
244  unsigned int m_ShrinkFactor;
245 
248 }; // end of class PersistentStatisticsVectorImageFilter
249 
250 
265 template <class TInputImage, class TOutputImage = TInputImage>
266 class ITK_EXPORT StreamingShrinkImageFilter : public PersistentFilterStreamingDecorator<PersistentShrinkImageFilter<TInputImage, TOutputImage>>
267 {
268 public:
272  typedef itk::SmartPointer<Self> Pointer;
273  typedef itk::SmartPointer<const Self> ConstPointer;
274 
276  itkNewMacro(Self);
277 
280 
281  typedef TInputImage InputImageType;
282  typedef TOutputImage OutputImageType;
284 
287 
288  using Superclass::SetInput;
290  {
291  this->GetFilter()->SetInput(input);
292  }
293 
295  {
296  return this->GetFilter()->GetInput();
297  }
298 
300  {
301  return this->GetFilter()->GetShrunkOutput();
302  }
303 
304  otbSetObjectMemberMacro(Filter, ShrinkFactor, unsigned int);
305  otbGetObjectMemberMacro(Filter, ShrinkFactor, unsigned int);
306 
307  void Update(void) override
308  {
309  m_StreamingManager->SetShrinkFactor(this->GetFilter()->GetShrinkFactor());
310  Superclass::Update();
311  }
312 
313 protected:
316  {
317  // Use a specific StreamingManager implementation
318  m_StreamingManager = StreamingShrinkStreamingManagerType::New();
319  this->GetStreamer()->SetStreamingManager(m_StreamingManager);
320  }
322 
325  {
326  }
327 
328 private:
329  StreamingShrinkImageFilter(const Self&) = delete;
330  void operator=(const Self&) = delete;
331 
333 };
334 
335 } // End namespace otb
336 
337 #ifndef OTB_MANUAL_INSTANTIATION
339 #endif
340 
341 #endif
otb::PersistentShrinkImageFilter::PixelType
TInputImage::PixelType PixelType
Definition: otbStreamingShrinkImageFilter.h:191
otb::StreamingShrinkImageRegionSplitter
Definition: otbStreamingShrinkImageFilter.h:34
otb::PersistentShrinkImageFilter::GetShrunkOutput
OutputImageType * GetShrunkOutput()
Definition: otbStreamingShrinkImageFilter.h:202
otb::StreamingShrinkImageRegionSplitter::RegionType
itk::ImageRegion< ImageDimension > RegionType
Definition: otbStreamingShrinkImageFilter.h:67
otb::StreamingShrinkImageFilter::Self
StreamingShrinkImageFilter Self
Definition: otbStreamingShrinkImageFilter.h:270
otb::StreamingShrinkImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingShrinkImageFilter.h:272
otb::StreamingShrinkImageRegionSplitter::GetImageDimension
static unsigned int GetImageDimension()
Definition: otbStreamingShrinkImageFilter.h:53
otb::StreamingShrinkImageRegionSplitter::Self
StreamingShrinkImageRegionSplitter Self
Definition: otbStreamingShrinkImageFilter.h:38
otbPersistentImageFilter.h
otb::PersistentShrinkImageFilter
Definition: otbStreamingShrinkImageFilter.h:170
otb::StreamingShrinkStreamingManager::PixelType
ImageType::InternalPixelType PixelType
Definition: otbStreamingShrinkImageFilter.h:129
otb::StreamingShrinkImageFilter::~StreamingShrinkImageFilter
~StreamingShrinkImageFilter() override
Definition: otbStreamingShrinkImageFilter.h:324
otb::StreamingManager
This class handles the streaming process used in the writers implementation.
Definition: otbStreamingManager.h:53
otb::PersistentImageFilter
This filter is the base class for all filter persisting data through multiple update....
Definition: otbPersistentImageFilter.h:47
otb::StreamingShrinkImageRegionSplitter::~StreamingShrinkImageRegionSplitter
~StreamingShrinkImageRegionSplitter() override
Definition: otbStreamingShrinkImageFilter.h:92
otb::StreamingShrinkStreamingManager::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbStreamingShrinkImageFilter.h:116
otb::StreamingShrinkImageFilter::StreamingShrinkImageFilter
StreamingShrinkImageFilter()
Definition: otbStreamingShrinkImageFilter.h:315
otbPersistentFilterStreamingDecorator.h
otb::PersistentShrinkImageFilter::SizeType
TInputImage::SizeType SizeType
Definition: otbStreamingShrinkImageFilter.h:189
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::StreamingShrinkImageFilter::Superclass
PersistentFilterStreamingDecorator< PersistentShrinkImageFilter< TInputImage, TOutputImage > > Superclass
Definition: otbStreamingShrinkImageFilter.h:271
otb::PersistentShrinkImageFilter::m_ShrunkOutput
OutputImagePointer m_ShrunkOutput
Definition: otbStreamingShrinkImageFilter.h:241
otb::StreamingShrinkImageRegionSplitter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbStreamingShrinkImageFilter.h:41
otbMacro.h
otb::StreamingShrinkImageFilter::m_StreamingManager
StreamingShrinkStreamingManagerPointerType m_StreamingManager
Definition: otbStreamingShrinkImageFilter.h:332
otb::PersistentShrinkImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbStreamingShrinkImageFilter.h:177
otb::StreamingShrinkImageFilter::GetOutput
OutputImageType * GetOutput()
Definition: otbStreamingShrinkImageFilter.h:299
otb::StreamingShrinkImageFilter::GetInput
const InputImageType * GetInput()
Definition: otbStreamingShrinkImageFilter.h:294
otb::StreamingShrinkStreamingManager::SizeType
RegionType::SizeType SizeType
Definition: otbStreamingShrinkImageFilter.h:128
otb::PersistentShrinkImageFilter::InputImageType
TInputImage InputImageType
Definition: otbStreamingShrinkImageFilter.h:183
otb::StreamingShrinkStreamingManager::ImagePointerType
ImageType::Pointer ImagePointerType
Definition: otbStreamingShrinkImageFilter.h:125
otb::StreamingShrinkImageRegionSplitter::StreamingShrinkImageRegionSplitter
StreamingShrinkImageRegionSplitter()
Definition: otbStreamingShrinkImageFilter.h:89
otb::PersistentShrinkImageFilter::IndexType
TInputImage::IndexType IndexType
Definition: otbStreamingShrinkImageFilter.h:190
otb::PersistentFilterStreamingDecorator::FilterType
TFilter FilterType
Definition: otbPersistentFilterStreamingDecorator.h:60
otb::Wrapper::Tags::Filter
static const std::string Filter
Definition: otbWrapperTags.h:39
otb::StreamingShrinkStreamingManager::RegionType
ImageType::RegionType RegionType
Definition: otbStreamingShrinkImageFilter.h:126
otb::PersistentShrinkImageFilter::DataObjectPointer
itk::DataObject::Pointer DataObjectPointer
Definition: otbStreamingShrinkImageFilter.h:200
otb::StreamingShrinkImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbStreamingShrinkImageFilter.h:282
otb::PersistentShrinkImageFilter::RegionType
TInputImage::RegionType RegionType
Definition: otbStreamingShrinkImageFilter.h:188
otb::StreamingShrinkImageRegionSplitter::IndexType
itk::Index< ImageDimension > IndexType
Definition: otbStreamingShrinkImageFilter.h:59
otb::StreamingShrinkImageRegionSplitter::SizeType
itk::Size< ImageDimension > SizeType
Definition: otbStreamingShrinkImageFilter.h:63
otb::PersistentShrinkImageFilter::m_ShrinkFactor
unsigned int m_ShrinkFactor
Definition: otbStreamingShrinkImageFilter.h:244
otb::PersistentShrinkImageFilter::Self
PersistentShrinkImageFilter Self
Definition: otbStreamingShrinkImageFilter.h:174
otbStreamingShrinkImageFilter.hxx
otb::StreamingShrinkImageFilter::SetInput
void SetInput(InputImageType *input)
Definition: otbStreamingShrinkImageFilter.h:289
otbStreamingManager.h
otb::StreamingShrinkImageRegionSplitter::m_TileDimension
unsigned int m_TileDimension
Definition: otbStreamingShrinkImageFilter.h:102
otb::StreamingShrinkStreamingManager::m_ShrinkFactor
unsigned int m_ShrinkFactor
Definition: otbStreamingShrinkImageFilter.h:155
otb::StreamingShrinkImageRegionSplitter::m_TileSizeAlignment
unsigned int m_TileSizeAlignment
Definition: otbStreamingShrinkImageFilter.h:103
otb::PersistentShrinkImageFilter::OutputImagePointer
TOutputImage::Pointer OutputImagePointer
Definition: otbStreamingShrinkImageFilter.h:195
otb::PersistentFilterStreamingDecorator
This filter link a persistent filter with a StreamingImageVirtualWriter.
Definition: otbPersistentFilterStreamingDecorator.h:47
otb::StreamingShrinkStreamingManager::Superclass
StreamingManager< TInputImage > Superclass
Definition: otbStreamingShrinkImageFilter.h:114
otb::StreamingShrinkImageFilter::StreamingShrinkStreamingManagerType
StreamingShrinkStreamingManager< InputImageType > StreamingShrinkStreamingManagerType
Definition: otbStreamingShrinkImageFilter.h:285
otb::StreamingShrinkImageRegionSplitter::m_SplitsPerDimension
itk::FixedArray< unsigned int, ImageDimension > m_SplitsPerDimension
Definition: otbStreamingShrinkImageFilter.h:101
otb::StreamingShrinkImageFilter::StreamingShrinkStreamingManagerPointerType
StreamingShrinkStreamingManagerType::Pointer StreamingShrinkStreamingManagerPointerType
Definition: otbStreamingShrinkImageFilter.h:286
otb::StreamingShrinkImageRegionSplitter::m_ShrinkFactor
unsigned int m_ShrinkFactor
Definition: otbStreamingShrinkImageFilter.h:104
otb::PersistentShrinkImageFilter::InputImagePointer
TInputImage::Pointer InputImagePointer
Definition: otbStreamingShrinkImageFilter.h:187
otb::PersistentShrinkImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingShrinkImageFilter.h:176
otb::StreamingShrinkStreamingManager::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingShrinkImageFilter.h:115
otb::StreamingShrinkImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbStreamingShrinkImageFilter.h:273
otb::StreamingShrinkImageRegionSplitter::IndexValueType
IndexType::IndexValueType IndexValueType
Definition: otbStreamingShrinkImageFilter.h:60
otb::StreamingShrinkImageFilter::InputImageType
TInputImage InputImageType
Definition: otbStreamingShrinkImageFilter.h:279
otb::StreamingShrinkStreamingManager::IndexType
RegionType::IndexType IndexType
Definition: otbStreamingShrinkImageFilter.h:127
otb::StreamingShrinkImageRegionSplitter::SizeValueType
SizeType::SizeValueType SizeValueType
Definition: otbStreamingShrinkImageFilter.h:64
otb::StreamingShrinkStreamingManager::ImageType
TInputImage ImageType
Definition: otbStreamingShrinkImageFilter.h:122
otbGetObjectMemberMacro
#define otbGetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:89
otb::StreamingShrinkImageFilter
Generates a quicklook of the input image.
Definition: otbStreamingShrinkImageFilter.h:266
otb::StreamingShrinkImageFilter::Update
void Update(void) override
Definition: otbStreamingShrinkImageFilter.h:307
otb::StreamingShrinkImageFilter::PersistentFilterType
Superclass::FilterType PersistentFilterType
Definition: otbStreamingShrinkImageFilter.h:283
otb::StreamingShrinkStreamingManager::Self
StreamingShrinkStreamingManager Self
Definition: otbStreamingShrinkImageFilter.h:113
otbSetObjectMemberMacro
#define otbSetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:79
otb::PersistentShrinkImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbStreamingShrinkImageFilter.h:194
otb::StreamingShrinkStreamingManager::GetShrinkFactor
unsigned int GetShrinkFactor() const
Definition: otbStreamingShrinkImageFilter.h:142
otb::PersistentShrinkImageFilter::m_Offset
IndexType m_Offset
Definition: otbStreamingShrinkImageFilter.h:247
otb::PersistentShrinkImageFilter::Superclass
PersistentImageFilter< TInputImage, TOutputImage > Superclass
Definition: otbStreamingShrinkImageFilter.h:175
otb::StreamingShrinkImageRegionSplitter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingShrinkImageFilter.h:40
otb::StreamingShrinkImageRegionSplitter::Superclass
itk::ImageRegionSplitter< 2 > Superclass
Definition: otbStreamingShrinkImageFilter.h:39
otb::StreamingShrinkStreamingManager::SetShrinkFactor
void SetShrinkFactor(unsigned int val)
Definition: otbStreamingShrinkImageFilter.h:137
otb::StreamingShrinkStreamingManager
Definition: otbStreamingShrinkImageFilter.h:109