mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-26 05:58:48 -05:00
Make ChunkedLodGlobes able to fully reset their data sets
This commit is contained in:
@@ -94,6 +94,9 @@ namespace openspace {
|
||||
return _finishedJobs.size();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
threadPool->clearTasks();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -172,6 +172,16 @@ namespace openspace {
|
||||
return true;
|
||||
}
|
||||
|
||||
void AsyncTileDataProvider::reset() {
|
||||
_enqueuedTileRequests.clear();
|
||||
_concurrentJobManager.reset();
|
||||
// also clear tiles that has just been finished loading
|
||||
while (hasLoadedTextureData()) {
|
||||
nextTileIOResult(); // get it and throw it away
|
||||
}
|
||||
getTextureDataProvider()->reset();
|
||||
}
|
||||
|
||||
|
||||
void AsyncTileDataProvider::clearRequestQueue() {
|
||||
_concurrentJobManager.clearEnqueuedJobs();
|
||||
|
||||
@@ -128,6 +128,7 @@ namespace openspace {
|
||||
bool hasLoadedTextureData() const;
|
||||
std::shared_ptr<TileIOResult> nextTileIOResult();
|
||||
|
||||
void reset();
|
||||
void clearRequestQueue();
|
||||
|
||||
std::shared_ptr<TileDataset> getTextureDataProvider() const;
|
||||
|
||||
@@ -128,8 +128,19 @@ namespace openspace {
|
||||
: _config(config)
|
||||
, hasBeenInitialized(false)
|
||||
{
|
||||
_initData = { gdalDatasetDesc, config.minimumTilePixelSize, config.dataType };
|
||||
|
||||
_initData = { "", gdalDatasetDesc, config.minimumTilePixelSize, config.dataType };
|
||||
ensureInitialized();
|
||||
_initData.initDirectory = CPLGetCurrentDir();
|
||||
}
|
||||
|
||||
void TileDataset::reset() {
|
||||
_cached._maxLevel = -1;
|
||||
if (_dataset != nullptr) {
|
||||
GDALClose((GDALDatasetH)_dataset);
|
||||
}
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
void TileDataset::ensureInitialized() {
|
||||
@@ -137,10 +148,12 @@ namespace openspace {
|
||||
initialize();
|
||||
hasBeenInitialized = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TileDataset::initialize() {
|
||||
gdalEnsureInitialized();
|
||||
|
||||
_dataset = gdalDataset(_initData.gdalDatasetDesc);
|
||||
|
||||
//Do any other initialization needed for the TileDataset
|
||||
@@ -162,7 +175,11 @@ namespace openspace {
|
||||
GDALDataset* TileDataset::gdalDataset(const std::string& gdalDatasetDesc) {
|
||||
GDALDataset* dataset = (GDALDataset *)GDALOpen(gdalDatasetDesc.c_str(), GA_ReadOnly);
|
||||
if (!dataset) {
|
||||
throw ghoul::RuntimeError("Failed to load dataset:\n" + gdalDatasetDesc);
|
||||
std::string correctedPath = ghoul::filesystem::FileSystem::ref().pathByAppendingComponent(_initData.initDirectory, gdalDatasetDesc);
|
||||
dataset = (GDALDataset *)GDALOpen(correctedPath.c_str(), GA_ReadOnly);
|
||||
if (!dataset) {
|
||||
throw ghoul::RuntimeError("Failed to load dataset:\n" + gdalDatasetDesc);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string originalDriverName = dataset->GetDriverName();
|
||||
@@ -668,20 +685,33 @@ namespace openspace {
|
||||
noDataValues[c] = _dataset->GetRasterBand(1)->GetNoDataValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
float noDataValue = _dataset->GetRasterBand(1)->GetNoDataValue();
|
||||
|
||||
for (size_t y = 0; y < region.numPixels.y; y++) {
|
||||
size_t yi = (region.numPixels.y - 1 - y) * bytesPerLine;
|
||||
size_t i = 0;
|
||||
for (size_t x = 0; x < region.numPixels.x; x++) {
|
||||
|
||||
for (size_t c = 0; c < _dataLayout.numRasters; c++) {
|
||||
|
||||
//float lastMaxR = preprocessData->maxValues[0];
|
||||
//float lastMinR = preprocessData->minValues[0];
|
||||
float val = TileDataType::interpretFloat(_dataLayout.gdalType, &(result->imageData[yi + i]));
|
||||
|
||||
if (val != noDataValue) {
|
||||
preprocessData->maxValues[c] = std::max(val, preprocessData->maxValues[c]);
|
||||
preprocessData->minValues[c] = std::min(val, preprocessData->minValues[c]);
|
||||
}
|
||||
|
||||
// ugly case for heightmap overlays and alpha
|
||||
/*
|
||||
if (c == 1 && _dataLayout.textureFormat.ghoulFormat == Texture::Format::RG) {
|
||||
if (val < 0.5) {
|
||||
preprocessData->maxValues[0] = lastMaxR;
|
||||
preprocessData->minValues[0] = lastMinR;
|
||||
}
|
||||
}*/
|
||||
|
||||
i += _dataLayout.bytesPerDatum;
|
||||
}
|
||||
}
|
||||
@@ -714,6 +744,15 @@ namespace openspace {
|
||||
if (hasMissingData && onHighLevel) {
|
||||
return CE_Fatal;
|
||||
}
|
||||
// ugly test for heightmap overlay
|
||||
if (_dataLayout.textureFormat.ghoulFormat == Texture::Format::RG) {
|
||||
// check the alpha
|
||||
if (result->preprocessData->maxValues[1] == 0.0
|
||||
&& result->preprocessData->minValues[1] == 0.0)
|
||||
{
|
||||
//return CE_Warning;
|
||||
}
|
||||
}
|
||||
return CE_None;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ namespace openspace {
|
||||
int maxChunkLevel();
|
||||
TileDepthTransform getDepthTransform();
|
||||
const TileDataLayout& getDataLayout();
|
||||
void reset();
|
||||
|
||||
|
||||
const static glm::ivec2 tilePixelStartOffset;
|
||||
@@ -167,6 +168,7 @@ namespace openspace {
|
||||
|
||||
// init data
|
||||
struct InitData {
|
||||
std::string initDirectory;
|
||||
std::string gdalDatasetDesc;
|
||||
int minimumPixelSize;
|
||||
GLuint dataType;
|
||||
|
||||
@@ -283,12 +283,7 @@ namespace openspace {
|
||||
|
||||
void CachingTileProvider::reset() {
|
||||
_tileCache->clear();
|
||||
_asyncTextureDataProvider->clearRequestQueue();
|
||||
|
||||
// also clear tiles that has just been finished loading
|
||||
while (_asyncTextureDataProvider->hasLoadedTextureData()) {
|
||||
_asyncTextureDataProvider->nextTileIOResult(); // get it and throw it away
|
||||
}
|
||||
_asyncTextureDataProvider->reset();
|
||||
}
|
||||
|
||||
int CachingTileProvider::maxLevel() {
|
||||
|
||||
Reference in New Issue
Block a user