OTB  6.7.0
Orfeo Toolbox
otbImageSeriesFileReader.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 template <class TImage, class TInternalImage>
32 {
33  m_ExtractorList = ExtractSelectionListType::New();
34 }
35 
36 template <class TImage, class TInternalImage>
37 void
40 {
41  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
42  {
43  this->m_ImageFileReaderList->PushBack(ReaderType::New());
44  this->m_OutputList->PushBack(OutputImageType::New());
45  m_ExtractorList->PushBack(ExtractSelectionListType::New());
46  }
47 }
48 
49 template <class TImage, class TInternalImage>
50 void
53 {
54  std::ostringstream msg;
55  msg << "Something wrong... Check the template definition of this class in the program...\n";
56  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
57  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
58  throw e;
59 }
60 
61 /* **********************************************************
62  * Methods that are specific to instantiation with Image type
63  * **********************************************************
64  */
65 
66 template <class TPixel, class TInternalPixel>
69 {
70  m_ExtractorList = ExtractSelectionListType::New();
71 }
72 
76 template <class TPixel, class TInternalPixel>
77 void
79 ::AllocateListOfComponents()
80 {
81  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
82  {
83  this->m_ImageFileReaderList->PushBack(ReaderType::New());
84  this->m_OutputList->PushBack(OutputImageType::New());
85  m_ExtractorList->PushBack(ExtractSelectionType::New());
86  }
87 }
89 
94 template <class TPixel, class TInternalPixel>
95 void
97 ::TestBandSelection(std::vector<unsigned int>& bands)
98 {
99  if (bands.size() != 1)
100  {
101  std::ostringstream msg;
102  msg << "Unable to handle multicomponent file from Image<> class\n";
103  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
104  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
105  throw e;
106  }
108 
109  if (bands[0] != 1)
110  {
111  std::ostringstream msg;
112  msg << "Unable to handle given band reading from multicomponent file with Image<> class\n";
113  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
114  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
115  throw e;
116  }
117  return;
118 }
119 
123 template <class TPixel, class TInternalPixel>
124 void
127 {
128  otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]);
129 
130  ReaderType * reader
131  = static_cast<ReaderType*>(this->m_ImageFileReaderList->GetNthElement(idx));
132 
133  reader->SetFileName(this->m_ListOfFileNames[idx]);
134 
135  ExtractSelectionType * selection
136  = static_cast<ExtractSelectionType*>(m_ExtractorList->GetNthElement(idx));
137 
138  selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]);
139 
140  selection->SetInput(reader->GetOutput());
141  selection->GraftOutput(this->m_OutputList->GetNthElement(idx));
142  selection->Update();
143 
144  this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput());
145 }
146 
147 /* *********************************************************************
148  * Methods that are specific to instantiation with Image type for TImage
149  * and VectorImage as TInternalImage
150  * *********************************************************************
151  */
152 
156 template <class TPixel, class TInternalPixel>
159 {
160  //this->m_OutputList = OutputImageListType::New();
161  //this->m_ImageFileReaderList = ReaderListType::New();
162  m_ExtractorList = ExtractSelectionListType::New();
163 }
165 
169 template <class TPixel, class TInternalPixel>
170 void
172 ::AllocateListOfComponents()
173 {
174  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
175  {
176  this->m_ImageFileReaderList->PushBack(ReaderType::New());
177  this->m_OutputList->PushBack(OutputImageType::New());
178  m_ExtractorList->PushBack(ExtractSelectionType::New());
179  }
180 }
182 
187 template <class TPixel, class TInternalPixel>
188 void
190 ::TestBandSelection(std::vector<unsigned int>& bands)
191 {
192  if (bands.size() != 1)
193  {
194  std::ostringstream msg;
195  msg << "Unable to handle multicomponent file from Image<> class as output\n";
196  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
197  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
198  throw e;
199  }
200  return;
201 }
203 
207 template <class TPixel, class TInternalPixel>
208 void
211 {
212  otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]);
213 
214  ReaderType * reader
215  = static_cast<ReaderType*>(this->m_ImageFileReaderList->GetNthElement(idx));
216 
217  reader->SetFileName(this->m_ListOfFileNames[idx]);
218 
219  ExtractSelectionType * selection
220  = static_cast<ExtractSelectionType*>(this->m_ExtractorList->GetNthElement(idx));
221 
222  selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]);
223  selection->SetChannel(this->m_ListOfBandSelection[idx][0]);
224 
225  selection->SetInput(reader->GetOutput());
226  selection->GraftOutput(this->m_OutputList->GetNthElement(idx));
227  selection->Update();
228 
229  this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput());
230 }
231 
232 /* ******************************************************************
233  * Methods that are specific to instantiation with VectorImage types
234  * ******************************************************************
235  */
236 
240 template <class TPixel, class TInternalPixel>
243 {
244  //this->m_OutputList = OutputImageListType::New();
245  //this->m_ImageFileReaderList = ReaderListType::New();
246  m_ExtractorList = ExtractSelectionListType::New();
247 }
249 
253 template <class TPixel, class TInternalPixel>
254 void
256 ::AllocateListOfComponents()
257 {
258  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
259  {
260  this->m_ImageFileReaderList->PushBack(ReaderType::New());
261  this->m_OutputList->PushBack(OutputImageType::New());
262  m_ExtractorList->PushBack(ExtractSelectionType::New());
263  }
264 }
266 
270 template <class TPixel, class TInternalPixel>
271 void
274 {
275  otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]);
276 
277  ReaderType * reader
278  = static_cast<ReaderType*>(this->m_ImageFileReaderList->GetNthElement(idx));
279 
280  reader->SetFileName(this->m_ListOfFileNames[idx]);
281 
282  ExtractSelectionType * selection
283  = static_cast<ExtractSelectionType*>(this->m_ExtractorList->GetNthElement(idx));
284 
285  selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]);
286 
287  for (std::vector<unsigned int>::iterator band = this->m_ListOfBandSelection[idx].begin();
288  band != this->m_ListOfBandSelection[idx].end();
289  ++band)
290  {
291  selection->SetChannel(*band);
292  }
293 
294  selection->SetInput(reader->GetOutput());
295  selection->GraftOutput(this->m_OutputList->GetNthElement(idx));
296  selection->Update();
297 
298  this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput());
299 }
300 
301 } // end of namespace otb
302 
303 #endif
virtual void Update()
Creation of an "otb" vector image which contains metadata.
virtual void SetChannel(unsigned int _arg)
Extract a subset of a mono-channel image.
Definition: otbExtractROI.h:43
void SetChannel(unsigned int channel)
Extract a spatial or spectral subset of a multi-channel image.
Extract a mono channel part of a multi-channel image.
void SetExtractionRegion(InputImageRegionType roi)
#define otbMsgDebugMacro(x)
Definition: otbMacro.h:64
virtual void GraftOutput(const DataObjectIdentifierType &key, DataObject *output)
virtual void SetInput(const InputImageType *image)
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Reader class dedicated to image series reading.
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:89
OutputImageType * GetOutput(unsigned int idx)