Orfeo Toolbox  4.0
otbWrapperInputVectorDataListParameter.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 #include "otbWrapperMacros.h"
22 
23 namespace otb
24 {
25 namespace Wrapper
26 {
27 
29 {
30  this->SetName("Input VectorData List");
31  this->SetKey("vdList");
34 }
35 
37 {
38 }
39 
40 bool
41 InputVectorDataListParameter::SetListFromFileName(const std::vector<std::string> & filenames)
42 {
43  // First clear previous file choosen
44  this->ClearValue();
45 
46  bool isOk = true;
47  for(unsigned int i=0; i<filenames.size(); i++)
48  {
49  const std::string filename = filenames[i];
50  // TODO : when the logger will be available, redirect the exception
51  // in the logger (like what is done in MsgReporter)
52  if (!filename.empty())
53  {
55  reader->SetFileName(filename);
56  try
57  {
58  reader->UpdateOutputInformation();
59  }
60  catch(itk::ExceptionObject & /*err*/)
61  {
62  this->ClearValue();
63  isOk = false;
64  break;
65  }
66 
67  // everything went fine, store the object references
68  m_ReaderList->PushBack(reader);
69  m_VectorDataList->PushBack(reader->GetOutput());
70  }
71  }
72 
73  if( !isOk )
74  {
75  return false;
76  }
77 
78  SetActive(true);
79  this->Modified();
80  return true;
81 }
82 
83 
84 void
86 {
87  m_ReaderList->PushBack(NULL);
88  m_VectorDataList->PushBack(NULL);
89  SetActive(false);
90  this->Modified();
91 }
92 
93 bool
94 InputVectorDataListParameter::AddFromFileName(const std::string & filename)
95 {
96  // TODO : when the logger will be available, redirect the exception
97  // in the logger (like what is done in MsgReporter)
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_VectorDataList->PushBack(reader->GetOutput());
115  SetActive(true);
116  this->Modified();
117  return true;
118  }
119 
120  return false;
121 }
122 
123 bool
124 InputVectorDataListParameter::SetNthFileName( const unsigned int id, const std::string & filename )
125 {
126  if( m_ReaderList->Size()<id )
127  {
128  itkExceptionMacro(<< "No vectordata "<<id<<". Only "<<m_ReaderList->Size()<<" vector data 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  if (!filename.empty())
134  {
136  reader->SetFileName(filename);
137  try
138  {
139  reader->UpdateOutputInformation();
140  }
141  catch(itk::ExceptionObject &)
142  {
143  this->ClearValue();
144  return false;
145  }
146 
147  m_ReaderList->SetNthElement(id, reader);
148  m_VectorDataList->SetNthElement(id, reader->GetOutput());
149 
150  this->Modified();
151  return true;
152  }
153 
154  return false;
155 }
156 
157 
158 std::vector<std::string>
160 {
161  if (m_ReaderList)
162  {
163  std::vector<std::string> filenames;
164  for(unsigned int i=0; i<m_ReaderList->Size(); i++)
165  {
166  if( m_ReaderList->GetNthElement(i) )
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 vector data "<<i<<". Only "<<m_ReaderList->Size()<<" vector data available.");
185  }
186 
187  return m_ReaderList->GetNthElement(i)->GetFileName();
188  }
189 
190  itkExceptionMacro(<< "No filename value");
191 }
192 
195 {
196  return m_VectorDataList;
197 }
198 
201 {
202  if(m_VectorDataList->Size()<i)
203  {
204  itkExceptionMacro(<< "No vector data "<<i<<". Only "<<m_VectorDataList->Size()<<" vector data available.");
205  }
206  return m_VectorDataList->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<vdList->Size(); i++)
218  {
219  vdList->GetNthElement( i )->UpdateOutputInformation();
220  }
221  }
222  catch(itk::ExceptionObject &)
223  {
224  return;
225  }
226 
227  m_VectorDataList = vdList;
229  for(unsigned int i=0; i<m_VectorDataList->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  vectorData->UpdateOutputInformation();
247  }
248  catch(itk::ExceptionObject &)
249  {
250  return;
251  }
252 
253  m_VectorDataList->PushBack( vectorData );
255 
256  this->Modified();
257 }
258 
259 bool
261 {
262  if (m_VectorDataList->Size() == 0)
263  {
264  return false;
265  }
266 
267  bool res(true);
268  unsigned int i(0);
269  while (i < m_VectorDataList->Size() && res == true)
270  {
271  res = m_VectorDataList->GetNthElement(i).IsNotNull();
272  i++;
273  }
274 
275  return res;
276 }
277 
278 
279 void
281 {
282  if(m_VectorDataList->Size()<id)
283  {
284  itkExceptionMacro(<< "No vector data "<<id<<". Only "<<m_VectorDataList->Size()<<" vector data available.");
285  }
286 
287  m_VectorDataList->Erase( id );
288  m_ReaderList->Erase( id );
289 
290  this->Modified();
291 }
292 
293 void
295 {
296  m_VectorDataList->Clear();
297  m_ReaderList->Clear();
298 
299  SetActive(false);
300  this->Modified();
301 }
302 
303 
304 }
305 }
306 

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