mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Rename: ChunkIndex -> TileIndex
This commit is contained in:
@@ -30,7 +30,6 @@ set(HEADER_FILES
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkedlodglobe.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunknode.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkindex.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunk.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkrenderer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling.h
|
||||
@@ -55,6 +54,7 @@ set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/temporaltileprovider.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tile.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileindex.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileselector.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tilediskcache.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledataset.h
|
||||
@@ -82,7 +82,6 @@ set(SOURCE_FILES
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkedlodglobe.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunknode.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkindex.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunk.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkrenderer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling.cpp
|
||||
@@ -107,6 +106,7 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/temporaltileprovider.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileindex.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileselector.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tilediskcache.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledataset.cpp
|
||||
|
||||
@@ -43,10 +43,10 @@ namespace openspace {
|
||||
|
||||
const float Chunk::DEFAULT_HEIGHT = 0.0f;
|
||||
|
||||
Chunk::Chunk(const RenderableGlobe& owner, const ChunkIndex& chunkIndex, bool initVisible)
|
||||
Chunk::Chunk(const RenderableGlobe& owner, const TileIndex& tileIndex, bool initVisible)
|
||||
: _owner(owner)
|
||||
, _surfacePatch(chunkIndex)
|
||||
, _index(chunkIndex)
|
||||
, _surfacePatch(tileIndex)
|
||||
, _tileIndex(tileIndex)
|
||||
, _isVisible(initVisible)
|
||||
{
|
||||
|
||||
@@ -60,16 +60,16 @@ namespace openspace {
|
||||
return _owner;
|
||||
}
|
||||
|
||||
const ChunkIndex Chunk::index() const {
|
||||
return _index;
|
||||
const TileIndex Chunk::tileIndex() const {
|
||||
return _tileIndex;
|
||||
}
|
||||
|
||||
bool Chunk::isVisible() const {
|
||||
return _isVisible;
|
||||
}
|
||||
|
||||
void Chunk::setIndex(const ChunkIndex& index) {
|
||||
_index = index;
|
||||
void Chunk::setIndex(const TileIndex& index) {
|
||||
_tileIndex = index;
|
||||
_surfacePatch = GeodeticPatch(index);
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ namespace openspace {
|
||||
|
||||
int desiredLevel = _owner.chunkedLodGlobe()->getDesiredLevel(*this, myRenderData);
|
||||
|
||||
if (desiredLevel < _index.level) return Status::WANT_MERGE;
|
||||
else if (_index.level < desiredLevel) return Status::WANT_SPLIT;
|
||||
if (desiredLevel < _tileIndex.level) return Status::WANT_MERGE;
|
||||
else if (_tileIndex.level < desiredLevel) return Status::WANT_SPLIT;
|
||||
else return Status::DO_NOTHING;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace openspace {
|
||||
|
||||
size_t HEIGHT_CHANNEL = 0;
|
||||
const TileProviderGroup& heightmaps = tileProviderManager->getTileProviderGroup(LayeredTextures::HeightMaps);
|
||||
std::vector<TileAndTransform> tiles = TileSelector::getTilesSortedByHighestResolution(heightmaps, _index);
|
||||
std::vector<TileAndTransform> tiles = TileSelector::getTilesSortedByHighestResolution(heightmaps, _tileIndex);
|
||||
bool lastHadMissingData = true;
|
||||
for (auto tile : tiles) {
|
||||
bool goodTile = tile.tile.status == Tile::Status::OK;
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <ostream>
|
||||
|
||||
#include <modules/globebrowsing/chunk/culling.h>
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator.h>
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace openspace {
|
||||
WANT_SPLIT,
|
||||
};
|
||||
|
||||
Chunk(const RenderableGlobe& owner, const ChunkIndex& chunkIndex, bool initVisible = true);
|
||||
Chunk(const RenderableGlobe& owner, const TileIndex& tileIndex, bool initVisible = true);
|
||||
|
||||
/// Updates chunk internally and returns a desired level
|
||||
Status update(const RenderData& data);
|
||||
@@ -68,16 +68,16 @@ namespace openspace {
|
||||
|
||||
const GeodeticPatch& surfacePatch() const;
|
||||
const RenderableGlobe& owner() const;
|
||||
const ChunkIndex index() const;
|
||||
const TileIndex tileIndex() const;
|
||||
bool isVisible() const;
|
||||
BoundingHeights getBoundingHeights() const;
|
||||
|
||||
void setIndex(const ChunkIndex& index);
|
||||
void setIndex(const TileIndex& index);
|
||||
|
||||
private:
|
||||
|
||||
const RenderableGlobe& _owner;
|
||||
ChunkIndex _index;
|
||||
TileIndex _tileIndex;
|
||||
bool _isVisible;
|
||||
GeodeticPatch _surfacePatch;
|
||||
|
||||
|
||||
@@ -54,10 +54,10 @@ namespace {
|
||||
|
||||
namespace openspace {
|
||||
|
||||
const ChunkIndex ChunkedLodGlobe::LEFT_HEMISPHERE_INDEX =
|
||||
ChunkIndex(0, 0, 1);
|
||||
const ChunkIndex ChunkedLodGlobe::RIGHT_HEMISPHERE_INDEX =
|
||||
ChunkIndex(1, 0, 1);
|
||||
const TileIndex ChunkedLodGlobe::LEFT_HEMISPHERE_INDEX =
|
||||
TileIndex(0, 0, 1);
|
||||
const TileIndex ChunkedLodGlobe::RIGHT_HEMISPHERE_INDEX =
|
||||
TileIndex(1, 0, 1);
|
||||
const GeodeticPatch ChunkedLodGlobe::COVERAGE =
|
||||
GeodeticPatch(0, 0, 90, 180);
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace openspace {
|
||||
screenSpaceBounds.expand(screenSpaceCorner);
|
||||
}
|
||||
|
||||
unsigned int colorBits = 1 + chunk.index().level % 6;
|
||||
unsigned int colorBits = 1 + chunk.tileIndex().level % 6;
|
||||
vec4 color = vec4(colorBits & 1, colorBits & 2, colorBits & 4, 0.3);
|
||||
|
||||
if (_owner.debugProperties().showChunkBounds) {
|
||||
@@ -251,4 +251,4 @@ namespace openspace {
|
||||
void ChunkedLodGlobe::update(const UpdateData& data) {
|
||||
_renderer->update();
|
||||
}
|
||||
} // namespace openspace
|
||||
} // namespace openspace
|
||||
|
||||
@@ -79,8 +79,8 @@ namespace openspace {
|
||||
void debugRenderChunk(const Chunk& chunk, const glm::dmat4& data) const;
|
||||
|
||||
static const GeodeticPatch COVERAGE;
|
||||
static const ChunkIndex LEFT_HEMISPHERE_INDEX;
|
||||
static const ChunkIndex RIGHT_HEMISPHERE_INDEX;
|
||||
static const TileIndex LEFT_HEMISPHERE_INDEX;
|
||||
static const TileIndex RIGHT_HEMISPHERE_INDEX;
|
||||
|
||||
// Covers all negative longitudes
|
||||
std::unique_ptr<ChunkNode> _leftRoot;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "ChunkIndex";
|
||||
const std::string _loggerCat = "TileIndex";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
@@ -37,7 +37,7 @@ namespace openspace {
|
||||
Creates the geodetic tile index for the Geodetic patch that covers the
|
||||
point p at the specified level
|
||||
*/
|
||||
ChunkIndex::ChunkIndex(const Geodetic2& point, int level)
|
||||
TileIndex::TileIndex(const Geodetic2& point, int level)
|
||||
: level(level) {
|
||||
int numIndicesAtLevel = 1 << level;
|
||||
double u = 0.5 + point.lon / (2 * M_PI);
|
||||
@@ -49,29 +49,29 @@ namespace openspace {
|
||||
y = floor(yIndexSpace);
|
||||
}
|
||||
|
||||
ChunkIndex ChunkIndex::child(Quad q) const {
|
||||
return ChunkIndex(2 * x + q % 2, 2 * y + q / 2, level + 1);
|
||||
TileIndex TileIndex::child(Quad q) const {
|
||||
return TileIndex(2 * x + q % 2, 2 * y + q / 2, level + 1);
|
||||
}
|
||||
|
||||
ChunkIndex ChunkIndex::parent() const {
|
||||
TileIndex TileIndex::parent() const {
|
||||
//ghoul_assert(level > 0, "tile at level 0 has no parent!");
|
||||
return ChunkIndex(x / 2, y / 2, level - 1);
|
||||
return TileIndex(x / 2, y / 2, level - 1);
|
||||
}
|
||||
|
||||
ChunkIndex& ChunkIndex::operator--() {
|
||||
TileIndex& TileIndex::operator--() {
|
||||
x /= 2;
|
||||
y /= 2;
|
||||
level--;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ChunkIndex ChunkIndex::operator--(int) {
|
||||
ChunkIndex tmp(*this);
|
||||
TileIndex TileIndex::operator--(int) {
|
||||
TileIndex tmp(*this);
|
||||
--(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
ChunkIndex& ChunkIndex::operator-=(unsigned int levels) {
|
||||
TileIndex& TileIndex::operator-=(unsigned int levels) {
|
||||
x <<= levels;
|
||||
y <<= levels;
|
||||
level -= levels;
|
||||
@@ -83,14 +83,14 @@ namespace openspace {
|
||||
Gets the tile at a specified offset from this tile.
|
||||
Accepts delta indices ranging from [-2^level, Infinity[
|
||||
*/
|
||||
ChunkIndex ChunkIndex::getRelatedTile(int deltaX, int deltaY) const {
|
||||
TileIndex TileIndex::getRelatedTile(int deltaX, int deltaY) const {
|
||||
int indicesAtThisLevel = 1 << level;
|
||||
int newX = (indicesAtThisLevel + x + deltaX) % indicesAtThisLevel;
|
||||
int newY = (indicesAtThisLevel + y + deltaY) % indicesAtThisLevel;
|
||||
return ChunkIndex(newX, newY, level);
|
||||
return TileIndex(newX, newY, level);
|
||||
}
|
||||
|
||||
int ChunkIndex::manhattan(const ChunkIndex& other) const {
|
||||
int TileIndex::manhattan(const TileIndex& other) const {
|
||||
ghoul_assert(level == other.level, "makes no sense if not on same level");
|
||||
return std::abs(x - other.x) + std::abs(y - other.y);
|
||||
}
|
||||
@@ -104,16 +104,16 @@ namespace openspace {
|
||||
26-46 | y
|
||||
46-64 | reserved for future use, e.g. time key
|
||||
*/
|
||||
ChunkHashKey ChunkIndex::hashKey() const {
|
||||
ChunkHashKey key = 0LL;
|
||||
TileHashKey TileIndex::hashKey() const {
|
||||
TileHashKey key = 0LL;
|
||||
key |= level;
|
||||
key |= x << 6;
|
||||
key |= ((ChunkHashKey)y) << 26;
|
||||
key |= ((TileHashKey)y) << 26;
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
std::string ChunkIndex::toString() const {
|
||||
std::string TileIndex::toString() const {
|
||||
std::stringstream ss;
|
||||
for (int i = level; i > 0; i--){
|
||||
char digit = '0';
|
||||
@@ -130,11 +130,11 @@ namespace openspace {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool ChunkIndex::operator==(const ChunkIndex& other) const {
|
||||
bool TileIndex::operator==(const TileIndex& other) const {
|
||||
return x == other.x && y == other.y && level == other.level;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const ChunkIndex& ci) {
|
||||
std::ostream& operator<<(std::ostream& os, const TileIndex& ci) {
|
||||
os << "{ x = " << ci.x << ", y = " << ci.y << ", level = " << ci.level << " }";
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -54,31 +54,31 @@ enum CardinalDirection {
|
||||
|
||||
|
||||
|
||||
using ChunkHashKey = uint64_t;
|
||||
using TileHashKey = uint64_t;
|
||||
|
||||
|
||||
struct ChunkIndex {
|
||||
struct TileIndex {
|
||||
|
||||
|
||||
int x, y, level;
|
||||
|
||||
|
||||
ChunkIndex() : x(0), y(0), level(0) { }
|
||||
ChunkIndex(int x, int y, int level) : x(x), y(y), level(level) { }
|
||||
ChunkIndex(const ChunkIndex& other) : x(other.x), y(other.y), level(other.level) { }
|
||||
ChunkIndex(const Geodetic2& point, int level);
|
||||
TileIndex() : x(0), y(0), level(0) { }
|
||||
TileIndex(int x, int y, int level) : x(x), y(y), level(level) { }
|
||||
TileIndex(const TileIndex& other) : x(other.x), y(other.y), level(other.level) { }
|
||||
TileIndex(const Geodetic2& point, int level);
|
||||
|
||||
|
||||
bool hasParent() const {
|
||||
return level > 0;
|
||||
}
|
||||
|
||||
ChunkIndex parent() const;
|
||||
TileIndex parent() const;
|
||||
|
||||
ChunkIndex& operator--();
|
||||
ChunkIndex operator--(int);
|
||||
TileIndex& operator--();
|
||||
TileIndex operator--(int);
|
||||
|
||||
ChunkIndex& operator-=(unsigned int levels);
|
||||
TileIndex& operator-=(unsigned int levels);
|
||||
|
||||
bool isWestChild() const {
|
||||
return x % 2 == 0;
|
||||
@@ -97,7 +97,7 @@ struct ChunkIndex {
|
||||
}
|
||||
|
||||
|
||||
ChunkIndex child(Quad q) const;
|
||||
TileIndex child(Quad q) const;
|
||||
|
||||
|
||||
std::string toString() const;
|
||||
@@ -106,17 +106,17 @@ struct ChunkIndex {
|
||||
Gets the tile at a specified offset from this tile.
|
||||
Accepts delta indices ranging from [-2^level, Infinity[
|
||||
*/
|
||||
ChunkIndex getRelatedTile(int deltaX, int deltaY) const;
|
||||
TileIndex getRelatedTile(int deltaX, int deltaY) const;
|
||||
|
||||
int manhattan(const ChunkIndex& other) const;
|
||||
int manhattan(const TileIndex& other) const;
|
||||
|
||||
ChunkHashKey hashKey() const;
|
||||
TileHashKey hashKey() const;
|
||||
|
||||
bool operator==(const ChunkIndex& other) const;
|
||||
bool operator==(const TileIndex& other) const;
|
||||
};
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const ChunkIndex& ti);
|
||||
std::ostream& operator<<(std::ostream& os, const TileIndex& ti);
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -158,18 +158,18 @@ namespace openspace {
|
||||
double projectedChunkAreaApprox = 8 * areaABC;
|
||||
|
||||
double scaledArea = globe.generalProperties().lodScaleFactor * projectedChunkAreaApprox;
|
||||
return chunk.index().level + round(scaledArea - 1);
|
||||
return chunk.tileIndex().level + round(scaledArea - 1);
|
||||
}
|
||||
|
||||
int EvaluateChunkLevelByAvailableTileData::getDesiredLevel(const Chunk& chunk, const RenderData& data) const {
|
||||
auto tileProvidermanager = chunk.owner().chunkedLodGlobe()->getTileProviderManager();
|
||||
auto heightMapProviders = tileProvidermanager->getTileProviderGroup(LayeredTextures::HeightMaps).getActiveTileProviders();
|
||||
int currLevel = chunk.index().level;
|
||||
int currLevel = chunk.tileIndex().level;
|
||||
|
||||
for (size_t i = 0; i < LayeredTextures::NUM_TEXTURE_CATEGORIES; i++) {
|
||||
auto tileProviderGroup = tileProvidermanager->getTileProviderGroup(i);
|
||||
for (auto tileProvider : tileProviderGroup.getActiveTileProviders()) {
|
||||
Tile::Status tileStatus = tileProvider->getTileStatus(chunk.index());
|
||||
Tile::Status tileStatus = tileProvider->getTileStatus(chunk.tileIndex());
|
||||
|
||||
if (tileStatus == Tile::Status::OK) {
|
||||
return UNKNOWN_DESIRED_LEVEL;
|
||||
|
||||
@@ -191,7 +191,7 @@ ChunkNode& ChunkNode::getChild(Quad quad) {
|
||||
void ChunkNode::split(int depth) {
|
||||
if (depth > 0 && isLeaf()) {
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
Chunk chunk(_chunk.owner(), _chunk.index().child((Quad)i));
|
||||
Chunk chunk(_chunk.owner(), _chunk.tileIndex().child((Quad)i));
|
||||
_children[i] = std::unique_ptr<ChunkNode>(new ChunkNode(chunk, this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/chunk/chunkrenderer.h>
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
void ChunkRenderer::renderChunk(const Chunk& chunk, const RenderData& data) {
|
||||
if (chunk.index().level < 10) {
|
||||
if (chunk.tileIndex().level < 10) {
|
||||
renderChunkGlobally(chunk, data);
|
||||
}
|
||||
else {
|
||||
@@ -184,7 +184,7 @@ namespace openspace {
|
||||
std::shared_ptr<LayeredTextureShaderUniformIdHandler> programUniformHandler,
|
||||
const Chunk& chunk)
|
||||
{
|
||||
const ChunkIndex& chunkIndex = chunk.index();
|
||||
const TileIndex& tileIndex = chunk.tileIndex();
|
||||
|
||||
std::array<std::vector<std::shared_ptr<TileProvider> >,
|
||||
LayeredTextures::NUM_TEXTURE_CATEGORIES> tileProviders;
|
||||
@@ -262,7 +262,7 @@ namespace openspace {
|
||||
auto tileProvider = it->get();
|
||||
|
||||
// Get the texture that should be used for rendering
|
||||
TileAndTransform tileAndTransform = TileSelector::getHighestResolutionTile(tileProvider, chunkIndex);
|
||||
TileAndTransform tileAndTransform = TileSelector::getHighestResolutionTile(tileProvider, tileIndex);
|
||||
if (tileAndTransform.tile.status == Tile::Status::Unavailable) {
|
||||
tileAndTransform.tile = tileProvider->getDefaultTile();
|
||||
tileAndTransform.uvTransform.uvOffset = { 0, 0 };
|
||||
@@ -279,7 +279,7 @@ namespace openspace {
|
||||
|
||||
// If blending is enabled, two more textures are needed
|
||||
if (layeredTexturePreprocessingData.layeredTextureInfo[category].layerBlendingEnabled) {
|
||||
TileAndTransform tileAndTransformParent1 = TileSelector::getHighestResolutionTile(tileProvider, chunkIndex, 1);
|
||||
TileAndTransform tileAndTransformParent1 = TileSelector::getHighestResolutionTile(tileProvider, tileIndex, 1);
|
||||
if (tileAndTransformParent1.tile.status == Tile::Status::Unavailable) {
|
||||
tileAndTransformParent1 = tileAndTransform;
|
||||
}
|
||||
@@ -291,7 +291,7 @@ namespace openspace {
|
||||
texUnits[category][i].blendTexture1,
|
||||
tileAndTransformParent1);
|
||||
|
||||
TileAndTransform tileAndTransformParent2 = TileSelector::getHighestResolutionTile(tileProvider, chunkIndex, 2);
|
||||
TileAndTransform tileAndTransformParent2 = TileSelector::getHighestResolutionTile(tileProvider, tileIndex, 2);
|
||||
if (tileAndTransformParent2.tile.status == Tile::Status::Unavailable) {
|
||||
tileAndTransformParent2 = tileAndTransformParent1;
|
||||
}
|
||||
@@ -381,7 +381,7 @@ namespace openspace {
|
||||
float distanceScaleFactor = chunk.owner().generalProperties().lodScaleFactor * ellipsoid.minimumRadius();
|
||||
programObject->setUniform("cameraPosition", vec3(cameraPosition));
|
||||
programObject->setUniform("distanceScaleFactor", distanceScaleFactor);
|
||||
programObject->setUniform("chunkLevel", chunk.index().level);
|
||||
programObject->setUniform("chunkLevel", chunk.tileIndex().level);
|
||||
}
|
||||
|
||||
// Calculate other uniform variables needed for rendering
|
||||
@@ -454,7 +454,7 @@ namespace openspace {
|
||||
if (performAnyBlending) {
|
||||
float distanceScaleFactor = chunk.owner().generalProperties().lodScaleFactor * chunk.owner().ellipsoid().minimumRadius();
|
||||
programObject->setUniform("distanceScaleFactor", distanceScaleFactor);
|
||||
programObject->setUniform("chunkLevel", chunk.index().level);
|
||||
programObject->setUniform("chunkLevel", chunk.tileIndex().level);
|
||||
}
|
||||
|
||||
// Calculate other uniform variables needed for rendering
|
||||
|
||||
@@ -115,10 +115,10 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
GeodeticPatch::GeodeticPatch(const ChunkIndex& chunkIndex) {
|
||||
Scalar deltaLat = (2 * M_PI) / ((double)(1 << chunkIndex.level));
|
||||
Scalar deltaLon = (2 * M_PI) / ((double)(1 << chunkIndex.level));
|
||||
Geodetic2 nwCorner(M_PI / 2 - deltaLat * chunkIndex.y, -M_PI + deltaLon * chunkIndex.x);
|
||||
GeodeticPatch::GeodeticPatch(const TileIndex& tileIndex) {
|
||||
Scalar deltaLat = (2 * M_PI) / ((double)(1 << tileIndex.level));
|
||||
Scalar deltaLon = (2 * M_PI) / ((double)(1 << tileIndex.level));
|
||||
Geodetic2 nwCorner(M_PI / 2 - deltaLat * tileIndex.y, -M_PI + deltaLon * tileIndex.x);
|
||||
_halfSize = Geodetic2(deltaLat / 2, deltaLon / 2);
|
||||
_center = Geodetic2(nwCorner.lat - _halfSize.lat, nwCorner.lon + _halfSize.lon);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
|
||||
GeodeticPatch(const GeodeticPatch& patch);
|
||||
|
||||
GeodeticPatch(const ChunkIndex& chunkIndex);
|
||||
GeodeticPatch(const TileIndex& tileIndex);
|
||||
|
||||
|
||||
void setCenter(const Geodetic2&);
|
||||
|
||||
@@ -62,7 +62,7 @@ void GlobeBrowsingModule::internalInitialize() {
|
||||
fTileProvider->registerClass<CachingTileProvider>("LRUCaching");
|
||||
fTileProvider->registerClass<SingleImageProvider>("SingleImage");
|
||||
fTileProvider->registerClass<TemporalTileProvider>("Temporal");
|
||||
fTileProvider->registerClass<ChunkIndexTileProvider>("ChunkIndex");
|
||||
fTileProvider->registerClass<ChunkIndexTileProvider>("TileIndex");
|
||||
fTileProvider->registerClass<SizeReferenceTileProvider>("SizeReference");
|
||||
|
||||
}
|
||||
|
||||
@@ -297,9 +297,9 @@ namespace openspace {
|
||||
// Get the uv coordinates to sample from
|
||||
Geodetic2 geodeticPosition = _ellipsoid.cartesianToGeodetic2(position);
|
||||
int chunkLevel = _chunkedLodGlobe->findChunkNode(
|
||||
geodeticPosition).getChunk().index().level;
|
||||
geodeticPosition).getChunk().tileIndex().level;
|
||||
|
||||
ChunkIndex chunkIdx = ChunkIndex(geodeticPosition, chunkLevel);
|
||||
TileIndex chunkIdx = TileIndex(geodeticPosition, chunkLevel);
|
||||
GeodeticPatch patch = GeodeticPatch(chunkIdx);
|
||||
Geodetic2 geoDiffPatch =
|
||||
patch.getCorner(Quad::NORTH_EAST) -
|
||||
|
||||
@@ -50,8 +50,8 @@ namespace openspace {
|
||||
|
||||
|
||||
DiskCachedTileLoadJob::DiskCachedTileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const ChunkIndex& chunkIndex, std::shared_ptr<TileDiskCache> tdc, CacheMode m)
|
||||
: TileLoadJob(textureDataProvider, chunkIndex)
|
||||
const TileIndex& tileIndex, std::shared_ptr<TileDiskCache> tdc, CacheMode m)
|
||||
: TileLoadJob(textureDataProvider, tileIndex)
|
||||
, _tileDiskCache(tdc)
|
||||
, _mode(m)
|
||||
{
|
||||
@@ -59,8 +59,8 @@ namespace openspace {
|
||||
}
|
||||
|
||||
DiskCachedTileLoadJob::DiskCachedTileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const ChunkIndex& chunkIndex, std::shared_ptr<TileDiskCache> tdc, const std::string cacheMode)
|
||||
: TileLoadJob(textureDataProvider, chunkIndex)
|
||||
const TileIndex& tileIndex, std::shared_ptr<TileDiskCache> tdc, const std::string cacheMode)
|
||||
: TileLoadJob(textureDataProvider, tileIndex)
|
||||
, _tileDiskCache(tdc)
|
||||
{
|
||||
if (cacheMode == "Disabled") _mode = CacheMode::Disabled;
|
||||
@@ -104,7 +104,7 @@ namespace openspace {
|
||||
_tileIOResult = _tileDiskCache->get(_chunkIndex);
|
||||
if (_tileIOResult == nullptr) {
|
||||
TileIOResult res = TileIOResult::createDefaultRes();
|
||||
res.chunkIndex = _chunkIndex;
|
||||
res.tileIndex = _chunkIndex;
|
||||
_tileIOResult = std::make_shared<TileIOResult>(res);
|
||||
}
|
||||
break;
|
||||
@@ -133,12 +133,12 @@ namespace openspace {
|
||||
return _tileDataset;
|
||||
}
|
||||
|
||||
bool AsyncTileDataProvider::enqueueTileIO(const ChunkIndex& chunkIndex) {
|
||||
if (satisfiesEnqueueCriteria(chunkIndex)) {
|
||||
auto job = std::make_shared<TileLoadJob>(_tileDataset, chunkIndex);
|
||||
//auto job = std::make_shared<DiskCachedTileLoadJob>(_tileDataset, chunkIndex, tileDiskCache, "ReadAndWrite");
|
||||
bool AsyncTileDataProvider::enqueueTileIO(const TileIndex& tileIndex) {
|
||||
if (satisfiesEnqueueCriteria(tileIndex)) {
|
||||
auto job = std::make_shared<TileLoadJob>(_tileDataset, tileIndex);
|
||||
//auto job = std::make_shared<DiskCachedTileLoadJob>(_tileDataset, tileIndex, tileDiskCache, "ReadAndWrite");
|
||||
_concurrentJobManager.enqueueJob(job);
|
||||
_enqueuedTileRequests[chunkIndex.hashKey()] = chunkIndex;
|
||||
_enqueuedTileRequests[tileIndex.hashKey()] = tileIndex;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -154,10 +154,10 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
bool AsyncTileDataProvider::satisfiesEnqueueCriteria(const ChunkIndex& chunkIndex) const {
|
||||
bool AsyncTileDataProvider::satisfiesEnqueueCriteria(const TileIndex& tileIndex) const {
|
||||
// only allow tile to be enqueued if it's not already enqueued
|
||||
//return _futureTileIOResults.find(chunkIndex.hashKey()) == _futureTileIOResults.end();
|
||||
return _enqueuedTileRequests.find(chunkIndex.hashKey()) == _enqueuedTileRequests.end();
|
||||
//return _futureTileIOResults.find(tileIndex.hashKey()) == _futureTileIOResults.end();
|
||||
return _enqueuedTileRequests.find(tileIndex.hashKey()) == _enqueuedTileRequests.end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -58,9 +58,9 @@ namespace openspace {
|
||||
|
||||
|
||||
TileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const ChunkIndex& chunkIndex)
|
||||
const TileIndex& tileIndex)
|
||||
: _tileDataset(textureDataProvider)
|
||||
, _chunkIndex(chunkIndex)
|
||||
, _chunkIndex(tileIndex)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -76,7 +76,7 @@ namespace openspace {
|
||||
|
||||
protected:
|
||||
|
||||
ChunkIndex _chunkIndex;
|
||||
TileIndex _chunkIndex;
|
||||
std::shared_ptr<TileDataset> _tileDataset;
|
||||
std::shared_ptr<TileIOResult> _tileIOResult;
|
||||
};
|
||||
@@ -96,11 +96,11 @@ namespace openspace {
|
||||
};
|
||||
|
||||
DiskCachedTileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const ChunkIndex& chunkIndex, std::shared_ptr<TileDiskCache> tdc,
|
||||
const TileIndex& tileIndex, std::shared_ptr<TileDiskCache> tdc,
|
||||
const std::string cacheMode);
|
||||
|
||||
DiskCachedTileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const ChunkIndex& chunkIndex, std::shared_ptr<TileDiskCache> tdc,
|
||||
const TileIndex& tileIndex, std::shared_ptr<TileDiskCache> tdc,
|
||||
CacheMode cacheMode = CacheMode::ReadOnly);
|
||||
|
||||
virtual void execute();
|
||||
@@ -124,7 +124,7 @@ namespace openspace {
|
||||
~AsyncTileDataProvider();
|
||||
|
||||
|
||||
bool enqueueTileIO(const ChunkIndex& chunkIndex);
|
||||
bool enqueueTileIO(const TileIndex& tileIndex);
|
||||
std::vector<std::shared_ptr<TileIOResult>> getTileIOResults();
|
||||
|
||||
void reset();
|
||||
@@ -134,7 +134,7 @@ namespace openspace {
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool satisfiesEnqueueCriteria(const ChunkIndex&) const;
|
||||
virtual bool satisfiesEnqueueCriteria(const TileIndex&) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace openspace {
|
||||
|
||||
std::shared_ptr<TileDataset> _tileDataset;
|
||||
ConcurrentJobManager<TileIOResult> _concurrentJobManager;
|
||||
std::unordered_map<ChunkHashKey, ChunkIndex> _enqueuedTileRequests;
|
||||
std::unordered_map<TileHashKey, TileIndex> _enqueuedTileRequests;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace openspace {
|
||||
|
||||
/**
|
||||
* Can be set by <code>TileProvider</code>s if the requested
|
||||
* <code>ChunkIndex</code> is undefined for that particular
|
||||
* <code>TileIndex</code> is undefined for that particular
|
||||
* provider.
|
||||
* texture and preprocessData are both null
|
||||
*/
|
||||
|
||||
@@ -220,16 +220,16 @@ namespace openspace {
|
||||
// Public interface //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::shared_ptr<TileIOResult> TileDataset::readTileData(ChunkIndex chunkIndex) {
|
||||
std::shared_ptr<TileIOResult> TileDataset::readTileData(TileIndex tileIndex) {
|
||||
ensureInitialized();
|
||||
IODescription io = getIODescription(chunkIndex);
|
||||
IODescription io = getIODescription(tileIndex);
|
||||
CPLErr worstError = CPLErr::CE_None;
|
||||
|
||||
// Build the Tile IO Result from the data we queride
|
||||
std::shared_ptr<TileIOResult> result = std::make_shared<TileIOResult>();
|
||||
result->imageData = readImageData(io, worstError);
|
||||
result->error = worstError;
|
||||
result->chunkIndex = chunkIndex;
|
||||
result->tileIndex = tileIndex;
|
||||
result->dimensions = glm::uvec3(io.write.region.numPixels, 1);
|
||||
result->nBytesImageData = io.write.totalNumBytes;
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace openspace {
|
||||
ensureInitialized();
|
||||
PixelRegion pixelRegion = { PixelCoordinate(0, 0), PixelRange(16, 16) };
|
||||
std::shared_ptr<TileIOResult> result = std::make_shared<TileIOResult>();
|
||||
result->chunkIndex = { 0, 0, 0 };
|
||||
result->tileIndex = { 0, 0, 0 };
|
||||
result->dimensions = glm::uvec3(pixelRegion.numPixels, 1);
|
||||
result->nBytesImageData = result->dimensions.x * result->dimensions.y * _dataLayout.bytesPerPixel;
|
||||
result->imageData = new char[result->nBytesImageData];
|
||||
@@ -352,16 +352,16 @@ namespace openspace {
|
||||
return ov;
|
||||
}
|
||||
|
||||
int TileDataset::gdalOverview(const ChunkIndex& chunkIndex) const {
|
||||
int TileDataset::gdalOverview(const TileIndex& tileIndex) const {
|
||||
int overviews = _dataset->GetRasterBand(1)->GetOverviewCount();
|
||||
int ov = overviews - (chunkIndex.level + _cached._tileLevelDifference + 1);
|
||||
int ov = overviews - (tileIndex.level + _cached._tileLevelDifference + 1);
|
||||
return glm::clamp(ov, 0, overviews - 1);
|
||||
}
|
||||
|
||||
|
||||
int TileDataset::gdalVirtualOverview(const ChunkIndex& chunkIndex) const {
|
||||
int TileDataset::gdalVirtualOverview(const TileIndex& tileIndex) const {
|
||||
int overviews = _dataset->GetRasterBand(1)->GetOverviewCount();
|
||||
int ov = overviews - (chunkIndex.level + _cached._tileLevelDifference + 1);
|
||||
int ov = overviews - (tileIndex.level + _cached._tileLevelDifference + 1);
|
||||
return ov;
|
||||
}
|
||||
|
||||
@@ -447,12 +447,12 @@ namespace openspace {
|
||||
return geodetic;
|
||||
}
|
||||
|
||||
IODescription TileDataset::getIODescription(const ChunkIndex& chunkIndex) const {
|
||||
IODescription TileDataset::getIODescription(const TileIndex& tileIndex) const {
|
||||
IODescription io;
|
||||
io.read.region = gdalPixelRegion(chunkIndex);
|
||||
io.read.region = gdalPixelRegion(tileIndex);
|
||||
|
||||
if (gdalHasOverviews()) {
|
||||
int overview = gdalOverview(chunkIndex);
|
||||
int overview = gdalOverview(tileIndex);
|
||||
io.read.overview = overview;
|
||||
io.read.region.downscalePow2(overview + 1);
|
||||
io.write.region = io.read.region;
|
||||
@@ -461,7 +461,7 @@ namespace openspace {
|
||||
else {
|
||||
io.read.overview = 0;
|
||||
io.write.region = io.read.region;
|
||||
int virtualOverview = gdalVirtualOverview(chunkIndex);
|
||||
int virtualOverview = gdalVirtualOverview(tileIndex);
|
||||
io.write.region.downscalePow2(virtualOverview + 1);
|
||||
PixelRegion scaledPadding = padding;
|
||||
|
||||
@@ -475,7 +475,7 @@ namespace openspace {
|
||||
io.write.region.roundDownToQuadratic();
|
||||
io.write.region.roundUpNumPixelToNearestMultipleOf(2);
|
||||
if (preRound != io.write.region.numPixels) {
|
||||
LDEBUG(chunkIndex << " | " << preRound.x << ", " << preRound.y << " --> " << io.write.region.numPixels.x << ", " << io.write.region.numPixels.y);
|
||||
LDEBUG(tileIndex << " | " << preRound.x << ", " << preRound.y << " --> " << io.write.region.numPixels.x << ", " << io.write.region.numPixels.y);
|
||||
}
|
||||
|
||||
|
||||
@@ -717,7 +717,7 @@ namespace openspace {
|
||||
|
||||
for (size_t c = 0; c < _dataLayout.numRasters; c++) {
|
||||
if (preprocessData->maxValues[c] > 8800.0f) {
|
||||
//LDEBUG("Bad preprocess data: " << preprocessData->maxValues[c] << " at " << region.chunkIndex);
|
||||
//LDEBUG("Bad preprocess data: " << preprocessData->maxValues[c] << " at " << region.tileIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,7 +738,7 @@ namespace openspace {
|
||||
hasMissingData |= result->preprocessData->maxValues[c] == missingDataValue;
|
||||
}
|
||||
|
||||
bool onHighLevel = result->chunkIndex.level > 6;
|
||||
bool onHighLevel = result->tileIndex.level > 6;
|
||||
if (hasMissingData && onHighLevel) {
|
||||
return CE_Fatal;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace openspace {
|
||||
|
||||
/**
|
||||
* Opens a GDALDataset in readonly mode and calculates meta data required for
|
||||
* reading tile using a ChunkIndex.
|
||||
* reading tile using a TileIndex.
|
||||
*
|
||||
* \param gdalDatasetDesc - A path to a specific file or raw XML describing the dataset
|
||||
* \param minimumPixelSize - minimum number of pixels per side per tile requested
|
||||
@@ -106,7 +106,7 @@ namespace openspace {
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// Public interface //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
std::shared_ptr<TileIOResult> readTileData(ChunkIndex chunkIndex);
|
||||
std::shared_ptr<TileIOResult> readTileData(TileIndex tileIndex);
|
||||
std::shared_ptr<TileIOResult> defaultTileData();
|
||||
int maxChunkLevel();
|
||||
TileDepthTransform getDepthTransform();
|
||||
@@ -139,8 +139,8 @@ namespace openspace {
|
||||
GDALDataset* gdalDataset(const std::string& gdalDatasetDesc);
|
||||
bool gdalHasOverviews() const;
|
||||
int gdalOverview(const PixelRange& baseRegionSize) const;
|
||||
int gdalOverview(const ChunkIndex& chunkIndex) const;
|
||||
int gdalVirtualOverview(const ChunkIndex& chunkIndex) const;
|
||||
int gdalOverview(const TileIndex& tileIndex) const;
|
||||
int gdalVirtualOverview(const TileIndex& tileIndex) const;
|
||||
PixelRegion gdalPixelRegion(const GeodeticPatch& geodeticPatch) const;
|
||||
PixelRegion gdalPixelRegion(GDALRasterBand* rasterBand) const;
|
||||
GDALRasterBand* gdalRasterBand(int overview, int raster = 1) const;
|
||||
@@ -152,7 +152,7 @@ namespace openspace {
|
||||
|
||||
PixelCoordinate geodeticToPixel(const Geodetic2& geo) const;
|
||||
Geodetic2 pixelToGeodetic(const PixelCoordinate& p) const;
|
||||
IODescription getIODescription(const ChunkIndex& chunkIndex) const;
|
||||
IODescription getIODescription(const TileIndex& tileIndex) const;
|
||||
char* readImageData(IODescription& io, CPLErr& worstError) const;
|
||||
CPLErr rasterIO(GDALRasterBand* rasterBand, const IODescription& io, char* dst) const;
|
||||
CPLErr repeatedRasterIO(GDALRasterBand* rasterBand, const IODescription& io, char* dst, int depth = 0) const;
|
||||
|
||||
@@ -56,15 +56,15 @@ namespace openspace {
|
||||
_cacheDir = cacheDir;
|
||||
}
|
||||
|
||||
bool TileDiskCache::has(const ChunkIndex& chunkIndex) const {
|
||||
File metaFile = getMetaDataFile(chunkIndex);
|
||||
bool TileDiskCache::has(const TileIndex& tileIndex) const {
|
||||
File metaFile = getMetaDataFile(tileIndex);
|
||||
return FileSys.fileExists(metaFile);
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<TileIOResult> TileDiskCache::get(const ChunkIndex& chunkIndex) {
|
||||
File metaDataFile = getMetaDataFile(chunkIndex);
|
||||
File dataFile = getDataFile(chunkIndex);
|
||||
std::shared_ptr<TileIOResult> TileDiskCache::get(const TileIndex& tileIndex) {
|
||||
File metaDataFile = getMetaDataFile(tileIndex);
|
||||
File dataFile = getDataFile(tileIndex);
|
||||
if (FileSys.fileExists(metaDataFile) && FileSys.fileExists(dataFile)) {
|
||||
// read meta
|
||||
std::ifstream ifsMeta;
|
||||
@@ -84,8 +84,8 @@ namespace openspace {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool TileDiskCache::put(const ChunkIndex& chunkIndex, std::shared_ptr<TileIOResult> tileIOResult) {
|
||||
File metaDataFile = getMetaDataFile(chunkIndex);
|
||||
bool TileDiskCache::put(const TileIndex& tileIndex, std::shared_ptr<TileIOResult> tileIOResult) {
|
||||
File metaDataFile = getMetaDataFile(tileIndex);
|
||||
if (!FileSys.fileExists(metaDataFile)) {
|
||||
std::ofstream ofsMeta;
|
||||
ofsMeta.open(metaDataFile.path());
|
||||
@@ -93,7 +93,7 @@ namespace openspace {
|
||||
ofsMeta.close();
|
||||
|
||||
std::ofstream ofsData;
|
||||
File dataFile = getDataFile(chunkIndex);
|
||||
File dataFile = getDataFile(tileIndex);
|
||||
ofsData.open(dataFile.path(), std::ofstream::binary);
|
||||
char * data = (char*)tileIOResult->imageData;
|
||||
ofsData.write(data, tileIOResult->nBytesImageData);
|
||||
@@ -103,21 +103,21 @@ namespace openspace {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string TileDiskCache::getFilePath(const ChunkIndex& chunkIndex) const {
|
||||
std::string TileDiskCache::getFilePath(const TileIndex& tileIndex) const {
|
||||
std::stringstream ss;
|
||||
ss << chunkIndex.level;
|
||||
ss << "_" << chunkIndex.x;
|
||||
ss << "_" << chunkIndex.y;
|
||||
ss << tileIndex.level;
|
||||
ss << "_" << tileIndex.x;
|
||||
ss << "_" << tileIndex.y;
|
||||
std::string filePath = FileSys.pathByAppendingComponent(_cacheDir.path(), ss.str());
|
||||
return filePath;
|
||||
}
|
||||
|
||||
File TileDiskCache::getMetaDataFile(const ChunkIndex& chunkIndex) const {
|
||||
return File(getFilePath(chunkIndex) + ".meta");
|
||||
File TileDiskCache::getMetaDataFile(const TileIndex& tileIndex) const {
|
||||
return File(getFilePath(tileIndex) + ".meta");
|
||||
}
|
||||
|
||||
File TileDiskCache::getDataFile(const ChunkIndex& chunkIndex) const {
|
||||
return File(getFilePath(chunkIndex) + ".data");
|
||||
File TileDiskCache::getDataFile(const TileIndex& tileIndex) const {
|
||||
return File(getFilePath(tileIndex) + ".data");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#define __TILE_DISK_CACHE_H__
|
||||
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
@@ -42,9 +42,9 @@ struct TileIOResult;
|
||||
public:
|
||||
TileDiskCache(const std::string& name);
|
||||
|
||||
std::shared_ptr<TileIOResult> get(const ChunkIndex& chunkIndex);
|
||||
bool has(const ChunkIndex& chunkIndex) const;
|
||||
bool put(const ChunkIndex& chunkIndex, std::shared_ptr<TileIOResult> tileIOResult);
|
||||
std::shared_ptr<TileIOResult> get(const TileIndex& tileIndex);
|
||||
bool has(const TileIndex& tileIndex) const;
|
||||
bool put(const TileIndex& tileIndex, std::shared_ptr<TileIOResult> tileIOResult);
|
||||
|
||||
|
||||
static const std::string CACHE_ROOT;
|
||||
@@ -54,9 +54,9 @@ struct TileIOResult;
|
||||
|
||||
Directory _cacheDir;
|
||||
|
||||
std::string getFilePath(const ChunkIndex& chunkIndex) const;
|
||||
File getMetaDataFile(const ChunkIndex& chunkIndex) const;
|
||||
File getDataFile(const ChunkIndex& chunkIndex) const;
|
||||
std::string getFilePath(const TileIndex& tileIndex) const;
|
||||
File getMetaDataFile(const TileIndex& tileIndex) const;
|
||||
File getDataFile(const TileIndex& tileIndex) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
143
modules/globebrowsing/tile/tileindex.cpp
Normal file
143
modules/globebrowsing/tile/tileindex.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 <modules/globebrowsing/tile/tileindex.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TileIndex";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
/**
|
||||
Creates the geodetic tile index for the Geodetic patch that covers the
|
||||
point p at the specified level
|
||||
*/
|
||||
TileIndex::TileIndex(const Geodetic2& point, int level)
|
||||
: level(level) {
|
||||
int numIndicesAtLevel = 1 << level;
|
||||
double u = 0.5 + point.lon / (2 * M_PI);
|
||||
double v = 0.25 - point.lat / (2 * M_PI);
|
||||
double xIndexSpace = u * numIndicesAtLevel;
|
||||
double yIndexSpace = v * numIndicesAtLevel;
|
||||
|
||||
x = floor(xIndexSpace);
|
||||
y = floor(yIndexSpace);
|
||||
}
|
||||
|
||||
TileIndex TileIndex::child(Quad q) const {
|
||||
return TileIndex(2 * x + q % 2, 2 * y + q / 2, level + 1);
|
||||
}
|
||||
|
||||
TileIndex TileIndex::parent() const {
|
||||
//ghoul_assert(level > 0, "tile at level 0 has no parent!");
|
||||
return TileIndex(x / 2, y / 2, level - 1);
|
||||
}
|
||||
|
||||
TileIndex& TileIndex::operator--() {
|
||||
x /= 2;
|
||||
y /= 2;
|
||||
level--;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TileIndex TileIndex::operator--(int) {
|
||||
TileIndex tmp(*this);
|
||||
--(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
TileIndex& TileIndex::operator-=(unsigned int levels) {
|
||||
x <<= levels;
|
||||
y <<= levels;
|
||||
level -= levels;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Gets the tile at a specified offset from this tile.
|
||||
Accepts delta indices ranging from [-2^level, Infinity[
|
||||
*/
|
||||
TileIndex TileIndex::getRelatedTile(int deltaX, int deltaY) const {
|
||||
int indicesAtThisLevel = 1 << level;
|
||||
int newX = (indicesAtThisLevel + x + deltaX) % indicesAtThisLevel;
|
||||
int newY = (indicesAtThisLevel + y + deltaY) % indicesAtThisLevel;
|
||||
return TileIndex(newX, newY, level);
|
||||
}
|
||||
|
||||
int TileIndex::manhattan(const TileIndex& other) const {
|
||||
ghoul_assert(level == other.level, "makes no sense if not on same level");
|
||||
return std::abs(x - other.x) + std::abs(y - other.y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Creates a hash which can be used as key in hash maps
|
||||
BITS | USAGE
|
||||
0-6 | level
|
||||
6-26 | x
|
||||
26-46 | y
|
||||
46-64 | reserved for future use, e.g. time key
|
||||
*/
|
||||
TileHashKey TileIndex::hashKey() const {
|
||||
TileHashKey key = 0LL;
|
||||
key |= level;
|
||||
key |= x << 6;
|
||||
key |= ((TileHashKey)y) << 26;
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
std::string TileIndex::toString() const {
|
||||
std::stringstream ss;
|
||||
for (int i = level; i > 0; i--){
|
||||
char digit = '0';
|
||||
int mask = 1 << (i - 1);
|
||||
if ((x & mask) != 0) {
|
||||
digit++;
|
||||
}
|
||||
if ((y & mask) != 0) {
|
||||
digit++;
|
||||
digit++;
|
||||
}
|
||||
ss << digit;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool TileIndex::operator==(const TileIndex& other) const {
|
||||
return x == other.x && y == other.y && level == other.level;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const TileIndex& ci) {
|
||||
os << "{ x = " << ci.x << ", y = " << ci.y << ", level = " << ci.level << " }";
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
126
modules/globebrowsing/tile/tileindex.h
Normal file
126
modules/globebrowsing/tile/tileindex.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __TILE_INDEX_H__
|
||||
#define __TILE_INDEX_H__
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
class Geodetic2;
|
||||
|
||||
enum Quad {
|
||||
NORTH_WEST = 0,
|
||||
NORTH_EAST,
|
||||
SOUTH_WEST,
|
||||
SOUTH_EAST
|
||||
};
|
||||
|
||||
enum CardinalDirection {
|
||||
WEST = 0,
|
||||
EAST,
|
||||
NORTH,
|
||||
SOUTH,
|
||||
};
|
||||
|
||||
|
||||
|
||||
using TileHashKey = uint64_t;
|
||||
|
||||
|
||||
struct TileIndex {
|
||||
|
||||
|
||||
int x, y, level;
|
||||
|
||||
|
||||
TileIndex() : x(0), y(0), level(0) { }
|
||||
TileIndex(int x, int y, int level) : x(x), y(y), level(level) { }
|
||||
TileIndex(const TileIndex& other) : x(other.x), y(other.y), level(other.level) { }
|
||||
TileIndex(const Geodetic2& point, int level);
|
||||
|
||||
|
||||
bool hasParent() const {
|
||||
return level > 0;
|
||||
}
|
||||
|
||||
TileIndex parent() const;
|
||||
|
||||
TileIndex& operator--();
|
||||
TileIndex operator--(int);
|
||||
|
||||
TileIndex& operator-=(unsigned int levels);
|
||||
|
||||
bool isWestChild() const {
|
||||
return x % 2 == 0;
|
||||
}
|
||||
|
||||
bool isEastChild() const {
|
||||
return x % 2 == 1;
|
||||
}
|
||||
|
||||
bool isNorthChild() const {
|
||||
return y % 2 == 0;
|
||||
}
|
||||
|
||||
bool isSouthChild() const {
|
||||
return y % 2 == 1;
|
||||
}
|
||||
|
||||
|
||||
TileIndex child(Quad q) const;
|
||||
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
/**
|
||||
Gets the tile at a specified offset from this tile.
|
||||
Accepts delta indices ranging from [-2^level, Infinity[
|
||||
*/
|
||||
TileIndex getRelatedTile(int deltaX, int deltaY) const;
|
||||
|
||||
int manhattan(const TileIndex& other) const;
|
||||
|
||||
TileHashKey hashKey() const;
|
||||
|
||||
bool operator==(const TileIndex& other) const;
|
||||
};
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const TileIndex& ti);
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
|
||||
#endif // __TILE_INDEX_H__
|
||||
@@ -81,7 +81,7 @@ namespace openspace {
|
||||
: imageData(nullptr)
|
||||
, dimensions(0, 0, 0)
|
||||
, preprocessData(nullptr)
|
||||
, chunkIndex(0, 0, 0)
|
||||
, tileIndex(0, 0, 0)
|
||||
, error(CE_None)
|
||||
, nBytesImageData(0)
|
||||
{
|
||||
@@ -105,7 +105,7 @@ namespace openspace {
|
||||
|
||||
void TileIOResult::serializeMetaData(std::ostream& os) {
|
||||
os << dimensions.x << " " << dimensions.y << " " << dimensions.z << std::endl;
|
||||
os << chunkIndex.x << " " << chunkIndex.y << " " << chunkIndex.level << std::endl;
|
||||
os << tileIndex.x << " " << tileIndex.y << " " << tileIndex.level << std::endl;
|
||||
os << error << std::endl;
|
||||
|
||||
// preprocess data
|
||||
@@ -121,7 +121,7 @@ namespace openspace {
|
||||
TileIOResult TileIOResult::deserializeMetaData(std::istream& is) {
|
||||
TileIOResult res;
|
||||
is >> res.dimensions.x >> res.dimensions.y >> res.dimensions.z;
|
||||
is >> res.chunkIndex.x >> res.chunkIndex.y >> res.chunkIndex.level;
|
||||
is >> res.tileIndex.x >> res.tileIndex.y >> res.tileIndex.level;
|
||||
int err; is >> err; res.error = (CPLErr) err;
|
||||
|
||||
res.preprocessData = nullptr;
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace openspace {
|
||||
char* imageData;
|
||||
glm::uvec3 dimensions;
|
||||
std::shared_ptr<TilePreprocessData> preprocessData;
|
||||
ChunkIndex chunkIndex;
|
||||
TileIndex tileIndex;
|
||||
CPLErr error;
|
||||
size_t nBytesImageData;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/cachingtileprovider.h>
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -129,21 +129,21 @@ namespace openspace {
|
||||
return _asyncTextureDataProvider->getTextureDataProvider()->maxChunkLevel();
|
||||
}
|
||||
|
||||
Tile CachingTileProvider::getTile(const ChunkIndex& chunkIndex) {
|
||||
Tile CachingTileProvider::getTile(const TileIndex& tileIndex) {
|
||||
Tile tile = Tile::TileUnavailable;
|
||||
|
||||
if (chunkIndex.level > maxLevel()) {
|
||||
if (tileIndex.level > maxLevel()) {
|
||||
tile.status = Tile::Status::OutOfRange;
|
||||
return tile;
|
||||
}
|
||||
|
||||
ChunkHashKey key = chunkIndex.hashKey();
|
||||
TileHashKey key = tileIndex.hashKey();
|
||||
|
||||
if (_tileCache->exist(key)) {
|
||||
return _tileCache->get(key);
|
||||
}
|
||||
else {
|
||||
_asyncTextureDataProvider->enqueueTileIO(chunkIndex);
|
||||
_asyncTextureDataProvider->enqueueTileIO(tileIndex);
|
||||
}
|
||||
|
||||
return tile;
|
||||
@@ -159,7 +159,7 @@ namespace openspace {
|
||||
void CachingTileProvider::initTexturesFromLoadedData() {
|
||||
auto readyTileIOResults = _asyncTextureDataProvider->getTileIOResults();
|
||||
for(auto tileIOResult : readyTileIOResults){
|
||||
ChunkHashKey key = tileIOResult->chunkIndex.hashKey();
|
||||
TileHashKey key = tileIOResult->tileIndex.hashKey();
|
||||
Tile tile = createTile(tileIOResult);
|
||||
_tileCache->put(key, tile);
|
||||
}
|
||||
@@ -170,13 +170,13 @@ namespace openspace {
|
||||
_framesSinceLastRequestFlush = 0;
|
||||
}
|
||||
|
||||
Tile::Status CachingTileProvider::getTileStatus(const ChunkIndex& chunkIndex) {
|
||||
Tile::Status CachingTileProvider::getTileStatus(const TileIndex& tileIndex) {
|
||||
auto tileDataset = _asyncTextureDataProvider->getTextureDataProvider();
|
||||
if (chunkIndex.level > tileDataset->maxChunkLevel()) {
|
||||
if (tileIndex.level > tileDataset->maxChunkLevel()) {
|
||||
return Tile::Status::OutOfRange;
|
||||
}
|
||||
|
||||
ChunkHashKey key = chunkIndex.hashKey();
|
||||
TileHashKey key = tileIndex.hashKey();
|
||||
|
||||
if (_tileCache->exist(key)) {
|
||||
return _tileCache->get(key).status;
|
||||
@@ -194,7 +194,7 @@ namespace openspace {
|
||||
return{ nullptr, nullptr, Tile::Status::IOError };
|
||||
}
|
||||
|
||||
ChunkHashKey key = tileIOResult->chunkIndex.hashKey();
|
||||
TileHashKey key = tileIOResult->tileIndex.hashKey();
|
||||
TileDataLayout dataLayout =
|
||||
_asyncTextureDataProvider->getTextureDataProvider()->getDataLayout();
|
||||
|
||||
|
||||
@@ -61,10 +61,10 @@ namespace openspace {
|
||||
* cache. If not, it may enqueue some IO operations on a
|
||||
* separate thread.
|
||||
*/
|
||||
virtual Tile getTile(const ChunkIndex& chunkIndex);
|
||||
virtual Tile getTile(const TileIndex& tileIndex);
|
||||
|
||||
virtual Tile getDefaultTile();
|
||||
virtual Tile::Status getTileStatus(const ChunkIndex& chunkIndex);
|
||||
virtual Tile::Status getTileStatus(const TileIndex& tileIndex);
|
||||
virtual TileDepthTransform depthTransform();
|
||||
virtual void update();
|
||||
virtual void reset();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/singleimageprovider.h>
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -55,7 +55,7 @@ namespace openspace {
|
||||
reset();
|
||||
}
|
||||
|
||||
Tile SingleImageProvider::getTile(const ChunkIndex& chunkIndex) {
|
||||
Tile SingleImageProvider::getTile(const TileIndex& tileIndex) {
|
||||
return _tile;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace openspace {
|
||||
return _tile;
|
||||
}
|
||||
|
||||
Tile::Status SingleImageProvider::getTileStatus(const ChunkIndex& index) {
|
||||
Tile::Status SingleImageProvider::getTileStatus(const TileIndex& index) {
|
||||
return _tile.status;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ namespace openspace {
|
||||
SingleImageProvider(const std::string& imagePath);
|
||||
virtual ~SingleImageProvider() { }
|
||||
|
||||
virtual Tile getTile(const ChunkIndex& chunkIndex);
|
||||
virtual Tile getTile(const TileIndex& tileIndex);
|
||||
virtual Tile getDefaultTile();
|
||||
virtual Tile::Status getTileStatus(const ChunkIndex& index);
|
||||
virtual Tile::Status getTileStatus(const TileIndex& index);
|
||||
virtual TileDepthTransform depthTransform();
|
||||
virtual void update();
|
||||
virtual void reset();
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <modules/globebrowsing/tile/tileprovider/cachingtileprovider.h>
|
||||
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
#include <openspace/engine/downloadmanager.h>
|
||||
|
||||
@@ -135,14 +135,14 @@ namespace openspace {
|
||||
return _currentTileProvider->depthTransform();
|
||||
}
|
||||
|
||||
Tile::Status TemporalTileProvider::getTileStatus(const ChunkIndex& chunkIndex) {
|
||||
Tile::Status TemporalTileProvider::getTileStatus(const TileIndex& tileIndex) {
|
||||
ensureUpdated();
|
||||
return _currentTileProvider->getTileStatus(chunkIndex);
|
||||
return _currentTileProvider->getTileStatus(tileIndex);
|
||||
}
|
||||
|
||||
Tile TemporalTileProvider::getTile(const ChunkIndex& chunkIndex) {
|
||||
Tile TemporalTileProvider::getTile(const TileIndex& tileIndex) {
|
||||
ensureUpdated();
|
||||
return _currentTileProvider->getTile(chunkIndex);
|
||||
return _currentTileProvider->getTile(tileIndex);
|
||||
}
|
||||
|
||||
Tile TemporalTileProvider::getDefaultTile() {
|
||||
|
||||
@@ -182,9 +182,9 @@ namespace openspace {
|
||||
|
||||
// These methods implements the TileProvider interface
|
||||
|
||||
virtual Tile getTile(const ChunkIndex& chunkIndex);
|
||||
virtual Tile getTile(const TileIndex& tileIndex);
|
||||
virtual Tile getDefaultTile();
|
||||
virtual Tile::Status getTileStatus(const ChunkIndex& chunkIndex);
|
||||
virtual Tile::Status getTileStatus(const TileIndex& tileIndex);
|
||||
virtual TileDepthTransform depthTransform();
|
||||
virtual void update();
|
||||
virtual void reset();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <modules/globebrowsing/tile/tileprovider/texttileprovider.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
@@ -65,11 +65,11 @@ namespace openspace {
|
||||
glDeleteFramebuffers(1, &_fbo);
|
||||
}
|
||||
|
||||
Tile TextTileProvider::getTile(const ChunkIndex& chunkIndex) {
|
||||
ChunkHashKey key = chunkIndex.hashKey();
|
||||
Tile TextTileProvider::getTile(const TileIndex& tileIndex) {
|
||||
TileHashKey key = tileIndex.hashKey();
|
||||
|
||||
if (!_tileCache.exist(key)) {
|
||||
_tileCache.put(key, createChunkIndexTile(chunkIndex));
|
||||
_tileCache.put(key, createChunkIndexTile(tileIndex));
|
||||
}
|
||||
|
||||
return _tileCache.get(key);
|
||||
@@ -80,7 +80,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
Tile::Status TextTileProvider::getTileStatus(const ChunkIndex& index) {
|
||||
Tile::Status TextTileProvider::getTileStatus(const TileIndex& index) {
|
||||
return Tile::Status::OK;
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ namespace openspace {
|
||||
_tileCache.clear();
|
||||
}
|
||||
|
||||
Tile TextTileProvider::createChunkIndexTile(const ChunkIndex& chunkIndex) {
|
||||
Tile tile = backgroundTile(chunkIndex);
|
||||
Tile TextTileProvider::createChunkIndexTile(const TileIndex& tileIndex) {
|
||||
Tile tile = backgroundTile(tileIndex);
|
||||
|
||||
// Keep track of defaultFBO and viewport to be able to reset state when done
|
||||
GLint defaultFBO;
|
||||
@@ -128,7 +128,7 @@ namespace openspace {
|
||||
);
|
||||
|
||||
ghoul_assert(_fontRenderer != nullptr, "_fontRenderer must not be null");
|
||||
renderText(*_fontRenderer, chunkIndex);
|
||||
renderText(*_fontRenderer, tileIndex);
|
||||
|
||||
// Reset state: bind default FBO and set viewport to what it was
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
|
||||
@@ -141,12 +141,12 @@ namespace openspace {
|
||||
return 1337; // unlimited
|
||||
}
|
||||
|
||||
ChunkHashKey TextTileProvider::toHash(const ChunkIndex& chunkIndex) const {
|
||||
return chunkIndex.hashKey();
|
||||
TileHashKey TextTileProvider::toHash(const TileIndex& tileIndex) const {
|
||||
return tileIndex.hashKey();
|
||||
}
|
||||
|
||||
|
||||
Tile TextTileProvider::backgroundTile(const ChunkIndex& chunkIndex) const {
|
||||
Tile TextTileProvider::backgroundTile(const TileIndex& tileIndex) const {
|
||||
glm::uvec4 color = { 0, 0, 0, 0 };
|
||||
return Tile::createPlainTile(_textureSize, color);
|
||||
}
|
||||
@@ -156,15 +156,15 @@ namespace openspace {
|
||||
// Chunk Index Tile Provider //
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ChunkIndexTileProvider::renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const {
|
||||
void ChunkIndexTileProvider::renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const {
|
||||
fontRenderer.render(
|
||||
*_font,
|
||||
glm::vec2(
|
||||
_textureSize.x / 4 - (_textureSize.x / 32) * log10(1 << chunkIndex.level),
|
||||
_textureSize.x / 4 - (_textureSize.x / 32) * log10(1 << tileIndex.level),
|
||||
_textureSize.y / 2 + _fontSize),
|
||||
glm::vec4(1.0, 0.0, 0.0, 1.0),
|
||||
"level: %i \nx: %i \ny: %i",
|
||||
chunkIndex.level, chunkIndex.x, chunkIndex.y
|
||||
tileIndex.level, tileIndex.x, tileIndex.y
|
||||
);
|
||||
}
|
||||
|
||||
@@ -201,11 +201,11 @@ namespace openspace {
|
||||
|
||||
}
|
||||
|
||||
void SizeReferenceTileProvider::renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const {
|
||||
GeodeticPatch patch(chunkIndex);
|
||||
void SizeReferenceTileProvider::renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const {
|
||||
GeodeticPatch patch(tileIndex);
|
||||
bool aboveEquator = patch.isNorthern();
|
||||
|
||||
double tileLongitudalLength = roundedLongitudalLength(chunkIndex);
|
||||
double tileLongitudalLength = roundedLongitudalLength(tileIndex);
|
||||
|
||||
std::string unit = "m";
|
||||
if (tileLongitudalLength > 9999) {
|
||||
@@ -227,8 +227,8 @@ namespace openspace {
|
||||
);
|
||||
}
|
||||
|
||||
int SizeReferenceTileProvider::roundedLongitudalLength(const ChunkIndex& chunkIndex) const {
|
||||
GeodeticPatch patch(chunkIndex);
|
||||
int SizeReferenceTileProvider::roundedLongitudalLength(const TileIndex& tileIndex) const {
|
||||
GeodeticPatch patch(tileIndex);
|
||||
bool aboveEquator = patch.isNorthern();
|
||||
double lat = aboveEquator ? patch.minLat() : patch.maxLat();
|
||||
double lon1 = patch.minLon();
|
||||
@@ -243,13 +243,13 @@ namespace openspace {
|
||||
return l;
|
||||
}
|
||||
|
||||
ChunkHashKey SizeReferenceTileProvider::toHash(const ChunkIndex& chunkIndex) const {
|
||||
int l = roundedLongitudalLength(chunkIndex);
|
||||
ChunkHashKey key = static_cast<ChunkHashKey>(l);
|
||||
TileHashKey SizeReferenceTileProvider::toHash(const TileIndex& tileIndex) const {
|
||||
int l = roundedLongitudalLength(tileIndex);
|
||||
TileHashKey key = static_cast<TileHashKey>(l);
|
||||
return key;
|
||||
}
|
||||
|
||||
Tile SizeReferenceTileProvider::backgroundTile(const ChunkIndex& chunkIndex) const {
|
||||
Tile SizeReferenceTileProvider::backgroundTile(const TileIndex& tileIndex) const {
|
||||
if (_backgroundTile.status == Tile::Status::OK) {
|
||||
Tile tile;
|
||||
auto t = _backgroundTile.texture;
|
||||
@@ -264,7 +264,7 @@ namespace openspace {
|
||||
}
|
||||
else {
|
||||
// use default background
|
||||
return TextTileProvider::backgroundTile(chunkIndex);
|
||||
return TextTileProvider::backgroundTile(tileIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace openspace {
|
||||
* Enables a simple way of providing tiles with any type of rendered text.
|
||||
* Internally it handles setting up a FBO for rendering the text, and defines a new
|
||||
* interface, consisting of only a single method for subclasses to implement:
|
||||
* renderText(const FontRenderer&, const ChunkIndex&) const;
|
||||
* renderText(const FontRenderer&, const TileIndex&) const;
|
||||
*/
|
||||
class TextTileProvider : public TileProvider {
|
||||
public:
|
||||
@@ -67,9 +67,9 @@ namespace openspace {
|
||||
|
||||
// The TileProvider interface below is implemented in this class
|
||||
|
||||
virtual Tile getTile(const ChunkIndex& chunkIndex);
|
||||
virtual Tile getTile(const TileIndex& tileIndex);
|
||||
virtual Tile getDefaultTile();
|
||||
virtual Tile::Status getTileStatus(const ChunkIndex& index);
|
||||
virtual Tile::Status getTileStatus(const TileIndex& index);
|
||||
virtual TileDepthTransform depthTransform();
|
||||
virtual void update();
|
||||
virtual void reset();
|
||||
@@ -79,26 +79,26 @@ namespace openspace {
|
||||
* Returns the tile which will be used to draw text onto.
|
||||
* Default implementation returns a tile with a plain transparent texture.
|
||||
*/
|
||||
virtual Tile backgroundTile(const ChunkIndex& chunkIndex) const;
|
||||
virtual Tile backgroundTile(const TileIndex& tileIndex) const;
|
||||
|
||||
|
||||
/**
|
||||
* Allow overriding of hash function.
|
||||
* Default is <code>ChunkIndex::hashKey()</code>
|
||||
* Default is <code>TileIndex::hashKey()</code>
|
||||
*
|
||||
* \param chunkIndex chunkIndex to hash
|
||||
* \param tileIndex tileIndex to hash
|
||||
* \returns hashkey used for in LRU cache for this tile
|
||||
*/
|
||||
virtual ChunkHashKey toHash(const ChunkIndex& chunkIndex) const;
|
||||
virtual TileHashKey toHash(const TileIndex& tileIndex) const;
|
||||
|
||||
/**
|
||||
* Uses the fontRenderer to render some text onto the tile texture provided in
|
||||
* backgroundTile(const ChunkIndex& chunkIndex).
|
||||
* backgroundTile(const TileIndex& tileIndex).
|
||||
*
|
||||
* \param fontRenderer used for rendering text onto texture
|
||||
* \param chunkIndex associated with the tile to be rendered onto
|
||||
* \param tileIndex associated with the tile to be rendered onto
|
||||
*/
|
||||
virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const = 0;
|
||||
virtual void renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const = 0;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _font;
|
||||
@@ -106,7 +106,7 @@ namespace openspace {
|
||||
size_t _fontSize;
|
||||
|
||||
private:
|
||||
Tile createChunkIndexTile(const ChunkIndex& chunkIndex);
|
||||
Tile createChunkIndexTile(const TileIndex& tileIndex);
|
||||
std::unique_ptr<ghoul::fontrendering::FontRenderer> _fontRenderer;
|
||||
|
||||
TileCache _tileCache;
|
||||
@@ -119,7 +119,7 @@ namespace openspace {
|
||||
*/
|
||||
class ChunkIndexTileProvider : public TextTileProvider {
|
||||
public:
|
||||
virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const;
|
||||
virtual void renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -130,15 +130,15 @@ namespace openspace {
|
||||
public:
|
||||
SizeReferenceTileProvider(const ghoul::Dictionary& dictionary);
|
||||
|
||||
virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const;
|
||||
virtual Tile backgroundTile(const ChunkIndex& chunkIndex) const;
|
||||
virtual void renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const;
|
||||
virtual Tile backgroundTile(const TileIndex& tileIndex) const;
|
||||
|
||||
virtual ChunkHashKey toHash(const ChunkIndex& chunkIndex) const;
|
||||
virtual TileHashKey toHash(const TileIndex& tileIndex) const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
int roundedLongitudalLength(const ChunkIndex& chunkIndex) const;
|
||||
int roundedLongitudalLength(const TileIndex& tileIndex) const;
|
||||
|
||||
Ellipsoid _ellipsoid;
|
||||
Tile _backgroundTile;
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace openspace {
|
||||
|
||||
/**
|
||||
* Interface for providing <code>Tile</code>s given a
|
||||
* <code>ChunkIndex</code>.
|
||||
* <code>TileIndex</code>.
|
||||
*/
|
||||
class TileProvider {
|
||||
public:
|
||||
@@ -76,7 +76,7 @@ namespace openspace {
|
||||
virtual ~TileProvider() { }
|
||||
|
||||
/**
|
||||
* Method for querying tiles, given a specified <code>ChunkIndex</code>.
|
||||
* Method for querying tiles, given a specified <code>TileIndex</code>.
|
||||
*
|
||||
* This method is expected to be invoked multiple times per frame,
|
||||
* and should therefore return quickly, e.g. not perform heavy I/O
|
||||
@@ -86,13 +86,13 @@ namespace openspace {
|
||||
* status and texture will be consistent over different invocations
|
||||
* of this method.
|
||||
*
|
||||
* \param chunkIndex specifying a region of a map for which
|
||||
* \param tileIndex specifying a region of a map for which
|
||||
* we want tile data.
|
||||
*
|
||||
* \returns The tile corresponding to the ChunkIndex by the time
|
||||
* \returns The tile corresponding to the TileIndex by the time
|
||||
* the method was invoked.
|
||||
*/
|
||||
virtual Tile getTile(const ChunkIndex& chunkIndex) = 0;
|
||||
virtual Tile getTile(const TileIndex& tileIndex) = 0;
|
||||
|
||||
/**
|
||||
* TileProviders must be able to provide a defualt
|
||||
@@ -107,9 +107,9 @@ namespace openspace {
|
||||
* Returns the status of a <code>Tile</code>. The <code>Tile::Status</code>
|
||||
* corresponds the <code>Tile</code> that would be returned
|
||||
* if the function <code>getTile</code> would be invoked with the same
|
||||
* <code>ChunkIndex</code> argument at this point in time.
|
||||
* <code>TileIndex</code> argument at this point in time.
|
||||
*/
|
||||
virtual Tile::Status getTileStatus(const ChunkIndex& index) = 0;
|
||||
virtual Tile::Status getTileStatus(const TileIndex& index) = 0;
|
||||
|
||||
/**
|
||||
* Get the associated depth transform for this TileProvider.
|
||||
@@ -132,13 +132,13 @@ namespace openspace {
|
||||
virtual void reset() = 0;
|
||||
|
||||
/**
|
||||
* \returns The maximum level as defined by <code>ChunkIndex</code>
|
||||
* \returns The maximum level as defined by <code>TileIndex</code>
|
||||
* that this TileProvider is able provide.
|
||||
*/
|
||||
virtual int maxLevel() = 0;
|
||||
};
|
||||
|
||||
typedef LRUCache<ChunkHashKey, Tile> TileCache;
|
||||
typedef LRUCache<TileHashKey, Tile> TileCache;
|
||||
|
||||
struct TileProviderInitData {
|
||||
int minimumPixelSize;
|
||||
|
||||
@@ -44,29 +44,29 @@ namespace openspace {
|
||||
|
||||
const TileSelector::CompareResolution TileSelector::HIGHEST_RES = TileSelector::CompareResolution();
|
||||
|
||||
TileAndTransform TileSelector::getHighestResolutionTile(TileProvider* tileProvider, ChunkIndex chunkIndex, int parents) {
|
||||
TileAndTransform 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 && chunkIndex.level > 1; i++) {
|
||||
ascendToParent(chunkIndex, uvTransform);
|
||||
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(chunkIndex.level > maximumLevel){
|
||||
ascendToParent(chunkIndex, uvTransform);
|
||||
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 (chunkIndex.level > 1) {
|
||||
Tile tile = tileProvider->getTile(chunkIndex);
|
||||
while (tileIndex.level > 1) {
|
||||
Tile tile = tileProvider->getTile(tileIndex);
|
||||
if (tile.status != Tile::Status::OK) {
|
||||
ascendToParent(chunkIndex, uvTransform);
|
||||
ascendToParent(tileIndex, uvTransform);
|
||||
}
|
||||
else return { tile, uvTransform };
|
||||
}
|
||||
@@ -74,14 +74,14 @@ namespace openspace {
|
||||
return{ Tile::TileUnavailable, uvTransform };
|
||||
}
|
||||
|
||||
TileAndTransform TileSelector::getHighestResolutionTile(const TileProviderGroup& tileProviderGroup, ChunkIndex chunkIndex) {
|
||||
TileAndTransform TileSelector::getHighestResolutionTile(const TileProviderGroup& tileProviderGroup, TileIndex tileIndex) {
|
||||
TileAndTransform mostHighResolution;
|
||||
mostHighResolution.tile = Tile::TileUnavailable;
|
||||
mostHighResolution.uvTransform.uvScale.x = 0;
|
||||
|
||||
auto activeProviders = tileProviderGroup.getActiveTileProviders();
|
||||
for (size_t i = 0; i < activeProviders.size(); i++) {
|
||||
TileAndTransform tileAndTransform = getHighestResolutionTile(activeProviders[i].get(), chunkIndex);
|
||||
TileAndTransform tileAndTransform = getHighestResolutionTile(activeProviders[i].get(), tileIndex);
|
||||
bool tileIsOk = tileAndTransform.tile.status == Tile::Status::OK;
|
||||
bool tileHasPreprocessData = tileAndTransform.tile.preprocessData != nullptr;
|
||||
bool tileIsHigherResolution = tileAndTransform.uvTransform.uvScale.x > mostHighResolution.uvTransform.uvScale.x;
|
||||
@@ -98,11 +98,11 @@ namespace openspace {
|
||||
return a.uvTransform.uvScale.x > b.uvTransform.uvScale.x;
|
||||
}
|
||||
|
||||
std::vector<TileAndTransform> TileSelector::getTilesSortedByHighestResolution(const TileProviderGroup& tileProviderGroup, const ChunkIndex& chunkIndex) {
|
||||
std::vector<TileAndTransform> TileSelector::getTilesSortedByHighestResolution(const TileProviderGroup& tileProviderGroup, const TileIndex& tileIndex) {
|
||||
auto activeProviders = tileProviderGroup.getActiveTileProviders();
|
||||
std::vector<TileAndTransform> tiles;
|
||||
for (auto provider : activeProviders){
|
||||
tiles.push_back(getHighestResolutionTile(provider.get(), chunkIndex));
|
||||
tiles.push_back(getHighestResolutionTile(provider.get(), tileIndex));
|
||||
}
|
||||
|
||||
|
||||
@@ -111,20 +111,20 @@ namespace openspace {
|
||||
return tiles;
|
||||
}
|
||||
|
||||
void TileSelector::ascendToParent(ChunkIndex& chunkIndex, TileUvTransform& uv) {
|
||||
void TileSelector::ascendToParent(TileIndex& tileIndex, TileUvTransform& uv) {
|
||||
uv.uvOffset *= 0.5;
|
||||
uv.uvScale *= 0.5;
|
||||
|
||||
if (chunkIndex.isEastChild()) {
|
||||
if (tileIndex.isEastChild()) {
|
||||
uv.uvOffset.x += 0.5;
|
||||
}
|
||||
|
||||
// In OpenGL, positive y direction is up
|
||||
if (chunkIndex.isNorthChild()) {
|
||||
if (tileIndex.isNorthChild()) {
|
||||
uv.uvOffset.y += 0.5;
|
||||
}
|
||||
|
||||
--chunkIndex;
|
||||
--tileIndex;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#define __TILE_SELECTOR_H__
|
||||
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
#include <modules/globebrowsing/tile/tileprovidermanager.h>
|
||||
|
||||
#include <vector>
|
||||
@@ -48,9 +48,9 @@ namespace openspace {
|
||||
|
||||
class TileSelector {
|
||||
public:
|
||||
static TileAndTransform getHighestResolutionTile(TileProvider* tileProvider, ChunkIndex chunkIndex, int parents = 0);
|
||||
static TileAndTransform getHighestResolutionTile(const TileProviderGroup& tileProviderGroup, ChunkIndex chunkIndex);
|
||||
static std::vector<TileAndTransform> getTilesSortedByHighestResolution(const TileProviderGroup&, const ChunkIndex& chunkIndex);
|
||||
static TileAndTransform getHighestResolutionTile(TileProvider* tileProvider, TileIndex tileIndex, int parents = 0);
|
||||
static TileAndTransform getHighestResolutionTile(const TileProviderGroup& tileProviderGroup, TileIndex tileIndex);
|
||||
static std::vector<TileAndTransform> getTilesSortedByHighestResolution(const TileProviderGroup&, const TileIndex& tileIndex);
|
||||
|
||||
|
||||
struct CompareResolution {
|
||||
@@ -60,7 +60,7 @@ namespace openspace {
|
||||
static const CompareResolution HIGHEST_RES;
|
||||
|
||||
private:
|
||||
static void ascendToParent(ChunkIndex& chunkIndex, TileUvTransform& uv);
|
||||
static void ascendToParent(TileIndex& tileIndex, TileUvTransform& uv);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user