diff --git a/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp b/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp index 66e8a0d9cf..f1adc0b6c4 100644 --- a/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp @@ -141,6 +141,11 @@ namespace openspace { return 1337; // unlimited } + ChunkHashKey TextTileProvider::toHash(const ChunkIndex& chunkIndex) const { + return chunkIndex.hashKey(); + } + + Tile TextTileProvider::backgroundTile(const ChunkIndex& chunkIndex) const { glm::uvec4 color = { 0, 0, 0, 0 }; return Tile::createPlainTile(_textureSize, color); @@ -198,14 +203,11 @@ namespace openspace { void SizeReferenceTileProvider::renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const { GeodeticPatch patch(chunkIndex); bool aboveEquator = patch.isNorthern(); - double lat = aboveEquator ? patch.minLat() : patch.maxLat(); - double lon1 = patch.minLon(); - double lon2 = patch.maxLon(); - double tileLongitudalLength = _ellipsoid.longitudalDistance(lat, lon1, lon2); - + + double tileLongitudalLength = roundedLongitudalLength(chunkIndex); std::string unit = "m"; - if (tileLongitudalLength > 10000) { + if (tileLongitudalLength > 9999) { tileLongitudalLength *= 0.001; unit = "km"; } @@ -224,6 +226,28 @@ namespace openspace { ); } + int SizeReferenceTileProvider::roundedLongitudalLength(const ChunkIndex& chunkIndex) const { + GeodeticPatch patch(chunkIndex); + bool aboveEquator = patch.isNorthern(); + double lat = aboveEquator ? patch.minLat() : patch.maxLat(); + double lon1 = patch.minLon(); + double lon2 = patch.maxLon(); + int l = static_cast(_ellipsoid.longitudalDistance(lat, lon1, lon2)); + + bool useKm = l > 9999; + if (useKm) l /= 1000; + l = std::round(l); + if (useKm) l *= 1000; + + return l; + } + + ChunkHashKey SizeReferenceTileProvider::toHash(const ChunkIndex& chunkIndex) const { + int l = roundedLongitudalLength(chunkIndex); + ChunkHashKey key = static_cast(l); + return key; + } + Tile SizeReferenceTileProvider::backgroundTile(const ChunkIndex& chunkIndex) const { if (_backgroundTile.status == Tile::Status::OK) { Tile tile; diff --git a/modules/globebrowsing/tile/tileprovider/texttileprovider.h b/modules/globebrowsing/tile/tileprovider/texttileprovider.h index 79e9f6523a..fe2d7bf065 100644 --- a/modules/globebrowsing/tile/tileprovider/texttileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.h @@ -76,6 +76,9 @@ 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; + + // Default implementation uses ChunkIndex::hashKey() + virtual ChunkHashKey toHash(const ChunkIndex& chunkIndex) const; // This method is pure and should be implemented by subclasses virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const = 0; @@ -109,7 +112,13 @@ namespace openspace { virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const; virtual Tile backgroundTile(const ChunkIndex& chunkIndex) const; + virtual ChunkHashKey toHash(const ChunkIndex& chunkIndex) const; + + private: + + int roundedLongitudalLength(const ChunkIndex& chunkIndex) const; + Ellipsoid _ellipsoid; Tile _backgroundTile; };