Feature/globebrowsing (#281)

* Solve bug related to corrupted texture tiles for certain sizes.

* Regard layer settings when sampling height map.

* Make Tile in to a class instead of a struct.

* Memory aware lru cache. Needs cleanup.

* Clean up and comment.

* Clean up and comment.

* Clean up

* Clean up and comment.

* Fix compilation error on Windows.

* Specify data type explicitly in GDAL xml config files for Utah height maps. Closes #242

* Update the key type for the memory aware lru cache and use a unordered map instead of a map.

* Solve pixel row size bug.

* Solve initialization bug.

* Add cache size as property of the globe browsing module.

* Use memory aware tile cache for text tile provider.

* Log GDAL errors as GHOUL messages

* Add the ability to toggle tile level limiting by available data

* Add ability to toggle GDAL logging

* Add lock guard to memory aware tile cache

* create base class rawtiledatareader that can be extended with different implementations than GDAL.

* Let GdalWrapper take care of global GDAL settings.

* Move iodescription to separate file

* Move some functionality from gdalrawtiledatareader to rawtiledatareader

* Move functionality from gdalrawtiledatareader to rawtiledatareader.

* GDAL is no longer a necessary dependency for the globebrowsing module. However to read tiles, the SimpleRawTileDataReader needs to be implemented. Otherwise GDAL is needed.

* Add ifdef check for GLOBEBROWSING_USE_GDAL

* Implement SimpleRawTileDataReader. Currently can only read pow 2 textures.

* Change ints to unsigned long longs

* Limit number of texture creations per tile provider per frame

* Solve linker error on windows

* Fix Windows build errors

* Fix crash in reading local patches

* Update lodglobe descriptions

* Abstract away overviews in gdal raw tile data reader

* Update Mars and Moon configs.

* Update screenshot script

* Update ghoul version

* Remove use of interaction depth below ellipsoid

* Normalize direction vector

* Use scale for distance swotch

* Go back to use of interaction depth below ellipsoid

* Fix comments on pull request.

* TileProviderByLevel error does not propagate up.

* Comment on mars and moon mod file

* Add model space cut off level as a property

* Update ChunkTile struct

* Minor clean up

* Go back tu constructor for ChunkTile
This commit is contained in:
Kalle Bladin
2017-04-13 10:14:47 +02:00
committed by GitHub
parent 53e2aedd81
commit 8a617ee254
88 changed files with 3895 additions and 1490 deletions
+67
View File
@@ -0,0 +1,67 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___LRU_CACHE___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___LRU_CACHE___H__
#include <list>
#include <unordered_map>
namespace openspace {
namespace globebrowsing {
namespace cache {
/**
* Templated class implementing a Least-Recently-Used Cache.
* <code>KeyType</code> needs to be an enumerable type.
*/
template<typename KeyType, typename ValueType>
class LRUCache {
public:
/**
* \param size is the maximum size of the cache given in number of cached items.
*/
LRUCache(size_t size);
void put(const KeyType& key, const ValueType& value);
void clear();
bool exist(const KeyType& key) const;
ValueType get(const KeyType& key);
size_t size() const;
private:
void clean();
std::list<std::pair<KeyType, ValueType>> _itemList;
std::unordered_map<KeyType, decltype(_itemList.begin())> _itemMap;
size_t _cacheSize;
};
} // namespace cache
} // namespace globebrowsing
} // namespace openspace
#include <modules/globebrowsing/cache/lrucache.inl>
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___LRU_CACHE___H__
+84
View File
@@ -0,0 +1,84 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <ghoul/misc/assert.h>
namespace openspace {
namespace globebrowsing {
namespace cache {
template<typename KeyType, typename ValueType>
LRUCache<KeyType, ValueType>::LRUCache(size_t size)
: _cacheSize(size)
{}
template<typename KeyType, typename ValueType>
void LRUCache<KeyType, ValueType>::clear() {
_itemList.erase(_itemList.begin(), _itemList.end());
_itemMap.erase(_itemMap.begin(), _itemMap.end());
}
template<typename KeyType, typename ValueType>
void LRUCache<KeyType, ValueType>::put(const KeyType& key, const ValueType& value) {
auto it = _itemMap.find(key);
if (it != _itemMap.end()) {
_itemList.erase(it->second);
_itemMap.erase(it);
}
_itemList.push_front(std::make_pair(key, value));
_itemMap.insert(std::make_pair(key, _itemList.begin()));
clean();
}
template<typename KeyType, typename ValueType>
bool LRUCache<KeyType, ValueType>::exist(const KeyType& key) const {
return _itemMap.count(key) > 0;
}
template<typename KeyType, typename ValueType>
ValueType LRUCache<KeyType, ValueType>::get(const KeyType& key) {
//ghoul_assert(exist(key), "Key " << key << " must exist");
auto it = _itemMap.find(key);
// Move list iterator pointing to value
_itemList.splice(_itemList.begin(), _itemList, it->second);
return it->second->second;
}
template<typename KeyType, typename ValueType>
size_t LRUCache<KeyType, ValueType>::size() const {
return _itemMap.size();
}
template<typename KeyType, typename ValueType>
void LRUCache<KeyType, ValueType>::clean() {
while (_itemMap.size() > _cacheSize) {
auto last_it = _itemList.end(); last_it--;
_itemMap.erase(last_it->first);
_itemList.pop_back();
}
}
} // namespace cache
} // namespace globebrowsing
} // namespace openspace
+58
View File
@@ -0,0 +1,58 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___MEMORY_AWARE_CACHEABLE___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___MEMORY_AWARE_CACHEABLE___H__
namespace openspace {
namespace globebrowsing {
namespace cache {
/**
* Base class to be extended by classes that need to be cached and make use of the
* memoryImpact interface. A class extending <code>MemoryAwareCacheable</code> needs to
* know its memory impact at initialization and hence provide the memory impact in its
* constructors. The memory impact can not change during the lifetime of an object that is
* a <code>MemoryAwareCacheable</code>.
*/
class MemoryAwareCacheable {
public:
/**
* \param memoryImpact is the memory impact of the object. Can for example be given
* in kilobytes.
*/
MemoryAwareCacheable(size_t memoryImpact) : _memoryImpact(memoryImpact) {};
~MemoryAwareCacheable() {};
size_t memoryImpact() { return _memoryImpact; };
protected:
size_t _memoryImpact;
};
} // namespace cache
} // namespace globebrowsing
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___MEMORY_AWARE_CACHEABLE___H__
+83
View File
@@ -0,0 +1,83 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___MEMORY_AWARE_LRU_CACHE___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___MEMORY_AWARE_LRU_CACHE___H__
#include <list>
#include <unordered_map>
namespace openspace {
namespace globebrowsing {
namespace cache {
/**
* Least recently used cache that knows about its memory impact. This class is templated
* and the second template argument <code>ValueType</code> needs to have a function
* <code>void memoryImpact()</code> that returns the size of the object given in whatever
* unit is used for size in the creation of the <code>MemoryAwareLRUCache</code>.
* It can for example be given in kilobytes.
* <code>KeyType</code> needs to be a size comparable type.
*/
template<typename KeyType, typename ValueType, typename HasherType>
class MemoryAwareLRUCache {
public:
/**
* \param maximumSize is the maximum size of the <code>MemoryAwareLRUCache</code>
* Once the maximum size is reached, the cache will start removing objects that were
* least recently used. The maximum size can for example be given in kilobytes. It
* must be the same size unit as used by the cached object class
* <code>ValueType</code>.
*/
MemoryAwareLRUCache(size_t maximumSize);
void put(const KeyType& key, const ValueType& value);
void clear();
bool exist(const KeyType& key) const;
ValueType get(const KeyType& key);
size_t size() const;
size_t maximumSize() const;
void setMaximumSize(size_t maximumSize);
private:
void clean();
using Item = std::pair<KeyType, ValueType>;
using Items = std::list<Item>;
Items _itemList;
std::unordered_map<KeyType, decltype(_itemList.begin()), HasherType> _itemMap;
size_t _cacheSize;
size_t _maximumCacheSize;
};
} // namespace cache
} // namespace globebrowsing
} // namespace openspace
#include <modules/globebrowsing/cache/memoryawarelrucache.inl>
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___MEMORY_AWARE_LRU_CACHE___H__
+100
View File
@@ -0,0 +1,100 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <ghoul/misc/assert.h>
namespace openspace {
namespace globebrowsing {
namespace cache {
template<typename KeyType, typename ValueType, typename HasherType>
MemoryAwareLRUCache<KeyType, ValueType, HasherType>::MemoryAwareLRUCache(size_t maximumSize)
: _maximumCacheSize(maximumSize)
, _cacheSize(0)
{}
template<typename KeyType, typename ValueType, typename HasherType>
void MemoryAwareLRUCache<KeyType, ValueType, HasherType>::clear() {
_itemList.clear();
_itemMap.clear();
_cacheSize = 0;
}
template<typename KeyType, typename ValueType, typename HasherType>
void MemoryAwareLRUCache<KeyType, ValueType, HasherType>::put(const KeyType& key, const ValueType& value) {
auto it = _itemMap.find(key);
if (it != _itemMap.end()) {
_cacheSize -= it->second->second.memoryImpact();
_itemList.erase(it->second);
_itemMap.erase(it);
}
_itemList.emplace_front(key, value);
_itemMap.emplace(key, _itemList.begin());
_cacheSize += _itemList.begin()->second.memoryImpact();
clean();
}
template<typename KeyType, typename ValueType, typename HasherType>
bool MemoryAwareLRUCache<KeyType, ValueType, HasherType>::exist(const KeyType& key) const {
return _itemMap.count(key) > 0;
}
template<typename KeyType, typename ValueType, typename HasherType>
ValueType MemoryAwareLRUCache<KeyType, ValueType, HasherType>::get(const KeyType& key) {
//ghoul_assert(exist(key), "Key " << key << " must exist");
auto it = _itemMap.at(key);
// Move list iterator pointing to value
_itemList.splice(_itemList.begin(), _itemList, it);
return it->second;
}
template<typename KeyType, typename ValueType, typename HasherType>
size_t MemoryAwareLRUCache<KeyType, ValueType, HasherType>::size() const {
return _cacheSize;
}
template<typename KeyType, typename ValueType, typename HasherType>
size_t MemoryAwareLRUCache<KeyType, ValueType, HasherType>::maximumSize() const {
return _maximumCacheSize;
}
template<typename KeyType, typename ValueType, typename HasherType>
void MemoryAwareLRUCache<KeyType, ValueType, HasherType>::setMaximumSize(size_t maximumSize) {
_maximumCacheSize = maximumSize;
}
template<typename KeyType, typename ValueType, typename HasherType>
void MemoryAwareLRUCache<KeyType, ValueType, HasherType>::clean() {
while (_cacheSize > _maximumCacheSize) {
auto last_it = _itemList.end();
last_it--;
_itemMap.erase(last_it->first);
_cacheSize -= last_it->second.memoryImpact();
_itemList.pop_back();
}
}
} // namespace cache
} // namespace globebrowsing
} // namespace openspace
+84
View File
@@ -0,0 +1,84 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/globebrowsing/cache/memoryawaretilecache.h>
#include <ghoul/ghoul.h>
#include <ghoul/logging/consolelog.h>
namespace openspace {
namespace globebrowsing {
namespace cache {
MemoryAwareTileCache* MemoryAwareTileCache::_singleton = nullptr;
std::mutex MemoryAwareTileCache::_mutexLock;
void MemoryAwareTileCache::create(size_t cacheSize) {
std::lock_guard<std::mutex> guard(_mutexLock);
_singleton = new MemoryAwareTileCache(cacheSize);
}
void MemoryAwareTileCache::destroy() {
std::lock_guard<std::mutex> guard(_mutexLock);
delete _singleton;
}
MemoryAwareTileCache& MemoryAwareTileCache::ref() {
std::lock_guard<std::mutex> guard(_mutexLock);
ghoul_assert(_singleton, "MemoryAwareTileCache not created");
return *_singleton;
}
void MemoryAwareTileCache::clear() {
std::lock_guard<std::mutex> guard(_mutexLock);
_tileCache.clear();
}
bool MemoryAwareTileCache::exist(ProviderTileKey key) const {
std::lock_guard<std::mutex> guard(_mutexLock);
return _tileCache.exist(key);
}
Tile MemoryAwareTileCache::get(ProviderTileKey key) {
std::lock_guard<std::mutex> guard(_mutexLock);
return _tileCache.get(key);
}
void MemoryAwareTileCache::put(ProviderTileKey key, Tile tile) {
std::lock_guard<std::mutex> guard(_mutexLock);
_tileCache.put(key, tile);
}
void MemoryAwareTileCache::setMaximumSize(size_t maximumSize) {
std::lock_guard<std::mutex> guard(_mutexLock);
_tileCache.setMaximumSize(maximumSize);
}
MemoryAwareTileCache::MemoryAwareTileCache(size_t cacheSize)
: _tileCache(cacheSize) {}
} // namespace cache
} // namespace globebrowsing
} // namespace openspace
+113
View File
@@ -0,0 +1,113 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___MEMORY_AWARE_TILE_CACHE___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___MEMORY_AWARE_TILE_CACHE___H__
#include <modules/globebrowsing/tile/tile.h>
#include <modules/globebrowsing/tile/tileindex.h>
#include <modules/globebrowsing/cache/memoryawarelrucache.h>
#include <memory>
#include <mutex>
namespace openspace {
namespace globebrowsing {
namespace cache {
struct ProviderTileKey {
TileIndex tileIndex;
unsigned int providerID;
bool operator==(const ProviderTileKey& r) const {
return (providerID == r.providerID) &&
(tileIndex == r.tileIndex);
}
};
struct ProviderTileHasher {
/**
Creates a hash which can be used as key in hash maps.
First set the bits to be unique for all tiles.
+-------+------------+-------+------------+
| USAGE | BIT RANGE | #BITS | MAX VALUE |
+-------+------------+-------+------------+
| level | 0 - 5 | 5 | 31 |
| x | 5 - 35 | 30 | 1073741824 |
| y | 35 - 64 | 29 | 536870912 |
+-------+------------+-------+------------+
Bits are then shifted depending on the tile provider used.
*/
unsigned long long operator()(const ProviderTileKey& t) const {
unsigned long long key = 0;
key |= static_cast<unsigned long long>(t.tileIndex.level);
key |= static_cast<unsigned long long>(t.tileIndex.x << 5);
key |= static_cast<unsigned long long>(t.tileIndex.y << 35);
// Now the key is unique for all tiles, however not for all tile providers.
// Add to the key depending on the tile provider to avoid some hash collisions.
// (All hash collisions can not be avoided due to the limit in 64 bit for the
// hash key)
// Idea: make some offset in the place of the bits for the x value. Lesser chance
// of having different x-value than having different tile provider ids.
key += static_cast<unsigned long long>(t.providerID << 25);
return key;
}
};
/**
* Singleton class used to cache tiles for all <code>CachingTileProvider</code>s.
*/
class MemoryAwareTileCache {
public:
static void create(size_t cacheSize);
static void destroy();
void clear();
bool exist(ProviderTileKey key) const;
Tile get(ProviderTileKey key);
void put(ProviderTileKey key, Tile tile);
void setMaximumSize(size_t maximumSize);
static MemoryAwareTileCache& ref();
private:
/**
* \param cacheSize is the cache size given in bytes.
*/
MemoryAwareTileCache(size_t cacheSize);
~MemoryAwareTileCache() = default;
static MemoryAwareTileCache* _singleton;
MemoryAwareLRUCache<ProviderTileKey, Tile, ProviderTileHasher> _tileCache;
static std::mutex _mutexLock;
};
} // namespace cache
} // namespace globebrowsing
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___MEMORY_AWARE_TILE_CACHE___H__