mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-21 20:39:08 -06:00
Clean up in tile providers
This commit is contained in:
@@ -23,9 +23,7 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tileprovider/cachingtileprovider.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
@@ -34,9 +32,6 @@
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "CachingTileProvider";
|
||||
|
||||
@@ -47,18 +42,15 @@ namespace {
|
||||
const std::string KeyFlushInterval = "FlushInterval";
|
||||
}
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
CachingTileProvider::CachingTileProvider(const ghoul::Dictionary& dictionary)
|
||||
: _framesSinceLastRequestFlush(0)
|
||||
{
|
||||
//
|
||||
std::string name = "Name unspecified";
|
||||
dictionary.getValue("Name", name);
|
||||
std::string _loggerCat = "CachingTileProvider : " + name;
|
||||
|
||||
|
||||
// 1. Get required Keys
|
||||
std::string filePath;
|
||||
if (!dictionary.getValue<std::string>(KeyFilePath, filePath)) {
|
||||
@@ -87,22 +79,26 @@ namespace openspace {
|
||||
LDEBUG("Default cacheSize overridden: " << cacheSize);
|
||||
}
|
||||
if (dictionary.getValue<double>(KeyFlushInterval, framesUntilRequestFlush)) {
|
||||
LDEBUG("Default framesUntilRequestFlush overridden: " << framesUntilRequestFlush);
|
||||
LDEBUG("Default framesUntilRequestFlush overridden: " <<
|
||||
framesUntilRequestFlush);
|
||||
}
|
||||
|
||||
|
||||
// Initialize instance variables
|
||||
auto tileDataset = std::make_shared<TileDataset>(filePath, config);
|
||||
|
||||
// only one thread per provider supported atm
|
||||
// (GDAL does not handle multiple threads for a single dataset very well
|
||||
// currently)
|
||||
auto threadPool = std::make_shared<ThreadPool>(1);
|
||||
|
||||
_asyncTextureDataProvider = std::make_shared<AsyncTileDataProvider>(tileDataset, threadPool);
|
||||
_asyncTextureDataProvider = std::make_shared<AsyncTileDataProvider>(
|
||||
tileDataset, threadPool);
|
||||
_tileCache = std::make_shared<TileCache>(cacheSize);
|
||||
_framesUntilRequestFlush = framesUntilRequestFlush;
|
||||
}
|
||||
|
||||
CachingTileProvider::CachingTileProvider(std::shared_ptr<AsyncTileDataProvider> tileReader,
|
||||
CachingTileProvider::CachingTileProvider(
|
||||
std::shared_ptr<AsyncTileDataProvider> tileReader,
|
||||
std::shared_ptr<TileCache> tileCache,
|
||||
int framesUntilFlushRequestQueue)
|
||||
: _asyncTextureDataProvider(tileReader)
|
||||
@@ -113,12 +109,10 @@ namespace openspace {
|
||||
|
||||
}
|
||||
|
||||
|
||||
CachingTileProvider::~CachingTileProvider(){
|
||||
clearRequestQueue();
|
||||
}
|
||||
|
||||
|
||||
void CachingTileProvider::update() {
|
||||
initTexturesFromLoadedData();
|
||||
if (_framesSinceLastRequestFlush++ > _framesUntilRequestFlush) {
|
||||
@@ -138,7 +132,6 @@ namespace openspace {
|
||||
Tile CachingTileProvider::getTile(const ChunkIndex& chunkIndex) {
|
||||
Tile tile = Tile::TileUnavailable;
|
||||
|
||||
|
||||
if (chunkIndex.level > maxLevel()) {
|
||||
tile.status = Tile::Status::OutOfRange;
|
||||
return tile;
|
||||
@@ -163,7 +156,6 @@ namespace openspace {
|
||||
return _defaultTile;
|
||||
}
|
||||
|
||||
|
||||
void CachingTileProvider::initTexturesFromLoadedData() {
|
||||
auto readyTileIOResults = _asyncTextureDataProvider->getTileIOResults();
|
||||
for(auto tileIOResult : readyTileIOResults){
|
||||
@@ -197,15 +189,17 @@ namespace openspace {
|
||||
return _asyncTextureDataProvider->getTextureDataProvider()->getDepthTransform();
|
||||
}
|
||||
|
||||
|
||||
Tile CachingTileProvider::createTile(std::shared_ptr<TileIOResult> tileIOResult) {
|
||||
if (tileIOResult->error != CE_None) {
|
||||
return{ nullptr, nullptr, Tile::Status::IOError };
|
||||
}
|
||||
|
||||
ChunkHashKey key = tileIOResult->chunkIndex.hashKey();
|
||||
TileDataLayout dataLayout = _asyncTextureDataProvider->getTextureDataProvider()->getDataLayout();
|
||||
Texture* texturePtr = new Texture(
|
||||
TileDataLayout dataLayout =
|
||||
_asyncTextureDataProvider->getTextureDataProvider()->getDataLayout();
|
||||
|
||||
// The texture should take ownership of the data
|
||||
std::shared_ptr<Texture> texture = std::make_shared<Texture>(
|
||||
tileIOResult->imageData,
|
||||
tileIOResult->dimensions,
|
||||
dataLayout.textureFormat.ghoulFormat,
|
||||
@@ -213,11 +207,9 @@ namespace openspace {
|
||||
dataLayout.glType,
|
||||
Texture::FilterMode::Linear,
|
||||
Texture::WrappingMode::ClampToEdge);
|
||||
|
||||
// The texture should take ownership of the data
|
||||
std::shared_ptr<Texture> texture = std::shared_ptr<Texture>(texturePtr);
|
||||
|
||||
texture->uploadTexture();
|
||||
|
||||
// AnisotropicMipMap must be set after texture is uploaded. Why?!
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
|
||||
@@ -230,6 +222,4 @@ namespace openspace {
|
||||
return tile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#ifndef __CACHING_TILE_PROVIDER_H__
|
||||
#define __CACHING_TILE_PROVIDER_H__
|
||||
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h> // absPath
|
||||
#include <ghoul/opengl/texture.h>
|
||||
@@ -35,12 +34,10 @@
|
||||
#include <modules/globebrowsing/tile/asynctilereader.h>
|
||||
#include <modules/globebrowsing/other/lrucache.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TILE PROVIDER //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
/**
|
||||
@@ -73,10 +70,8 @@ namespace openspace {
|
||||
virtual void reset();
|
||||
virtual int maxLevel();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// Helper functions //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -101,7 +96,6 @@ namespace openspace {
|
||||
*/
|
||||
void clearRequestQueue();
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// Member variables //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -117,7 +111,4 @@ namespace openspace {
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // __CACHING_TILE_PROVIDER_H__
|
||||
@@ -25,7 +25,6 @@
|
||||
#ifndef __TILE_PROVIDER_H__
|
||||
#define __TILE_PROVIDER_H__
|
||||
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h> // absPath
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
@@ -34,12 +33,10 @@
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
#include <modules/globebrowsing/other/lrucache.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TILE PROVIDER //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
using namespace ghoul::opengl;
|
||||
@@ -73,13 +70,11 @@ namespace openspace {
|
||||
TileProvider(const ghoul::Dictionary& dictionary);
|
||||
|
||||
/**
|
||||
* Virtual constructor that subclasses should override to do
|
||||
* Virtual destructor that subclasses should override to do
|
||||
* clean up.
|
||||
*/
|
||||
virtual ~TileProvider() { }
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method for querying tiles, given a specified <code>ChunkIndex</code>.
|
||||
*
|
||||
@@ -108,16 +103,16 @@ namespace openspace {
|
||||
*/
|
||||
virtual Tile getDefaultTile() = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the status of the <code>Tile</code> to be returned
|
||||
* if the <code>getTile</code> were to be invoked by this point
|
||||
* in time.
|
||||
* Returns the status of a <code>Tile</code>. The <code>Tile::Status</code>
|
||||
* corresponds the <code>Tile</code> that would be returned
|
||||
* if the function <code>getTile</code> would be invoked with the same
|
||||
* <code>ChunkIndex</code> argument at this point in time.
|
||||
*/
|
||||
virtual Tile::Status getTileStatus(const ChunkIndex& index) = 0;
|
||||
|
||||
/**
|
||||
* Get the associated depth transform for this TileProviders
|
||||
* Get the associated depth transform for this TileProvider.
|
||||
* This is necessary for TileProviders serving height map
|
||||
* data, in order to correcly map pixel values to meters.
|
||||
*/
|
||||
@@ -125,7 +120,7 @@ namespace openspace {
|
||||
|
||||
/**
|
||||
* This method should be called once per frame. Here, TileProviders
|
||||
* are given the opportunity to update internal state.
|
||||
* are given the opportunity to update their internal state.
|
||||
*/
|
||||
virtual void update() = 0;
|
||||
|
||||
@@ -143,10 +138,8 @@ namespace openspace {
|
||||
virtual int maxLevel() = 0;
|
||||
};
|
||||
|
||||
|
||||
typedef LRUCache<ChunkHashKey, Tile> TileCache;
|
||||
|
||||
|
||||
struct TileProviderInitData {
|
||||
int minimumPixelSize;
|
||||
int threads;
|
||||
@@ -157,7 +150,4 @@ namespace openspace {
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // __TILE_PROVIDER_H__
|
||||
Reference in New Issue
Block a user