Orfeo Toolbox  3.16
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  return true;
153  }
154 
155  return false;
156 }
157 
158 
159 std::vector<std::string>
161 {
162  if (m_ReaderList)
163  {
164  std::vector<std::string> filenames;
165  for(unsigned int i=0; i<m_ReaderList->Size(); i++)
166  {
167  if( m_ReaderList->GetNthElement(i) )
168  filenames.push_back( m_ReaderList->GetNthElement(i)->GetFileName() );
169  }
170 
171  return filenames;
172  }
173 
174  itkExceptionMacro(<< "No filename value");
175 }
176 
177 
178 std::string
180 {
181  if (m_ReaderList)
182  {
183  if(m_ReaderList->Size()<i)
184  {
185  itkExceptionMacro(<< "No image "<<i<<". Only "<<m_ReaderList->Size()<<" images available.");
186  }
187 
188  return m_ReaderList->GetNthElement(i)->GetFileName();
189  }
190 
191  itkExceptionMacro(<< "No filename value");
192 }
193 
196 {
197  return m_ImageList;
198 }
199 
202 {
203  if(m_ImageList->Size()<i)
204  {
205  itkExceptionMacro(<< "No image "<<i<<". Only "<<m_ImageList->Size()<<" images available.");
206  }
207  return m_ImageList->GetNthElement(i);
208 }
209 
210 void
212 {
213  // Check input availability
214  // TODO : when the logger will be available, redirect the exception
215  // in the logger (like what is done in MsgReporter)
216  try
217  {
218  for(unsigned int i=0; i<imList->Size(); i++)
219  {
220  imList->GetNthElement( i )->UpdateOutputInformation();
221  }
222  }
223  catch(itk::ExceptionObject &)
224  {
225  return;
226  }
227 
228  m_ImageList = imList;
230  for(unsigned int i=0; i<m_ImageList->Size(); i++)
231  {
233  }
234 
235  SetActive(true);
236  this->Modified();
237 }
238 
239 void
241 {
242  // Check input availability
243  // TODO : when the logger will be available, redirect the exception
244  // in the logger (like what is done in MsgReporter)
245  try
246  {
247  image->UpdateOutputInformation();
248  }
249  catch(itk::ExceptionObject &)
250  {
251  return;
252  }
253 
254  m_ImageList->PushBack( image );
256 
257  this->Modified();
258 }
259 
260 bool
262 {
263  if(m_ImageList->Size() == 0)
264  {
265  return false;
266  }
267 
268  bool res(true);
269  unsigned int i(0);
270  while(i < m_ImageList->Size() && res == true)
271  {
272  res = m_ImageList->GetNthElement(i).IsNotNull();
273  i++;
274  }
275 
276  return res;
277 }
278 
279 
280 void
282 {
283  if(m_ImageList->Size()<id)
284  {
285  itkExceptionMacro(<< "No image "<<id<<". Only "<<m_ImageList->Size()<<" images available.");
286  }
287 
288  m_ImageList->Erase( id );
289  m_ReaderList->Erase( id );
290 
291  this->Modified();
292 }
293 
294 void
296 {
297  m_ImageList->Clear();
298  m_ReaderList->Clear();
299 
300  SetActive(false);
301  this->Modified();
302 }
303 
304 
305 }
306 }
307 

Generated at Sun Jun 16 2013 01:02:28 for Orfeo Toolbox with doxygen 1.8.3.1