Fix bounding heights (used for culling) for chunks with heightmap overlays

This commit is contained in:
Erik Broberg
2016-07-15 13:48:00 -04:00
parent c25d1cdc88
commit d06c470636
3 changed files with 40 additions and 22 deletions

View File

@@ -100,20 +100,44 @@ namespace openspace {
// In the future, this should be abstracted away and more easily queryable.
// One must also handle how to sample pick one out of multiplte heightmaps
auto tileProvidermanager = owner()->getTileProviderManager();
auto heightMapProviders = tileProvidermanager->getTileProviderGroup(LayeredTextures::HeightMaps).getActiveTileProviders();
if (heightMapProviders.size() > 0) {
TileAndTransform tileAndTransform = TileSelector::getHighestResolutionTile(heightMapProviders[0].get(), _index);
if (tileAndTransform.tile.status == Tile::Status::OK) {
std::shared_ptr<TilePreprocessData> preprocessData = tileAndTransform.tile.preprocessData;
if ((preprocessData != nullptr) && preprocessData->maxValues.size() > 0) {
boundingHeights.max = preprocessData->maxValues[0];
auto tileProviderManager = owner()->getTileProviderManager();
auto heightMapProviders = tileProviderManager->getTileProviderGroup(LayeredTextures::HeightMaps).getActiveTileProviders();
const TileProviderGroup& heightmaps = tileProviderManager->getTileProviderGroup(LayeredTextures::HeightMaps);
TileAndTransform mostHighResHeightmap = TileSelector::getHighestResolutionTile(heightmaps, _index);
if (mostHighResHeightmap.tile.status == Tile::Status::OK) {
auto preprocessData = mostHighResHeightmap.tile.preprocessData;
if (preprocessData != nullptr && preprocessData->minValues[0] < preprocessData->maxValues[0]) {
boundingHeights.min = preprocessData->minValues[0];
boundingHeights.max = preprocessData->maxValues[0];
boundingHeights.available = true;
}
}
const TileProviderGroup& heightmapOverlays = tileProviderManager->getTileProviderGroup(LayeredTextures::HeightMapOverlays);
TileAndTransform mostHighResHeightmapOverlay = TileSelector::getHighestResolutionTile(heightmapOverlays, _index);
if (mostHighResHeightmapOverlay.tile.status == Tile::Status::OK) {
auto preprocessData = mostHighResHeightmapOverlay.tile.preprocessData;
if (preprocessData != nullptr && preprocessData->minValues[0] < preprocessData->maxValues[0]) {
if (boundingHeights.available) {
boundingHeights.min = std::min(boundingHeights.min, preprocessData->minValues[0]);
boundingHeights.max = std::max(boundingHeights.max, preprocessData->maxValues[0]);
}
else {
boundingHeights.min = preprocessData->minValues[0];
boundingHeights.max = preprocessData->maxValues[0];
boundingHeights.available = true;
if (preprocessData->hasMissingData[0]) {
boundingHeights.min = std::min(0.0f, preprocessData->minValues[0]);
boundingHeights.max = std::max(0.0f, preprocessData->maxValues[0]);
}
}
}
}
return boundingHeights;
}

View File

@@ -675,13 +675,15 @@ namespace openspace {
TilePreprocessData* preprocessData = new TilePreprocessData();
preprocessData->maxValues.resize(_dataLayout.numRasters);
preprocessData->minValues.resize(_dataLayout.numRasters);
preprocessData->hasMissingData.resize(_dataLayout.numRasters);
std::vector<float> noDataValues;
noDataValues.resize(_dataLayout.numRasters);
for (size_t c = 0; c < _dataLayout.numRasters; c++) {
preprocessData->maxValues[c] = -FLT_MAX;
preprocessData->minValues[c] = FLT_MAX;
preprocessData->hasMissingData[c] = false;
noDataValues[c] = _dataset->GetRasterBand(1)->GetNoDataValue();
}
@@ -695,23 +697,14 @@ namespace openspace {
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;
}
}*/
else {
preprocessData->hasMissingData[c] = true;
}
i += _dataLayout.bytesPerDatum;
}
}

View File

@@ -46,6 +46,7 @@ namespace openspace {
struct TilePreprocessData {
std::vector<float> maxValues;
std::vector<float> minValues;
std::vector<bool> hasMissingData;
void serialize(std::ostream& s);
static TilePreprocessData deserialize(std::istream& s);