Orfeo Toolbox  3.16
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  && itksys::SystemTools::FileExists(filename.c_str()))
54  {
56  reader->SetFileName(filename);
57  try
58  {
59  reader->UpdateOutputInformation();
60  }
61  catch(itk::ExceptionObject &)
62  {
63  this->ClearValue();
64  isOk = false;
65  break;
66  }
67 
68  // everything went fine, store the object references
69  m_ReaderList->PushBack(reader);
70  m_VectorDataList->PushBack(reader->GetOutput());
71  }
72  }
73 
74  if( !isOk )
75  {
76  return false;
77  }
78 
79  SetActive(true);
80  this->Modified();
81  return true;
82 }
83 
84 
85 void
87 {
88  m_ReaderList->PushBack(NULL);
89  m_VectorDataList->PushBack(NULL);
90  SetActive(false);
91  this->Modified();
92 }
93 
94 bool
95 InputVectorDataListParameter::AddFromFileName(const std::string & filename)
96 {
97  // TODO : when the logger will be available, redirect the exception
98  // in the logger (like what is done in MsgReporter)
99  if (!filename.empty()
100  && itksys::SystemTools::FileExists(filename.c_str()))
101  {
103  reader->SetFileName(filename);
104 
105  try
106  {
107  reader->UpdateOutputInformation();
108  }
109  catch(itk::ExceptionObject & /*err*/)
110  {
111  return false;
112  }
113 
114  // everything went fine, store the object references
115  m_ReaderList->PushBack(reader);
116  m_VectorDataList->PushBack(reader->GetOutput());
117  SetActive(true);
118  this->Modified();
119  return true;
120  }
121 
122  return false;
123 }
124 
125 bool
126 InputVectorDataListParameter::SetNthFileName( const unsigned int id, const std::string & filename )
127 {
128  if( m_ReaderList->Size()<id )
129  {
130  itkExceptionMacro(<< "No vectordata "<<id<<". Only "<<m_ReaderList->Size()<<" vector data available.");
131  }
132 
133  // TODO : when the logger will be available, redirect the exception
134  // in the logger (like what is done in MsgReporter)
135  if (!filename.empty()
136  && itksys::SystemTools::FileExists(filename.c_str()))
137  {
139  reader->SetFileName(filename);
140 
141  try
142  {
143  reader->UpdateOutputInformation();
144  }
145  catch(itk::ExceptionObject &)
146  {
147  this->ClearValue();
148  return false;
149  }
150 
151  m_ReaderList->SetNthElement(id, reader);
152  m_VectorDataList->SetNthElement(id, reader->GetOutput());
153 
154  this->Modified();
155  return true;
156  }
157  return false;
158 }
159 
160 
161 std::vector<std::string>
163 {
164  if (m_ReaderList)
165  {
166  std::vector<std::string> filenames;
167  for(unsigned int i=0; i<m_ReaderList->Size(); i++)
168  {
169  if( m_ReaderList->GetNthElement(i) )
170  filenames.push_back( m_ReaderList->GetNthElement(i)->GetFileName() );
171  }
172 
173  return filenames;
174  }
175 
176 
177  itkExceptionMacro(<< "No filename value");
178 }
179 
180 
181 std::string
183 {
184  if (m_ReaderList)
185  {
186  if(m_ReaderList->Size()<i)
187  {
188  itkExceptionMacro(<< "No vector data "<<i<<". Only "<<m_ReaderList->Size()<<" vector data available.");
189  }
190 
191  return m_ReaderList->GetNthElement(i)->GetFileName();
192  }
193 
194  itkExceptionMacro(<< "No filename value");
195 }
196 
199 {
200  return m_VectorDataList;
201 }
202 
205 {
206  if(m_VectorDataList->Size()<i)
207  {
208  itkExceptionMacro(<< "No vector data "<<i<<". Only "<<m_VectorDataList->Size()<<" vector data available.");
209  }
210  return m_VectorDataList->GetNthElement(i);
211 }
212 
213 void
215 {
216  // Check input availability
217  // TODO : when the logger will be available, redirect the exception
218  // in the logger (like what is done in MsgReporter)
219  try
220  {
221  for(unsigned int i=0; i<vdList->Size(); i++)
222  {
223  vdList->GetNthElement( i )->UpdateOutputInformation();
224  }
225  }
226  catch(itk::ExceptionObject &)
227  {
228  return;
229  }
230 
231  m_VectorDataList = vdList;
233  for(unsigned int i=0; i<m_VectorDataList->Size(); i++)
234  {
236  }
237 
238  SetActive(true);
239  this->Modified();
240 }
241 
242 void
244 {
245  // Check input availability
246  // TODO : when the logger will be available, redirect the exception
247  // in the logger (like what is done in MsgReporter)
248  try
249  {
250  vectorData->UpdateOutputInformation();
251  }
252  catch(itk::ExceptionObject &)
253  {
254  return;
255  }
256 
257  m_VectorDataList->PushBack( vectorData );
259 
260  this->Modified();
261 }
262 
263 bool
265 {
266  if (m_VectorDataList->Size() == 0)
267  {
268  return false;
269  }
270 
271  bool res(true);
272  unsigned int i(0);
273  while (i < m_VectorDataList->Size() && res == true)
274  {
275  res = m_VectorDataList->GetNthElement(i).IsNotNull();
276  i++;
277  }
278 
279  return res;
280 }
281 
282 
283 void
285 {
286  if(m_VectorDataList->Size()<id)
287  {
288  itkExceptionMacro(<< "No vector data "<<id<<". Only "<<m_VectorDataList->Size()<<" vector data available.");
289  }
290 
291  m_VectorDataList->Erase( id );
292  m_ReaderList->Erase( id );
293 
294  this->Modified();
295 }
296 
297 void
299 {
300  m_VectorDataList->Clear();
301  m_ReaderList->Clear();
302 
303  SetActive(false);
304  this->Modified();
305 }
306 
307 
308 }
309 }
310 

Generated at Sun Feb 3 2013 00:59:13 for Orfeo Toolbox with doxygen 1.8.1.1