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

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

Update the source code for HPC support. Automatically adding nested outputs for the HPC support (should this be available for every support?). Add capability to store the metadata in the Collection DataBase?. Addition of the zcfg2sql to import any existing ZCFG file into the Collection DB. Add the support to invoke a callback (for history purpose) in case a [callback] section contains at least one parameter defined (url). Add support to convert maps and map to JSON (for callback use only by now). Fix some memory leaks (some are still there).

  • Property svn:keywords set to Id
File size: 15.0 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/zip" << std::endl;
100  std::cout << "    </Supported>" << std::endl;
101}
102
103void printOutputImage(){
104  std::cout << "   <LiteralData>" << std::endl;
105  std::cout << "    dataType = string" << std::endl;
106  std::cout << "    <Default>" << std::endl;
107  std::cout << "     value = float" << std::endl;
108  std::cout << "     AllowedValues = uint8,uint16,int16n,int32,int32,float,double" << std::endl;
109  std::cout << "    </Default>" << std::endl;
110  std::cout << "   </LiteralData>" << std::endl;
111}
112
113void printOutputComplexImage(){
114  std::cout << "   <LiteralData>" << std::endl;
115  std::cout << "    dataType = string" << std::endl;
116  std::cout << "    <Default>" << std::endl;
117  std::cout << "     value = cfloat" << std::endl;
118  std::cout << "     AllowedValues = cfloat,cdouble" << std::endl;
119  std::cout << "    </Default>" << std::endl;
120  std::cout << "   </LiteralData>" << std::endl;
121}
122
123int main(int itkNotUsed(argc), char * itkNotUsed(argv)[]) 
124{ 
125  typedef otb::Image<unsigned short, 2> ImageType; 
126 
127  ImageType::Pointer image = ImageType::New(); 
128 
129  const char * ITK_AUTOLOAD_PATH = itksys::SystemTools::GetEnv("ITK_AUTOLOAD_PATH");
130  std::cerr << "INFO: Module search path: " << (ITK_AUTOLOAD_PATH ? ITK_AUTOLOAD_PATH : "none (check ITK_AUTOLOAD_PATH)") << std::endl;
131
132  std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications();
133  if (list.size() == 0)
134    std::cerr << "ERROR: no module found." << std::endl;
135  else{
136    std::cerr << "INFO: Available modules :" << std::endl;
137    for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it){
138      std::string filename= *it + ".zcfg";
139      std::ofstream out(filename.c_str(),std::ofstream::out);
140      std::streambuf *coutbuf = std::cout.rdbuf();
141      std::cout.rdbuf(out.rdbuf());
142
143      std::cerr << *it << std::endl;
144      std::cout << "[" << *it << "]" << std::endl;
145      Application::Pointer m_Application=ApplicationRegistry::CreateApplication(*it);
146      std::string s0 = m_Application->GetDescription();
147      s0=ReplaceAll(ReplaceAll(s0,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
148      std::cout << " Title = " << s0 << std::endl;
149      s0 = m_Application->GetDocLongDescription();
150      s0=ReplaceAll(ReplaceAll(s0,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
151      std::cout << " Abstract = " << s0 << std::endl;
152      const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
153      std::cout << " storeSupported = true"<< std::endl;
154      std::cout << " statusSupported = true" << std::endl;
155      std::cout << " serviceProvider = " << *it << std::endl;
156      std::cout << " serviceType = OTB" << std::endl;
157      std::cout << " <DataInputs>" << std::endl;
158      for (unsigned int i = 0; i < appKeyList.size(); i++){
159        const std::string paramKey(appKeyList[i]);
160        Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
161        ParameterType type = m_Application->GetParameterType(paramKey);
162        Role role = m_Application->GetParameterRole(paramKey);
163     
164        if(paramKey!="inxml" && paramKey!="outxml" && role==0 && type!=17 
165           && type!=ParameterType_OutputFilename && type!=ParameterType_OutputVectorData){
166          std::vector<std::string> values;
167          std::string s = m_Application->GetParameterDescription(paramKey);
168          s=ReplaceAll(ReplaceAll(ReplaceAll(s,std::string("\n"),std::string("")),std::string("\t"),std::string("")),std::string("<"),std::string("&lt;"));
169          std::cout << "  [" << paramKey << "]" << std::endl;
170          if(s.length()>0){
171            std::cout << "   Title = " << s << std::endl;
172            std::cout << "   Abstract = " << s << std::endl;
173          }else{
174            std::cout << "   Title = " << paramKey << std::endl;
175            std::cout << "   Abstract = " << paramKey << std::endl;
176          }
177          std::cout << "   minOccurs = " << m_Application->IsMandatory(paramKey) << std::endl;
178          /* Bounded and unbounded parameters */
179          if(type == ParameterType_StringList || type == ParameterType_InputImageList
180             || type == ParameterType_InputVectorDataList || type == ParameterType_InputFilenameList
181             || type == ParameterType_ListView)
182            std::cout << "   maxOccurs = 1024" << std::endl;
183          else
184            std::cout << "   maxOccurs = 1" << std::endl;
185          std::replace( s.begin(), s.end(), '\n', ' ');
186         
187          if(type == ParameterType_StringList || type == ParameterType_String || type == ParameterType_Float
188             || type == ParameterType_Int || type == ParameterType_Choice || type == ParameterType_ListView
189             || type == ParameterType_RAM || type == ParameterType_Empty || type == ParameterType_Directory){
190            std::cout << "   <LiteralData>" << std::endl;
191            std::string lt;
192            if(type == ParameterType_Int || type == ParameterType_RAM)
193              lt="integer";
194            if(type == ParameterType_Float)
195              lt="float";
196            if(type == ParameterType_String || type == ParameterType_StringList
197               || type == ParameterType_Choice || type == ParameterType_Directory
198               || type == ParameterType_ListView)
199              lt="string";
200            if(type == ParameterType_Empty)
201              lt="boolean";
202            std::cout << "    dataType = " << lt << std::endl;
203            if(type == ParameterType_Choice || type == ParameterType_ListView){
204              const std::vector<std::string> nList = m_Application->GetChoiceNames(paramKey);
205              const std::vector<std::string> keysList = m_Application->GetChoiceKeys(paramKey);
206              if(keysList.size()==0){
207                std::cout << "    <Default />" << std::endl;
208              }
209              for (unsigned int j = 0; j < keysList.size(); j++){
210                const std::string key(keysList[j]);
211                if(j==0){
212                  std::cout << "    <Default>" << std::endl;
213                  if(m_Application->HasValue(paramKey))
214                    std::cout << "    value = " << m_Application->GetParameterAsString(paramKey) << std::endl;
215                  else
216                    std::cout << "    value = " << key << std::endl;
217                }
218                else{
219                  if(j==1){
220                    std::cout << "    AllowedValues = "+keysList[0]+",";
221                  }
222                  std::cout << keysList[j];
223                  if(j+1>=keysList.size()){
224                    std::cout << std::endl;
225                    std::cout << "    </Default>" << std::endl;
226                  }
227                  else
228                    std::cout << ",";
229                }
230              }
231            }
232            else{
233              if(type!=17 && m_Application->HasValue(paramKey)){
234                std::cout << "    <Default>" << std::endl;
235                std::cout << "     value = " << m_Application->GetParameterAsString(paramKey) << std::endl;
236                std::cout << "    </Default>" << std::endl;
237              }
238              else
239                std::cout << "    <Default />" << std::endl;
240            }
241            std::cout << "   </LiteralData>" << std::endl;
242          }
243          else{
244            if(type == ParameterType_OutputImage)
245              printOutputImage();
246            else{
247              if(type == ParameterType_ComplexOutputImage){
248                printOutputComplexImage();
249              }else{
250                std::cout << "   <ComplexData>" << std::endl;
251                if(type == ParameterType_InputImage || type == ParameterType_InputImageList || type == ParameterType_ComplexInputImage){
252                  printImages();
253                }
254                else
255                  if(type == ParameterType_InputVectorData || type == ParameterType_InputVectorDataList){
256                    printVector();
257                  }
258                  else
259                    if(type == ParameterType_InputFilename || type == ParameterType_OutputFilename){
260                     
261                      std::string geoid("geoid");
262                      if(paramKey.find(geoid)!= std::string::npos)
263                        printGeoid();
264                      else{
265                        std::string dtype("vector");
266                        std::string descr(m_Application->GetParameterDescription(paramKey));
267                        if(descr.find(dtype)!= std::string::npos)
268                          printVector();
269                        else{
270                          std::string dtype1("ASCII");
271                          if(descr.find(dtype1)!= std::string::npos)
272                            printAscii();
273                          else{
274                            std::string dtype2("XML");
275                            std::string dtype3("xml");
276                            if(descr.find(dtype2)!= std::string::npos || descr.find(dtype3)!= std::string::npos)
277                              printXml();
278                            else
279                              printImages();
280                          }
281                        }
282                      }
283                    }
284                std::cout << "   </ComplexData>" << std::endl;
285              }
286            }
287          }
288
289
290        }
291      }
292      std::cout << " </DataInputs>" << std::endl;
293      std::cout << " <DataOutputs>" << std::endl;
294      int hasOutput=-1;
295      for (unsigned int i = 0; i < appKeyList.size(); i++){
296        const std::string paramKey(appKeyList[i]);
297        std::vector<std::string> values;
298        Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
299        ParameterType type = m_Application->GetParameterType(paramKey);
300        Role role = m_Application->GetParameterRole(paramKey);
301       
302        if(paramKey!="inxml" && paramKey!="outxml" &&
303           ((type == ParameterType_OutputVectorData || type == ParameterType_OutputImage
304             || type == ParameterType_OutputImage || type == ParameterType_ComplexOutputImage
305             || type == ParameterType_OutputFilename) || role==1) && type != ParameterType_Group){
306          hasOutput=1;
307          std::vector<std::string> values;
308          Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
309          ParameterType type = m_Application->GetParameterType(paramKey);
310          Role role = m_Application->GetParameterRole(paramKey);
311          std::cout << "  [" << paramKey << "]" << std::endl;
312          std::string s=m_Application->GetParameterDescription(paramKey);
313          if(s.length()>0){
314            s=ReplaceAll(ReplaceAll(s,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
315            std::cout << "   Title = " << s << std::endl;
316            std::cout << "   Abstract = " << s << std::endl;
317          }else{
318            std::cout << "   Title = " << paramKey << std::endl;
319            std::cout << "   Abstract = " << paramKey << std::endl;
320          }
321
322          if(type == ParameterType_OutputImage || type == ParameterType_ComplexOutputImage){
323            std::cout << "   <ComplexData>" << std::endl;
324            printImages();
325            std::cout << "   </ComplexData>" << std::endl;
326          }
327          else
328            if(type == ParameterType_OutputVectorData || type == ParameterType_OutputImage){
329              std::cout << "   <ComplexData>" << std::endl;
330              if(type == ParameterType_OutputImage)
331                printImages();
332              else
333                printVector();
334              std::cout << "   </ComplexData>" << std::endl;
335            }
336            else
337              if(type == ParameterType_String || type == ParameterType_StringList
338                 || type == ParameterType_Float || type == ParameterType_Int){
339                std::cout << "   <LiteralData>" << std::endl;
340                std::string lt;
341                if(type == ParameterType_Int)
342                  lt="integer";
343                if(type == ParameterType_Float)
344                  lt="float";
345                if(type == ParameterType_String || type == ParameterType_StringList)
346                  lt="string";
347                std::cout << "    dataType = " << lt << std::endl;
348                std::cout << "    <Default />" << std::endl;
349                std::cout << "   </LiteralData>" << std::endl;
350              }
351              else
352                if(type == ParameterType_OutputFilename){
353                  std::cout << "   <ComplexData>" << std::endl;
354                  std::string descr(m_Application->GetParameterDescription(paramKey));
355                  std::string dtype("csv");
356                  std::string dtype1("CSV");
357                  if(descr.find(dtype)!= std::string::npos || descr.find(dtype1)!= std::string::npos)
358                    printCSV();
359                  else{
360                    std::string dtype2("text file");
361                    if(descr.find(dtype2)!= std::string::npos)
362                      printAscii();
363                    else{
364                      std::string dtype2("XML");
365                      std::string dtype3("xml");
366                      if(descr.find(dtype2)!= std::string::npos || descr.find(dtype3)!= std::string::npos)
367                        printXml();
368                      else{
369                        std::string dtype4("vector");
370                        std::string dtype5("Vector");
371                        if(descr.find(dtype4)!= std::string::npos || descr.find(dtype5)!= std::string::npos)
372                          printVector();
373                        else{
374                          std::string dtype6("kmz");
375                          std::string dtype7("Kmz");
376                          if(descr.find(dtype6)!= std::string::npos || descr.find(dtype6)!= std::string::npos)
377                            printKmz();
378                          else
379                            printUnknown();
380                        }
381                      }
382                    }
383                  }
384                  std::cout << "   </ComplexData>" << std::endl;
385                }
386        }
387      }
388      if(hasOutput<0)
389        printDefaultOutput();
390      std::cout << " </DataOutputs>" << std::endl;
391      std::cout.rdbuf(coutbuf);
392    }
393  }
394 
395  return EXIT_SUCCESS; 
396}
397
Note: See TracBrowser for help on using the repository browser.

Search

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