mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 20:21:24 -06:00
Move ChunkTile selection to TileProvider interface
This commit is contained in:
@@ -200,7 +200,7 @@ namespace globebrowsing {
|
||||
for (const auto& layer : heightMapLayers) {
|
||||
TileProvider* tileProvider = layer->tileProvider();
|
||||
// Transform the uv coordinates to the current tile texture
|
||||
ChunkTile chunkTile = TileSelector::getHighestResolutionTile(tileProvider, tileIndex);
|
||||
ChunkTile chunkTile = tileProvider->getChunkTile(tileIndex);
|
||||
const auto& tile = chunkTile.tile;
|
||||
const auto& uvTransform = chunkTile.uvTransform;
|
||||
const auto& depthTransform = tileProvider->depthTransform();
|
||||
|
||||
@@ -83,11 +83,8 @@ namespace globebrowsing {
|
||||
|
||||
}
|
||||
|
||||
ChunkTilePile Layer::getChunkTilePile(
|
||||
const TileIndex& tileIndex,
|
||||
int pileSize) const {
|
||||
return std::move(TileSelector::getHighestResolutionTilePile(
|
||||
_tileProvider.get(), tileIndex, pileSize));
|
||||
ChunkTilePile Layer::getChunkTilePile(const TileIndex& tileIndex, int pileSize) const {
|
||||
return std::move(_tileProvider->getChunkTilePile(tileIndex, pileSize));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <modules/globebrowsing/tile/chunktile.h>
|
||||
#include <modules/globebrowsing/tile/tileselector.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
@@ -61,5 +63,57 @@ float TileProvider::noDataValueAsFloat() {
|
||||
return std::numeric_limits<float>::min();
|
||||
}
|
||||
|
||||
ChunkTile TileProvider::getChunkTile(TileIndex tileIndex, int parents){
|
||||
TileUvTransform uvTransform;
|
||||
uvTransform.uvOffset = glm::vec2(0, 0);
|
||||
uvTransform.uvScale = glm::vec2(1, 1);
|
||||
|
||||
// Step 1. Traverse 0 or more parents up the chunkTree as requested by the caller
|
||||
for (int i = 0; i < parents && tileIndex.level > 1; i++) {
|
||||
TileSelector::ascendToParent(tileIndex, uvTransform);
|
||||
}
|
||||
|
||||
// Step 2. Traverse 0 or more parents up the chunkTree to make sure we're inside
|
||||
// the range of defined data.
|
||||
int maximumLevel = maxLevel();
|
||||
while(tileIndex.level > maximumLevel){
|
||||
TileSelector::ascendToParent(tileIndex, uvTransform);
|
||||
}
|
||||
|
||||
// Step 3. Traverse 0 or more parents up the chunkTree until we find a chunk that
|
||||
// has a loaded tile ready to use.
|
||||
while (tileIndex.level > 1) {
|
||||
Tile tile = getTile(tileIndex);
|
||||
if (tile.status != Tile::Status::OK) {
|
||||
TileSelector::ascendToParent(tileIndex, uvTransform);
|
||||
}
|
||||
else return { tile, uvTransform };
|
||||
}
|
||||
|
||||
return{ Tile::TileUnavailable, uvTransform };
|
||||
}
|
||||
|
||||
ChunkTilePile TileProvider::getChunkTilePile(TileIndex tileIndex, int pileSize){
|
||||
ghoul_assert(pileSize >= 0, "pileSize must be positive");
|
||||
ChunkTilePile chunkTilePile;
|
||||
chunkTilePile.chunkTiles.resize(pileSize);
|
||||
for (size_t i = 0; i < pileSize; ++i){
|
||||
chunkTilePile.chunkTiles[i] = getChunkTile(tileIndex, i);
|
||||
if (chunkTilePile.chunkTiles[i].tile.status == Tile::Status::Unavailable) {
|
||||
if(i>0){
|
||||
chunkTilePile.chunkTiles[i].tile = chunkTilePile.chunkTiles[i-1].tile;
|
||||
chunkTilePile.chunkTiles[i].uvTransform.uvOffset = chunkTilePile.chunkTiles[i-1].uvTransform.uvOffset;
|
||||
chunkTilePile.chunkTiles[i].uvTransform.uvScale = chunkTilePile.chunkTiles[i-1].uvTransform.uvScale;
|
||||
}
|
||||
else{
|
||||
chunkTilePile.chunkTiles[i].tile = getDefaultTile();
|
||||
chunkTilePile.chunkTiles[i].uvTransform.uvOffset = { 0, 0 };
|
||||
chunkTilePile.chunkTiles[i].uvTransform.uvScale = { 1, 1 };
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::move(chunkTilePile);
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class ChunkTile;
|
||||
class ChunkTilePile;
|
||||
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
@@ -96,6 +99,13 @@ namespace globebrowsing {
|
||||
*/
|
||||
virtual Tile getTile(const TileIndex& tileIndex) = 0;
|
||||
|
||||
|
||||
virtual ChunkTile getChunkTile(TileIndex tileIndex, int parents = 0);
|
||||
|
||||
|
||||
virtual ChunkTilePile getChunkTilePile(TileIndex tileIndex, int pileSize);
|
||||
|
||||
|
||||
/**
|
||||
* TileProviders must be able to provide a defualt
|
||||
* <code>Tile</code> which may be used by clients in cases when
|
||||
|
||||
@@ -42,65 +42,13 @@ namespace globebrowsing {
|
||||
|
||||
const TileSelector::CompareResolution TileSelector::HIGHEST_RES = TileSelector::CompareResolution();
|
||||
|
||||
ChunkTilePile TileSelector::getHighestResolutionTilePile(TileProvider* tileProvider, TileIndex tileIndex, int pileSize){
|
||||
ghoul_assert(pileSize >= 0, "pileSize must be positive");
|
||||
ChunkTilePile chunkTilePile;
|
||||
chunkTilePile.chunkTiles.resize(pileSize);
|
||||
for (size_t i = 0; i < pileSize; ++i){
|
||||
chunkTilePile.chunkTiles[i] = TileSelector::getHighestResolutionTile(tileProvider, tileIndex, i);
|
||||
if (chunkTilePile.chunkTiles[i].tile.status == Tile::Status::Unavailable) {
|
||||
if(i>0){
|
||||
chunkTilePile.chunkTiles[i].tile = chunkTilePile.chunkTiles[i-1].tile;
|
||||
chunkTilePile.chunkTiles[i].uvTransform.uvOffset = chunkTilePile.chunkTiles[i-1].uvTransform.uvOffset;
|
||||
chunkTilePile.chunkTiles[i].uvTransform.uvScale = chunkTilePile.chunkTiles[i-1].uvTransform.uvScale;
|
||||
}
|
||||
else{
|
||||
chunkTilePile.chunkTiles[i].tile = tileProvider->getDefaultTile();
|
||||
chunkTilePile.chunkTiles[i].uvTransform.uvOffset = { 0, 0 };
|
||||
chunkTilePile.chunkTiles[i].uvTransform.uvScale = { 1, 1 };
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::move(chunkTilePile);
|
||||
}
|
||||
|
||||
ChunkTile TileSelector::getHighestResolutionTile(TileProvider* tileProvider, TileIndex tileIndex, int parents) {
|
||||
TileUvTransform uvTransform;
|
||||
uvTransform.uvOffset = glm::vec2(0, 0);
|
||||
uvTransform.uvScale = glm::vec2(1, 1);
|
||||
|
||||
// Step 1. Traverse 0 or more parents up the chunkTree as requested by the caller
|
||||
for (int i = 0; i < parents && tileIndex.level > 1; i++) {
|
||||
ascendToParent(tileIndex, uvTransform);
|
||||
}
|
||||
|
||||
// Step 2. Traverse 0 or more parents up the chunkTree to make sure we're inside
|
||||
// the range of defined data.
|
||||
int maximumLevel = tileProvider->maxLevel();
|
||||
while(tileIndex.level > maximumLevel){
|
||||
ascendToParent(tileIndex, uvTransform);
|
||||
}
|
||||
|
||||
// Step 3. Traverse 0 or more parents up the chunkTree until we find a chunk that
|
||||
// has a loaded tile ready to use.
|
||||
while (tileIndex.level > 1) {
|
||||
Tile tile = tileProvider->getTile(tileIndex);
|
||||
if (tile.status != Tile::Status::OK) {
|
||||
ascendToParent(tileIndex, uvTransform);
|
||||
}
|
||||
else return { tile, uvTransform };
|
||||
}
|
||||
|
||||
return{ Tile::TileUnavailable, uvTransform };
|
||||
}
|
||||
|
||||
ChunkTile TileSelector::getHighestResolutionTile(const LayerGroup& layerGroup, TileIndex tileIndex) {
|
||||
ChunkTile mostHighResolution;
|
||||
mostHighResolution.tile = Tile::TileUnavailable;
|
||||
mostHighResolution.uvTransform.uvScale.x = 0;
|
||||
|
||||
for (const auto& layer : layerGroup.activeLayers()) {
|
||||
ChunkTile chunkTile = getHighestResolutionTile(layer->tileProvider(), tileIndex);
|
||||
ChunkTile chunkTile = layer->tileProvider()->getChunkTile(tileIndex);
|
||||
bool tileIsOk = chunkTile.tile.status == Tile::Status::OK;
|
||||
bool tileHasMetaData = chunkTile.tile.metaData != nullptr;
|
||||
bool tileIsHigherResolution = chunkTile.uvTransform.uvScale.x > mostHighResolution.uvTransform.uvScale.x;
|
||||
@@ -120,7 +68,7 @@ namespace globebrowsing {
|
||||
std::vector<ChunkTile> TileSelector::getTilesSortedByHighestResolution(const LayerGroup& layerGroup, const TileIndex& tileIndex) {
|
||||
std::vector<ChunkTile> tiles;
|
||||
for (const auto& layer : layerGroup.activeLayers()) {
|
||||
tiles.push_back(getHighestResolutionTile(layer->tileProvider(), tileIndex));
|
||||
tiles.push_back(layer->tileProvider()->getChunkTile(tileIndex));
|
||||
}
|
||||
|
||||
std::sort(tiles.begin(), tiles.end(), TileSelector::HIGHEST_RES);
|
||||
|
||||
@@ -41,12 +41,7 @@ namespace globebrowsing {
|
||||
|
||||
class TileSelector {
|
||||
public:
|
||||
static ChunkTile getHighestResolutionTile(TileProvider* tileProvider, TileIndex tileIndex, int parents = 0);
|
||||
static ChunkTile getHighestResolutionTile(
|
||||
const LayerGroup& layerGroup,
|
||||
TileIndex tileIndex
|
||||
);
|
||||
static ChunkTilePile getHighestResolutionTilePile(TileProvider* tileProvider, TileIndex tileIndex, int pileSize);
|
||||
static ChunkTile getHighestResolutionTile(const LayerGroup& layerGroup, TileIndex tileIndex);
|
||||
static std::vector<ChunkTile> getTilesSortedByHighestResolution(const LayerGroup& layerGroup, const TileIndex& tileIndex);
|
||||
|
||||
struct CompareResolution {
|
||||
@@ -55,7 +50,6 @@ namespace globebrowsing {
|
||||
|
||||
static const CompareResolution HIGHEST_RES;
|
||||
|
||||
private:
|
||||
static void ascendToParent(TileIndex& tileIndex, TileUvTransform& uv);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user