OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGeoidManager.cpp
Go to the documentation of this file.
1 //*****************************************************************************
2 // FILE: ossimGeoidManager.cpp
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // AUTHOR: Oscar Kramer
7 //
8 // DESCRIPTION: Contains implementation of class ossimGeoidManager
9 //
10 // LIMITATIONS: None.
11 //
12 //*****************************************************************************
13 // $Id: ossimGeoidManager.cpp 22906 2014-09-30 17:28:52Z dburken $
14 
15 
17 
18 #include <ossim/base/ossimCommon.h>
29 //***
30 // Define Trace flags for use within this file:
31 //***
32 #include <ossim/base/ossimTrace.h>
33 static ossimTrace traceExec ("ossimGeoidManager:exec");
34 static ossimTrace traceDebug ("ossimGeoidManager:debug");
35 
36 RTTI_DEF1(ossimGeoidManager, "ossimGeoidManager", ossimGeoid);
37 
38 //ossimGeoidManager* ossimGeoidManager::theInstance = 0;
39 
40 //*****************************************************************************
41 // CONSTRUCTOR: ossimGeoidManager
42 //
43 //*****************************************************************************
45 {
46  // theInstance = this;
48 }
49 
50 //*****************************************************************************
51 // DESTRUCTOR: ~ossimGeoidManager
52 //
53 //*****************************************************************************
55 {
56 // vector<ossimGeoid*>::iterator g = theGeoidList.begin();
57 // while (g != theGeoidList.end())
58 // {
59 // delete *g;
60 // ++g;
61 // }
62  clear();
63 }
64 
65 //*****************************************************************************
66 // METHOD: ossimGeoidManager::clear()
67 //
68 //*****************************************************************************
70 {
71  theGeoidList.clear();
72 }
73 
74 //*****************************************************************************
75 // METHOD: ossimGeoidManager::instance()
76 //
77 //*****************************************************************************
79 {
80  static ossimGeoidManager inst;
81 // if (!theInstance)
82 // {
83 // theInstance = new ossimGeoidManager();
84 // }
85 
86  //return theInstance;
87  return &inst;
88 }
89 
90 //*****************************************************************************
91 // METHOD: ossimElevManager::addGeoidSource
92 //
93 //*****************************************************************************
95 {
96  if(!toFrontFlag)
97  {
98  theGeoidList.push_back(geoid);
99  }
100  else
101  {
102  theGeoidList.insert(theGeoidList.begin(), geoid);
103  }
104 }
105 
107  const char* /* prefix */ ) const
108 {
109  return true;
110 }
111 
112 //*****************************************************************************
113 // METHOD: ossimGeoidManager::loadState()
114 //
115 //*****************************************************************************
117  const char* prefix)
118 {
119  static const char MODULE[] = "ossimGeoidManager::loadState()";
120 
121  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG)
122  << "DEBUG: " << MODULE << ", entering...\n";
123 
124  //---
125  // Look for geoid sources:
126  // Note: the ossimInit::initializeElevation() does not pass a prefix to us
127  // as it should...
128  //---
129  std::string geoidMgrPrefix = prefix ? prefix : "geoid.manager.";
130 
131  ossimString regExpression = ossimString("^(") + geoidMgrPrefix.c_str() +
132  "geoid_source[0-9]+.)";
133 
134  vector<ossimString> keys = kwl.getSubstringKeyList( regExpression );
135  if ( keys.size() )
136  {
137  for ( ossim_uint32 idx = 0; idx < keys.size(); ++idx )
138  {
139  std::string newPrefix = keys[idx];
140 
141  // See if enable flag is set to false.
142  bool enabled = true;
143  std::string key = ossimKeywordNames::ENABLED_KW;
144  std::string value = kwl.findKey( newPrefix, key );
145  if ( value.size() )
146  {
147  enabled = ossimString( value ).toBool();
148  }
149 
150  if ( enabled )
151  {
152  // Get the type:
154  value = kwl.findKey( newPrefix, key );
155 
156  if ( (value == "geoid_image" ) || ( value == "ossimGeoidImage" ) )
157  {
159  if ( geoid->loadState( kwl, newPrefix.c_str() ) )
160  {
161  if (traceDebug())
162  {
164  << "DEBUG: " << MODULE
165  << "\nAdded geoid: " << geoid->getShortName() << "\n";
166  }
167  addGeoid(geoid.get());
168  }
169  }
170  }
171  }
172  }
173 
174  // End of "geoid_sources" block.
175 
176  // Look for the ngs geoid directories
177  const char* lookup = kwl.find(prefix, "geoid_99_directory");
178  ossimByteOrder geoidNgsByteOrder = OSSIM_LITTLE_ENDIAN;
179  const char* byteOrder = kwl.find(prefix, "geoid_99_directory.byte_order");
180  if (!lookup)
181  {
182  lookup = kwl.find(prefix, "geoid_ngs_directory");
183  byteOrder = kwl.find(prefix, "geoid_ngs_directory.byte_order");
184  }
185  if(byteOrder)
186  {
187  if(ossimString(byteOrder).contains("little"))
188  {
189  geoidNgsByteOrder = OSSIM_LITTLE_ENDIAN;
190  }
191  else
192  {
193  geoidNgsByteOrder = OSSIM_BIG_ENDIAN;
194  }
195  }
196  if(lookup)
197  {
198  ossimFilename f = lookup;
199  if (f.isDir())
200  {
201  ossimRefPtr<ossimGeoid> geoid = new ossimGeoidNgs(f, geoidNgsByteOrder);
202 
204  {
205  if (traceDebug())
206  {
208  << "DEBUG: " << MODULE
209  << "\nAdded geoid dir: " << f.c_str() << "\n";
210  }
211  addGeoid(geoid.get());
212  }
213  else
214  {
215  geoid = 0;
216  }
217  }
218  }
219 
221  geoidGrid1996 = geoidGrid1996.dirCat("geoids");
222  geoidGrid1996 = geoidGrid1996.dirCat("geoid1996");
223  geoidGrid1996 = geoidGrid1996.dirCat("egm96.grd");
224 
225  if(!geoidGrid1996.exists())
226  {
228  geoidGrid1996 = geoidGrid1996.dirCat("geoids");
229  geoidGrid1996 = geoidGrid1996.dirCat("geoid1996");
230  geoidGrid1996 = geoidGrid1996.dirCat("egm96.grd");
231  }
232 
233  if( geoidGrid1996.exists() )
234  {
235  ossimRefPtr<ossimGeoid> geoid = new ossimGeoidEgm96(geoidGrid1996);
237  {
238  if (traceDebug())
239  {
241  << "DEBUG: " << MODULE
242  << "\nAdded geoid egm 96: " << geoidGrid1996.c_str()
243  << "\n";
244  }
245  addGeoid(geoid.get());
246  }
247  else
248  {
249  geoid = 0;
250  }
251  }
252  else
253  {
254  // Look for the geoid Earth Gravity Model (EGM) 96 directory.
255  lookup = kwl.find(prefix, "geoid_egm_96_grid");
256  if (lookup)
257  {
258  ossimFilename f = lookup;
259  if (f.isDir() || f.isFile())
260  {
262 
264  {
265  if (traceDebug())
266  {
268  << "DEBUG: " << MODULE
269  << "\nAdded geoid egm 96: " << f.c_str()
270  << "\n";
271  }
272 
273  addGeoid(geoid.get());
274  }
275  else
276  {
277  geoid = 0;
278  }
279  }
280  }
281  }
282  if (traceExec())
283  {
285  << "DEBUG: " << MODULE << ", returning...\n";
286  }
287 
288  return true;
289 }
290 
291 
292 //*****************************************************************************
293 // METHOD: ossimGeoidManager::open()
294 //
295 //*****************************************************************************
297 {
298  std::vector<ossimRefPtr<ossimGeoid> >::iterator g = theGeoidList.begin();
299  bool status = true;
300  while (g != theGeoidList.end())
301  {
302  status &= (*g)->open(dir, byteOrder);
303  ++g;
304  }
305 
306  return status;
307 }
308 
309 //*****************************************************************************
310 // METHOD: ossimGeoidManager::open()
311 //
312 //*****************************************************************************
314 {
315  double offset = ossim::nan();
316  std::vector<ossimRefPtr<ossimGeoid> >::iterator geoid =
317  theGeoidList.begin();
318 
319  while ( ossim::isnan(offset) && (geoid != theGeoidList.end()))
320  {
321  offset = ((*geoid))->offsetFromEllipsoid(gpt);
322  ++geoid;
323  }
324 
325  return offset;
326 }
327 
328 ossimGeoid* ossimGeoidManager::findGeoidByShortName(const ossimString& shortName, bool caseSensitive)
329 {
330  ossim_uint32 idx=0;
331  ossimString testString = shortName;
332  if(shortName == "identity")
333  {
334  return theIdentityGeoid.get();
335  }
336  if(!caseSensitive)
337  {
338  testString = testString.downcase();
339  }
340  for(idx = 0; idx < theGeoidList.size(); ++idx)
341  {
342  if(!caseSensitive)
343  {
344  if(theGeoidList[idx]->getShortName().downcase() == testString)
345  {
346  return theGeoidList[idx].get();
347  }
348  }
349  else
350  {
351  if(theGeoidList[idx]->getShortName() == testString)
352  {
353  return theGeoidList[idx].get();
354  }
355  }
356  }
357  return 0;
358 }
Represents serializable keyword/value map.
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
static const ossimErrorCode OSSIM_OK
ossimFilename getInstalledOssimSupportDir() const
const char * find(const char *key) const
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of the object to a keyword list.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
ossimRefPtr< ossimGeoid > theIdentityGeoid
bool isDir() const
virtual ossimString getShortName() const
Definition: ossimObject.cpp:48
static const char * TYPE_KW
Generic geoid source which uses a image handler for reading the grid.
bool exists() const
ossimGeoid * findGeoidByShortName(const ossimString &shortName, bool caseSensitive=true)
bool toBool() const
String to numeric methods.
unsigned int ossim_uint32
static ossimGeoidManager * instance()
Implements singelton pattern:
bool isFile() const
RTTI_DEF1(ossimGeoidManager, "ossimGeoidManager", ossimGeoid)
ossimByteOrder
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
virtual void addGeoid(ossimRefPtr< ossimGeoid > geoid, bool toFrontFlag=false)
Permits adding additional geoids to the list:
static const char * ENABLED_KW
Identity geoid.
Definition: ossimGeoid.h:48
std::vector< ossimString > getSubstringKeyList(const ossimString &regularExpression) const
return status
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
static ossimEnvironmentUtility * instance()
virtual ossimErrorCode getErrorStatus() const
virtual void clear()
Permits to clear the GeoidList.
ossimFilename dirCat(const ossimFilename &file) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
virtual bool open(const ossimFilename &dir, ossimByteOrder byteOrder)
Permits initialization of geoids from directory name.
std::vector< ossimRefPtr< ossimGeoid > > theGeoidList
ossimFilename getUserOssimSupportDir() const
virtual double offsetFromEllipsoid(const ossimGpt &gpt)
ossimGeoidManager()
Private constructor.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91