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 &)
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  filenames.push_back( m_ReaderList->GetNthElement(i)->GetFileName() );
168  }
169 
170  return filenames;
171  }
172 
173  itkExceptionMacro(<< "No filename value");
174 }
175 
176 
177 std::string
179 {
180  if (m_ReaderList)
181  {
182  if(m_ReaderList->Size()<i)
183  {
184  itkExceptionMacro(<< "No image "<<i<<". Only "<<m_ReaderList->Size()<<" images available.");
185  }
186 
187  return m_ReaderList->GetNthElement(i)->GetFileName();
188  }
189 
190  itkExceptionMacro(<< "No filename value");
191 }
192 
195 {
196  return m_ImageList;
197 }
198 
201 {
202  if(m_ImageList->Size()<i)
203  {
204  itkExceptionMacro(<< "No image "<<i<<". Only "<<m_ImageList->Size()<<" images available.");
205  }
206  return m_ImageList->GetNthElement(i);
207 }
208 
209 void
211 {
212  // Check input availability
213  // TODO : when the logger will be available, redirect the exception
214  // in the logger (like what is done in MsgReporter)
215  try
216  {
217  for(unsigned int i=0; i<imList->Size(); i++)
218  {
219  imList->GetNthElement( i )->UpdateOutputInformation();
220  }
221  }
222  catch(itk::ExceptionObject &)
223  {
224  return;
225  }
226 
227  m_ImageList = imList;
229  for(unsigned int i=0; i<m_ImageList->Size(); i++)
230  {
232  }
233 
234  SetActive(true);
235  this->Modified();
236 }
237 
238 void
240 {
241  // Check input availability
242  // TODO : when the logger will be available, redirect the exception
243  // in the logger (like what is done in MsgReporter)
244  try
245  {
246  image->UpdateOutputInformation();
247  }
248  catch(itk::ExceptionObject &)
249  {
250  return;
251  }
252 
253  m_ImageList->PushBack( image );
255 
256  this->Modified();
257 }
258 
259 bool
261 {
262  if(m_ImageList->Size() == 0)
263  {
264  return false;
265  }
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 Feb 3 2013 00:59:12 for Orfeo Toolbox with doxygen 1.8.1.1