OTB  9.0.0
Orfeo Toolbox
otbImageSeriesFileReader.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
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 
23 #ifndef otbImageSeriesFileReader_hxx
24 #define otbImageSeriesFileReader_hxx
26 
27 namespace otb
28 {
29 
30 template <class TImage, class TInternalImage>
32 {
33  m_ExtractorList = ExtractSelectionListType::New();
34 }
35 
36 template <class TImage, class TInternalImage>
38 {
39  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
40  {
41  this->m_ImageFileReaderList->PushBack(ReaderType::New());
42  this->m_OutputList->PushBack(OutputImageType::New());
43  m_ExtractorList->PushBack(ExtractSelectionListType::New());
44  }
45 }
46 
47 template <class TImage, class TInternalImage>
49 {
50  std::ostringstream msg;
51  msg << "Something wrong... Check the template definition of this class in the program...\n";
52  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
53  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
54  throw e;
55 }
56 
57 /* **********************************************************
58  * Methods that are specific to instantiation with Image type
59  * **********************************************************
60  */
61 
62 template <class TPixel, class TInternalPixel>
64 {
65  m_ExtractorList = ExtractSelectionListType::New();
66 }
67 
71 template <class TPixel, class TInternalPixel>
73 {
74  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
75  {
76  this->m_ImageFileReaderList->PushBack(ReaderType::New());
77  this->m_OutputList->PushBack(OutputImageType::New());
78  m_ExtractorList->PushBack(ExtractSelectionType::New());
79  }
80 }
82 
87 template <class TPixel, class TInternalPixel>
88 void ImageSeriesFileReader<Image<TPixel, 2>, Image<TInternalPixel, 2>>::TestBandSelection(std::vector<unsigned int>& bands)
89 {
90  if (bands.size() != 1)
91  {
92  std::ostringstream msg;
93  msg << "Unable to handle multicomponent file from Image<> class\n";
94  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
95  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
96  throw e;
97  }
99 
100  if (bands[0] != 1)
101  {
102  std::ostringstream msg;
103  msg << "Unable to handle given band reading from multicomponent file with Image<> class\n";
104  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
105  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
106  throw e;
107  }
108  return;
109 }
110 
114 template <class TPixel, class TInternalPixel>
116 {
117  otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]);
118 
119  ReaderType* reader = static_cast<ReaderType*>(this->m_ImageFileReaderList->GetNthElement(idx));
120 
121  reader->SetFileName(this->m_ListOfFileNames[idx]);
122 
123  ExtractSelectionType* selection = static_cast<ExtractSelectionType*>(m_ExtractorList->GetNthElement(idx));
124 
125  selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]);
126 
127  selection->SetInput(reader->GetOutput());
128  selection->GraftOutput(this->m_OutputList->GetNthElement(idx));
129  selection->Update();
130 
131  this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput());
132 }
133 
134 /* *********************************************************************
135  * Methods that are specific to instantiation with Image type for TImage
136  * and VectorImage as TInternalImage
137  * *********************************************************************
138  */
139 
143 template <class TPixel, class TInternalPixel>
145 {
146  // this->m_OutputList = OutputImageListType::New();
147  // this->m_ImageFileReaderList = ReaderListType::New();
148  m_ExtractorList = ExtractSelectionListType::New();
149 }
151 
155 template <class TPixel, class TInternalPixel>
157 {
158  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
159  {
160  this->m_ImageFileReaderList->PushBack(ReaderType::New());
161  this->m_OutputList->PushBack(OutputImageType::New());
162  m_ExtractorList->PushBack(ExtractSelectionType::New());
163  }
164 }
166 
171 template <class TPixel, class TInternalPixel>
172 void ImageSeriesFileReader<Image<TPixel, 2>, VectorImage<TInternalPixel, 2>>::TestBandSelection(std::vector<unsigned int>& bands)
173 {
174  if (bands.size() != 1)
175  {
176  std::ostringstream msg;
177  msg << "Unable to handle multicomponent file from Image<> class as output\n";
178  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
179  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
180  throw e;
181  }
182  return;
183 }
185 
189 template <class TPixel, class TInternalPixel>
191 {
192  otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]);
193 
194  ReaderType* reader = static_cast<ReaderType*>(this->m_ImageFileReaderList->GetNthElement(idx));
195 
196  reader->SetFileName(this->m_ListOfFileNames[idx]);
197 
198  ExtractSelectionType* selection = static_cast<ExtractSelectionType*>(this->m_ExtractorList->GetNthElement(idx));
199 
200  selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]);
201  selection->SetChannel(this->m_ListOfBandSelection[idx][0]);
202 
203  selection->SetInput(reader->GetOutput());
204  selection->GraftOutput(this->m_OutputList->GetNthElement(idx));
205  selection->Update();
206 
207  this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput());
208 }
209 
210 /* ******************************************************************
211  * Methods that are specific to instantiation with VectorImage types
212  * ******************************************************************
213  */
214 
218 template <class TPixel, class TInternalPixel>
220 {
221  // this->m_OutputList = OutputImageListType::New();
222  // this->m_ImageFileReaderList = ReaderListType::New();
223  m_ExtractorList = ExtractSelectionListType::New();
224 }
226 
230 template <class TPixel, class TInternalPixel>
232 {
233  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
234  {
235  this->m_ImageFileReaderList->PushBack(ReaderType::New());
236  this->m_OutputList->PushBack(OutputImageType::New());
237  m_ExtractorList->PushBack(ExtractSelectionType::New());
238  }
239 }
241 
245 template <class TPixel, class TInternalPixel>
247 {
248  otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]);
249 
250  ReaderType* reader = static_cast<ReaderType*>(this->m_ImageFileReaderList->GetNthElement(idx));
251 
252  reader->SetFileName(this->m_ListOfFileNames[idx]);
253 
254  ExtractSelectionType* selection = static_cast<ExtractSelectionType*>(this->m_ExtractorList->GetNthElement(idx));
255 
256  selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]);
257 
258  for (std::vector<unsigned int>::iterator band = this->m_ListOfBandSelection[idx].begin(); band != this->m_ListOfBandSelection[idx].end(); ++band)
259  {
260  selection->SetChannel(*band);
261  }
262 
263  selection->SetInput(reader->GetOutput());
264  selection->GraftOutput(this->m_OutputList->GetNthElement(idx));
265  selection->Update();
266 
267  this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput());
268 }
269 
270 } // end of namespace otb
271 
272 #endif
otb::MultiChannelExtractROI::SetChannel
void SetChannel(unsigned int channel)
Definition: otbMultiChannelExtractROI.hxx:48
otb::ImageSeriesFileReader::ImageSeriesFileReader
ImageSeriesFileReader()
Definition: otbImageSeriesFileReader.hxx:31
otb::bands
Definition: otbParserXPlugins.h:52
otb::ImageSeriesFileReader
Reader class dedicated to image series reading.
Definition: otbImageSeriesFileReader.h:52
otbImageSeriesFileReader.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Image
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:89
otb::ImageSeriesFileReaderBase< TImage, TImage >::GenerateData
void GenerateData(void) override
Definition: otbImageSeriesFileReaderBase.hxx:316
otb::ImageSeriesFileReader< VectorImage< TPixel, 2 >, VectorImage< TInternalPixel, 2 > >::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbImageSeriesFileReader.h:440
otb::MultiChannelExtractROI
Extract a spatial or spectral subset of a multi-channel image.
Definition: otbMultiChannelExtractROI.h:47
otb::ExtractROIBase::SetExtractionRegion
void SetExtractionRegion(InputImageRegionType roi)
Definition: otbExtractROIBase.hxx:105
otb::MultiToMonoChannelExtractROI
Extract a mono channel part of a multi-channel image.
Definition: otbMultiToMonoChannelExtractROI.h:46
otbMsgDebugMacro
#define otbMsgDebugMacro(x)
Definition: otbMacro.h:62
otb::ImageFileReader::SetFileName
virtual void SetFileName(const std::string &extendedFileName)
Definition: otbImageFileReader.hxx:609
otb::ImageSeriesFileReaderException
Definition: otbImageSeriesFileReaderBase.h:39
otb::ImageSeriesFileReader< Image< TPixel, 2 >, VectorImage< TInternalPixel, 2 > >::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbImageSeriesFileReader.h:329
otb::ImageSeriesFileReader::AllocateListOfComponents
virtual void AllocateListOfComponents(void)
Definition: otbImageSeriesFileReader.hxx:37
otb::ImageFileReader
Reads image data.
Definition: otbImageFileReader.h:68
otb::MultiToMonoChannelExtractROI::SetChannel
virtual void SetChannel(unsigned int _arg)
otb::ImageSeriesFileReader< Image< TPixel, 2 >, Image< TInternalPixel, 2 > >::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbImageSeriesFileReader.h:220
otb::ExtractROI
Extract a subset of a mono-channel image.
Definition: otbExtractROI.h:43
otb::VectorImage
Creation of an "otb" vector image which contains metadata.
Definition: otbVectorImage.h:45
otb::ImageSeriesFileReader::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbImageSeriesFileReader.h:109