mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 11:09:37 -06:00
Factored out async reading from tile data provision, creating an endpoint for future disk caching of tile
This commit is contained in:
@@ -51,7 +51,8 @@ set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/distanceswitch.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/patchcoverageprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/texturedataprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tiledataset.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/asynctilereader.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.h
|
||||
@@ -87,7 +88,8 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/distanceswitch.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/patchcoverageprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/texturedataprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tiledataset.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/asynctilereader.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.cpp
|
||||
|
||||
113
modules/globebrowsing/other/asynctexturedataprovider.cpp
Normal file
113
modules/globebrowsing/other/asynctexturedataprovider.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/logging/logmanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h> // abspath
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <modules/globebrowsing/other/asynctexturedataprovider.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
#include <modules/globebrowsing/geodetics/angle.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "AsyncTextureDataProvider";
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
AsyncTileDataProvider::AsyncTileDataProvider(const std::string& filename, int minNumPixels, ThreadPool& pool)
|
||||
: _textureDataProvider(std::shared_ptr<TileDataset>(new TileDataset(filename, minNumPixels)))
|
||||
, _concurrentJobManager(pool)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AsyncTileDataProvider::AsyncTileDataProvider(
|
||||
std::shared_ptr<TileDataset> textureDataProvider,
|
||||
ThreadPool& pool)
|
||||
: _textureDataProvider(textureDataProvider)
|
||||
, _concurrentJobManager(pool)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AsyncTileDataProvider::~AsyncTileDataProvider() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<TileDataset> AsyncTileDataProvider::getTextureDataProvider() const {
|
||||
return _textureDataProvider;
|
||||
}
|
||||
|
||||
bool AsyncTileDataProvider::enqueueTextureData(const ChunkIndex& chunkIndex) {
|
||||
if (satisfiesEnqueueCriteria(chunkIndex)) {
|
||||
std::shared_ptr<TileLoadJob> job = std::shared_ptr<TileLoadJob>(
|
||||
new TileLoadJob(_textureDataProvider, chunkIndex));
|
||||
|
||||
_concurrentJobManager.enqueueJob(job);
|
||||
_enqueuedTileRequests[chunkIndex.hashKey()] = chunkIndex;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AsyncTileDataProvider::hasLoadedTextureData() const{
|
||||
return _concurrentJobManager.numFinishedJobs() > 0;
|
||||
}
|
||||
|
||||
std::shared_ptr<TileIOResult> AsyncTileDataProvider::nextTileIOResult() {
|
||||
auto tileIOResult = _concurrentJobManager.popFinishedJob()->product();
|
||||
HashKey key = tileIOResult->rawTileData->chunkIndex.hashKey();
|
||||
if (_enqueuedTileRequests.find(key) != _enqueuedTileRequests.end()) {
|
||||
_enqueuedTileRequests.erase(key);
|
||||
}
|
||||
return tileIOResult;
|
||||
}
|
||||
|
||||
|
||||
bool AsyncTileDataProvider::satisfiesEnqueueCriteria(const ChunkIndex& chunkIndex) const {
|
||||
auto it = _enqueuedTileRequests.begin();
|
||||
auto end = _enqueuedTileRequests.end();
|
||||
for (; it != end; it++) {
|
||||
const ChunkIndex& otherChunk = it->second;
|
||||
if (chunkIndex.level == otherChunk.level &&
|
||||
chunkIndex.manhattan(otherChunk) < 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void AsyncTileDataProvider::clearRequestQueue() {
|
||||
_concurrentJobManager.clearEnqueuedJobs();
|
||||
_enqueuedTileRequests.clear();
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
113
modules/globebrowsing/other/asynctilereader.cpp
Normal file
113
modules/globebrowsing/other/asynctilereader.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/logging/logmanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h> // abspath
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <modules/globebrowsing/other/asynctilereader.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
#include <modules/globebrowsing/geodetics/angle.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "AsyncTextureDataProvider";
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
AsyncTileDataProvider::AsyncTileDataProvider(const std::string& filename, int minNumPixels, ThreadPool& pool)
|
||||
: _textureDataProvider(std::shared_ptr<TileDataset>(new TileDataset(filename, minNumPixels)))
|
||||
, _concurrentJobManager(pool)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AsyncTileDataProvider::AsyncTileDataProvider(
|
||||
std::shared_ptr<TileDataset> textureDataProvider,
|
||||
ThreadPool& pool)
|
||||
: _textureDataProvider(textureDataProvider)
|
||||
, _concurrentJobManager(pool)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AsyncTileDataProvider::~AsyncTileDataProvider() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<TileDataset> AsyncTileDataProvider::getTextureDataProvider() const {
|
||||
return _textureDataProvider;
|
||||
}
|
||||
|
||||
bool AsyncTileDataProvider::enqueueTextureData(const ChunkIndex& chunkIndex) {
|
||||
if (satisfiesEnqueueCriteria(chunkIndex)) {
|
||||
std::shared_ptr<TileLoadJob> job = std::shared_ptr<TileLoadJob>(
|
||||
new TileLoadJob(_textureDataProvider, chunkIndex));
|
||||
|
||||
_concurrentJobManager.enqueueJob(job);
|
||||
_enqueuedTileRequests[chunkIndex.hashKey()] = chunkIndex;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AsyncTileDataProvider::hasLoadedTextureData() const{
|
||||
return _concurrentJobManager.numFinishedJobs() > 0;
|
||||
}
|
||||
|
||||
std::shared_ptr<TileIOResult> AsyncTileDataProvider::nextTileIOResult() {
|
||||
auto tileIOResult = _concurrentJobManager.popFinishedJob()->product();
|
||||
HashKey key = tileIOResult->rawTileData->chunkIndex.hashKey();
|
||||
if (_enqueuedTileRequests.find(key) != _enqueuedTileRequests.end()) {
|
||||
_enqueuedTileRequests.erase(key);
|
||||
}
|
||||
return tileIOResult;
|
||||
}
|
||||
|
||||
|
||||
bool AsyncTileDataProvider::satisfiesEnqueueCriteria(const ChunkIndex& chunkIndex) const {
|
||||
auto it = _enqueuedTileRequests.begin();
|
||||
auto end = _enqueuedTileRequests.end();
|
||||
for (; it != end; it++) {
|
||||
const ChunkIndex& otherChunk = it->second;
|
||||
if (chunkIndex.level == otherChunk.level &&
|
||||
chunkIndex.manhattan(otherChunk) < 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void AsyncTileDataProvider::clearRequestQueue() {
|
||||
_concurrentJobManager.clearEnqueuedJobs();
|
||||
_enqueuedTileRequests.clear();
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
121
modules/globebrowsing/other/asynctilereader.h
Normal file
121
modules/globebrowsing/other/asynctilereader.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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 __ASYNC_TILE_DATA_PROVIDER_H__
|
||||
#define __ASYNC_TILE_DATA_PROVIDER_H__
|
||||
|
||||
//#include <modules/globebrowsing/other/tileprovider.h>
|
||||
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
|
||||
#include <modules/globebrowsing/other/concurrentjobmanager.h>
|
||||
#include <modules/globebrowsing/other/threadpool.h>
|
||||
#include <modules/globebrowsing/other/tiledataset.h>
|
||||
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
|
||||
struct TileLoadJob : public Job<TileIOResult> {
|
||||
TileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const ChunkIndex& chunkIndex)
|
||||
: _textureDataProvider(textureDataProvider)
|
||||
, _chunkIndex(chunkIndex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual ~TileLoadJob() { }
|
||||
|
||||
virtual void execute() {
|
||||
_uninitedTexture = _textureDataProvider->readTileData(_chunkIndex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual std::shared_ptr<TileIOResult> product() {
|
||||
return _uninitedTexture;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
ChunkIndex _chunkIndex;
|
||||
std::shared_ptr<TileDataset> _textureDataProvider;
|
||||
std::shared_ptr<TileIOResult> _uninitedTexture;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class AsyncTileDataProvider {
|
||||
public:
|
||||
|
||||
AsyncTileDataProvider(const std::string& filename, int minNumPixels, ThreadPool& pool);
|
||||
AsyncTileDataProvider(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
ThreadPool& pool);
|
||||
|
||||
~AsyncTileDataProvider();
|
||||
|
||||
|
||||
|
||||
bool enqueueTextureData(const ChunkIndex& chunkIndex);
|
||||
bool hasLoadedTextureData() const;
|
||||
std::shared_ptr<TileIOResult> nextTileIOResult();
|
||||
|
||||
void clearRequestQueue();
|
||||
|
||||
std::shared_ptr<TileDataset> getTextureDataProvider() const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool satisfiesEnqueueCriteria(const ChunkIndex&) const;
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<TileDataset> _textureDataProvider;
|
||||
ConcurrentJobManager<TileIOResult> _concurrentJobManager;
|
||||
std::unordered_map<HashKey, ChunkIndex> _enqueuedTileRequests;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // __ASYNC_TILE_DATA_PROVIDER_H__
|
||||
@@ -90,7 +90,7 @@ namespace openspace {
|
||||
return _finishedJobs.pop();
|
||||
}
|
||||
|
||||
size_t numFinishedJobs() {
|
||||
size_t numFinishedJobs() const{
|
||||
return _finishedJobs.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
_cond.notify_one();
|
||||
}
|
||||
|
||||
size_t size() {
|
||||
size_t size() const{
|
||||
std::unique_lock<std::mutex> mlock(_mutex);
|
||||
size_t s = _queue.size();
|
||||
mlock.unlock();
|
||||
@@ -87,8 +87,8 @@ public:
|
||||
|
||||
private:
|
||||
std::queue<T> _queue;
|
||||
std::mutex _mutex;
|
||||
std::condition_variable _cond;
|
||||
mutable std::mutex _mutex;
|
||||
mutable std::condition_variable _cond;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
#include <ghoul/filesystem/filesystem.h> // abspath
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <modules/globebrowsing/other/texturedataprovider.h>
|
||||
#include <modules/globebrowsing/other/tiledataset.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
#include <modules/globebrowsing/geodetics/angle.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TextureDataProvider";
|
||||
const std::string _loggerCat = "TileDataset";
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@ namespace {
|
||||
namespace openspace {
|
||||
|
||||
// INIT THIS TO FALSE AFTER REMOVED FROM TILEPROVIDER
|
||||
bool TextureDataProvider::GdalHasBeenInitialized = false;
|
||||
bool TileDataset::GdalHasBeenInitialized = false;
|
||||
|
||||
TextureDataProvider::TextureDataProvider(const std::string& fileName, int minimumPixelSize)
|
||||
TileDataset::TileDataset(const std::string& fileName, int minimumPixelSize)
|
||||
: _minimumPixelSize(minimumPixelSize)
|
||||
{
|
||||
|
||||
@@ -59,18 +59,18 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
TextureDataProvider::~TextureDataProvider() {
|
||||
TileDataset::~TileDataset() {
|
||||
delete _dataset;
|
||||
}
|
||||
|
||||
int TextureDataProvider::calculateTileLevelDifference(GDALDataset* dataset, int minimumPixelSize) {
|
||||
int TileDataset::calculateTileLevelDifference(GDALDataset* dataset, int minimumPixelSize) {
|
||||
GDALRasterBand* firstBand = dataset->GetRasterBand(1);
|
||||
int numOverviews = firstBand->GetOverviewCount();
|
||||
int sizeLevel0 = firstBand->GetOverview(numOverviews - 1)->GetXSize();
|
||||
return log2(minimumPixelSize) - log2(sizeLevel0);
|
||||
}
|
||||
|
||||
TileDepthTransform TextureDataProvider::calculateTileDepthTransform() {
|
||||
TileDepthTransform TileDataset::calculateTileDepthTransform() {
|
||||
GDALRasterBand* firstBand = _dataset->GetRasterBand(1);
|
||||
GDALDataType gdalType = firstBand->GetRasterDataType();
|
||||
|
||||
@@ -83,17 +83,17 @@ namespace openspace {
|
||||
return transform;
|
||||
}
|
||||
|
||||
int TextureDataProvider::getMaximumLevel() const {
|
||||
int TileDataset::getMaximumLevel() const {
|
||||
int numOverviews = _dataset->GetRasterBand(1)->GetOverviewCount();
|
||||
int maximumLevel = numOverviews - 1 - _tileLevelDifference;
|
||||
return maximumLevel;
|
||||
}
|
||||
|
||||
TileDepthTransform TextureDataProvider::getDepthTransform() const {
|
||||
TileDepthTransform TileDataset::getDepthTransform() const {
|
||||
return _depthTransform;
|
||||
}
|
||||
|
||||
std::shared_ptr<TileIOResult> TextureDataProvider::getTextureData(ChunkIndex chunkIndex)
|
||||
std::shared_ptr<TileIOResult> TileDataset::readTileData(ChunkIndex chunkIndex)
|
||||
{
|
||||
GdalDataRegion region(_dataset, chunkIndex, _tileLevelDifference);
|
||||
DataLayout dataLayout(_dataset, region);
|
||||
@@ -135,7 +135,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<RawTileData> TextureDataProvider::createRawTileData(const GdalDataRegion& region,
|
||||
std::shared_ptr<RawTileData> TileDataset::createRawTileData(const GdalDataRegion& region,
|
||||
const DataLayout& dataLayout, const char* imageData)
|
||||
{
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace openspace {
|
||||
|
||||
|
||||
|
||||
size_t TextureDataProvider::numberOfBytes(GDALDataType gdalType) {
|
||||
size_t TileDataset::numberOfBytes(GDALDataType gdalType) {
|
||||
switch (gdalType) {
|
||||
case GDT_Byte: return sizeof(GLubyte);
|
||||
case GDT_UInt16: return sizeof(GLushort);
|
||||
@@ -184,7 +184,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
glm::uvec2 TextureDataProvider::geodeticToPixel(GDALDataset* dataSet, const Geodetic2& geo) {
|
||||
glm::uvec2 TileDataset::geodeticToPixel(GDALDataset* dataSet, const Geodetic2& geo) {
|
||||
double padfTransform[6];
|
||||
CPLErr err = dataSet->GetGeoTransform(padfTransform);
|
||||
|
||||
@@ -222,7 +222,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
RawTileData::TextureFormat TextureDataProvider::getTextureFormat(
|
||||
RawTileData::TextureFormat TileDataset::getTextureFormat(
|
||||
int rasterCount, GDALDataType gdalType)
|
||||
{
|
||||
RawTileData::TextureFormat format;
|
||||
@@ -292,7 +292,7 @@ namespace openspace {
|
||||
|
||||
|
||||
|
||||
GLuint TextureDataProvider::getOpenGLDataType(GDALDataType gdalType) {
|
||||
GLuint TileDataset::getOpenGLDataType(GDALDataType gdalType) {
|
||||
switch (gdalType) {
|
||||
case GDT_Byte: return GL_UNSIGNED_BYTE;
|
||||
case GDT_UInt16: return GL_UNSIGNED_SHORT;
|
||||
@@ -308,7 +308,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
TextureDataProvider::GdalDataRegion::GdalDataRegion(GDALDataset * dataSet,
|
||||
TileDataset::GdalDataRegion::GdalDataRegion(GDALDataset * dataSet,
|
||||
const ChunkIndex& chunkIndex, int tileLevelDifference)
|
||||
: chunkIndex(chunkIndex)
|
||||
{
|
||||
@@ -352,7 +352,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
TextureDataProvider::DataLayout::DataLayout(GDALDataset* dataSet, const GdalDataRegion& region) {
|
||||
TileDataset::DataLayout::DataLayout(GDALDataset* dataSet, const GdalDataRegion& region) {
|
||||
// Assume all raster bands have the same data type
|
||||
gdalType = dataSet->GetRasterBand(1)->GetRasterDataType();
|
||||
bytesPerDatum = numberOfBytes(gdalType);
|
||||
@@ -22,8 +22,8 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __TEXTURE_DATA_PROVIDER_H__
|
||||
#define __TEXTURE_DATA_PROVIDER_H__
|
||||
#ifndef __TILE_DATASET_H__
|
||||
#define __TILE_DATASET_H__
|
||||
|
||||
//#include <modules/globebrowsing/other/tileprovider.h>
|
||||
|
||||
@@ -86,14 +86,14 @@ namespace openspace {
|
||||
|
||||
|
||||
|
||||
class TextureDataProvider {
|
||||
class TileDataset {
|
||||
public:
|
||||
|
||||
TextureDataProvider(const std::string& fileName, int minimumPixelSize);
|
||||
~TextureDataProvider();
|
||||
TileDataset(const std::string& fileName, int minimumPixelSize);
|
||||
~TileDataset();
|
||||
|
||||
|
||||
std::shared_ptr<TileIOResult> getTextureData(ChunkIndex chunkIndex);
|
||||
std::shared_ptr<TileIOResult> readTileData(ChunkIndex chunkIndex);
|
||||
|
||||
int getMaximumLevel() const;
|
||||
|
||||
@@ -184,4 +184,4 @@ namespace openspace {
|
||||
|
||||
|
||||
|
||||
#endif // __TEXTURE_DATA_PROVIDER_H__
|
||||
#endif // __TILE_DATASET_H__
|
||||
@@ -54,12 +54,10 @@ namespace openspace {
|
||||
int tileCacheSize,
|
||||
int minimumPixelSize,
|
||||
int framesUntilRequestFlush)
|
||||
: _filePath(filePath)
|
||||
, _tileCache(tileCacheSize) // setting cache size
|
||||
: _tileCache(tileCacheSize) // setting cache size
|
||||
, _framesSinceLastRequestFlush(0)
|
||||
, _framesUntilRequestFlush(framesUntilRequestFlush)
|
||||
, _tileLoadManager(TileProviderManager::tileRequestThreadPool)
|
||||
, _rawTextureTileDataProvider(filePath, minimumPixelSize)
|
||||
, _asyncTextureDataProvider(filePath, minimumPixelSize, TileProviderManager::tileRequestThreadPool)
|
||||
{
|
||||
// Set a temporary texture
|
||||
std::string fileName = "textures/earth_bluemarble.jpg";
|
||||
@@ -75,7 +73,6 @@ namespace openspace {
|
||||
_defaultTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
_defaultTexture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TileProvider::~TileProvider(){
|
||||
@@ -84,30 +81,21 @@ namespace openspace {
|
||||
|
||||
|
||||
void TileProvider::prerender() {
|
||||
//_rawTextureTileDataProvider.updateAsyncRequests();
|
||||
initTexturesFromLoadedData();
|
||||
|
||||
if (_framesSinceLastRequestFlush++ > _framesUntilRequestFlush) {
|
||||
clearRequestQueue();
|
||||
}
|
||||
}
|
||||
|
||||
void TileProvider::initTexturesFromLoadedData() {
|
||||
while (_tileLoadManager.numFinishedJobs() > 0) {
|
||||
std::shared_ptr<TileIOResult> tileIOResult= _tileLoadManager.popFinishedJob()->product();
|
||||
while (_asyncTextureDataProvider.hasLoadedTextureData()) {
|
||||
std::shared_ptr<TileIOResult> tileIOResult = _asyncTextureDataProvider.nextTileIOResult();
|
||||
initializeAndAddToCache(tileIOResult);
|
||||
}
|
||||
/*
|
||||
while (_rawTextureTileDataProvider.hasTextureTileData()) {
|
||||
auto rawTextureTile = _rawTextureTileDataProvider.nextTextureTile();
|
||||
initializeAndAddToCache(rawTextureTile);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void TileProvider::clearRequestQueue() {
|
||||
_tileLoadManager.clearEnqueuedJobs();
|
||||
_queuedTileRequests.clear();
|
||||
_asyncTextureDataProvider.clearRequestQueue();
|
||||
_framesSinceLastRequestFlush = 0;
|
||||
}
|
||||
|
||||
@@ -117,7 +105,7 @@ namespace openspace {
|
||||
uvTransform.uvOffset = glm::vec2(0, 0);
|
||||
uvTransform.uvScale = glm::vec2(1, 1);
|
||||
|
||||
int maximumLevel = _rawTextureTileDataProvider.getMaximumLevel();
|
||||
int maximumLevel = _asyncTextureDataProvider.getTextureDataProvider()->getMaximumLevel();
|
||||
|
||||
while(chunkIndex.level > maximumLevel){
|
||||
transformFromParent(chunkIndex, uvTransform);
|
||||
@@ -146,7 +134,7 @@ namespace openspace {
|
||||
|
||||
// As we didn't have this tile, push it to the request queue
|
||||
// post order enqueueing tiles --> enqueue tiles at low levels first
|
||||
enqueueTileRequest(chunkIndex);
|
||||
_asyncTextureDataProvider.enqueueTextureData(chunkIndex);
|
||||
|
||||
return tile;
|
||||
}
|
||||
@@ -175,51 +163,21 @@ namespace openspace {
|
||||
return _tileCache.get(hashkey).texture;
|
||||
}
|
||||
else {
|
||||
enqueueTileRequest(chunkIndex);
|
||||
_asyncTextureDataProvider.enqueueTextureData(chunkIndex);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool TileProvider::enqueueTileRequest(const ChunkIndex& chunkIndex) {
|
||||
HashKey key = chunkIndex.hashKey();
|
||||
auto it = _queuedTileRequests.begin();
|
||||
auto end = _queuedTileRequests.end();
|
||||
for (; it != end; it++) {
|
||||
const ChunkIndex& otherChunk = it->second;
|
||||
if (chunkIndex.level == otherChunk.level &&
|
||||
chunkIndex.manhattan(otherChunk) < 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<TextureTileLoadJob> job = std::shared_ptr<TextureTileLoadJob>(
|
||||
new TextureTileLoadJob(this, chunkIndex));
|
||||
_tileLoadManager.enqueueJob(job);
|
||||
_queuedTileRequests[key] = chunkIndex;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<Texture> TileProvider::getDefaultTexture() {
|
||||
return _defaultTexture;
|
||||
}
|
||||
|
||||
TileDepthTransform TileProvider::depthTransform() {
|
||||
return _rawTextureTileDataProvider.getDepthTransform();
|
||||
return _asyncTextureDataProvider.getTextureDataProvider()->getDepthTransform();
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<TileIOResult> TileProvider::syncDownloadData(
|
||||
const ChunkIndex& chunkIndex) {
|
||||
|
||||
std::shared_ptr<TileIOResult> res = _rawTextureTileDataProvider.getTextureData(chunkIndex);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void TileProvider::initializeAndAddToCache(std::shared_ptr<TileIOResult> tileIOResult) {
|
||||
|
||||
std::shared_ptr<RawTileData> tileData = tileIOResult->rawTileData;
|
||||
|
||||
@@ -37,8 +37,7 @@
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/other/lrucache.h>
|
||||
#include <modules/globebrowsing/other/concurrentjobmanager.h>
|
||||
#include <modules/globebrowsing/other/texturedataprovider.h>
|
||||
#include <modules/globebrowsing/other/asynctilereader.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TILE PROVIDER //
|
||||
@@ -92,7 +91,7 @@ namespace openspace {
|
||||
|
||||
private:
|
||||
|
||||
friend class TextureTileLoadJob;
|
||||
friend class TileLoadJob;
|
||||
|
||||
|
||||
|
||||
@@ -104,11 +103,7 @@ namespace openspace {
|
||||
|
||||
void transformFromParent(const ChunkIndex& ci, TileUvTransform& uv) const;
|
||||
|
||||
/**
|
||||
Fetches all the needeed texture data from the GDAL dataset.
|
||||
*/
|
||||
std::shared_ptr<TileIOResult> syncDownloadData(
|
||||
const ChunkIndex& chunkIndex);
|
||||
|
||||
|
||||
/**
|
||||
Creates an OpenGL texture and pushes the data to the GPU.
|
||||
@@ -116,8 +111,6 @@ namespace openspace {
|
||||
void initializeAndAddToCache(
|
||||
std::shared_ptr<TileIOResult> uninitedTexture);
|
||||
|
||||
bool enqueueTileRequest(const ChunkIndex& ci);
|
||||
|
||||
void clearRequestQueue();
|
||||
|
||||
void initTexturesFromLoadedData();
|
||||
@@ -131,17 +124,12 @@ namespace openspace {
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LRUCache<HashKey, MetaTexture> _tileCache;
|
||||
std::unordered_map<HashKey, ChunkIndex> _queuedTileRequests;
|
||||
|
||||
int _framesSinceLastRequestFlush;
|
||||
int _framesUntilRequestFlush;
|
||||
|
||||
const std::string _filePath;
|
||||
|
||||
|
||||
TextureDataProvider _rawTextureTileDataProvider;
|
||||
|
||||
ConcurrentJobManager<TileIOResult> _tileLoadManager;
|
||||
AsyncTileDataProvider _asyncTextureDataProvider;
|
||||
|
||||
std::shared_ptr<Texture> _defaultTexture;
|
||||
|
||||
@@ -155,38 +143,4 @@ namespace openspace {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
struct TextureTileLoadJob : public Job<TileIOResult> {
|
||||
TextureTileLoadJob(TileProvider * tileProvider, const ChunkIndex& chunkIndex)
|
||||
: _tileProvider(tileProvider)
|
||||
, _chunkIndex(chunkIndex) {
|
||||
|
||||
}
|
||||
|
||||
virtual ~TextureTileLoadJob() { }
|
||||
|
||||
virtual void execute() {
|
||||
_uninitedTexture = _tileProvider->syncDownloadData(_chunkIndex);
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<TileIOResult> product() {
|
||||
return _uninitedTexture;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
ChunkIndex _chunkIndex;
|
||||
TileProvider * _tileProvider;
|
||||
std::shared_ptr<TileIOResult> _uninitedTexture;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __TILE_PROVIDER_H__
|
||||
Reference in New Issue
Block a user