[550] | 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 | |
---|
[563] | 82 | void 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 | |
---|
[550] | 89 | void 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 | |
---|
| 103 | void 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 | |
---|
| 113 | void 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 | |
---|
| 123 | int 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 << "ERROR: 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: Available modules : none." << std::endl; |
---|
| 135 | else{ |
---|
| 136 | std::cerr << "ERROR: 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"; |
---|
[555] | 139 | std::ofstream out(filename.c_str(),std::ofstream::out); |
---|
[550] | 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("<")); |
---|
| 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 | std::cout << " maxOccurs = 1024" << std::endl; |
---|
| 182 | else |
---|
| 183 | std::cout << " maxOccurs = 1" << std::endl; |
---|
| 184 | std::replace( s.begin(), s.end(), '\n', ' '); |
---|
| 185 | |
---|
| 186 | if(type == ParameterType_StringList || type == ParameterType_String || type == ParameterType_Float |
---|
| 187 | || type == ParameterType_Int || type == ParameterType_Choice || type == ParameterType_ListView |
---|
| 188 | || type == ParameterType_RAM || type == ParameterType_Empty || type == ParameterType_Directory){ |
---|
| 189 | std::cout << " <LiteralData>" << std::endl; |
---|
| 190 | std::string lt; |
---|
| 191 | if(type == ParameterType_Int || type == ParameterType_RAM) |
---|
| 192 | lt="integer"; |
---|
| 193 | if(type == ParameterType_Float) |
---|
| 194 | lt="float"; |
---|
| 195 | if(type == ParameterType_String || type == ParameterType_StringList |
---|
| 196 | || type == ParameterType_Choice || type == ParameterType_Directory |
---|
| 197 | || type == ParameterType_ListView) |
---|
| 198 | lt="string"; |
---|
| 199 | if(type == ParameterType_Empty) |
---|
| 200 | lt="boolean"; |
---|
| 201 | std::cout << " dataType = " << lt << std::endl; |
---|
| 202 | if(type == ParameterType_Choice || type == ParameterType_ListView){ |
---|
| 203 | const std::vector<std::string> nList = m_Application->GetChoiceNames(paramKey); |
---|
| 204 | const std::vector<std::string> keysList = m_Application->GetChoiceKeys(paramKey); |
---|
| 205 | if(keysList.size()==0){ |
---|
| 206 | std::cout << " <Default />" << std::endl; |
---|
| 207 | } |
---|
| 208 | for (unsigned int j = 0; j < keysList.size(); j++){ |
---|
| 209 | const std::string key(keysList[j]); |
---|
| 210 | if(j==0){ |
---|
| 211 | std::cout << " <Default>" << std::endl; |
---|
| 212 | if(m_Application->HasValue(paramKey)) |
---|
| 213 | std::cout << " value = " << m_Application->GetParameterAsString(paramKey) << std::endl; |
---|
| 214 | else |
---|
| 215 | std::cout << " value = " << key << std::endl; |
---|
| 216 | } |
---|
| 217 | else{ |
---|
| 218 | if(j==1){ |
---|
| 219 | std::cout << " AllowedValues = "+keysList[0]+","; |
---|
| 220 | } |
---|
| 221 | std::cout << keysList[j]; |
---|
| 222 | if(j+1>=keysList.size()){ |
---|
| 223 | std::cout << std::endl; |
---|
| 224 | std::cout << " </Default>" << std::endl; |
---|
| 225 | } |
---|
| 226 | else |
---|
| 227 | std::cout << ","; |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | else{ |
---|
| 232 | if(type!=17 && m_Application->HasValue(paramKey)){ |
---|
| 233 | std::cout << " <Default>" << std::endl; |
---|
| 234 | std::cout << " value = " << m_Application->GetParameterAsString(paramKey) << std::endl; |
---|
| 235 | std::cout << " </Default>" << std::endl; |
---|
| 236 | } |
---|
| 237 | else |
---|
| 238 | std::cout << " <Default />" << std::endl; |
---|
| 239 | } |
---|
| 240 | std::cout << " </LiteralData>" << std::endl; |
---|
| 241 | } |
---|
| 242 | else{ |
---|
| 243 | if(type == ParameterType_OutputImage) |
---|
| 244 | printOutputImage(); |
---|
| 245 | else{ |
---|
| 246 | if(type == ParameterType_ComplexOutputImage){ |
---|
| 247 | printOutputComplexImage(); |
---|
| 248 | }else{ |
---|
| 249 | std::cout << " <ComplexData>" << std::endl; |
---|
| 250 | if(type == ParameterType_InputImage || type == ParameterType_InputImageList || type == ParameterType_ComplexInputImage){ |
---|
| 251 | printImages(); |
---|
| 252 | } |
---|
| 253 | else |
---|
| 254 | if(type == ParameterType_InputVectorData || type == ParameterType_InputVectorDataList){ |
---|
| 255 | printVector(); |
---|
| 256 | } |
---|
| 257 | else |
---|
| 258 | if(type == ParameterType_InputFilename || type == ParameterType_OutputFilename){ |
---|
| 259 | |
---|
| 260 | std::string geoid("geoid"); |
---|
| 261 | if(paramKey.find(geoid)!= std::string::npos) |
---|
| 262 | printGeoid(); |
---|
| 263 | else{ |
---|
| 264 | std::string dtype("vector"); |
---|
| 265 | std::string descr(m_Application->GetParameterDescription(paramKey)); |
---|
| 266 | if(descr.find(dtype)!= std::string::npos) |
---|
| 267 | printVector(); |
---|
| 268 | else{ |
---|
| 269 | std::string dtype1("ASCII"); |
---|
| 270 | if(descr.find(dtype1)!= std::string::npos) |
---|
| 271 | printAscii(); |
---|
| 272 | else{ |
---|
| 273 | std::string dtype2("XML"); |
---|
| 274 | std::string dtype3("xml"); |
---|
| 275 | if(descr.find(dtype2)!= std::string::npos || descr.find(dtype3)!= std::string::npos) |
---|
| 276 | printXml(); |
---|
| 277 | else |
---|
| 278 | printImages(); |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | std::cout << " </ComplexData>" << std::endl; |
---|
| 284 | } |
---|
| 285 | } |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | std::cout << " <DataInputs>" << std::endl; |
---|
| 292 | std::cout << " <DataOutputs>" << std::endl; |
---|
| 293 | int hasOutput=-1; |
---|
| 294 | for (unsigned int i = 0; i < appKeyList.size(); i++){ |
---|
| 295 | const std::string paramKey(appKeyList[i]); |
---|
| 296 | std::vector<std::string> values; |
---|
| 297 | Parameter::Pointer param = m_Application->GetParameterByKey(paramKey); |
---|
| 298 | ParameterType type = m_Application->GetParameterType(paramKey); |
---|
| 299 | Role role = m_Application->GetParameterRole(paramKey); |
---|
| 300 | |
---|
| 301 | if(paramKey!="inxml" && paramKey!="outxml" && |
---|
| 302 | ((type == ParameterType_OutputVectorData || type == ParameterType_OutputImage |
---|
| 303 | || type == ParameterType_OutputImage || type == ParameterType_ComplexOutputImage |
---|
| 304 | || type == ParameterType_OutputFilename) || role==1) && type != ParameterType_Group){ |
---|
| 305 | hasOutput=1; |
---|
| 306 | std::vector<std::string> values; |
---|
| 307 | Parameter::Pointer param = m_Application->GetParameterByKey(paramKey); |
---|
| 308 | ParameterType type = m_Application->GetParameterType(paramKey); |
---|
| 309 | Role role = m_Application->GetParameterRole(paramKey); |
---|
| 310 | std::cout << " [" << paramKey << "]" << std::endl; |
---|
| 311 | std::string s=m_Application->GetParameterDescription(paramKey); |
---|
| 312 | if(s.length()>0){ |
---|
| 313 | std::cout << " Title = " << s << std::endl; |
---|
| 314 | std::cout << " Abstract = " << s << std::endl; |
---|
| 315 | }else{ |
---|
| 316 | std::cout << " Title = " << paramKey << std::endl; |
---|
| 317 | std::cout << " Abstract = " << paramKey << std::endl; |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | if(type == ParameterType_OutputImage || type == ParameterType_ComplexOutputImage){ |
---|
| 321 | std::cout << " <ComplexData>" << std::endl; |
---|
| 322 | printImages(); |
---|
| 323 | std::cout << " </ComplexData>" << std::endl; |
---|
| 324 | } |
---|
| 325 | else |
---|
| 326 | if(type == ParameterType_OutputVectorData || type == ParameterType_OutputImage){ |
---|
| 327 | std::cout << " <ComplexData>" << std::endl; |
---|
| 328 | if(type == ParameterType_OutputImage) |
---|
| 329 | printImages(); |
---|
| 330 | else |
---|
| 331 | printVector(); |
---|
| 332 | std::cout << " </ComplexData>" << std::endl; |
---|
| 333 | } |
---|
| 334 | else |
---|
| 335 | if(type == ParameterType_String || type == ParameterType_StringList |
---|
| 336 | || type == ParameterType_Float || type == ParameterType_Int){ |
---|
| 337 | std::cout << " <LiteralData>" << std::endl; |
---|
| 338 | std::string lt; |
---|
| 339 | if(type == ParameterType_Int) |
---|
| 340 | lt="integer"; |
---|
| 341 | if(type == ParameterType_Float) |
---|
| 342 | lt="float"; |
---|
| 343 | if(type == ParameterType_String || type == ParameterType_StringList) |
---|
| 344 | lt="string"; |
---|
| 345 | std::cout << " dataType = " << lt << std::endl; |
---|
| 346 | std::cout << " <Default />" << std::endl; |
---|
| 347 | std::cout << " </LiteralData>" << std::endl; |
---|
| 348 | } |
---|
| 349 | else |
---|
| 350 | if(type == ParameterType_OutputFilename){ |
---|
| 351 | std::cout << " <ComplexData>" << std::endl; |
---|
| 352 | std::string descr(m_Application->GetParameterDescription(paramKey)); |
---|
| 353 | std::string dtype("csv"); |
---|
| 354 | std::string dtype1("CSV"); |
---|
| 355 | if(descr.find(dtype)!= std::string::npos || descr.find(dtype1)!= std::string::npos) |
---|
| 356 | printCSV(); |
---|
| 357 | else{ |
---|
| 358 | std::string dtype2("text file"); |
---|
| 359 | if(descr.find(dtype2)!= std::string::npos) |
---|
| 360 | printAscii(); |
---|
| 361 | else{ |
---|
| 362 | std::string dtype2("XML"); |
---|
| 363 | std::string dtype3("xml"); |
---|
| 364 | if(descr.find(dtype2)!= std::string::npos || descr.find(dtype3)!= std::string::npos) |
---|
| 365 | printXml(); |
---|
| 366 | else{ |
---|
| 367 | std::string dtype4("vector"); |
---|
| 368 | std::string dtype5("Vector"); |
---|
| 369 | if(descr.find(dtype4)!= std::string::npos || descr.find(dtype5)!= std::string::npos) |
---|
| 370 | printVector(); |
---|
[563] | 371 | else{ |
---|
| 372 | std::string dtype6("kmz"); |
---|
| 373 | std::string dtype7("Kmz"); |
---|
| 374 | if(descr.find(dtype6)!= std::string::npos || descr.find(dtype6)!= std::string::npos) |
---|
| 375 | printKmz(); |
---|
| 376 | else |
---|
| 377 | printUnknown(); |
---|
| 378 | } |
---|
[550] | 379 | } |
---|
| 380 | } |
---|
| 381 | } |
---|
| 382 | std::cout << " </ComplexData>" << std::endl; |
---|
| 383 | } |
---|
| 384 | } |
---|
| 385 | } |
---|
| 386 | if(hasOutput<0) |
---|
| 387 | printDefaultOutput(); |
---|
| 388 | std::cout << " </DataOutputs>" << std::endl; |
---|
| 389 | std::cout.rdbuf(coutbuf); |
---|
| 390 | } |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | return EXIT_SUCCESS; |
---|
| 394 | } |
---|
| 395 | |
---|