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