OTB  9.0.0
Orfeo Toolbox
otbImageIOBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2023 Centre National d'Etudes Spatiales (CNES)
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 otbImageIOBase_h
23 #define otbImageIOBase_h
24 
25 #include "otbImageMetadata.h"
26 #include "itkLightProcessObject.h"
27 #include "itkIndent.h"
28 #include "itkImageIORegion.h"
29 #include "vnl/vnl_vector.h"
30 
31 #include <string>
32 #include <typeinfo>
33 #include <vector>
34 
35 #include "OTBImageBaseExport.h"
36 
37 namespace otb
38 {
39 
69 class OTBImageBase_EXPORT ImageIOBase : public itk::LightProcessObject
70 {
71 public:
73  typedef ImageIOBase Self;
74  typedef itk::LightProcessObject Superclass;
75  typedef itk::SmartPointer<Self> Pointer;
76 
78  itkTypeMacro(ImageIOBase, Superclass);
79 
81  itkSetStringMacro(FileName);
82  itkGetStringMacro(FileName);
84 
86  typedef long IndexValueType;
87  typedef unsigned long SizeValueType;
88 
96  {
97  };
98 
102  typedef enum {
115  MATRIX
116  } IOPixelType;
117 
122  typedef enum { UNKNOWNCOMPONENTTYPE, UCHAR, CHAR, USHORT, SHORT, UINT, INT, ULONG, LONG, FLOAT, DOUBLE, CSHORT, CINT, CFLOAT, CDOUBLE } IOComponentType;
123 
127  void SetNumberOfDimensions(unsigned int);
128  itkGetConstMacro(NumberOfDimensions, unsigned int);
130 
134  virtual void SetDimensions(unsigned int i, unsigned int dim);
135  virtual unsigned int GetDimensions(unsigned int i) const
136  {
137  return m_Dimensions[i];
138  }
140 
143  virtual void SetOrigin(unsigned int i, double origin);
144  virtual double GetOrigin(unsigned int i) const
145  {
146  return m_Origin[i];
147  }
149 
152  virtual void SetSpacing(unsigned int i, double spacing);
153  virtual double GetSpacing(unsigned int i) const
154  {
155  return m_Spacing[i];
156  }
158 
161  virtual void SetDirection(unsigned int i, std::vector<double>& direction);
162  virtual void SetDirection(unsigned int i, vnl_vector<double>& direction);
163  virtual std::vector<double> GetDirection(unsigned int i) const
164  {
165  return m_Direction[i];
166  }
168 
171  virtual std::vector<double> GetDefaultDirection(unsigned int i) const;
172 
179  itkSetMacro(IORegion, itk::ImageIORegion);
180  itkGetConstReferenceMacro(IORegion, itk::ImageIORegion);
182 
188  itkSetEnumMacro(PixelType, IOPixelType);
189  itkGetEnumMacro(PixelType, IOPixelType);
191 
198  virtual bool SetPixelTypeInfo(const std::type_info& ptype);
199 
202  itkSetEnumMacro(ComponentType, IOComponentType);
203  itkGetEnumMacro(ComponentType, IOComponentType);
204  virtual const std::type_info& GetComponentTypeInfo() const;
206 
211  itkSetMacro(NumberOfComponents, unsigned int);
212  itkGetConstReferenceMacro(NumberOfComponents, unsigned int);
214 
216  itkSetMacro(UseCompression, bool);
217  itkGetConstMacro(UseCompression, bool);
218  itkBooleanMacro(UseCompression);
220 
222  itkSetMacro(UseStreamedReading, bool);
223  itkGetConstMacro(UseStreamedReading, bool);
224  itkBooleanMacro(UseStreamedReading);
226 
228  itkSetMacro(UseStreamedWriting, bool);
229  itkGetConstMacro(UseStreamedWriting, bool);
230  itkBooleanMacro(UseStreamedWriting);
232 
233 
236  static std::string GetComponentTypeAsString(IOComponentType);
237 
240  static std::string GetPixelTypeAsString(IOPixelType);
241 
244  typedef enum { ASCII, Binary, TypeNotApplicable } FileType;
245 
248  typedef enum { BigEndian, LittleEndian, OrderNotApplicable } ByteOrder;
249 
252  itkSetEnumMacro(FileType, FileType);
253  itkGetEnumMacro(FileType, FileType);
255  {
256  this->SetFileType(ASCII);
257  }
259  {
260  this->SetFileType(Binary);
261  }
263 
275  itkSetEnumMacro(ByteOrder, ByteOrder);
276  itkGetEnumMacro(ByteOrder, ByteOrder);
278  {
279  this->SetByteOrder(BigEndian);
280  }
282  {
283  this->SetByteOrder(LittleEndian);
284  }
286 
289  static std::string GetFileTypeAsString(FileType);
290 
293  static std::string GetByteOrderAsString(ByteOrder);
294 
296  typedef std::streamoff SizeType;
297 
299  typedef size_t BufferSizeType;
300 
307  virtual SizeType GetPixelStride() const;
308 
310  SizeType GetImageSizeInPixels() const;
311 
313  SizeType GetImageSizeInBytes() const;
314 
317  SizeType GetImageSizeInComponents() const;
318 
319 
324  virtual unsigned int GetComponentSize() const;
325 
328  virtual unsigned int GetOverviewsCount() = 0;
329 
332  virtual std::vector<std::string> GetOverviewsInfo() = 0;
333 
336  virtual void SetOutputImagePixelType(bool isComplexInternalPixelType, bool isVectorImage) = 0;
337 
338  /*-------- This part of the interfaces deals with reading data ----- */
339 
342  virtual bool CanReadFile(const char*) = 0;
343 
346  virtual bool CanStreamRead()
347  {
348  return false;
349  }
350 
353  virtual void ReadImageInformation() = 0;
354 
356  virtual void Read(void* buffer) = 0;
357 
358 
359  /*-------- This part of the interfaces deals with writing data ----- */
360 
363  virtual bool CanWriteFile(const char*) = 0;
364 
370  virtual bool CanStreamWrite()
371  {
372  return false;
373  }
374 
377  virtual void WriteImageInformation() = 0;
378 
382  virtual void Write(const void* buffer) = 0;
383 
384  /* --- Support reading and writing data as a series of files. --- */
385 
391  virtual bool SupportsDimension(unsigned long dim)
392  {
393  return (dim == 2);
394  }
395 
407  virtual itk::ImageIORegion GenerateStreamableReadRegionFromRequestedRegion(const itk::ImageIORegion& requested) const;
408 
409 
424  virtual unsigned int GetActualNumberOfSplitsForWriting(unsigned int numberOfRequestedSplits, const itk::ImageIORegion& pasteRegion,
425  const itk::ImageIORegion& largestPossibleRegion);
426 
433  virtual itk::ImageIORegion GetSplitRegionForWriting(unsigned int ithPiece, unsigned int numberOfActualSplits, const itk::ImageIORegion& pasteRegion,
434  const itk::ImageIORegion& largestPossibleRegion);
435 
437  typedef std::vector<std::string> ArrayOfExtensionsType;
438 
443  const ArrayOfExtensionsType& GetSupportedReadExtensions() const;
444 
449  const ArrayOfExtensionsType& GetSupportedWriteExtensions() const;
450 
456  void DoMapBuffer(void* buffer, size_t numberOfPixels, std::vector<unsigned int>& bandList);
457 
459  itkGetConstReferenceMacro(AttachedFileNames, std::vector<std::string>);
460 
461  const ImageMetadata & GetImageMetadata() const;
462 
463  void SetImageMetadata(ImageMetadata);
464 
465 protected:
466  ImageIOBase();
467  ~ImageIOBase() override;
468  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
469 
472 
476 
480 
483 
485  std::string m_FileName;
486 
489  unsigned int m_NumberOfComponents;
490 
492  unsigned int m_NumberOfDimensions;
493 
496 
499 
502 
505  itk::ImageIORegion m_IORegion;
506 
508  std::vector<SizeValueType> m_Dimensions;
509 
512  std::vector<double> m_Spacing;
513 
515  std::vector<double> m_Origin;
516 
518  std::vector<std::vector<double>> m_Direction;
519 
522  std::vector<SizeType> m_Strides;
523 
525  virtual void Reset(const bool freeDynamic = true);
526 
528  void Resize(const unsigned int numDimensions, const unsigned int* dimensions);
529 
532  virtual unsigned int GetPixelSize() const;
533 
540  void ComputeStrides();
541 
544  SizeType GetComponentStride() const;
545 
548  SizeType GetRowStride() const;
549 
552  SizeType GetSliceStride() const;
553 
555  void WriteBufferAsASCII(std::ostream& os, const void* buffer, IOComponentType ctype, SizeType numberOfBytesToWrite);
556 
558  void ReadBufferAsASCII(std::istream& os, void* buffer, IOComponentType ctype, SizeType numberOfBytesToBeRead);
559 
561  bool ReadBufferAsBinary(std::istream& os, void* buffer, SizeType numberOfBytesToBeRead);
562 
563 
565  void AddSupportedReadExtension(const char* extension);
566 
568  void AddSupportedWriteExtension(const char* extension);
569 
572  virtual unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(unsigned int numberOfRequestedSplits, const itk::ImageIORegion& pasteRegion) const;
573 
576  virtual itk::ImageIORegion GetSplitRegionForWritingCanStreamWrite(unsigned int ithPiece, unsigned int numberOfActualSplits,
577  const itk::ImageIORegion& pasteRegion) const;
578 
580  std::vector<std::string> m_AttachedFileNames;
581 
584 
588  std::vector<unsigned int> m_BandList;
589 
590 private:
591  ImageIOBase(const Self&) = delete;
592  void operator=(const Self&) = delete;
593 
596 };
597 
598 } // end namespace itk
599 
600 #endif // otbImageIOBase_h
otb::ImageIOBase::RGBA
@ RGBA
Definition: otbImageIOBase.h:106
otb::ImageIOBase::ByteOrder
ByteOrder
Definition: otbImageIOBase.h:248
otb::ImageIOBase::CanStreamRead
virtual bool CanStreamRead()
Definition: otbImageIOBase.h:346
otb::ImageIOBase::SCALAR
@ SCALAR
Definition: otbImageIOBase.h:104
otb::ImageIOBase::GetOrigin
virtual double GetOrigin(unsigned int i) const
Definition: otbImageIOBase.h:144
otb::ImageIOBase::SetByteOrderToLittleEndian
void SetByteOrderToLittleEndian()
Definition: otbImageIOBase.h:281
otb::ImageIOBase::GetDirection
virtual std::vector< double > GetDirection(unsigned int i) const
Definition: otbImageIOBase.h:163
otb::ImageIOBase::USHORT
@ USHORT
Definition: otbImageIOBase.h:122
otb::ImageIOBase::DIFFUSIONTENSOR3D
@ DIFFUSIONTENSOR3D
Definition: otbImageIOBase.h:112
otb::ImageIOBase::m_SupportedReadExtensions
ArrayOfExtensionsType m_SupportedReadExtensions
Definition: otbImageIOBase.h:594
otb::ImageIOBase::SetFileTypeToBinary
void SetFileTypeToBinary()
Definition: otbImageIOBase.h:258
otb::ImageIOBase::SizeValueType
unsigned long SizeValueType
Definition: otbImageIOBase.h:87
otb::ImageIOBase::OFFSET
@ OFFSET
Definition: otbImageIOBase.h:107
otb::ImageIOBase::IndexValueType
long IndexValueType
Definition: otbImageIOBase.h:82
otb::ImageIOBase::GetSpacing
virtual double GetSpacing(unsigned int i) const
Definition: otbImageIOBase.h:153
otb::Wrapper::XML::Write
OTBApplicationEngine_EXPORT void Write(const std::string &filename, Application::Pointer application)
otb::ImageIOBase::UNKNOWNPIXELTYPE
@ UNKNOWNPIXELTYPE
Definition: otbImageIOBase.h:103
otb::ImageIOBase::m_UseStreamedReading
bool m_UseStreamedReading
Definition: otbImageIOBase.h:498
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ImageIOBase::BufferSizeType
vcl_size_t BufferSizeType
Definition: otbImageIOBase.h:299
otb::ImageIOBase::Superclass
itk::LightProcessObject Superclass
Definition: otbImageIOBase.h:74
otb::ImageIOBase::SetFileTypeToASCII
void SetFileTypeToASCII()
Definition: otbImageIOBase.h:254
otb::ImageIOBase::UnknownType
Definition: otbImageIOBase.h:95
otb::ImageIOBase::m_ByteOrder
ByteOrder m_ByteOrder
Definition: otbImageIOBase.h:478
otb::ImageIOBase::m_FileType
FileType m_FileType
Definition: otbImageIOBase.h:479
otb::ImageIOBase::SYMMETRICSECONDRANKTENSOR
@ SYMMETRICSECONDRANKTENSOR
Definition: otbImageIOBase.h:111
otb::ImageIOBase::FileType
FileType
Definition: otbImageIOBase.h:244
otb::ImageIOBase::SizeType
std::streamoff SizeType
Definition: otbImageIOBase.h:296
otb::ImageIOBase::GetDimensions
virtual unsigned int GetDimensions(unsigned int i) const
Definition: otbImageIOBase.h:135
otb::ImageIOBase::m_Strides
std::vector< SizeType > m_Strides
Definition: otbImageIOBase.h:522
otb::ImageIOBase::m_Direction
std::vector< std::vector< double > > m_Direction
Definition: otbImageIOBase.h:518
otb::ImageIOBase::ArrayOfExtensionsType
std::vector< std::string > ArrayOfExtensionsType
Definition: otbImageIOBase.h:437
otb::ImageIOBase::Self
ImageIOBase Self
Definition: otbImageIOBase.h:73
otb::ImageIOBase::m_BandList
std::vector< unsigned int > m_BandList
Definition: otbImageIOBase.h:588
otb::ImageIOBase::VECTOR
@ VECTOR
Definition: otbImageIOBase.h:108
otb::ImageIOBase::m_UseStreamedWriting
bool m_UseStreamedWriting
Definition: otbImageIOBase.h:501
otb::ImageIOBase::m_Initialized
bool m_Initialized
Definition: otbImageIOBase.h:482
otb::ImageIOBase::m_PixelType
IOPixelType m_PixelType
Definition: otbImageIOBase.h:471
otb::ImageIOBase::POINT
@ POINT
Definition: otbImageIOBase.h:109
otb::ImageIOBase::m_Spacing
std::vector< double > m_Spacing
Definition: otbImageIOBase.h:512
otb::ImageIOBase::SetByteOrderToBigEndian
void SetByteOrderToBigEndian()
Definition: otbImageIOBase.h:277
otb::ImageIOBase::COVARIANTVECTOR
@ COVARIANTVECTOR
Definition: otbImageIOBase.h:110
otb::ImageIOBase::m_UseCompression
bool m_UseCompression
Definition: otbImageIOBase.h:495
otb::Wrapper::XML::Read
OTBApplicationEngine_EXPORT int Read(const std::string &filename, Application::Pointer application)
otb::ImageIOBase::m_AttachedFileNames
std::vector< std::string > m_AttachedFileNames
Definition: otbImageIOBase.h:580
otb::ImageIOBase::m_NumberOfComponents
unsigned int m_NumberOfComponents
Definition: otbImageIOBase.h:489
otb::ImageIOBase::m_IORegion
itk::ImageIORegion m_IORegion
Definition: otbImageIOBase.h:505
otb::ImageIOBase::m_Dimensions
std::vector< SizeValueType > m_Dimensions
Definition: otbImageIOBase.h:508
otb::ImageIOBase::m_ComponentType
IOComponentType m_ComponentType
Definition: otbImageIOBase.h:475
otb::ImageIOBase
Abstract superclass defines image IO interface.
Definition: otbImageIOBase.h:69
otb::ImageIOBase::SupportsDimension
virtual bool SupportsDimension(unsigned long dim)
Definition: otbImageIOBase.h:391
otb::ImageIOBase::m_FileName
std::string m_FileName
Definition: otbImageIOBase.h:485
otb::ImageIOBase::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageIOBase.h:75
otb::ImageIOBase::CanStreamWrite
virtual bool CanStreamWrite()
Definition: otbImageIOBase.h:370
otb::ImageMetadata
Generic class containing image metadata used in OTB.
Definition: otbImageMetadata.h:270
otb::ImageIOBase::m_Origin
std::vector< double > m_Origin
Definition: otbImageIOBase.h:515
otb::ImageIOBase::IOPixelType
IOPixelType
Definition: otbImageIOBase.h:102
otb::ImageIOBase::RGB
@ RGB
Definition: otbImageIOBase.h:105
otbImageMetadata.h
otb::ImageIOBase::IOComponentType
IOComponentType
Definition: otbImageIOBase.h:122
otb::ImageIOBase::COMPLEX
@ COMPLEX
Definition: otbImageIOBase.h:113
otb::ImageIOBase::m_SupportedWriteExtensions
ArrayOfExtensionsType m_SupportedWriteExtensions
Definition: otbImageIOBase.h:595
otb::ImageIOBase::m_Imd
ImageMetadata m_Imd
Definition: otbImageIOBase.h:583
otb::ImageIOBase::FIXEDARRAY
@ FIXEDARRAY
Definition: otbImageIOBase.h:114
otb::ImageIOBase::m_NumberOfDimensions
unsigned int m_NumberOfDimensions
Definition: otbImageIOBase.h:492