Orfeo Toolbox  4.0
otbImageSeriesFileReader.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12  Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved.
13  See ITCopyright.txt for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 
21 #ifndef __otbImageSeriesFileReader_txx
22 #define __otbImageSeriesFileReader_txx
24 
25 namespace otb {
26 
27 template <class TImage, class TInternalImage>
30 {
31  m_ExtractorList = ExtractSelectionListType::New();
32 }
33 
34 template <class TImage, class TInternalImage>
35 void
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>
48 void
50 ::GenerateData(unsigned int idx)
51 {
52  std::ostringstream msg;
53  msg << "Something wrong... Check the template definition of this class in the program...\n";
54  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
55  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
56  throw e;
57 }
58 
59 /* **********************************************************
60  * Methods that are specific to instanciation with Image type
61  * **********************************************************
62  */
63 
64 template <class TPixel, class TInternalPixel>
67 {
68  m_ExtractorList = ExtractSelectionListType::New();
69 }
70 
74 template <class TPixel, class TInternalPixel>
75 void
77 ::AllocateListOfComponents()
78 {
79  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
80  {
81  this->m_ImageFileReaderList->PushBack(ReaderType::New());
82  this->m_OutputList->PushBack(OutputImageType::New());
83  m_ExtractorList->PushBack(ExtractSelectionType::New());
84  }
85 }
86 
91 template <class TPixel, class TInternalPixel>
92 void
94 ::TestBandSelection(std::vector<unsigned int>& bands)
95 {
96  if (bands.size() != 1)
97  {
98  std::ostringstream msg;
99  msg << "Unable to handle multicomponent file from Image<> class\n";
100  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
101  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
102  throw e;
103  }
104 
105  if (bands[0] != 1)
106  {
107  std::ostringstream msg;
108  msg << "Unable to handle given band reading from multicomponent file with Image<> class\n";
109  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
110  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
111  throw e;
112  }
113  return;
114 }
115 
119 template <class TPixel, class TInternalPixel>
120 void
122 ::GenerateData(unsigned int idx)
123 {
124  otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]);
125 
126  ReaderType * reader
127  = static_cast<ReaderType*>(this->m_ImageFileReaderList->GetNthElement(idx));
128 
129  reader->SetFileName(this->m_ListOfFileNames[idx]);
130 
131  ExtractSelectionType * selection
132  = static_cast<ExtractSelectionType*>(m_ExtractorList->GetNthElement(idx));
133 
134  selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]);
135 
136  selection->SetInput(reader->GetOutput());
137  selection->GraftOutput(this->m_OutputList->GetNthElement(idx));
138  selection->Update();
139 
140  this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput());
141 }
142 
143 /* *********************************************************************
144  * Methods that are specific to instanciation with Image type for TImage
145  * and VectorImage as TInternalImage
146  * *********************************************************************
147  */
148 
152 template <class TPixel, class TInternalPixel>
155 {
156  //this->m_OutputList = OutputImageListType::New();
157  //this->m_ImageFileReaderList = ReaderListType::New();
158  m_ExtractorList = ExtractSelectionListType::New();
159 }
160 
164 template <class TPixel, class TInternalPixel>
165 void
167 ::AllocateListOfComponents()
168 {
169  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
170  {
171  this->m_ImageFileReaderList->PushBack(ReaderType::New());
172  this->m_OutputList->PushBack(OutputImageType::New());
173  m_ExtractorList->PushBack(ExtractSelectionType::New());
174  }
175 }
176 
181 template <class TPixel, class TInternalPixel>
182 void
184 ::TestBandSelection(std::vector<unsigned int>& bands)
185 {
186  if (bands.size() != 1)
187  {
188  std::ostringstream msg;
189  msg << "Unable to handle multicomponent file from Image<> class as output\n";
190  msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
191  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
192  throw e;
193  }
194  return;
195 }
196 
200 template <class TPixel, class TInternalPixel>
201 void
203 ::GenerateData(unsigned int idx)
204 {
205  otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]);
206 
207  ReaderType * reader
208  = static_cast<ReaderType*>(this->m_ImageFileReaderList->GetNthElement(idx));
209 
210  reader->SetFileName(this->m_ListOfFileNames[idx]);
211 
212  ExtractSelectionType * selection
213  = static_cast<ExtractSelectionType*>(this->m_ExtractorList->GetNthElement(idx));
214 
215  selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]);
216  selection->SetChannel(this->m_ListOfBandSelection[idx][0]);
217 
218  selection->SetInput(reader->GetOutput());
219  selection->GraftOutput(this->m_OutputList->GetNthElement(idx));
220  selection->Update();
221 
222  this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput());
223 }
224 
225 /* ******************************************************************
226  * Methods that are specific to instanciation with VectorImage types
227  * ******************************************************************
228  */
229 
233 template <class TPixel, class TInternalPixel>
236 {
237  //this->m_OutputList = OutputImageListType::New();
238  //this->m_ImageFileReaderList = ReaderListType::New();
239  m_ExtractorList = ExtractSelectionListType::New();
240 }
241 
245 template <class TPixel, class TInternalPixel>
246 void
248 ::AllocateListOfComponents()
249 {
250  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
251  {
252  this->m_ImageFileReaderList->PushBack(ReaderType::New());
253  this->m_OutputList->PushBack(OutputImageType::New());
254  m_ExtractorList->PushBack(ExtractSelectionType::New());
255  }
256 }
257 
261 template <class TPixel, class TInternalPixel>
262 void
264 ::GenerateData(unsigned int idx)
265 {
266  otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]);
267 
268  ReaderType * reader
269  = static_cast<ReaderType*>(this->m_ImageFileReaderList->GetNthElement(idx));
270 
271  reader->SetFileName(this->m_ListOfFileNames[idx]);
272 
273  ExtractSelectionType * selection
274  = static_cast<ExtractSelectionType*>(this->m_ExtractorList->GetNthElement(idx));
275 
276  selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]);
277 
278  for (std::vector<unsigned int>::iterator band = this->m_ListOfBandSelection[idx].begin();
279  band != this->m_ListOfBandSelection[idx].end();
280  ++band)
281  {
282  selection->SetChannel(*band);
283  }
284 
285  selection->SetInput(reader->GetOutput());
286  selection->GraftOutput(this->m_OutputList->GetNthElement(idx));
287  selection->Update();
288 
289  this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput());
290 }
291 
292 } // end of namespace otb
293 
294 #endif

Generated at Sat Mar 8 2014 16:01:00 for Orfeo Toolbox with doxygen 1.8.3.1