source: branches/prototype-v0/thirds/otb2zcfg/otb2zcfg.cxx @ 848

Last change on this file since 848 was 848, checked in by djay, 7 years ago

Check and set the default pixel type as proposed by Manuel.

  • Property svn:keywords set to Id
File size: 16.2 KB
Line 
1#include "otbWrapperApplicationRegistry.h"
2#include "otbWrapperApplication.h"
3#include "otbImage.h"
4#include <iostream> 
5
6using namespace otb::Wrapper;
7
8std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) {
9    size_t start_pos = 0;
10    while((start_pos = str.find(from, start_pos)) != std::string::npos) {
11        str.replace(start_pos, from.length(), to);
12        start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
13    }
14    return str;
15}
16
17void printDefaultOutput(){
18  std::cout << "  [Result]" << std::endl;
19  std::cout << "   Title = the result message" << std::endl;
20  std::cout << "   Abstract = the result message" << std::endl;
21  std::cout << "   <LiteralData>" << std::endl;
22  std::cout << "    dataType = string" << std::endl;
23  std::cout << "    <Default />" << std::endl;
24  std::cout << "   </LiteralData>" << std::endl;
25}
26
27void printAscii(){
28  std::cout << "    <Default>" << std::endl;
29  std::cout << "     mimeType = text/plain" << std::endl;
30  std::cout << "     encoding = ascii" << std::endl;
31  std::cout << "    </Default>" << std::endl;
32}
33
34void printXml(){
35  std::cout << "    <Default>" << std::endl;
36  std::cout << "     mimeType = text/xml" << std::endl;
37  std::cout << "     encoding = utf-8" << std::endl;
38  std::cout << "    </Default>" << std::endl;
39}
40
41void printGeoid(){
42  std::cout << "    <Default>" << std::endl;
43  std::cout << "     mimeType = application/octet-stream" << std::endl;
44  std::cout << "    </Default>" << std::endl;
45}
46
47void printCSV(){
48  std::cout << "    <Default>" << std::endl;
49  std::cout << "     mimeType = text/csv" << std::endl;
50  std::cout << "     encoding = utf-8" << std::endl;
51  std::cout << "    </Default>" << std::endl;
52}
53
54void printUnknown(){
55  std::cout << "    <Default>" << std::endl;
56  std::cout << "     mimeType = text/xml" << std::endl;
57  std::cout << "     encoding = utf-8" << std::endl;
58  std::cout << "    </Default>" << std::endl;
59  std::cout << "    <Supported>" << std::endl;
60  std::cout << "     mimeType = text/plain" << std::endl;
61  std::cout << "     encoding = utf-8" << std::endl;
62  std::cout << "    </Supported>" << std::endl;
63}
64
65void printImages(){
66  std::cout << "    <Default>" << std::endl;
67  std::cout << "     mimeType = image/tiff" << std::endl;
68  std::cout << "    </Default>" << std::endl;
69#if defined(OTB_USE_JPEG2000)
70  std::cout << "    <Supported>" << std::endl;
71  std::cout << "     mimeType = image/jp2" << std::endl;
72  std::cout << "    </Supported>" << std::endl;
73#endif
74  std::cout << "    <Supported>" << std::endl;
75  std::cout << "     mimeType = image/jpeg" << std::endl;
76  std::cout << "    </Supported>" << std::endl;
77  std::cout << "    <Supported>" << std::endl;
78  std::cout << "     mimeType = image/png" << std::endl;
79  std::cout << "    </Supported>" << std::endl;
80}
81
82void printKmz(){
83  std::cout << "    <Default>" << std::endl;
84  std::cout << "     mimeType = application/vnd.google-earth.kmz" << std::endl;
85  std::cout << "     extension = kmz" << std::endl;
86  std::cout << "    </Default>" << std::endl;
87}
88
89void printVector(){
90  std::cout << "    <Default>" << std::endl;
91  std::cout << "     mimeType = text/xml" << std::endl;
92  std::cout << "     encoding = utf-8" << std::endl;
93  std::cout << "    </Default>" << std::endl;
94  std::cout << "    <Supported>" << std::endl;
95  std::cout << "     mimeType = application/vnd.google-earth.kml+xml" << std::endl;
96  std::cout << "     encoding = utf-8" << std::endl;
97  std::cout << "    </Supported>" << std::endl;
98  std::cout << "    <Supported>" << std::endl;
99  std::cout << "     mimeType = application/json" << std::endl;
100  std::cout << "     encoding = utf-8" << std::endl;
101  std::cout << "    </Supported>" << std::endl;
102  std::cout << "    <Supported>" << std::endl;
103  std::cout << "     mimeType = application/zip" << std::endl;
104  std::cout << "    </Supported>" << std::endl;
105}
106
107void printOutputImage(ImagePixelType pt){
108  std::cout << "   <LiteralData>" << std::endl;
109  std::cout << "    dataType = string" << std::endl;
110  std::cout << "    <Default>" << std::endl;
111  // Check for the default pixel type
112  switch(pt){
113  case ImagePixelType_uint8:
114    std::cout << "     value = uint8" << std::endl;
115    break;
116  case ImagePixelType_int16:
117    std::cout << "     value = int16" << std::endl;
118    break;
119  case ImagePixelType_uint16:
120    std::cout << "     value = uint16" << std::endl;
121    break;
122  case ImagePixelType_int32:
123    std::cout << "     value = int32" << std::endl;
124    break;
125  case ImagePixelType_uint32:
126    std::cout << "     value = uint8" << std::endl;
127    break;
128  case ImagePixelType_double:
129    std::cout << "     value = uint8" << std::endl;
130    break;
131  default:
132    std::cout << "     value = float" << std::endl;
133    break;
134  }
135  std::cout << "     AllowedValues = uint8,uint16,int16,int32,int32,float,double" << std::endl;
136  std::cout << "    </Default>" << std::endl;
137  std::cout << "   </LiteralData>" << std::endl;
138}
139
140void printOutputComplexImage(ComplexImagePixelType pt){
141  std::cout << "   <LiteralData>" << std::endl;
142  std::cout << "    dataType = string" << std::endl;
143  std::cout << "    <Default>" << std::endl;
144  // Check for the default pixel type
145  switch(pt){
146  case ComplexImagePixelType_double:
147    std::cout << "     value = cdouble" << std::endl;
148    break;
149  default:
150    std::cout << "     value = cfloat" << std::endl;
151    break;
152  }
153  std::cout << "     AllowedValues = cfloat,cdouble" << std::endl;
154  std::cout << "    </Default>" << std::endl;
155  std::cout << "   </LiteralData>" << std::endl;
156}
157
158int main(int itkNotUsed(argc), char * itkNotUsed(argv)[]) 
159{ 
160  typedef otb::Image<unsigned short, 2> ImageType; 
161 
162  ImageType::Pointer image = ImageType::New(); 
163 
164  const char * ITK_AUTOLOAD_PATH = itksys::SystemTools::GetEnv("ITK_AUTOLOAD_PATH");
165  std::cerr << "INFO: Module search path: " << (ITK_AUTOLOAD_PATH ? ITK_AUTOLOAD_PATH : "none (check ITK_AUTOLOAD_PATH)") << std::endl;
166
167  std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications();
168  if (list.size() == 0)
169    std::cerr << "ERROR: no module found." << std::endl;
170  else{
171    std::cerr << "INFO: Available modules :" << std::endl;
172    for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it){
173      std::string filename= *it + ".zcfg";
174      std::ofstream out(filename.c_str(),std::ofstream::out);
175      std::streambuf *coutbuf = std::cout.rdbuf();
176      std::cout.rdbuf(out.rdbuf());
177
178      std::cerr << *it << std::endl;
179      std::cout << "[" << *it << "]" << std::endl;
180      Application::Pointer m_Application=ApplicationRegistry::CreateApplication(*it);
181      std::string s0 = m_Application->GetDescription();
182      s0=ReplaceAll(ReplaceAll(s0,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
183      std::cout << " Title = " << s0 << std::endl;
184      s0 = m_Application->GetDocLongDescription();
185      s0=ReplaceAll(ReplaceAll(s0,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
186      std::cout << " Abstract = " << s0 << std::endl;
187      const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
188      std::cout << " storeSupported = true"<< std::endl;
189      std::cout << " statusSupported = true" << std::endl;
190      std::cout << " serviceProvider = " << *it << std::endl;
191      std::cout << " serviceType = OTB" << std::endl;
192      std::cout << " <DataInputs>" << std::endl;
193      for (unsigned int i = 0; i < appKeyList.size(); i++){
194        const std::string paramKey(appKeyList[i]);
195        Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
196        ParameterType type = m_Application->GetParameterType(paramKey);
197        Role role = m_Application->GetParameterRole(paramKey);
198     
199        if(paramKey!="inxml" && paramKey!="outxml" && role==0 && type!=17 
200           && type!=ParameterType_OutputFilename && type!=ParameterType_OutputVectorData){
201          std::vector<std::string> values;
202          std::string s = m_Application->GetParameterDescription(paramKey);
203          s=ReplaceAll(ReplaceAll(ReplaceAll(s,std::string("\n"),std::string("")),std::string("\t"),std::string("")),std::string("<"),std::string("&lt;"));
204          std::cout << "  [" << paramKey << "]" << std::endl;
205          if(s.length()>0){
206            std::cout << "   Title = " << s << std::endl;
207            std::cout << "   Abstract = " << s << std::endl;
208          }else{
209            std::cout << "   Title = " << paramKey << std::endl;
210            std::cout << "   Abstract = " << paramKey << std::endl;
211          }
212          std::cout << "   minOccurs = " << m_Application->IsMandatory(paramKey) << std::endl;
213          /* Bounded and unbounded parameters */
214          if(type == ParameterType_StringList || type == ParameterType_InputImageList
215             || type == ParameterType_InputVectorDataList || type == ParameterType_InputFilenameList
216             || type == ParameterType_ListView)
217            std::cout << "   maxOccurs = 1024" << std::endl;
218          else
219            std::cout << "   maxOccurs = 1" << std::endl;
220          std::replace( s.begin(), s.end(), '\n', ' ');
221         
222          if(type == ParameterType_StringList || type == ParameterType_String || type == ParameterType_Float
223             || type == ParameterType_Int || type == ParameterType_Choice || type == ParameterType_ListView
224             || type == ParameterType_RAM || type == ParameterType_Empty || type == ParameterType_Directory){
225            std::cout << "   <LiteralData>" << std::endl;
226            std::string lt;
227            if(type == ParameterType_Int || type == ParameterType_RAM)
228              lt="integer";
229            if(type == ParameterType_Float)
230              lt="float";
231            if(type == ParameterType_String || type == ParameterType_StringList
232               || type == ParameterType_Choice || type == ParameterType_Directory
233               || type == ParameterType_ListView)
234              lt="string";
235            if(type == ParameterType_Empty)
236              lt="boolean";
237            std::cout << "    dataType = " << lt << std::endl;
238            if(type == ParameterType_Choice || type == ParameterType_ListView){
239              const std::vector<std::string> nList = m_Application->GetChoiceNames(paramKey);
240              const std::vector<std::string> keysList = m_Application->GetChoiceKeys(paramKey);
241              if(keysList.size()==0){
242                std::cout << "    <Default />" << std::endl;
243              }
244              for (unsigned int j = 0; j < keysList.size(); j++){
245                const std::string key(keysList[j]);
246                if(j==0){
247                  std::cout << "    <Default>" << std::endl;
248                  if(m_Application->HasValue(paramKey))
249                    std::cout << "    value = " << m_Application->GetParameterAsString(paramKey) << std::endl;
250                  else
251                    std::cout << "    value = " << key << std::endl;
252                }
253                else{
254                  if(j==1){
255                    std::cout << "    AllowedValues = "+keysList[0]+",";
256                  }
257                  std::cout << keysList[j];
258                  if(j+1>=keysList.size()){
259                    std::cout << std::endl;
260                    std::cout << "    </Default>" << std::endl;
261                  }
262                  else
263                    std::cout << ",";
264                }
265              }
266            }
267            else{
268              if(type!=17 && m_Application->HasValue(paramKey)){
269                std::cout << "    <Default>" << std::endl;
270                std::cout << "     value = " << m_Application->GetParameterAsString(paramKey) << std::endl;
271                std::cout << "    </Default>" << std::endl;
272              }
273              else
274                std::cout << "    <Default />" << std::endl;
275            }
276            std::cout << "   </LiteralData>" << std::endl;
277          }
278          else{
279            if(type == ParameterType_OutputImage){
280              printOutputImage(m_Application->GetParameterOutputImagePixelType(paramKey));
281            }
282            else{
283              if(type == ParameterType_ComplexOutputImage){
284                printOutputComplexImage(m_Application->GetParameterComplexOutputImagePixelType(paramKey));
285              }else{
286                std::cout << "   <ComplexData>" << std::endl;
287                if(type == ParameterType_InputImage || type == ParameterType_InputImageList || type == ParameterType_ComplexInputImage){
288                  printImages();
289                }
290                else
291                  if(type == ParameterType_InputVectorData || type == ParameterType_InputVectorDataList){
292                    printVector();
293                  }
294                  else
295                    if(type == ParameterType_InputFilename || type == ParameterType_OutputFilename){
296                     
297                      std::string geoid("geoid");
298                      if(paramKey.find(geoid)!= std::string::npos)
299                        printGeoid();
300                      else{
301                        std::string dtype("vector");
302                        std::string descr(m_Application->GetParameterDescription(paramKey));
303                        if(descr.find(dtype)!= std::string::npos)
304                          printVector();
305                        else{
306                          std::string dtype1("ASCII");
307                          if(descr.find(dtype1)!= std::string::npos)
308                            printAscii();
309                          else{
310                            std::string dtype2("XML");
311                            std::string dtype3("xml");
312                            if(descr.find(dtype2)!= std::string::npos || descr.find(dtype3)!= std::string::npos)
313                              printXml();
314                            else
315                              printImages();
316                          }
317                        }
318                      }
319                    }
320                std::cout << "   </ComplexData>" << std::endl;
321              }
322            }
323          }
324
325
326        }
327      }
328      std::cout << " </DataInputs>" << std::endl;
329      std::cout << " <DataOutputs>" << std::endl;
330      int hasOutput=-1;
331      for (unsigned int i = 0; i < appKeyList.size(); i++){
332        const std::string paramKey(appKeyList[i]);
333        std::vector<std::string> values;
334        Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
335        ParameterType type = m_Application->GetParameterType(paramKey);
336        Role role = m_Application->GetParameterRole(paramKey);
337       
338        if(paramKey!="inxml" && paramKey!="outxml" &&
339           ((type == ParameterType_OutputVectorData || type == ParameterType_OutputImage
340             || type == ParameterType_OutputImage || type == ParameterType_ComplexOutputImage
341             || type == ParameterType_OutputFilename) || role==1) && type != ParameterType_Group){
342          hasOutput=1;
343          std::vector<std::string> values;
344          Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
345          ParameterType type = m_Application->GetParameterType(paramKey);
346          Role role = m_Application->GetParameterRole(paramKey);
347          std::cout << "  [" << paramKey << "]" << std::endl;
348          std::string s=m_Application->GetParameterDescription(paramKey);
349          if(s.length()>0){
350            s=ReplaceAll(ReplaceAll(s,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
351            std::cout << "   Title = " << s << std::endl;
352            std::cout << "   Abstract = " << s << std::endl;
353          }else{
354            std::cout << "   Title = " << paramKey << std::endl;
355            std::cout << "   Abstract = " << paramKey << std::endl;
356          }
357
358          if(type == ParameterType_OutputImage || type == ParameterType_ComplexOutputImage){
359            std::cout << "   <ComplexData>" << std::endl;
360            printImages();
361            std::cout << "   </ComplexData>" << std::endl;
362          }
363          else
364            if(type == ParameterType_OutputVectorData || type == ParameterType_OutputImage){
365              std::cout << "   <ComplexData>" << std::endl;
366              if(type == ParameterType_OutputImage)
367                printImages();
368              else
369                printVector();
370              std::cout << "   </ComplexData>" << std::endl;
371            }
372            else
373              if(type == ParameterType_String || type == ParameterType_StringList
374                 || type == ParameterType_Float || type == ParameterType_Int){
375                std::cout << "   <LiteralData>" << std::endl;
376                std::string lt;
377                if(type == ParameterType_Int)
378                  lt="integer";
379                if(type == ParameterType_Float)
380                  lt="float";
381                if(type == ParameterType_String || type == ParameterType_StringList)
382                  lt="string";
383                std::cout << "    dataType = " << lt << std::endl;
384                std::cout << "    <Default />" << std::endl;
385                std::cout << "   </LiteralData>" << std::endl;
386              }
387              else
388                if(type == ParameterType_OutputFilename){
389                  std::cout << "   <ComplexData>" << std::endl;
390                  std::string descr(m_Application->GetParameterDescription(paramKey));
391                  std::string dtype("csv");
392                  std::string dtype1("CSV");
393                  if(descr.find(dtype)!= std::string::npos || descr.find(dtype1)!= std::string::npos)
394                    printCSV();
395                  else{
396                    std::string dtype2("text file");
397                    if(descr.find(dtype2)!= std::string::npos)
398                      printAscii();
399                    else{
400                      std::string dtype2("XML");
401                      std::string dtype3("xml");
402                      if(descr.find(dtype2)!= std::string::npos || descr.find(dtype3)!= std::string::npos)
403                        printXml();
404                      else{
405                        std::string dtype4("vector");
406                        std::string dtype5("Vector");
407                        if(descr.find(dtype4)!= std::string::npos || descr.find(dtype5)!= std::string::npos)
408                          printVector();
409                        else{
410                          std::string dtype6("kmz");
411                          std::string dtype7("Kmz");
412                          if(descr.find(dtype6)!= std::string::npos || descr.find(dtype6)!= std::string::npos)
413                            printKmz();
414                          else
415                            printUnknown();
416                        }
417                      }
418                    }
419                  }
420                  std::cout << "   </ComplexData>" << std::endl;
421                }
422        }
423      }
424      if(hasOutput<0)
425        printDefaultOutput();
426      std::cout << " </DataOutputs>" << std::endl;
427      std::cout.rdbuf(coutbuf);
428    }
429  }
430 
431  return EXIT_SUCCESS; 
432}
433
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png