OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimPluginProjectionFactory.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // "Copyright Centre National d'Etudes Spatiales"
4 //
5 // License: LGPL
6 //
7 // See LICENSE.txt file in the top level directory for more details.
8 //
9 //----------------------------------------------------------------------------
10 // $Id$
11 
12 //***
13 // Note to programmer: To add a new model, search this file for "ADD_MODEL"
14 // to locate places requiring editing. Functional example below...
15 //
16 // ADD_MODEL: Include all sensor model headers here:
17 //***
20 #include <ossim/base/ossimRefPtr.h>
22 #include "ossimRadarSatModel.h"
23 #include "ossimEnvisatAsarModel.h"
24 #include "ossimTerraSarModel.h"
25 //#include <ossim/projection/ossimCosmoSkymedModel.h>
26 #include "ossimRadarSat2Model.h"
27 #include "ossimErsSarModel.h"
28 #include "ossimAlosPalsarModel.h"
29 #include "ossimPleiadesModel.h"
31 #include "ossimTileMapModel.h"
32 #include "ossimSpot6Model.h"
33 
34 //***
35 // Define Trace flags for use within this file:
36 //***
37 #include <ossim/base/ossimTrace.h>
38 static ossimTrace traceExec = ossimTrace("ossimPluginProjectionFactory:exec");
39 static ossimTrace traceDebug = ossimTrace("ossimPluginProjectionFactory:debug");
40 
41 
42 #include <ossimFormosatModel.h>
44 
45 namespace ossimplugins
46 {
47 
48 
50 {
51  static ossimPluginProjectionFactory* factoryInstance =
53 
54  return factoryInstance;
55 }
56 
58  const ossimFilename& filename, ossim_uint32 /*entryIdx*/)const
59 {
60  static const char MODULE[] = "ossimPluginProjectionFactory::createProjection(ossimFilename& filename)";
61  ossimRefPtr<ossimProjection> projection = 0;
62  //traceDebug.setTraceFlag(true);
63 
64  if(traceDebug())
65  {
67  << MODULE << " DEBUG: testing ossimRadarSat2Model" << std::endl;
68  }
69 
70  if ( !projection )
71  {
73  if ( model->open(filename) )
74  {
75  // Check if a coarse grid was generated, and use it instead:
76  projection = model->getReplacementOcgModel().get();
77  if (projection.valid())
78  model = 0; // Have OCG, don't need this one anymore
79  else
80  projection = model.get();
81  }
82  else
83  {
84  model = 0;
85  }
86  }
87 
88  if(traceDebug())
89  {
91  << MODULE << " DEBUG: testing ossimPleiadesModel" << std::endl;
92  }
93 
94  // Pleiades
95  if ( !projection )
96  {
98  if ( model->open(filename) )
99  {
100  projection = model.get();
101  }
102  else
103  {
104  model = 0;
105  }
106  }
107 
108  if(traceDebug())
109  {
111  << MODULE << " DEBUG: testing ossimTerraSarModel" << std::endl;
112  }
113 
114  if ( !projection )
115  {
117 
118  if ( model->open(filename) )
119  {
120  // Check if a coarse grid was generated, and use it instead:
121  projection = model->getReplacementOcgModel().get();
122  if (projection.valid())
123  model = 0; // Have OCG, don't need this one anymore
124  else
125  projection = model.get();
126  }
127  else
128  {
129  model = 0;
130  }
131  }
132 
133  if(traceDebug())
134  {
136  << MODULE << " DEBUG: testing ossimErsSarModel" << std::endl;
137  }
138 
139  if ( !projection )
140  {
142  if ( model->open(filename) )
143  {
144  projection = model.get();
145  }
146  else
147  {
148  model = 0;
149  }
150  }
151 
152  if(traceDebug())
153  {
155  << MODULE << " DEBUG: testing ossimEnvisatSarModel" << std::endl;
156  }
157 
158  if (!projection)
159  {
161  if (model->open(filename))
162  {
163  projection = model.get();
164  }
165  else
166  {
167  model = 0;
168  }
169  }
170 
171  if(traceDebug())
172  {
174  << MODULE << " DEBUG: testing ossimRadarSatModel" << std::endl;
175  }
176 
177  if (!projection)
178  {
180  if (model->open(filename))
181  {
182  projection = model.get();
183  }
184  else
185  {
186  model = 0;
187  }
188  }
189 
190  if(traceDebug())
191  {
193  << MODULE << " DEBUG: testing ossimAlosPalsarModel" << std::endl;
194  }
195 
196  if (!projection)
197  {
199  if (model->open(filename))
200  {
201  projection = model.get();
202  }
203  else
204  {
205  model = 0;
206  }
207  }
208 
209  if(traceDebug())
210  {
212  << MODULE << " DEBUG: testing ossimFormosatModel" << std::endl;
213  }
214 
215  ossimFilename formosatTest = filename;
216  formosatTest = formosatTest.setExtension("geom");
217  if(!formosatTest.exists())
218  {
219  formosatTest = filename.path();
220  formosatTest = formosatTest.dirCat(ossimFilename("METADATA.DIM"));
221  if (formosatTest.exists() == false)
222  {
223  formosatTest = filename.path();
224  formosatTest = formosatTest.dirCat(ossimFilename("metadata.dim"));
225  }
226  }
227  if(formosatTest.exists())
228  {
229  //---
230  // Check the basename of the input file. So we don't create a projection
231  // for ancillary files, icon.jpg amd preview.jpg.
232  //---
233  ossimFilename baseName = filename.file();
234  baseName.downcase();
235 
236  if ( (baseName != "icon.jpg" ) && ( baseName != "preview.jpg" ) )
237  {
240  if(meta->loadXmlFile(formosatTest))
241  {
243  if(!model->getErrorStatus())
244  {
245  projection = model.get();
246 
247  }
248  model = 0;
249  }
250  }
251  }
252 
253  if(traceDebug())
254  {
256  << MODULE << " DEBUG: testing ossimTileMapModel" << std::endl;
257  }
258 
259  if (!projection)
260  {
262  if (model->open(filename))
263  {
264  projection = model.get();
265  }
266  else
267  {
268  model = 0;
269  }
270  }
271 
272  if(traceDebug())
273  {
275  << MODULE << " DEBUG: testing ossimSpot6Model" << std::endl;
276  }
277 
278  // Spot6
279  if ( !projection )
280  {
282  if ( model->open(filename) )
283  {
284  projection = model.get();
285  }
286  else
287  {
288  model = 0;
289  }
290  }
291 
292  //***
293  // ADD_MODEL: (Please leave this comment for the next programmer)
294  //***
295  //if(traceDebug())
296  //{
297  // ossimNotify(ossimNotifyLevel_DEBUG)
298  // << MODULE << " DEBUG: testing MY_NEW_MODEL" << std::endl;
299  //}
300 
301  // MY_NEW_MODEL
302  //if ( !projection )
303  //{
304  // ossimRefPtr<MY_NEW_MODEL> model = new MY_NEW_MODEL();
305  // if ( model->open(filename) )
306  //{
307  // projection = model.get();
308  //}
309  // else
310  // {
311  // model = 0;
312  // }
313  //}
314 
315  return projection.release();
316 }
317 
319  const ossimString& name)const
320 {
321  static const char MODULE[] = "ossimPluginProjectionFactory::createProjection(ossimString& name)";
322 
323  if(traceDebug())
324  {
326  << MODULE << " DEBUG: Entering ...." << std::endl;
327  }
328 
329  // else if (name == STATIC_TYPE_NAME(ossimCosmoSkymedModel))
330  // {
331  // return new ossimCosmoSkymedModel;
332  // }
334  {
335  return new ossimRadarSat2Model();
336  }
337  else if (name == STATIC_TYPE_NAME(ossimTerraSarModel))
338  {
339  return new ossimTerraSarModel();
340  }
341  else if (name == STATIC_TYPE_NAME(ossimErsSarModel))
342  {
343  return new ossimErsSarModel;
344  }
345  else if (name == STATIC_TYPE_NAME(ossimEnvisatAsarModel))
346  {
347  return new ossimEnvisatAsarModel;
348  }
349  else if (name == STATIC_TYPE_NAME(ossimRadarSatModel))
350  {
351  return new ossimRadarSatModel;
352  }
353  else if (name == STATIC_TYPE_NAME(ossimAlosPalsarModel))
354  {
355  return new ossimAlosPalsarModel;
356  }
357  else if (name == STATIC_TYPE_NAME(ossimFormosatModel))
358  {
359  return new ossimFormosatModel;
360  }
361  else if (name == STATIC_TYPE_NAME(ossimTileMapModel))
362  {
363  return new ossimTileMapModel;
364  }
365  else if (name == STATIC_TYPE_NAME(ossimPleiadesModel))
366  {
367  return new ossimPleiadesModel;
368  }
369  else if (name == STATIC_TYPE_NAME(ossimSpot6Model))
370  {
371  return new ossimSpot6Model;
372  }
373 
374  //***
375  // ADD_MODEL: (Please leave this comment for the next programmer)
376  //***
377 // if(name == MY_NEW_MODEL)
378 // return new myNewModel;
379 
380 
381  if(traceDebug())
382  {
384  << MODULE << " DEBUG: Leaving ...." << std::endl;
385  }
386 
387  return 0;
388 }
389 
391  const ossimKeywordlist& kwl, const char* prefix)const
392 {
393  ossimRefPtr<ossimProjection> result = 0;
394  static const char MODULE[] = "ossimPluginProjectionFactory::createProjection(ossimKeywordlist& kwl)";
395 
396  if(traceDebug())
397  {
399  << MODULE << " DEBUG: Start ...." << std::endl;
400  }
401 
402  const char* lookup = kwl.find(prefix, ossimKeywordNames::TYPE_KW);
403  if (lookup)
404  {
405  ossimString type = lookup;
406 
407  if (type == "ossimRadarSat2Model")
408  {
409  result = new ossimRadarSat2Model();
410  if ( !result->loadState(kwl, prefix) )
411  {
412  result = 0;
413  }
414  }
415  else if (type == "ossimTerraSarModel")
416  {
417  result = new ossimTerraSarModel();
418  if ( !result->loadState(kwl, prefix) )
419  {
420  result = 0;
421  }
422  }
423  else if (type == "ossimErsSarModel")
424  {
425  result = new ossimErsSarModel();
426  if ( !result->loadState(kwl, prefix) )
427  {
428  result = 0;
429  }
430  }
431  else if (type == "ossimEnvisatAsarModel")
432  {
433  result = new ossimEnvisatAsarModel();
434  if ( !result->loadState(kwl, prefix) )
435  {
436  result = 0;
437  }
438  }
439  else if (type == "ossimRadarSatModel")
440  {
441  result = new ossimRadarSatModel();
442  if ( !result->loadState(kwl, prefix) )
443  {
444  result = 0;
445  }
446  }
447  else if (type == "ossimAlosPalsarModel")
448  {
449  result = new ossimAlosPalsarModel();
450  if ( !result->loadState(kwl, prefix) )
451  {
452  result = 0;
453  }
454  }
455  else if (type == "ossimFormosatModel")
456  {
457  result = new ossimFormosatModel();
458  if ( !result->loadState(kwl, prefix) )
459  {
460  result = 0;
461  }
462  }
463  else if (type == "ossimTileMapModel")
464  {
465  result = new ossimTileMapModel();
466  if ( !result->loadState(kwl, prefix) )
467  {
468  result = 0;
469  }
470  }
471  else if (type == "ossimPleiadesModel")
472  {
473  result = new ossimPleiadesModel();
474  if ( !result->loadState(kwl, prefix) )
475  {
476  result = 0;
477  }
478  }
479  else if (type == "ossimSpot6Model")
480  {
481  result = new ossimSpot6Model();
482  if ( !result->loadState(kwl, prefix) )
483  {
484  result = 0;
485  }
486  }
487 
488  //***
489  // ADD_MODEL: (Please leave this comment for the next programmer)
490  //***
491 // else if (type == "ossimSpot6Model")
492 // {
493 // result = new ossimSpot6Model();
494 // if ( !result->loadState(kwl, prefix) )
495 // {
496 // result = 0;
497 // }
498 // }
499 
500  }
501 
502  if(traceDebug())
503  {
505  << MODULE << " DEBUG: End ...." << std::endl;
506  }
507 
508  return result.release();
509 }
510 
512  const ossimString& typeName)const
513 {
514  return createProjection(typeName);
515 }
516 
518  const ossimKeywordlist& kwl, const char* prefix)const
519 {
520  return createProjection(kwl, prefix);
521 }
522 
523 
524 void ossimPluginProjectionFactory::getTypeNameList(std::vector<ossimString>& typeList)const
525 {
526  typeList.push_back(STATIC_TYPE_NAME(ossimRadarSatModel));
527  typeList.push_back(STATIC_TYPE_NAME(ossimRadarSat2Model));
528  typeList.push_back(STATIC_TYPE_NAME(ossimTerraSarModel));
529  // result.push_back(STATIC_TYPE_NAME(ossimCosmoSkymedModel));
530  typeList.push_back(STATIC_TYPE_NAME(ossimEnvisatAsarModel));
531  typeList.push_back(STATIC_TYPE_NAME(ossimErsSarModel));
532  typeList.push_back(STATIC_TYPE_NAME(ossimAlosPalsarModel));
533  typeList.push_back(STATIC_TYPE_NAME(ossimFormosatModel));
534  typeList.push_back(STATIC_TYPE_NAME(ossimTileMapModel));
535  typeList.push_back(STATIC_TYPE_NAME(ossimPleiadesModel));
536  typeList.push_back(STATIC_TYPE_NAME(ossimSpot6Model));
537 
538  //***
539  // ADD_MODEL: Please leave this comment for the next programmer. Add above.
540  //***
541  //typeList.push_back(STATIC_TYPE_NAME(MY_NEW_MODEL));
542 }
543 
545 {
546  ossimFilename temp(filename);
547  temp.downcase();
548 
549  ossimString os = temp.beforePos(4);
550 
551  if(temp.ext()=="otb")
552  {
553  return true;
554  }
555  else if(os == "http")
556  {
557  return true;
558  }
559  return false;
560 }
561 
562 } // End: namespace ossimplugins
This class is able to direct localisation and indirect localisation using the AlosPalsar sensor model...
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
This class is able to direct localisation and indirect localisation using the RadarSat sensor model...
This class allows for direct localisation and indirect localisation using the TerraSar sensor model...
bool isTileMap(const ossimFilename &filename) const
static const char * TYPE_KW
#define STATIC_TYPE_NAME(T)
Definition: ossimRtti.h:325
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
static ossimPluginProjectionFactory * instance()
This class is able to direct localisation and indirect localisation using the ErsSar sensor model...
bool exists() const
unsigned int ossim_uint32
T * release()
Definition: ossimRefPtr.h:93
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
virtual ossimProjection * createProjection(const ossimFilename &filename, ossim_uint32 entryIdx) const
takes a filename.
This class is able to direct localisation and indirect localisation using the EnvisatAsar sensor mode...
This class allows for direct localisation and indirect localisation using the RadarSat2 sensor model...
ossimFilename dirCat(const ossimFilename &file) const
ossimString beforePos(std::string::size_type pos) const
bool loadXmlFile(const ossimFilename &file)
virtual ossimObject * createObject(const ossimString &typeName) const
ossimFilename file() const
ossimString ext() const
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
ossimFilename path() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)