Orfeo Toolbox  4.0
otbWrapperInputImageListParameter.cxx
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 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
19 #include "itksys/SystemTools.hxx"
20 
21 namespace otb
22 {
23 namespace Wrapper
24 {
25 
27 {
28  this->SetName("Input Image List");
29  this->SetKey("inList");
32 }
33 
35 {
36 }
37 
38 bool
39 InputImageListParameter::SetListFromFileName(const std::vector<std::string> & filenames)
40 {
41  // First clear previous file choosen
42  this->ClearValue();
43 
44  bool isOk = true;
45  for(unsigned int i=0; i<filenames.size(); i++)
46  {
47  const std::string filename = filenames[i];
48  // TODO : when the logger will be available, redirect the exception
49  // in the logger (like what is done in MsgReporter)
50  // File existance checked by the reader
51  if (!filename.empty())
52  {
54  reader->SetFileName(filename);
55  try
56  {
57  reader->UpdateOutputInformation();
58  }
59  catch(itk::ExceptionObject & /*err*/)
60  {
61  this->ClearValue();
62  isOk = false;
63  break;
64  }
65 
66  // everything went fine, store the object references
67  m_ReaderList->PushBack(reader);
68  m_ImageList->PushBack(reader->GetOutput());
69  }
70  }
71 
72  if( !isOk )
73  {
74  return false;
75  }
76 
77  SetActive(true);
78  this->Modified();
79  return true;
80 }
81 
82 
83 void
85 {
86  m_ReaderList->PushBack(NULL);
87  m_ImageList->PushBack(NULL);
88  SetActive(false);
89  this->Modified();
90 }
91 
92 bool
93 InputImageListParameter::AddFromFileName(const std::string & filename)
94 {
95  // TODO : when the logger will be available, redirect the exception
96  // in the logger (like what is done in MsgReporter)
97  // File existance checked by the reader
98  if (!filename.empty())
99  {
101  reader->SetFileName(filename);
102  try
103  {
104  reader->UpdateOutputInformation();
105  }
106  catch(itk::ExceptionObject & /*err*/)
107  {
108  this->ClearValue();
109  return false;
110  }
111 
112  // everything went fine, store the object references
113  m_ReaderList->PushBack(reader);
114  m_ImageList->PushBack(reader->GetOutput());
115  SetActive(true);
116  this->Modified();
117  return true;
118  }
119 
120  return false;
121 }
122 
123 bool
124 InputImageListParameter::SetNthFileName( const unsigned int id, const std::string & filename )
125 {
126  if( m_ReaderList->Size()<id )
127  {
128  itkExceptionMacro(<< "No image "<<id<<". Only "<<m_ReaderList->Size()<<" images available.");
129  }
130 
131  // TODO : when the logger will be available, redirect the exception
132  // in the logger (like what is done in MsgReporter)
133  // File existance checked by the reader
134  if (!filename.empty())
135  {
137  reader->SetFileName(filename);
138  try
139  {
140  reader->UpdateOutputInformation();
141  }
142  catch(itk::ExceptionObject &)
143  {
144  this->ClearValue();
145  return false;
146  }
147 
148  m_ReaderList->SetNthElement(id, reader);
149  m_ImageList->SetNthElement(id, reader->GetOutput());
150 
151  this->Modified();
152  SetActive(true);
153  return true;
154  }
155 
156  return false;
157 }
158 
159 
160 std::vector<std::string>
162 {
163  if (m_ReaderList)
164  {
165  std::vector<std::string> filenames;
166  for(unsigned int i=0; i<m_ReaderList->Size(); i++)
167  {
168  if( m_ReaderList->GetNthElement(i) )
169  filenames.push_back( m_ReaderList->GetNthElement(i)->GetFileName() );
170  }
171 
172  return filenames;
173  }
174 
175  itkExceptionMacro(<< "No filename value");
176 }
177 
178 
179 std::string
181 {
182  if (m_ReaderList)
183  {
184  if(m_ReaderList->Size()<i)
185  {
186  itkExceptionMacro(<< "No image "<<i<<". Only "<<m_ReaderList->Size()<<" images available.");
187  }
188 
189  return m_ReaderList->GetNthElement(i)->GetFileName();
190  }
191 
192  itkExceptionMacro(<< "No filename value");
193 }
194 
197 {
198  return m_ImageList;
199 }
200 
203 {
204  if(m_ImageList->Size()<i)
205  {
206  itkExceptionMacro(<< "No image "<<i<<". Only "<<m_ImageList->Size()<<" images available.");
207  }
208  return m_ImageList->GetNthElement(i);
209 }
210 
211 void
213 {
214  // Check input availability
215  // TODO : when the logger will be available, redirect the exception
216  // in the logger (like what is done in MsgReporter)
217  try
218  {
219  for(unsigned int i=0; i<imList->Size(); i++)
220  {
221  imList->GetNthElement( i )->UpdateOutputInformation();
222  }
223  }
224  catch(itk::ExceptionObject &)
225  {
226  return;
227  }
228 
229  m_ImageList = imList;
231  for(unsigned int i=0; i<m_ImageList->Size(); i++)
232  {
234  }
235 
236  SetActive(true);
237  this->Modified();
238 }
239 
240 void
242 {
243  // Check input availability
244  // TODO : when the logger will be available, redirect the exception
245  // in the logger (like what is done in MsgReporter)
246  try
247  {
248  image->UpdateOutputInformation();
249  }
250  catch(itk::ExceptionObject &)
251  {
252  return;
253  }
254 
255  m_ImageList->PushBack( image );
257 
258  this->Modified();
259 }
260 
261 bool
263 {
264  if(m_ImageList->Size() == 0)
265  {
266  return false;
267  }
268 
269  bool res(true);
270  unsigned int i(0);
271  while(i < m_ImageList->Size() && res == true)
272  {
273  res = m_ImageList->GetNthElement(i).IsNotNull();
274  i++;
275  }
276 
277  return res;
278 }
279 
280 
281 void
283 {
284  if(m_ImageList->Size()<id)
285  {
286  itkExceptionMacro(<< "No image "<<id<<". Only "<<m_ImageList->Size()<<" images available.");
287  }
288 
289  m_ImageList->Erase( id );
290  m_ReaderList->Erase( id );
291 
292  this->Modified();
293 }
294 
295 void
297 {
298  m_ImageList->Clear();
299  m_ReaderList->Clear();
300 
301  SetActive(false);
302  this->Modified();
303 }
304 
305 
306 }
307 }
308 

Generated at Sat Mar 8 2014 16:28:49 for Orfeo Toolbox with doxygen 1.8.3.1