mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 11:18:22 -05:00
Implement serialization of TileIOResults
This commit is contained in:
@@ -42,6 +42,16 @@ namespace openspace {
|
||||
|
||||
|
||||
|
||||
void TileLoadJob::execute() {
|
||||
_uninitedTexture = _tileDataset->readTileData(_chunkIndex);
|
||||
}
|
||||
|
||||
void DiskCachedTileLoadJob::execute() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
AsyncTileDataProvider::AsyncTileDataProvider(
|
||||
std::shared_ptr<TileDataset> tileDataset,
|
||||
std::shared_ptr<ThreadPool> pool)
|
||||
|
||||
@@ -40,14 +40,20 @@
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct LoadJob : public Job<TileIOResult> {
|
||||
virtual void execute() = 0;
|
||||
virtual std::shared_ptr<TileIOResult> product() = 0;
|
||||
};
|
||||
|
||||
|
||||
struct TileLoadJob : LoadJob {
|
||||
|
||||
struct TileLoadJob : public Job<TileIOResult> {
|
||||
TileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const ChunkIndex& chunkIndex)
|
||||
: _tileDataset(textureDataProvider)
|
||||
@@ -58,25 +64,25 @@ namespace openspace {
|
||||
|
||||
virtual ~TileLoadJob() { }
|
||||
|
||||
virtual void execute() {
|
||||
_uninitedTexture = _tileDataset->readTileData(_chunkIndex);
|
||||
}
|
||||
|
||||
|
||||
virtual void execute();
|
||||
|
||||
virtual std::shared_ptr<TileIOResult> product() {
|
||||
return _uninitedTexture;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
|
||||
ChunkIndex _chunkIndex;
|
||||
std::shared_ptr<TileDataset> _tileDataset;
|
||||
std::shared_ptr<TileIOResult> _uninitedTexture;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct DiskCachedTileLoadJob : public TileLoadJob {
|
||||
virtual void execute();
|
||||
};
|
||||
|
||||
|
||||
class AsyncTileDataProvider {
|
||||
@@ -107,7 +113,6 @@ namespace openspace {
|
||||
ConcurrentJobManager<TileIOResult> _concurrentJobManager;
|
||||
std::unordered_map<HashKey, ChunkIndex> _enqueuedTileRequests;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace {
|
||||
@@ -43,6 +47,95 @@ namespace {
|
||||
|
||||
|
||||
namespace openspace {
|
||||
void TilePreprocessData::serialize(std::stringstream& s) {
|
||||
s << maxValues.size() << std::endl;
|
||||
for (float f : maxValues) {
|
||||
s << f << " ";
|
||||
}
|
||||
s << std::endl;
|
||||
for (float f : minValues) {
|
||||
s << f << " ";
|
||||
}
|
||||
s << std::endl;
|
||||
}
|
||||
|
||||
|
||||
TilePreprocessData TilePreprocessData::deserialize(std::stringstream& s) {
|
||||
TilePreprocessData res;
|
||||
int n; s >> n;
|
||||
res.maxValues.resize(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
s >> res.maxValues[i];
|
||||
}
|
||||
res.minValues.resize(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
s >> res.minValues[i];
|
||||
}
|
||||
|
||||
return std::move(res);
|
||||
}
|
||||
|
||||
TileIOResult::TileIOResult()
|
||||
: imageData(nullptr)
|
||||
, dimensions(0, 0, 0)
|
||||
, preprocessData(nullptr)
|
||||
, chunkIndex(0, 0, 0)
|
||||
, error(CE_None)
|
||||
, nBytesImageData(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TileIOResult::serialize(std::stringstream& s) {
|
||||
s << dimensions.x << " " << dimensions.y << " " << dimensions.z << std::endl;
|
||||
s << chunkIndex.x << " " << chunkIndex.y << " " << chunkIndex.level << std::endl;
|
||||
s << error << std::endl;
|
||||
|
||||
// preprocess data
|
||||
s << (preprocessData != nullptr) << std::endl;
|
||||
if (preprocessData != nullptr) {
|
||||
preprocessData->serialize(s);
|
||||
}
|
||||
|
||||
s << nBytesImageData << std::endl;
|
||||
|
||||
char binaryDataSeparator = 'Ö'; // sweden represent!
|
||||
s << binaryDataSeparator;
|
||||
if (nBytesImageData) {
|
||||
char* buffer = reinterpret_cast<char*>(imageData);
|
||||
s.write(buffer, nBytesImageData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TileIOResult TileIOResult::deserialize(std::stringstream& s) {
|
||||
TileIOResult res;
|
||||
s >> res.dimensions.x >> res.dimensions.y >> res.dimensions.z;
|
||||
s >> res.chunkIndex.x >> res.chunkIndex.y >> res.chunkIndex.level;
|
||||
int err; s >> err; res.error = (CPLErr) err;
|
||||
|
||||
res.preprocessData = nullptr;
|
||||
bool hasPreprocessData;
|
||||
s >> hasPreprocessData;
|
||||
if (hasPreprocessData) {
|
||||
TilePreprocessData preprocessData = TilePreprocessData::deserialize(s);
|
||||
res.preprocessData = std::make_shared<TilePreprocessData>(preprocessData);
|
||||
}
|
||||
|
||||
s >> res.nBytesImageData;
|
||||
|
||||
char binaryDataSeparator;
|
||||
s >> binaryDataSeparator; // not used
|
||||
|
||||
char* buffer = new char[res.nBytesImageData]();
|
||||
s.read(buffer, res.nBytesImageData);
|
||||
res.imageData = reinterpret_cast<void*>(buffer);
|
||||
|
||||
return std::move(res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// INIT THIS TO FALSE AFTER REMOVED FROM TILEPROVIDER
|
||||
bool TileDataset::GdalHasBeenInitialized = false;
|
||||
@@ -142,6 +235,7 @@ namespace openspace {
|
||||
result->chunkIndex = chunkIndex;
|
||||
result->imageData = getImageDataFlippedY(region, _dataLayout, imageData);
|
||||
result->dimensions = glm::uvec3(region.numPixels, 1);
|
||||
result->nBytesImageData = _dataLayout.bytesPerPixel * region.numPixels.x * region.numPixels.y;
|
||||
if (_doPreprocessing) {
|
||||
result->preprocessData = preprocess(imageData, region, _dataLayout);
|
||||
}
|
||||
@@ -214,7 +308,7 @@ namespace openspace {
|
||||
}
|
||||
}
|
||||
|
||||
return std::shared_ptr < TilePreprocessData>(preprocessData);
|
||||
return std::shared_ptr<TilePreprocessData>(preprocessData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,21 +32,29 @@
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/other/threadpool.h>
|
||||
|
||||
#include <ghoul/filesystem/file.h>
|
||||
|
||||
|
||||
#include "gdal_priv.h"
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
namespace openspace {
|
||||
using namespace ghoul::opengl;
|
||||
using namespace ghoul::filesystem;
|
||||
|
||||
struct TilePreprocessData {
|
||||
std::vector<float> maxValues;
|
||||
std::vector<float> minValues;
|
||||
|
||||
void serialize(std::stringstream& s);
|
||||
static TilePreprocessData deserialize(std::stringstream& s);
|
||||
};
|
||||
|
||||
struct TextureFormat {
|
||||
@@ -54,16 +62,25 @@ namespace openspace {
|
||||
GLuint glFormat;
|
||||
};
|
||||
|
||||
|
||||
struct TileIOResult {
|
||||
TileIOResult();
|
||||
|
||||
void* imageData;
|
||||
glm::uvec3 dimensions;
|
||||
std::shared_ptr<TilePreprocessData> preprocessData;
|
||||
ChunkIndex chunkIndex;
|
||||
CPLErr error;
|
||||
size_t nBytesImageData;
|
||||
|
||||
void serialize(std::stringstream& s);
|
||||
static TileIOResult deserialize(std::stringstream& s);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
struct TileDepthTransform {
|
||||
float depthScale;
|
||||
float depthOffset;
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
void CachingTileProvider::initializeAndAddToCache(std::shared_ptr<TileIOResult> tileIOResult) {
|
||||
void CachingTileProvider::initializeAndAddToCache(std::shared_ptr<TileIOResult> tileIOResult) {
|
||||
HashKey key = tileIOResult->chunkIndex.hashKey();
|
||||
TileDataset::DataLayout dataLayout = _asyncTextureDataProvider->getTextureDataProvider()->getDataLayout();
|
||||
Texture* texturePtr = new Texture(
|
||||
|
||||
Reference in New Issue
Block a user