OTB  9.0.0
Orfeo Toolbox
otbMultiImageFileWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017-2019 CS Systemes d'Information (CS SI)
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 otbMultiImageFileWriter_h
22 #define otbMultiImageFileWriter_h
23 
24 #include "otbImageFileWriter.h"
25 #include "otbImage.h"
26 #include "itkImageBase.h"
27 #include "itkProcessObject.h"
28 #include "itkImageIOBase.h"
29 #include "OTBImageIOExport.h"
30 
31 #include <memory>
32 
33 namespace otb
34 {
35 
47 class OTBImageIO_EXPORT MultiImageFileWriter : public itk::ProcessObject
48 {
49 public:
52  typedef itk::ProcessObject Superclass;
53  typedef itk::SmartPointer<Self> Pointer;
54  typedef itk::SmartPointer<const Self> ConstPointer;
55 
56  itkNewMacro(Self);
57 
58  itkTypeMacro(MultiImageFileWriter, itk::ProcessObject);
59 
61  typedef itk::ImageBase<2> ImageBaseType;
62  typedef ImageBaseType::RegionType RegionType;
63  typedef ImageBaseType::IndexType IndexType;
64  typedef ImageBaseType::IndexValueType IndexValueType;
65  typedef ImageBaseType::SizeType SizeType;
66  typedef ImageBaseType::SizeValueType SizeValueType;
67 
70  void SetNumberOfDivisionsStrippedStreaming(unsigned int nbDivisions);
71 
74  void SetNumberOfDivisionsTiledStreaming(unsigned int nbDivisions);
75 
79  void SetNumberOfLinesStrippedStreaming(unsigned int nbLinesPerStrip);
80 
90  void SetAutomaticStrippedStreaming(unsigned int availableRAM = 0, double bias = 1.0);
91 
94  void SetTileDimensionTiledStreaming(unsigned int tileDimension);
95 
106  void SetAutomaticTiledStreaming(unsigned int availableRAM = 0, double bias = 1.0);
107 
114  void SetAutomaticAdaptativeStreaming(unsigned int availableRAM = 0, double bias = 1.0);
115 
116  virtual void UpdateOutputData(itk::DataObject* itkNotUsed(output)) override;
117 
128  template <class TImage>
129  void AddInputImage(const TImage* inputPtr, const std::string& fileName);
130 
131 
135  template <class TWriter>
136  void AddInputWriter(typename TWriter::Pointer writer);
137 
138  virtual void UpdateOutputInformation() override;
139 
140  virtual void Update() override
141  {
142  this->UpdateOutputInformation();
143  this->UpdateOutputData(NULL);
144  }
145 
146 protected:
149  {
150  }
151 
153  virtual void GenerateData(void) override;
154 
159  virtual void GenerateInputRequestedRegion() override;
160 
162  virtual void InitializeStreaming();
163 
167  void ResetAllRequestedRegions(ImageBaseType* imagePtr);
168 
170  virtual RegionType GetStreamRegion(int inputIndex);
171 
172  void operator=(const MultiImageFileWriter&) = delete;
173 
174  void ObserveSourceFilterProgress(itk::Object* object, const itk::EventObject& event)
175  {
176  if (typeid(event) != typeid(itk::ProgressEvent))
177  {
178  return;
179  }
180 
181  itk::ProcessObject* processObject = dynamic_cast<itk::ProcessObject*>(object);
182  if (processObject)
183  {
184  m_DivisionProgress = processObject->GetProgress();
185  }
186 
187  this->UpdateFilterProgress();
188  }
189 
191  {
192  this->UpdateProgress((m_DivisionProgress + m_CurrentDivision) / m_NumberOfDivisions);
193  }
194 
195 private:
200 
201  // Division parameters
202  unsigned int m_NumberOfDivisions;
203  unsigned int m_CurrentDivision;
205 
207  unsigned long m_ObserverID;
208 
214  class SinkBase
215  {
216  public:
218  {
219  }
220  SinkBase(ImageBaseType::ConstPointer inputImage) : m_InputImage(inputImage)
221  {
222  }
223  virtual ~SinkBase()
224  {
225  }
226  virtual ImageBaseType::ConstPointer GetInput() const
227  {
228  return m_InputImage;
229  }
230  virtual ImageBaseType::Pointer GetInput()
231  {
232  return const_cast<ImageBaseType*>(m_InputImage.GetPointer());
233  }
234  virtual void WriteImageInformation() = 0;
235  virtual void Write(const RegionType& streamRegion) = 0;
236  virtual bool CanStreamWrite() const = 0;
237  typedef std::shared_ptr<SinkBase> Pointer;
238 
239 
240  virtual itk::ImageRegion<2> GetRegionToWrite() const = 0;
241 
242  protected:
244  ImageBaseType::ConstPointer m_InputImage;
245  };
246 
252  template <class TImage>
253  class Sink : public SinkBase
254  {
255  public:
257  {
258  }
259  Sink(typename TImage::ConstPointer inputImage, const std::string& filename);
261 
262  virtual ~Sink()
263  {
264  }
265 
266  void WriteImageInformation() override;
267  void Write(const RegionType& streamRegion) override;
268  bool CanStreamWrite() const override;
269  typedef std::shared_ptr<Sink> Pointer;
270 
274  itk::ImageRegion<2> GetRegionToWrite() const override;
275 
276  private:
279 
282  };
283 
285  typedef std::vector<std::shared_ptr<SinkBase>> SinkListType;
287 
288  std::vector<RegionType> m_StreamRegionList;
289 };
290 
291 } // end of namespace otb
292 
293 #ifndef OTB_MANUAL_INSTANTIATION
295 #endif
296 
297 #endif // otbMultiImageFileWriter_h
otb::MultiImageFileWriter::Superclass
itk::ProcessObject Superclass
Definition: otbMultiImageFileWriter.h:52
otb::MultiImageFileWriter::UpdateFilterProgress
void UpdateFilterProgress()
Definition: otbMultiImageFileWriter.h:190
otb::MultiImageFileWriter
Streams a pipeline with multiple outputs. It writes each output to a file. Inputs are connected to th...
Definition: otbMultiImageFileWriter.h:47
otb::MultiImageFileWriter::~MultiImageFileWriter
virtual ~MultiImageFileWriter()
Definition: otbMultiImageFileWriter.h:148
otb::MultiImageFileWriter::StreamingManagerType
StreamingManager< FakeOutputType > StreamingManagerType
Definition: otbMultiImageFileWriter.h:197
otb::MultiImageFileWriter::SinkBase::GetInput
virtual ImageBaseType::Pointer GetInput()
Definition: otbMultiImageFileWriter.h:230
otb::MultiImageFileWriter::FakeOutputType
otb::Image< unsigned char, 2 > FakeOutputType
Definition: otbMultiImageFileWriter.h:196
otb::MultiImageFileWriter::m_IsObserving
bool m_IsObserving
Definition: otbMultiImageFileWriter.h:206
otb::MultiImageFileWriter::SizeType
ImageBaseType::SizeType SizeType
Definition: otbMultiImageFileWriter.h:65
otb::StreamingManager
This class handles the streaming process used in the writers implementation.
Definition: otbStreamingManager.h:53
otbImage.h
otb::MultiImageFileWriter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbMultiImageFileWriter.h:53
otb::MultiImageFileWriter::Sink::m_ImageIO
otb::ImageIOBase::Pointer m_ImageIO
Definition: otbMultiImageFileWriter.h:281
otb::MultiImageFileWriter::m_ObserverID
unsigned long m_ObserverID
Definition: otbMultiImageFileWriter.h:207
otb::Wrapper::XML::Write
OTBApplicationEngine_EXPORT void Write(const std::string &filename, Application::Pointer application)
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Image
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:89
otb::MultiImageFileWriter::IndexType
ImageBaseType::IndexType IndexType
Definition: otbMultiImageFileWriter.h:63
otb::MultiImageFileWriter::Sink::Pointer
std::shared_ptr< Sink > Pointer
Definition: otbMultiImageFileWriter.h:269
otbMultiImageFileWriter.hxx
otb::MultiImageFileWriter::Sink::~Sink
virtual ~Sink()
Definition: otbMultiImageFileWriter.h:262
otb::MultiImageFileWriter::SinkBase::GetInput
virtual ImageBaseType::ConstPointer GetInput() const
Definition: otbMultiImageFileWriter.h:226
otb::MultiImageFileWriter::Sink::Sink
Sink()
Definition: otbMultiImageFileWriter.h:256
otb::MultiImageFileWriter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbMultiImageFileWriter.h:54
otb::MultiImageFileWriter::IndexValueType
ImageBaseType::IndexValueType IndexValueType
Definition: otbMultiImageFileWriter.h:64
otb::ImageFileWriter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageFileWriter.h:72
otb::MultiImageFileWriter::m_StreamRegionList
std::vector< RegionType > m_StreamRegionList
Definition: otbMultiImageFileWriter.h:288
otb::MultiImageFileWriter::m_DivisionProgress
float m_DivisionProgress
Definition: otbMultiImageFileWriter.h:204
otb::MultiImageFileWriter::m_SinkList
SinkListType m_SinkList
Definition: otbMultiImageFileWriter.h:286
otb::MultiImageFileWriter::RegionType
ImageBaseType::RegionType RegionType
Definition: otbMultiImageFileWriter.h:62
otb::MultiImageFileWriter::ImageBaseType
itk::ImageBase< 2 > ImageBaseType
Definition: otbMultiImageFileWriter.h:58
otb::MultiImageFileWriter::Update
virtual void Update() override
Definition: otbMultiImageFileWriter.h:140
otb::MultiImageFileWriter::SinkBase::Pointer
std::shared_ptr< SinkBase > Pointer
Definition: otbMultiImageFileWriter.h:237
otb::MultiImageFileWriter::Sink
Definition: otbMultiImageFileWriter.h:253
otb::Wrapper::ImageBaseType
itk::ImageBase< 2 > ImageBaseType
Definition: otbWrapperTypes.h:180
otb::StreamingManager::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingManager.h:59
otb::MultiImageFileWriter::m_NumberOfDivisions
unsigned int m_NumberOfDivisions
Definition: otbMultiImageFileWriter.h:202
otb::MultiImageFileWriter::SizeValueType
ImageBaseType::SizeValueType SizeValueType
Definition: otbMultiImageFileWriter.h:66
otb::MultiImageFileWriter::Sink::m_Writer
otb::ImageFileWriter< TImage >::Pointer m_Writer
Definition: otbMultiImageFileWriter.h:278
otb::MultiImageFileWriter::SinkListType
std::vector< std::shared_ptr< SinkBase > > SinkListType
Definition: otbMultiImageFileWriter.h:285
otb::MultiImageFileWriter::SinkBase::m_InputImage
ImageBaseType::ConstPointer m_InputImage
Definition: otbMultiImageFileWriter.h:244
otb::MultiImageFileWriter::SinkBase::SinkBase
SinkBase(ImageBaseType::ConstPointer inputImage)
Definition: otbMultiImageFileWriter.h:220
otb::MultiImageFileWriter::Self
MultiImageFileWriter Self
Definition: otbMultiImageFileWriter.h:51
otbImageFileWriter.h
otb::ImageIOBase::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageIOBase.h:75
otb::MultiImageFileWriter::ObserveSourceFilterProgress
void ObserveSourceFilterProgress(itk::Object *object, const itk::EventObject &event)
Definition: otbMultiImageFileWriter.h:174
otb::MultiImageFileWriter::SinkBase::~SinkBase
virtual ~SinkBase()
Definition: otbMultiImageFileWriter.h:223
otb::MultiImageFileWriter::m_CurrentDivision
unsigned int m_CurrentDivision
Definition: otbMultiImageFileWriter.h:203
otb::MultiImageFileWriter::SinkBase::SinkBase
SinkBase()
Definition: otbMultiImageFileWriter.h:217
otb::MultiImageFileWriter::m_StreamingManager
StreamingManagerType::Pointer m_StreamingManager
Definition: otbMultiImageFileWriter.h:199
otb::MultiImageFileWriter::SinkBase
Definition: otbMultiImageFileWriter.h:214