OTB  10.0.0
Orfeo Toolbox
otbStreamingShrinkImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 
26 #include "OTBImageManipulationExport.h"
27 #include "otbStreamingManager.h"
28 #include "otbMacro.h"
29 
30 namespace otb
31 {
32 
33 class OTBImageManipulation_EXPORT StreamingShrinkImageRegionSplitter : public itk::ImageRegionSplitter<2>
34 {
35 public:
38  typedef itk::ImageRegionSplitter<2> Superclass;
39  typedef itk::SmartPointer<Self> Pointer;
40  typedef itk::SmartPointer<const Self> ConstPointer;
41 
43  itkNewMacro(Self);
44 
46  itkTypeMacro(StreamingShrinkImageRegionSplitter, itk::Object);
47 
49  itkStaticConstMacro(ImageDimension, unsigned int, 2);
50 
52  static unsigned int GetImageDimension()
53  {
54  return ImageDimension;
55  }
56 
58  typedef itk::Index<ImageDimension> IndexType;
59  typedef IndexType::IndexValueType IndexValueType;
60 
62  typedef itk::Size<ImageDimension> SizeType;
63  typedef SizeType::SizeValueType SizeValueType;
64 
66  typedef itk::ImageRegion<ImageDimension> RegionType;
67 
73  unsigned int GetNumberOfSplits(const RegionType& region, unsigned int requestedNumber) override;
74 
78  RegionType GetSplit(unsigned int i, unsigned int numberOfPieces, const RegionType& region) override;
79 
80  itkGetMacro(TileSizeAlignment, unsigned int);
81 
82  itkGetMacro(TileDimension, unsigned int);
83 
84  itkSetMacro(ShrinkFactor, unsigned int);
85  itkGetMacro(ShrinkFactor, unsigned int);
86 
87 protected:
88  StreamingShrinkImageRegionSplitter() : m_SplitsPerDimension(0U), m_TileDimension(0), m_TileSizeAlignment(0), m_ShrinkFactor(10)
89  {
90  }
92  {
93  }
94  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
95 
96 private:
99 
100  itk::FixedArray<unsigned int, ImageDimension> m_SplitsPerDimension;
101  unsigned int m_TileDimension;
102  unsigned int m_TileSizeAlignment;
103  unsigned int m_ShrinkFactor;
104 };
105 
106 
107 template <class TInputImage>
108 class ITK_EXPORT StreamingShrinkStreamingManager : public StreamingManager<TInputImage>
109 {
110 public:
114  typedef itk::SmartPointer<Self> Pointer;
115  typedef itk::SmartPointer<const Self> ConstPointer;
116 
118  itkNewMacro(Self);
119 
122 
123  typedef TInputImage ImageType;
124  typedef typename ImageType::Pointer ImagePointerType;
125  typedef typename ImageType::RegionType RegionType;
126  typedef typename RegionType::IndexType IndexType;
127  typedef typename RegionType::SizeType SizeType;
128  typedef typename ImageType::InternalPixelType PixelType;
129 
130  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
131 
134  void PrepareStreaming(itk::DataObject* input, const RegionType& region) override;
135 
136  void SetShrinkFactor(unsigned int val)
137  {
138  m_ShrinkFactor = val;
139  }
140 
141  unsigned int GetShrinkFactor() const
142  {
143  return m_ShrinkFactor;
144  }
145 
146 protected:
149 
150 private:
153 
154  unsigned int m_ShrinkFactor;
155 };
156 
157 
168 template <class TInputImage, class TOutputImage = TInputImage>
169 class ITK_EXPORT PersistentShrinkImageFilter : public PersistentImageFilter<TInputImage, TOutputImage>
170 {
171 public:
175  typedef itk::SmartPointer<Self> Pointer;
176  typedef itk::SmartPointer<const Self> ConstPointer;
177 
179  itkNewMacro(Self);
180 
183 
185  typedef TInputImage InputImageType;
186  typedef typename TInputImage::Pointer InputImagePointer;
187  typedef typename TInputImage::RegionType RegionType;
188  typedef typename TInputImage::SizeType SizeType;
189  typedef typename TInputImage::IndexType IndexType;
190  typedef typename TInputImage::PixelType PixelType;
191 
193  typedef TOutputImage OutputImageType;
194  typedef typename TOutputImage::Pointer OutputImagePointer;
195 
196  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
197 
199  typedef typename itk::DataObject::Pointer DataObjectPointer;
200 
202  {
203  return m_ShrunkOutput;
204  }
205 
206  void Synthetize(void) override;
207 
208  void Reset(void) override;
209 
210  itkSetMacro(ShrinkFactor, unsigned int);
211  itkGetMacro(ShrinkFactor, unsigned int);
212 
213 protected:
215 
216  ~PersistentShrinkImageFilter() override;
217 
218  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
219 
220  void BeforeThreadedGenerateData() override;
221 
223  void DynamicThreadedGenerateData(const RegionType& outputRegionForThread) override;
224 
225  void AfterThreadedGenerateData() override;
226 
230  void AllocateOutputs() override;
231 
232  void GenerateOutputInformation() override;
233 
234 
235 private:
237  void operator=(const Self&) = delete;
238 
239  /* the output shrunk image */
241 
243  unsigned int m_ShrinkFactor;
244 
247 }; // end of class PersistentStatisticsVectorImageFilter
248 
249 
264 template <class TInputImage, class TOutputImage = TInputImage>
265 class ITK_EXPORT StreamingShrinkImageFilter : public PersistentFilterStreamingDecorator<PersistentShrinkImageFilter<TInputImage, TOutputImage>>
266 {
267 public:
271  typedef itk::SmartPointer<Self> Pointer;
272  typedef itk::SmartPointer<const Self> ConstPointer;
273 
275  itkNewMacro(Self);
276 
279 
280  typedef TInputImage InputImageType;
281  typedef TOutputImage OutputImageType;
283 
286 
287  using Superclass::SetInput;
289  {
290  this->GetFilter()->SetInput(input);
291  }
292 
294  {
295  return this->GetFilter()->GetInput();
296  }
297 
299  {
300  return this->GetFilter()->GetShrunkOutput();
301  }
302 
303  otbSetObjectMemberMacro(Filter, ShrinkFactor, unsigned int);
304  otbGetObjectMemberMacro(Filter, ShrinkFactor, unsigned int);
305 
306  void Update(void) override
307  {
308  m_StreamingManager->SetShrinkFactor(this->GetFilter()->GetShrinkFactor());
309  Superclass::Update();
310  }
311 
312 protected:
315  {
316  // Use a specific StreamingManager implementation
317  m_StreamingManager = StreamingShrinkStreamingManagerType::New();
318  this->GetStreamer()->SetStreamingManager(m_StreamingManager);
319  }
321 
324  {
325  }
326 
327 private:
329  void operator=(const Self&) = delete;
330 
332 };
333 
334 } // End namespace otb
335 
336 #ifndef OTB_MANUAL_INSTANTIATION
338 #endif
339 
340 #endif
This filter link a persistent filter with a StreamingImageVirtualWriter.
This filter is the base class for all filter persisting data through multiple update....
PersistentShrinkImageFilter(const Self &)=delete
itk::SmartPointer< const Self > ConstPointer
void operator=(const Self &)=delete
PersistentImageFilter< TInputImage, TOutputImage > Superclass
This class handles the streaming process used in the writers implementation.
Generates a quicklook of the input image.
PersistentFilterStreamingDecorator< PersistentShrinkImageFilter< TInputImage, TOutputImage > > Superclass
otbSetObjectMemberMacro(Filter, ShrinkFactor, unsigned int)
StreamingShrinkStreamingManagerType::Pointer StreamingShrinkStreamingManagerPointerType
StreamingShrinkStreamingManagerPointerType m_StreamingManager
otbGetObjectMemberMacro(Filter, ShrinkFactor, unsigned int)
void operator=(const Self &)=delete
StreamingShrinkImageFilter(const Self &)=delete
itk::SmartPointer< const Self > ConstPointer
StreamingShrinkStreamingManager< InputImageType > StreamingShrinkStreamingManagerType
unsigned int GetNumberOfSplits(const RegionType &region, unsigned int requestedNumber) override
RegionType GetSplit(unsigned int i, unsigned int numberOfPieces, const RegionType &region) override
StreamingShrinkImageRegionSplitter(const StreamingShrinkImageRegionSplitter &)=delete
itk::FixedArray< unsigned int, ImageDimension > m_SplitsPerDimension
itk::ImageRegion< ImageDimension > RegionType
void operator=(const StreamingShrinkImageRegionSplitter &)=delete
void PrintSelf(std::ostream &os, itk::Indent indent) const override
StreamingShrinkStreamingManager(const StreamingShrinkStreamingManager &)=delete
void operator=(const StreamingShrinkStreamingManager &)=delete
static const std::string Filter
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.