OTB  7.2.0
Orfeo Toolbox
otbImageFileWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2020 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;
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 
105  StreamingManagerType* GetStreamingManager(void)
106  {
107  return m_StreamingManager;
108  }
109 
112  void SetStreamingManager(StreamingManagerType* streamingManager)
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 
273 
274  StreamingManagerPointerType m_StreamingManager;
275 
277  unsigned long m_ObserverID;
278  InputIndexType m_ShiftOutputIndex;
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 instanciations 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
OutputImageType::PixelType OutputImagePixelType
itk::SmartPointer< Self > Pointer
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
Superclass::DataObjectPointer DataObjectPointer
otb::ImageIOBase::Pointer m_ImageIO
StreamingManagerType::Pointer StreamingManagerPointerType
StreamingManager< InputImageType > StreamingManagerType
void SetStreamingManager(StreamingManagerType *streamingManager)
InputImageType::IndexType InputIndexType
ExtendedFilenameToWriterOptions FNameHelperType
InputImageType::RegionType InputImageRegionType
OutputImageType::RegionType OutputImageRegionType
itk::SmartPointer< Self > Pointer
InputIndexType m_ShiftOutputIndex
Abstract superclass defines image IO interface.
StreamingManagerType * GetStreamingManager(void)
OutputImageType::Pointer OutputImagePointer
Converts an extended filename to writer options.
itk::ImageIORegion m_IORegion
void ObserveSourceFilterProgress(itk::Object *object, const itk::EventObject &event)
itk::ProcessObject Superclass
unsigned int m_NumberOfDivisions
InputImageType::Pointer InputImagePointer
This class handles the streaming process used in the writers implementation.
itk::SmartPointer< Self > Pointer
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
FNameHelperType::Pointer m_FilenameHelper
unsigned int m_CurrentDivision
std::vector< unsigned int > m_BandList
StreamingManagerPointerType m_StreamingManager
Writes image data to a single file with streaming process.
itk::SimpleFastMutexLock m_Lock
itk::SmartPointer< const Self > ConstPointer
InputImageType::PixelType InputImagePixelType