OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimElevationCellDatabase.cpp
Go to the documentation of this file.
2 
3 RTTI_DEF1(ossimElevationCellDatabase, "ossimElevationCellDatabase", ossimElevationDatabase);
4 
5 void ossimElevationCellDatabase::getOpenCellList(std::vector<ossimFilename>& list) const
6 {
7  CellMap::const_iterator iter = m_cacheMap.begin();
8 
9  while(iter!=m_cacheMap.end())
10  {
11  if ( iter->second->m_handler.valid() )
12  {
13  list.push_back(iter->second->m_handler->getFilename());
14  }
15  ++iter;
16  }
17 
18 }
19 
21  const ossim_float64& minLon,
22  const ossim_float64& maxLat,
23  const ossim_float64& maxLon,
24  std::vector<ossimFilename>& cells,
25  ossim_uint32 maxNumberOfCells )
26 {
27  const ossim_float64 SEARCH_SPACING = 0.1;
28  ossimGpt gpt(0.0, 0.0, 0.0);
29  ossimFilename f;
30  ossim_uint32 limitNumberOfCells = maxNumberOfCells>0?maxNumberOfCells:999999999;
31  // Latitude loop:
32  ossim_float64 lat = minLat;
33  while ( (lat <= maxLat) &&(cells.size() < limitNumberOfCells))
34  {
35  gpt.lat = lat;
36 
37  // Longitude loop:
38  ossim_float64 lon = minLon;
39  while ( (lon <= maxLon ) &&(cells.size()< limitNumberOfCells))
40  {
41  gpt.lon = lon;
42 
44  if ( h.valid() )
45  {
46  // Get the file name:
47  f = h->getFilename();
48 
49  if ( f.size() )
50  {
51  // See if it's already in the list, i.e. duplicate:
52  std::vector<ossimFilename>::const_iterator i = cells.begin();
53  while ( i != cells.end() )
54  {
55  if ( f == (*i) )
56  {
57  break;
58  }
59  ++i;
60  }
61 
62  if ( i == cells.end() )
63  {
64  // Add it to the list:
65  cells.push_back( f );
66  }
67  }
68  }
69 
70  if ( lon < maxLon )
71  {
72  lon = ossim::min<ossim_float64>( (lon+SEARCH_SPACING), maxLon );
73  }
74  else
75  {
76  break;
77  }
78 
79  } // Matches: while ( lon <= maxLon )
80 
81  if ( lat < maxLat )
82  {
83  lat = ossim::min<ossim_float64>( (lat+SEARCH_SPACING), maxLat );
84  }
85  else
86  {
87  break;
88  }
89 
90  } // Matches: while ( lat <= maxLat )
91 
92 } // End: ossimElevationCellDatabase::getCellsForBounds( ... )
93 
94 /*
95  * New code caches null handlers so that createCell() is not called
96  * unnecessarily. drb - 20170509
97  */
98 #if 1
100  const ossimGpt& gpt)
101 {
103 
104  ossim_uint64 id = createId(gpt);
105 
106  m_cacheMapMutex.lock();
107 
108  CellMap::iterator iter = m_cacheMap.find(id);
109  if(iter != m_cacheMap.end())
110  {
111  iter->second->updateTimestamp();
112  result = iter->second->m_handler.get();
113  }
114  else
115  {
116  m_cacheMapMutex.unlock();
117 
118  result = createCell(gpt);
119 
120  m_cacheMapMutex.lock();
121 
122  //---
123  // Code speed up:
124  // Add it to the cache even if it's not valid so this database will not
125  // call createCell(...) again.
126  //---
127  m_cacheMap.insert(std::make_pair(id, new CellInfo(id, result.get())));
128 
129  // Check the map size and purge cells if needed.
130  if(m_cacheMap.size() > m_maxOpenCells)
131  {
133  }
134  }
135 
136  m_cacheMapMutex.unlock();
137 
138  return result;
139 }
140 #else
142 {
144  ossim_uint64 id = createId(gpt);
145 
146  {
147  std::lock_guard<std::mutex> lock(m_cacheMapMutex);
148  CellMap::iterator iter = m_cacheMap.find(id);
149  if(iter != m_cacheMap.end())
150  {
151  iter->second->updateTimestamp();
152  result = iter->second->m_handler.get();
153 
154  return result.get();
155  }
156  }
157 
158  result = createCell(gpt);
159 
160  {
161  std::lock_guard<std::mutex> lock(m_cacheMapMutex);
162  if(result.valid())
163  {
164  m_cacheMap.insert(std::make_pair(id, new CellInfo(id, result.get())));
165 
166  // Check the map size and purge cells if needed.
167  if(m_cacheMap.size() > m_maxOpenCells)
168  {
170  }
171  }
172  }
173 
174  return result;
175 }
176 #endif
177 
178 bool ossimElevationCellDatabase::loadState(const ossimKeywordlist& kwl, const char* prefix)
179 {
180  ossimString minOpenCells = kwl.find(prefix, "min_open_cells");
181  ossimString maxOpenCells = kwl.find(prefix, "max_open_cells");
182  if(!minOpenCells.empty()&&
183  !maxOpenCells.empty())
184  {
185  m_minOpenCells = minOpenCells.toUInt32();
186  m_maxOpenCells = maxOpenCells.toUInt32();
188  {
189  std::swap(m_minOpenCells, m_maxOpenCells);
190  }
191  }
192  ossimString memoryMapCellsFlag = kwl.find(prefix, "memory_map_cells");
193  if(!memoryMapCellsFlag.empty())
194  {
195  m_memoryMapCellsFlag = memoryMapCellsFlag.toBool();
196  }
197  return ossimElevationDatabase::loadState(kwl, prefix);
198 }
199 
200 bool ossimElevationCellDatabase::saveState(ossimKeywordlist& kwl, const char* prefix)const
201 {
202  kwl.add(prefix, "memory_map_cells", m_memoryMapCellsFlag, true);
203  kwl.add(prefix, "min_open_cells", m_minOpenCells, true);
204  kwl.add(prefix, "max_open_cells", m_maxOpenCells, true);
205 
206  if(m_geoid.valid())
207  {
208  kwl.add(prefix, "geoid.type", m_geoid->getShortName(), true);
209  }
210 
211  return ossimElevationDatabase::saveState(kwl, prefix);
212 }
213 
215 {
216  ossimKeywordlist kwl;
217  saveState(kwl);
218  out << "\nossimElevationCellDatabase @ "<< (ossim_uint64) this << kwl << ends;
219  return out;
220 }
221 
222 
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual ossimRefPtr< ossimElevCellHandler > createCell(const ossimGpt &)
virtual const ossimFilename & getFilename() const
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
ossim_uint32 toUInt32() const
virtual ossimString getShortName() const
Definition: ossimObject.cpp:48
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
RTTI_DEF1(ossimElevationCellDatabase, "ossimElevationCellDatabase", ossimElevationDatabase)
virtual ossimRefPtr< ossimElevCellHandler > getOrCreateCellHandler(const ossimGpt &gpt)
ossim_float64 lon
Definition: ossimGpt.h:266
ossimRefPtr< ossimGeoid > m_geoid
std::string::size_type size() const
Definition: ossimString.h:405
bool toBool() const
String to numeric methods.
std::string::iterator begin()
Definition: ossimString.h:420
unsigned long long ossim_uint64
unsigned int ossim_uint32
virtual void getOpenCellList(std::vector< ossimFilename > &list) const
virtual ossim_uint64 createId(const ossimGpt &) const
virtual std::ostream & print(std::ostream &out) const
Outputs theErrorStatus as an ossimErrorCode and an ossimString.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
bool empty() const
Definition: ossimString.h:411
void getCellsForBounds(const ossim_float64 &minLat, const ossim_float64 &minLon, const ossim_float64 &maxLat, const ossim_float64 &maxLon, std::vector< ossimFilename > &cells, ossim_uint32 maxNumberOfCells=0)
Gets a list of elevation cells needed to cover bounding box.
ossim_float64 lat
Definition: ossimGpt.h:265
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
ossim_float64 min< ossim_float64 >(ossim_float64 a, ossim_float64 b)
Definition: ossimCommon.h:223