OTB  9.0.0
Orfeo Toolbox
otbImageFileReader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 otbImageFileReader_h
22 #define otbImageFileReader_h
23 
24 #if defined(__GNUC__) || defined(__clang__)
25 #pragma GCC diagnostic push
26 #pragma GCC diagnostic ignored "-Wunused-parameter"
27 #include "itkImageSource.h"
28 #pragma GCC diagnostic pop
29 #else
30 #include "itkImageSource.h"
31 #endif
32 #include "otbImageIOBase.h"
33 #include "itkExceptionObject.h"
34 #include "itkImageRegion.h"
35 #include "OTBImageIOExport.h"
36 
41 #include <string>
42 
43 namespace otb
44 {
45 
67 template <class TOutputImage, class ConvertPixelTraits = DefaultConvertPixelTraits<typename TOutputImage::IOPixelType>>
68 class OTBImageIO_EXPORT_TEMPLATE ImageFileReader : public itk::ImageSource<TOutputImage>
69 {
70 public:
73  typedef itk::ImageSource<TOutputImage> Superclass;
74  typedef itk::SmartPointer<Self> Pointer;
75 
77  itkNewMacro(Self);
78 
80  itkTypeMacro(ImageFileReader, ImageSource);
81 
83  typedef typename TOutputImage::SizeType SizeType;
84 
86  typedef typename TOutputImage::IndexType IndexType;
87 
89  typedef typename TOutputImage::RegionType ImageRegionType;
90 
92  typedef typename TOutputImage::InternalPixelType OutputImagePixelType;
93 
96 
98  void GenerateOutputInformation(void) override;
99 
101  void GenerateData() override;
102 
108  void EnlargeOutputRequestedRegion(itk::DataObject* output) override;
109 
116  void SetImageIO(otb::ImageIOBase* imageIO);
117  itkGetObjectMacro(ImageIO, otb::ImageIOBase);
119 
120  virtual void SetFileName(const std::string& extendedFileName);
121 
122  virtual const char* GetFileName() const;
123 
126  unsigned int GetOverviewsCount();
127 
128 
131  std::vector<std::string> GetOverviewsInfo();
132 
133  // Retrieve the real source file name if derived dataset */
134  static std::string GetDerivedDatasetSourceFileName(const std::string& filename);
135 
136 protected:
137  ImageFileReader();
138  ~ImageFileReader() override;
139  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
140 
142  void DoConvertBuffer(void* buffer, size_t numberOfPixels);
143 
144 private:
148  void TestValidImageIO();
149 
153  bool GetGdalReadImageFileName(const std::string& filename, std::string& GdalFileName);
154 
155  ImageFileReader(const Self&) = delete;
156  void operator=(const Self&) = delete;
157 
159  bool m_UserSpecifiedImageIO; // keep track whether the
160  // ImageIO is user specified
161 
162  std::string m_FileName; // The file to be read
163 
165 
166  // The region that the ImageIO class will return when we ask to
167  // produce the requested region.
168  itk::ImageIORegion m_ActualIORegion;
169 
171 
172  unsigned int m_AdditionalNumber;
173 
176  std::vector<unsigned int> m_BandList;
177 
181  unsigned int m_IOComponents;
182 };
183 
184 } // namespace otb
185 
186 #ifndef OTB_MANUAL_INSTANTIATION
187 #include "otbImageFileReader.hxx"
188 #endif
189 
190 #include "otbImage.h"
191 #include "otbVectorImage.h"
192 #include <complex>
193 
194 namespace otb
195 {
196 
197 // Prevent implicit instantiation of common types to improve build performance
198 // Explicit instantiations are provided in the .cxx
199 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<unsigned int, 2>>;
200 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<int, 2>>;
201 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<unsigned char, 2>>;
202 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<char, 2>>;
203 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<unsigned short, 2>>;
204 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<short, 2>>;
205 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<float, 2>>;
206 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<double, 2>>;
207 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<std::complex<int>, 2>>;
208 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<std::complex<short>, 2>>;
209 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<std::complex<float>, 2>>;
210 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<Image<std::complex<double>, 2>>;
211 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<unsigned int, 2>>;
212 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<int, 2>>;
213 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<unsigned char, 2>>;
214 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<char, 2>>;
215 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<unsigned short, 2>>;
216 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<short, 2>>;
217 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<float, 2>>;
218 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<double, 2>>;
219 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<std::complex<int>, 2>>;
220 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<std::complex<short>, 2>>;
221 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<std::complex<float>, 2>>;
222 extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader<VectorImage<std::complex<double>, 2>>;
223 }
224 
225 #endif // otbImageFileReader_h
otb::ImageFileReader::m_FilenameHelper
FNameHelperType::Pointer m_FilenameHelper
Definition: otbImageFileReader.h:170
otb::ImageFileReader::m_BandList
std::vector< unsigned int > m_BandList
Definition: otbImageFileReader.h:176
otb::ExtendedFilenameToReaderOptions
Converts an extended filename to reader options.
Definition: otbExtendedFilenameToReaderOptions.h:52
otbExtendedFilenameToReaderOptions.h
otb::ImageFileReader::Superclass
itk::ImageSource< TOutputImage > Superclass
Definition: otbImageFileReader.h:73
otb::ImageFileReader::m_IOComponents
unsigned int m_IOComponents
Definition: otbImageFileReader.h:181
otb::ImageFileReader::m_ActualIORegion
itk::ImageIORegion m_ActualIORegion
Definition: otbImageFileReader.h:168
otbVectorImage.h
otbImage.h
otb::ImageFileReader::m_UserSpecifiedImageIO
bool m_UserSpecifiedImageIO
Definition: otbImageFileReader.h:159
otb::ImageFileReader::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageFileReader.h:74
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ExtendedFilenameToReaderOptions::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbExtendedFilenameToReaderOptions.h:57
otb::ImageFileReader::m_FileName
std::string m_FileName
Definition: otbImageFileReader.h:162
otbDefaultConvertPixelTraits.h
otbImageIOBase.h
otb::ImageFileReader::OutputImagePixelType
TOutputImage::InternalPixelType OutputImagePixelType
Definition: otbImageFileReader.h:92
otbImageFileReader.hxx
otbMetadataSupplierInterface.h
otb::ImageFileReader::SizeType
TOutputImage::SizeType SizeType
Definition: otbImageFileReader.h:80
otb::ImageFileReader::m_ImageIO
otb::ImageIOBase::Pointer m_ImageIO
Definition: otbImageFileReader.h:158
otb::ImageFileReader::ImageRegionType
TOutputImage::RegionType ImageRegionType
Definition: otbImageFileReader.h:89
otb::ImageFileReader::IndexType
TOutputImage::IndexType IndexType
Definition: otbImageFileReader.h:86
otb::ImageFileReader::m_UseStreaming
bool m_UseStreaming
Definition: otbImageFileReader.h:164
otb::ImageIOBase
Abstract superclass defines image IO interface.
Definition: otbImageIOBase.h:69
otb::ImageIOBase::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageIOBase.h:75
otb::ImageFileReader::m_AdditionalNumber
unsigned int m_AdditionalNumber
Definition: otbImageFileReader.h:172
otb::ImageFileReader
Reads image data.
Definition: otbImageFileReader.h:68
otb::ImageFileReader::Self
ImageFileReader Self
Definition: otbImageFileReader.h:72
otbImageFileReaderException.h
otb::ImageFileReader::FNameHelperType
ExtendedFilenameToReaderOptions FNameHelperType
Definition: otbImageFileReader.h:95