OTB  9.0.0
Orfeo Toolbox
otbImageFileWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2020 CS Systemes d'Information (CS SI)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbImageFileWriter_h
23 #define otbImageFileWriter_h
24 
25 #include "otbImageIOBase.h"
26 #include "itkProcessObject.h"
27 #include "otbStreamingManager.h"
29 #include "itkFastMutexLock.h"
30 #include <string>
31 #include "OTBImageIOExport.h"
32 
33 namespace otb
34 {
35 
65 template <class TInputImage>
66 class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter : public itk::ProcessObject
67 {
68 public:
71  typedef itk::ProcessObject Superclass;
72  typedef itk::SmartPointer<Self> Pointer;
73  typedef itk::SmartPointer<const Self> ConstPointer;
74 
76  itkNewMacro(Self);
77 
79  itkTypeMacro(ImageFileWriter, itk::ProcessObject);
80 
82  typedef TInputImage InputImageType;
83  typedef typename InputImageType::Pointer InputImagePointer;
84  typedef typename InputImageType::RegionType InputImageRegionType;
85  typedef typename InputImageType::PixelType InputImagePixelType;
86  typedef typename InputImageType::IndexType InputIndexType;
87  typedef TInputImage OutputImageType;
88  typedef typename OutputImageType::Pointer OutputImagePointer;
89  typedef typename OutputImageType::RegionType OutputImageRegionType;
90  typedef typename OutputImageType::PixelType OutputImagePixelType;
91  typedef typename Superclass::DataObjectPointer DataObjectPointer;
92 
95 
97  itkStaticConstMacro(InputImageDimension, unsigned int, InputImageType::ImageDimension);
98 
102 
106  {
107  return m_StreamingManager;
108  }
109 
113  {
114  m_StreamingManager = streamingManager;
115  }
116 
119  void SetNumberOfDivisionsStrippedStreaming(unsigned int nbDivisions);
120 
123  void SetNumberOfDivisionsTiledStreaming(unsigned int nbDivisions);
124 
128  void SetNumberOfLinesStrippedStreaming(unsigned int nbLinesPerStrip);
129 
139  void SetAutomaticStrippedStreaming(unsigned int availableRAM = 0, double bias = 1.0);
140 
143  void SetTileDimensionTiledStreaming(unsigned int tileDimension);
144 
155  void SetAutomaticTiledStreaming(unsigned int availableRAM = 0, double bias = 1.0);
156 
163  void SetAutomaticAdaptativeStreaming(unsigned int availableRAM = 0, double bias = 1.0);
164 
166  using Superclass::SetInput;
167  virtual void SetInput(const InputImageType* input);
168 
170  const InputImageType* GetInput();
171 
174  void Update() override;
175 
176  virtual void SetFileName(const std::string& extendedFileName);
177 
178  virtual const char* GetFileName() const;
179 
182  void SetIORegion(const itk::ImageIORegion& region);
183  itkGetConstReferenceMacro(IORegion, itk::ImageIORegion);
185 
187  itkSetMacro(UseCompression, bool);
188  itkGetConstReferenceMacro(UseCompression, bool);
189  itkBooleanMacro(UseCompression);
191 
198  itkSetMacro(UseInputMetaDataDictionary, bool);
199  itkGetConstReferenceMacro(UseInputMetaDataDictionary, bool);
200  itkBooleanMacro(UseInputMetaDataDictionary);
202 
203  itkSetObjectMacro(ImageIO, otb::ImageIOBase);
204  itkGetObjectMacro(ImageIO, otb::ImageIOBase);
205  itkGetConstObjectMacro(ImageIO, otb::ImageIOBase);
206 
207  itkGetConstObjectMacro(FilenameHelper, FNameHelperType);
208 
210  const bool& GetAbortGenerateData() const override;
211 
212  void SetAbortGenerateData(const bool val) override;
213 
214 protected:
215  ImageFileWriter();
216  ~ImageFileWriter() override;
217  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
218 
220  void GenerateData(void) override;
221 
223  void GenerateOutputInformation(void) override;
224 
225 private:
226  ImageFileWriter(const ImageFileWriter&) = delete;
227  void operator=(const ImageFileWriter&) = delete;
228 
229  void ObserveSourceFilterProgress(itk::Object* object, const itk::EventObject& event)
230  {
231  if (typeid(event) != typeid(itk::ProgressEvent))
232  {
233  return;
234  }
235 
236  itk::ProcessObject* processObject = dynamic_cast<itk::ProcessObject*>(object);
237  if (processObject)
238  {
239  m_DivisionProgress = processObject->GetProgress();
240  }
241 
242  this->UpdateFilterProgress();
243  }
244 
246  {
247  this->UpdateProgress((m_DivisionProgress + m_CurrentDivision) / m_NumberOfDivisions);
248  }
249 
250  unsigned int m_NumberOfDivisions;
251  unsigned int m_CurrentDivision;
253 
255  std::string m_FileName;
256 
258 
259  bool m_UserSpecifiedImageIO; // track whether the ImageIO is user specified
260 
261  itk::ImageIORegion m_IORegion;
262  bool m_UserSpecifiedIORegion; // track whether the region is user specified
263  bool m_FactorySpecifiedImageIO; // track whether the factory mechanism set the ImageIO
265  bool m_UseInputMetaDataDictionary; // whether to use the
266  // MetaDataDictionary from the
267  // input or not.
268 
269  bool m_WriteGeomFile; // Write a geom file to store the
270  // kwl
271 
272  FNameHelperType::Pointer m_FilenameHelper;
273 
275 
277  unsigned long m_ObserverID;
279 
282  std::vector<unsigned int> m_BandList;
283 
287  unsigned int m_IOComponents;
288 
290  itk::SimpleFastMutexLock m_Lock;
291 };
292 
293 } // end namespace otb
294 
295 #ifndef OTB_MANUAL_INSTANTIATION
296 #include "otbImageFileWriter.hxx"
297 #endif
298 
299 #include "otbImage.h"
300 #include "otbVectorImage.h"
301 #include <complex>
302 
303 namespace otb
304 {
305 
306 // Prevent implicit instantiation of common types to improve build performance
307 // Explicit instantiations are provided in the .cxx
308 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<unsigned int, 2>>;
309 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<int, 2>>;
310 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<unsigned char, 2>>;
311 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<char, 2>>;
312 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<unsigned short, 2>>;
313 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<short, 2>>;
314 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<float, 2>>;
315 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<double, 2>>;
316 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<std::complex<int>, 2>>;
317 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<std::complex<short>, 2>>;
318 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<std::complex<float>, 2>>;
319 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<std::complex<double>, 2>>;
320 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<unsigned int, 2>>;
321 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<int, 2>>;
322 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<unsigned char, 2>>;
323 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<char, 2>>;
324 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<unsigned short, 2>>;
325 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<short, 2>>;
326 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<float, 2>>;
327 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<double, 2>>;
328 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<std::complex<int>, 2>>;
329 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<std::complex<short>, 2>>;
330 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<std::complex<float>, 2>>;
331 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<std::complex<double>, 2>>;
332 }
333 
334 #endif
otb::ImageFileWriter::FNameHelperType
ExtendedFilenameToWriterOptions FNameHelperType
Definition: otbImageFileWriter.h:94
otb::ImageFileWriter::m_UserSpecifiedIORegion
bool m_UserSpecifiedIORegion
Definition: otbImageFileWriter.h:262
otb::ImageFileWriter::Superclass
itk::ProcessObject Superclass
Definition: otbImageFileWriter.h:71
otb::ImageFileWriter::m_DivisionProgress
float m_DivisionProgress
Definition: otbImageFileWriter.h:252
otb::ImageFileWriter::m_ShiftOutputIndex
InputIndexType m_ShiftOutputIndex
Definition: otbImageFileWriter.h:278
otb::ImageFileWriter::GetStreamingManager
StreamingManagerType * GetStreamingManager(void)
Definition: otbImageFileWriter.h:105
otbImageFileWriter.hxx
otb::ImageFileWriter::ObserveSourceFilterProgress
void ObserveSourceFilterProgress(itk::Object *object, const itk::EventObject &event)
Definition: otbImageFileWriter.h:229
otbVectorImage.h
otb::ImageFileWriter::m_FilenameHelper
FNameHelperType::Pointer m_FilenameHelper
Definition: otbImageFileWriter.h:272
otb::ImageFileWriter::m_FactorySpecifiedImageIO
bool m_FactorySpecifiedImageIO
Definition: otbImageFileWriter.h:263
otb::StreamingManager
This class handles the streaming process used in the writers implementation.
Definition: otbStreamingManager.h:53
otb::ImageFileWriter::m_IORegion
itk::ImageIORegion m_IORegion
Definition: otbImageFileWriter.h:261
otb::ImageFileWriter::m_FileName
std::string m_FileName
Definition: otbImageFileWriter.h:255
otbImage.h
otb::ImageFileWriter::m_UseCompression
bool m_UseCompression
Definition: otbImageFileWriter.h:264
otb::ImageFileWriter::m_UseInputMetaDataDictionary
bool m_UseInputMetaDataDictionary
Definition: otbImageFileWriter.h:265
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbExtendedFilenameToWriterOptions.h
otb::ImageFileWriter::m_IOComponents
unsigned int m_IOComponents
Definition: otbImageFileWriter.h:287
otb::ExtendedFilenameToWriterOptions
Converts an extended filename to writer options.
Definition: otbExtendedFilenameToWriterOptions.h:53
otb::ImageFileWriter::m_Lock
itk::SimpleFastMutexLock m_Lock
Definition: otbImageFileWriter.h:290
otb::ImageFileWriter::InputImagePixelType
InputImageType::PixelType InputImagePixelType
Definition: otbImageFileWriter.h:85
otb::ImageFileWriter::m_StreamingManager
StreamingManagerPointerType m_StreamingManager
Definition: otbImageFileWriter.h:274
otbImageIOBase.h
otb::ImageFileWriter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbImageFileWriter.h:73
otb::ImageFileWriter::Self
ImageFileWriter Self
Definition: otbImageFileWriter.h:70
otb::ImageFileWriter::UpdateFilterProgress
void UpdateFilterProgress()
Definition: otbImageFileWriter.h:245
otb::ImageFileWriter::m_CurrentDivision
unsigned int m_CurrentDivision
Definition: otbImageFileWriter.h:251
otb::ImageFileWriter::OutputImagePixelType
OutputImageType::PixelType OutputImagePixelType
Definition: otbImageFileWriter.h:90
otb::ImageFileWriter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageFileWriter.h:72
otb::ImageFileWriter::DataObjectPointer
Superclass::DataObjectPointer DataObjectPointer
Definition: otbImageFileWriter.h:91
otb::ImageFileWriter::InputIndexType
InputImageType::IndexType InputIndexType
Definition: otbImageFileWriter.h:86
otb::ImageFileWriter::m_BandList
std::vector< unsigned int > m_BandList
Definition: otbImageFileWriter.h:282
otbStreamingManager.h
otb::ImageFileWriter::m_ObserverID
unsigned long m_ObserverID
Definition: otbImageFileWriter.h:277
otb::StreamingManager::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingManager.h:59
otb::ImageFileWriter::SetStreamingManager
void SetStreamingManager(StreamingManagerType *streamingManager)
Definition: otbImageFileWriter.h:112
otb::ImageFileWriter::StreamingManagerPointerType
StreamingManagerType::Pointer StreamingManagerPointerType
Definition: otbImageFileWriter.h:101
otb::ImageFileWriter::m_ImageIO
otb::ImageIOBase::Pointer m_ImageIO
Definition: otbImageFileWriter.h:257
otb::ImageFileWriter::m_UserSpecifiedImageIO
bool m_UserSpecifiedImageIO
Definition: otbImageFileWriter.h:259
otb::ImageFileWriter::m_WriteGeomFile
bool m_WriteGeomFile
Definition: otbImageFileWriter.h:269
otb::ImageFileWriter
Writes image data to a single file with streaming process.
Definition: otbImageFileWriter.h:66
otb::ImageFileWriter::OutputImageType
TInputImage OutputImageType
Definition: otbImageFileWriter.h:87
otb::ImageIOBase
Abstract superclass defines image IO interface.
Definition: otbImageIOBase.h:69
otb::ImageFileWriter::StreamingManagerType
StreamingManager< InputImageType > StreamingManagerType
Definition: otbImageFileWriter.h:100
otb::ImageFileWriter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbImageFileWriter.h:89
otb::ImageFileWriter::InputImageType
TInputImage InputImageType
Definition: otbImageFileWriter.h:79
otb::ImageFileWriter::m_IsObserving
bool m_IsObserving
Definition: otbImageFileWriter.h:276
otb::ImageIOBase::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageIOBase.h:75
otb::ImageFileWriter::m_NumberOfDivisions
unsigned int m_NumberOfDivisions
Definition: otbImageFileWriter.h:250
otb::ImageFileWriter::InputImagePointer
InputImageType::Pointer InputImagePointer
Definition: otbImageFileWriter.h:83
otb::ImageFileWriter::OutputImagePointer
OutputImageType::Pointer OutputImagePointer
Definition: otbImageFileWriter.h:88
otb::ImageFileWriter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbImageFileWriter.h:84