OTB  6.7.0
Orfeo Toolbox
otbImageFileWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 otbImageFileWriter_h
22 #define otbImageFileWriter_h
23 
24 #include "otbImageIOBase.h"
25 #include "itkProcessObject.h"
26 #include "otbStreamingManager.h"
28 #include "itkFastMutexLock.h"
29 #include <string>
30 #include "OTBImageIOExport.h"
31 
32 namespace otb
33 {
34 
64 template <class TInputImage>
65 class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter : public itk::ProcessObject
66 {
67 public:
73 
75  itkNewMacro(Self);
76 
79 
81  typedef TInputImage InputImageType;
82  typedef typename InputImageType::Pointer InputImagePointer;
83  typedef typename InputImageType::RegionType InputImageRegionType;
84  typedef typename InputImageType::PixelType InputImagePixelType;
86  typedef TInputImage OutputImageType;
87  typedef typename OutputImageType::Pointer OutputImagePointer;
88  typedef typename OutputImageType::RegionType OutputImageRegionType;
89  typedef typename OutputImageType::PixelType OutputImagePixelType;
90  typedef typename Superclass::DataObjectPointer DataObjectPointer;
91 
94 
96  itkStaticConstMacro(InputImageDimension, unsigned int,
97  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 
208  const bool & GetAbortGenerateData() const override;
209 
210  void SetAbortGenerateData(const bool val) override;
211 
212 protected:
213  ImageFileWriter();
214  ~ImageFileWriter() override;
215  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
216 
218  void GenerateData(void) override;
219 
221  void GenerateOutputInformation(void) override;
222 
223 private:
224  ImageFileWriter(const ImageFileWriter &) = delete;
225  void operator =(const ImageFileWriter&) = delete;
226 
228  {
229  if (typeid(event) != typeid(itk::ProgressEvent))
230  {
231  return;
232  }
233 
234  itk::ProcessObject* processObject = dynamic_cast<itk::ProcessObject*>(object);
235  if (processObject)
236  {
237  m_DivisionProgress = processObject->GetProgress();
238  }
239 
240  this->UpdateFilterProgress();
241  }
242 
244  {
245  this->UpdateProgress( (m_DivisionProgress + m_CurrentDivision) / m_NumberOfDivisions );
246  }
247 
248  unsigned int m_NumberOfDivisions;
249  unsigned int m_CurrentDivision;
251 
253  std::string m_FileName;
254 
256 
257  bool m_UserSpecifiedImageIO; //track whether the ImageIO is user specified
258 
260  bool m_UserSpecifiedIORegion; // track whether the region is user specified
261  bool m_FactorySpecifiedImageIO; //track whether the factory mechanism set the ImageIO
263  bool m_UseInputMetaDataDictionary; // whether to use the
264  // MetaDataDictionary from the
265  // input or not.
266 
267  bool m_WriteGeomFile; // Write a geom file to store the
268  // kwl
269 
271 
273 
275  unsigned long m_ObserverID;
277 
280  std::vector<unsigned int> m_BandList;
281 
285  unsigned int m_IOComponents;
286 
289 };
290 
291 } // end namespace otb
292 
293 #ifndef OTB_MANUAL_INSTANTIATION
294 #include "otbImageFileWriter.hxx"
295 #endif
296 
297 #include "otbImage.h"
298 #include "otbVectorImage.h"
299 #include <complex>
300 
301 namespace otb {
302 
303 // Prevent implicit instanciation of common types to improve build performance
304 // Explicit instanciations are provided in the .cxx
305 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<unsigned int, 2>>;
306 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<int, 2>>;
307 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<unsigned char, 2>>;
308 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<char, 2>>;
309 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<unsigned short, 2>>;
310 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<short, 2>>;
311 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<float, 2>>;
312 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<double, 2>>;
313 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<std::complex<int>, 2>>;
314 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<std::complex<short>, 2>>;
315 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<std::complex<float>, 2>>;
316 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<Image<std::complex<double>, 2>>;
317 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<unsigned int, 2>>;
318 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<int, 2>>;
319 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<unsigned char, 2>>;
320 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<char, 2>>;
321 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<unsigned short, 2>>;
322 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<short, 2>>;
323 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<float, 2>>;
324 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<double, 2>>;
325 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<std::complex<int>, 2>>;
326 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<std::complex<short>, 2>>;
327 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<std::complex<float>, 2>>;
328 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter<VectorImage<std::complex<double>, 2>>;
329 
330 }
331 
332 #endif
OutputImageType::PixelType OutputImagePixelType
itk::SmartPointer< Self > Pointer
Superclass::DataObjectPointer DataObjectPointer
virtual const float & GetProgress() const
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
InputIndexType m_ShiftOutputIndex
Abstract superclass defines image IO interface.
StreamingManagerType * GetStreamingManager(void)
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
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.
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