From 1be37a9333f72c3bfe381315cc0ca1ce9acc85c7 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Tue, 30 Aug 2016 18:15:00 -0400 Subject: [PATCH 01/12] Add a simple abstract class for providing Tiles with text. Refactor ChunkIndexTileProvider --- modules/globebrowsing/CMakeLists.txt | 4 +- ...xtileprovider.cpp => texttileprovider.cpp} | 55 +++++++++++-------- ...indextileprovider.h => texttileprovider.h} | 52 +++++++++++++----- .../tile/tileproviderfactory.cpp | 2 +- 4 files changed, 72 insertions(+), 41 deletions(-) rename modules/globebrowsing/tile/tileprovider/{chunkindextileprovider.cpp => texttileprovider.cpp} (83%) rename modules/globebrowsing/tile/tileprovider/{chunkindextileprovider.h => texttileprovider.h} (72%) diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index 1894705a8a..1bfbfbd7ef 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -50,7 +50,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/tileprovider.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/singleimageprovider.h - ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/chunkindextileprovider.h + ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/texttileprovider.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/cachingtileprovider.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/temporaltileprovider.h @@ -101,7 +101,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/tileprovider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/singleimageprovider.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/chunkindextileprovider.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/texttileprovider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/cachingtileprovider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/temporaltileprovider.cpp diff --git a/modules/globebrowsing/tile/tileprovider/chunkindextileprovider.cpp b/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp similarity index 83% rename from modules/globebrowsing/tile/tileprovider/chunkindextileprovider.cpp rename to modules/globebrowsing/tile/tileprovider/texttileprovider.cpp index b734b4e3d7..22ca983073 100644 --- a/modules/globebrowsing/tile/tileprovider/chunkindextileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include @@ -40,18 +40,17 @@ namespace { - const std::string _loggerCat = "TileProvider"; + const std::string _loggerCat = "TextTileProvider"; } namespace openspace { - ChunkIndexTileProvider::ChunkIndexTileProvider(const glm::uvec2& textureSize, size_t fontSize) + TextTileProvider::TextTileProvider(const glm::uvec2& textureSize, size_t fontSize) : _tileCache(500) , _textureSize(textureSize) , _fontSize(fontSize) { - using namespace ghoul::fontrendering; _font = OsEng.fontManager().font("Mono", _fontSize); _fontRenderer = std::unique_ptr(FontRenderer::createDefault()); @@ -61,11 +60,11 @@ namespace openspace { glGenFramebuffers(1, &_fbo); } - ChunkIndexTileProvider::~ChunkIndexTileProvider() { + TextTileProvider::~TextTileProvider() { glDeleteFramebuffers(1, &_fbo); } - Tile ChunkIndexTileProvider::getTile(const ChunkIndex& chunkIndex) { + Tile TextTileProvider::getTile(const ChunkIndex& chunkIndex) { ChunkHashKey key = chunkIndex.hashKey(); if (!_tileCache.exist(key)) { @@ -75,31 +74,31 @@ namespace openspace { return _tileCache.get(key); } - Tile ChunkIndexTileProvider::getDefaultTile() { + Tile TextTileProvider::getDefaultTile() { return Tile::TileUnavailable; } - Tile::Status ChunkIndexTileProvider::getTileStatus(const ChunkIndex& index) { + Tile::Status TextTileProvider::getTileStatus(const ChunkIndex& index) { return Tile::Status::OK; } - TileDepthTransform ChunkIndexTileProvider::depthTransform() { + TileDepthTransform TextTileProvider::depthTransform() { TileDepthTransform transform; transform.depthOffset = 0.0f; transform.depthScale = 1.0f; return transform; } - void ChunkIndexTileProvider::update() { + void TextTileProvider::update() { // nothing to be done } - void ChunkIndexTileProvider::reset() { + void TextTileProvider::reset() { _tileCache.clear(); } - Tile ChunkIndexTileProvider::createChunkIndexTile(const ChunkIndex& chunkIndex) { + Tile TextTileProvider::createChunkIndexTile(const ChunkIndex& chunkIndex) { glm::uvec4 color = { 0, 0, 0, 0 }; Tile tile = Tile::createPlainTile(_textureSize, color); @@ -128,15 +127,8 @@ namespace openspace { static_cast(tile.texture->height()) ); - _fontRenderer->render( - *_font, - glm::vec2( - _textureSize.x / 4 - (_textureSize.x / 32) * log10(1 << chunkIndex.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 - ); + ghoul_assert(_fontRenderer != nullptr, "_fontRenderer must not be null"); + renderText(*_fontRenderer, chunkIndex); // Reset state: bind default FBO and set viewport to what it was glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); @@ -145,10 +137,27 @@ namespace openspace { return tile; } - - int ChunkIndexTileProvider::maxLevel() { + int TextTileProvider::maxLevel() { return 1337; // unlimited } + + + void ChunkIndexTileProvider::renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const { + fontRenderer.render( + *_font, + glm::vec2( + _textureSize.x / 4 - (_textureSize.x / 32) * log10(1 << chunkIndex.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 + ); + } + + + + + } // namespace openspace diff --git a/modules/globebrowsing/tile/tileprovider/chunkindextileprovider.h b/modules/globebrowsing/tile/tileprovider/texttileprovider.h similarity index 72% rename from modules/globebrowsing/tile/tileprovider/chunkindextileprovider.h rename to modules/globebrowsing/tile/tileprovider/texttileprovider.h index 30b9e1ddb7..9d4b304c9e 100644 --- a/modules/globebrowsing/tile/tileprovider/chunkindextileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __CHUNK_INDEX_TILE_PROVIDER_H__ -#define __CHUNK_INDEX_TILE_PROVIDER_H__ +#ifndef __TEXT_TILE_PROVIDER_H__ +#define __TEXT_TILE_PROVIDER_H__ #include #include // absPath @@ -45,12 +45,21 @@ namespace openspace { - - - class ChunkIndexTileProvider : public TileProvider { + using namespace ghoul::fontrendering; + + /** + * This abstract class implements the TilProvider interface and 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: + * \code renderText(const FontRenderer&, const ChunkIndex&) const \endcode + */ + class TextTileProvider : public TileProvider { public: - ChunkIndexTileProvider(const glm::uvec2& textureSize = {512, 512}, size_t fontSize = 48); - virtual ~ChunkIndexTileProvider(); + TextTileProvider(const glm::uvec2& textureSize = {512, 512}, size_t fontSize = 48); + virtual ~TextTileProvider(); + + // Methods below are implemented in this class virtual Tile getTile(const ChunkIndex& chunkIndex); virtual Tile getDefaultTile(); @@ -59,18 +68,31 @@ namespace openspace { virtual void update(); virtual void reset(); virtual int maxLevel(); - private: - Tile createChunkIndexTile(const ChunkIndex& chunkIndex); - std::shared_ptr _font; - std::unique_ptr _fontRenderer; - TileCache _tileCache; + // This method is pure and should be implemented by subclasses + + virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const = 0; + + protected: + std::shared_ptr _font; glm::uvec2 _textureSize; size_t _fontSize; - - GLuint _fbo; + private: + Tile createChunkIndexTile(const ChunkIndex& chunkIndex); + std::unique_ptr _fontRenderer; + + TileCache _tileCache; + GLuint _fbo; + }; + + /** + * Provides \class Tiles with the chunk index rendered as text onto its tiles. + */ + class ChunkIndexTileProvider : public TextTileProvider { + public: + virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const; }; @@ -79,4 +101,4 @@ namespace openspace { -#endif // __CHUNK_INDEX_TILE_PROVIDER_H__ \ No newline at end of file +#endif // __TEXT_TILE_PROVIDER_H__ \ No newline at end of file diff --git a/modules/globebrowsing/tile/tileproviderfactory.cpp b/modules/globebrowsing/tile/tileproviderfactory.cpp index c1a88c4d22..22119644c5 100644 --- a/modules/globebrowsing/tile/tileproviderfactory.cpp +++ b/modules/globebrowsing/tile/tileproviderfactory.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include From b5b6b38dce8a00afe9ef2b4b5938b219a1ad6100 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Tue, 30 Aug 2016 19:24:49 -0400 Subject: [PATCH 02/12] Use globe browsing scene --- openspace.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openspace.cfg b/openspace.cfg index aafd84b3c7..db6e5e0240 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -12,11 +12,11 @@ return { --Scene = "${SCENE}/globebrowsing.scene", -- Scene = "${SCENE}/globebrowsing-debug.scene", - -- Scene = "${SCENE}/globebrowsing.scene", + Scene = "${SCENE}/globebrowsing.scene", -- Scene = "${SCENE}/rosetta.scene", -- Scene = "${SCENE}/dawn.scene", -- Scene = "${SCENE}/newhorizons.scene", - Scene = "${SCENE}/osirisrex.scene", + -- Scene = "${SCENE}/osirisrex.scene", --Scene = "${SCENE}/debugmodel.scene", --Scene = "${SCENE}/rosetta.scene", From bf1dddf103c241c42770f79cb2b8125b232937e4 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Tue, 30 Aug 2016 19:26:22 -0400 Subject: [PATCH 03/12] Separate Tile and TileProvider. Remove necessary includes --- modules/globebrowsing/CMakeLists.txt | 3 +- modules/globebrowsing/tile/tile.cpp | 72 +++++++++++++++++++ modules/globebrowsing/tile/tile.h | 59 +++++++++++++++ .../tile/tileprovider/tileprovider.cpp | 51 ------------- .../tile/tileprovider/tileprovider.h | 29 +------- 5 files changed, 135 insertions(+), 79 deletions(-) create mode 100644 modules/globebrowsing/tile/tile.cpp create mode 100644 modules/globebrowsing/tile/tile.h diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index 1bfbfbd7ef..cf589d9810 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -54,6 +54,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/cachingtileprovider.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/temporaltileprovider.h + ${CMAKE_CURRENT_SOURCE_DIR}/tile/tile.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileselector.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tilediskcache.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledataset.h @@ -105,7 +106,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/cachingtileprovider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/temporaltileprovider.cpp - + ${CMAKE_CURRENT_SOURCE_DIR}/tile/tile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileselector.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tilediskcache.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledataset.cpp diff --git a/modules/globebrowsing/tile/tile.cpp b/modules/globebrowsing/tile/tile.cpp new file mode 100644 index 0000000000..a7489dfe60 --- /dev/null +++ b/modules/globebrowsing/tile/tile.cpp @@ -0,0 +1,72 @@ +/***************************************************************************************** +* * +* 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 + +#include + +namespace { + const std::string _loggerCat = "Tile"; +} + + +namespace openspace { + + const Tile Tile::TileUnavailable = {nullptr, nullptr, Tile::Status::Unavailable }; + + + Tile Tile::createPlainTile(const glm::uvec2& size, const glm::uvec4& color) { + using namespace ghoul::opengl; + + // Create pixel data + int numBytes = size.x * size.y * 4 * 1; + char* pixels = new char[numBytes]; + size_t numPixels = size.x * size.y; + size_t i = 0; + for (size_t p = 0; p < numPixels; p++){ + pixels[i++] = color.r; + pixels[i++] = color.g; + pixels[i++] = color.b; + pixels[i++] = color.a; + } + + // Create ghoul texture + auto texture = std::make_shared(glm::uvec3(size, 1)); + texture->setDataOwnership(Texture::TakeOwnership::Yes); + texture->setPixelData(pixels); + texture->uploadTexture(); + texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + + // Create tile + Tile tile; + tile.status = Tile::Status::OK; + tile.preprocessData = nullptr; + tile.texture = texture; + + return tile; + } + + + +} // namespace openspace diff --git a/modules/globebrowsing/tile/tile.h b/modules/globebrowsing/tile/tile.h new file mode 100644 index 0000000000..9d3feaf409 --- /dev/null +++ b/modules/globebrowsing/tile/tile.h @@ -0,0 +1,59 @@ +/***************************************************************************************** +* * +* 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_H__ +#define __TILE_H__ + +#include // Texture + +#include // TilePreprocessData + + +namespace openspace { + + using namespace ghoul::opengl; + + struct Tile { + std::shared_ptr texture; + std::shared_ptr preprocessData; + + enum class Status { Unavailable, OutOfRange, IOError, OK } status; + + + /** + * Instantiaes a new tile unicolored tile. The texture gets the provided size and + * color in rgba. Color values ranges between 0-255. + */ + static Tile createPlainTile(const glm::uvec2& size, const glm::uvec4& color); + + static const Tile TileUnavailable; + + }; + +} // namespace openspace + + + + +#endif // __TILE_H__ \ No newline at end of file diff --git a/modules/globebrowsing/tile/tileprovider/tileprovider.cpp b/modules/globebrowsing/tile/tileprovider/tileprovider.cpp index c3010e99a8..5e73089d24 100644 --- a/modules/globebrowsing/tile/tileprovider/tileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/tileprovider.cpp @@ -22,25 +22,10 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include - #include -#include - -#include - -#include -#include #include -#include -#include - -#include - -#include - @@ -51,40 +36,4 @@ namespace { namespace openspace { - const Tile Tile::TileUnavailable = {nullptr, nullptr, Tile::Status::Unavailable }; - - - Tile Tile::createPlainTile(const glm::uvec2& size, const glm::uvec4& color) { - using namespace ghoul::opengl; - - // Create pixel data - int numBytes = size.x * size.y * 4 * 1; - char* pixels = new char[numBytes]; - size_t numPixels = size.x * size.y; - size_t i = 0; - for (size_t p = 0; p < numPixels; p++){ - pixels[i++] = color.r; - pixels[i++] = color.g; - pixels[i++] = color.b; - pixels[i++] = color.a; - } - - // Create ghoul texture - auto texture = std::make_shared(glm::uvec3(size, 1)); - texture->setDataOwnership(Texture::TakeOwnership::Yes); - texture->setPixelData(pixels); - texture->uploadTexture(); - texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); - - // Create tile - Tile tile; - tile.status = Tile::Status::OK; - tile.preprocessData = nullptr; - tile.texture = texture; - - return tile; - } - - - } // namespace openspace diff --git a/modules/globebrowsing/tile/tileprovider/tileprovider.h b/modules/globebrowsing/tile/tileprovider/tileprovider.h index eac5587fd0..82f3ca4849 100644 --- a/modules/globebrowsing/tile/tileprovider/tileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/tileprovider.h @@ -25,27 +25,17 @@ #ifndef __TILE_PROVIDER_H__ #define __TILE_PROVIDER_H__ -#include - -#include -#include - -#include #include // absPath #include -#include -#include -#include - -#include +#include #include ////////////////////////////////////////////////////////////////////////////////////////// -// TILE PROVIDER // +// TILE PROVIDER // ////////////////////////////////////////////////////////////////////////////////////////// @@ -56,22 +46,7 @@ namespace openspace { - struct Tile { - std::shared_ptr texture; - std::shared_ptr preprocessData; - enum class Status { Unavailable, OutOfRange, IOError, OK } status; - - - /** - * Instantiaes a new tile unicolored tile. The texture gets the provided size and - * color in rgba. Color values ranges between 0-255. - */ - static Tile createPlainTile(const glm::uvec2& size, const glm::uvec4& color); - - static const Tile TileUnavailable; - - }; class TileProvider { public: From b56eeade880606160bf968ae15028fbfb72c9122 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Tue, 30 Aug 2016 20:05:16 -0400 Subject: [PATCH 04/12] Fix misspelling of SingleImageProvider --- .../tile/tileprovider/singleimageprovider.cpp | 16 ++++++++-------- .../tile/tileprovider/singleimageprovider.h | 6 +++--- .../globebrowsing/tile/tileproviderfactory.cpp | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/globebrowsing/tile/tileprovider/singleimageprovider.cpp b/modules/globebrowsing/tile/tileprovider/singleimageprovider.cpp index 4642dc7e1c..f7d38c0561 100644 --- a/modules/globebrowsing/tile/tileprovider/singleimageprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/singleimageprovider.cpp @@ -45,37 +45,37 @@ namespace openspace { - SingleImagePrivoder::SingleImagePrivoder(const std::string& imagePath) + SingleImageProvider::SingleImageProvider(const std::string& imagePath) : _imagePath(imagePath) { reset(); } - Tile SingleImagePrivoder::getTile(const ChunkIndex& chunkIndex) { + Tile SingleImageProvider::getTile(const ChunkIndex& chunkIndex) { return _tile; } - Tile SingleImagePrivoder::getDefaultTile() { + Tile SingleImageProvider::getDefaultTile() { return _tile; } - Tile::Status SingleImagePrivoder::getTileStatus(const ChunkIndex& index) { + Tile::Status SingleImageProvider::getTileStatus(const ChunkIndex& index) { return _tile.status; } - TileDepthTransform SingleImagePrivoder::depthTransform() { + TileDepthTransform SingleImageProvider::depthTransform() { TileDepthTransform transform; transform.depthOffset = 0.0f; transform.depthScale = 1.0f; return transform; } - void SingleImagePrivoder::update() { + void SingleImageProvider::update() { // nothing to be done } - void SingleImagePrivoder::reset() { + void SingleImageProvider::reset() { _tile = Tile(); _tile.texture = std::shared_ptr(ghoul::io::TextureReader::ref().loadTexture(_imagePath).release()); _tile.status = _tile.texture != nullptr ? Tile::Status::OK : Tile::Status::IOError; @@ -85,7 +85,7 @@ namespace openspace { _tile.texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); } - int SingleImagePrivoder::maxLevel() { + int SingleImageProvider::maxLevel() { return 1337; // unlimited } diff --git a/modules/globebrowsing/tile/tileprovider/singleimageprovider.h b/modules/globebrowsing/tile/tileprovider/singleimageprovider.h index 817562c2fa..7b55f9c0f9 100644 --- a/modules/globebrowsing/tile/tileprovider/singleimageprovider.h +++ b/modules/globebrowsing/tile/tileprovider/singleimageprovider.h @@ -49,10 +49,10 @@ namespace openspace { using namespace ghoul::opengl; - class SingleImagePrivoder : public TileProvider { + class SingleImageProvider : public TileProvider { public: - SingleImagePrivoder(const std::string& imagePath); - virtual ~SingleImagePrivoder() { } + SingleImageProvider(const std::string& imagePath); + virtual ~SingleImageProvider() { } virtual Tile getTile(const ChunkIndex& chunkIndex); virtual Tile getDefaultTile(); diff --git a/modules/globebrowsing/tile/tileproviderfactory.cpp b/modules/globebrowsing/tile/tileproviderfactory.cpp index 22119644c5..c50a4d0e9e 100644 --- a/modules/globebrowsing/tile/tileproviderfactory.cpp +++ b/modules/globebrowsing/tile/tileproviderfactory.cpp @@ -109,7 +109,7 @@ namespace openspace { }}); _factoryMap.insert({ "SingleImage", [](const std::string& file, const TileProviderInitData& initData) { - auto tileProvider = std::make_shared(file); + auto tileProvider = std::make_shared(file); return tileProvider; } }); From 8d17ad7e348941d8bcd4032bd27bea796ba8fb04 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Tue, 30 Aug 2016 23:52:53 -0400 Subject: [PATCH 05/12] Remove TileProviderFactory and instantiate TileProviders using FactoryManager instead --- data/scene/lodearth/lodearth.mod | 6 +- data/scene/lodmars/lodmars.mod | 28 ++-- modules/globebrowsing/CMakeLists.txt | 2 - modules/globebrowsing/globebrowsingmodule.cpp | 38 +++--- .../tile/tileprovider/cachingtileprovider.cpp | 59 ++++++++- .../tile/tileprovider/cachingtileprovider.h | 3 +- .../tile/tileprovider/singleimageprovider.cpp | 10 ++ .../tile/tileprovider/singleimageprovider.h | 2 + .../tileprovider/temporaltileprovider.cpp | 31 +++-- .../tile/tileprovider/temporaltileprovider.h | 12 +- .../tile/tileprovider/texttileprovider.h | 1 + .../tile/tileprovider/tileprovider.cpp | 26 ++++ .../tile/tileprovider/tileprovider.h | 11 +- .../tile/tileproviderfactory.cpp | 123 ------------------ .../globebrowsing/tile/tileproviderfactory.h | 61 --------- .../tile/tileprovidermanager.cpp | 11 +- 16 files changed, 182 insertions(+), 242 deletions(-) delete mode 100644 modules/globebrowsing/tile/tileproviderfactory.cpp delete mode 100644 modules/globebrowsing/tile/tileproviderfactory.h diff --git a/data/scene/lodearth/lodearth.mod b/data/scene/lodearth/lodearth.mod index 9e2fe6fa64..af0aae94f4 100644 --- a/data/scene/lodearth/lodearth.mod +++ b/data/scene/lodearth/lodearth.mod @@ -1,7 +1,7 @@ return { -- Earth barycenter module { - Name = "EarthBarycenter", + Name = "EarthCenterOfMass", Parent = "SolarSystemBarycenter", Transform = { Translation = { @@ -34,7 +34,7 @@ return { -- RenderableGlobe module { Name = "LodEarth", - Parent = "EarthBarycenter", + Parent = "EarthCenterOfMass", Transform = { Rotation = { Type = "SpiceRotation", @@ -118,6 +118,8 @@ return { Name = "Terrain tileset", FilePath = "map_service_configs/TERRAIN.wms", Enabled = true, + MinimumPixelSize = 90, + DoPreProcessing = true, }, }, HeightMapOverlays = { diff --git a/data/scene/lodmars/lodmars.mod b/data/scene/lodmars/lodmars.mod index b378e8859b..b95ebdf89d 100644 --- a/data/scene/lodmars/lodmars.mod +++ b/data/scene/lodmars/lodmars.mod @@ -1,13 +1,9 @@ +local marsEllipsoid = {3396190.0, 3396190.0, 3376200.0} return { -- Mars barycenter module { - Name = "MarsBarycenter", + Name = "MarsCenterOfMass", Parent = "SolarSystemBarycenter", - }, - -- RenderableGlobe module - { - Name = "LodMars", - Parent = "MarsBarycenter", Transform = { Translation = { Type = "SpiceEphemeris", @@ -18,6 +14,13 @@ return { "${OPENSPACE_DATA}/spice/de430_1850-2150.bsp" } }, + }, + }, + -- RenderableGlobe module + { + Name = "LodMars", + Parent = "MarsCenterOfMass", + Transform = { Rotation = { Type = "SpiceRotation", SourceFrame = "IAU_MARS", @@ -30,9 +33,7 @@ return { }, Renderable = { Type = "RenderableGlobe", - Frame = "IAU_MARS", - Body = "MARS BARYCENTER", - Radii = {3396190.0, 3396190.0, 3376200.0}, -- Mars' radii + Radii = marsEllipsoid, -- Mars' radii CameraMinHeight = 1000, InteractionDepthBelowEllipsoid = 10000, -- Useful when having negative height map values SegmentsPerPatch = 90, @@ -51,7 +52,6 @@ return { { Name = "MARS_Viking_MDIM21", FilePath = "map_service_configs/MARS_Viking_MDIM21.xml", - Enabled = true, }, { Name = "Mars Viking Clr", @@ -92,15 +92,21 @@ return { Name = "Mola Elevation", FilePath = "map_service_configs/Mola_Elevation.xml", Enabled = true, + MinimumPixelSize = 90, + DoPreProcessing = true, }, { Name = "West_Candor_Chasma_DEM_longlat_global", FilePath = "map_datasets/West_Candor_Chasma_DEM_longlat_global.vrt", --Enabled = true, + MinimumPixelSize = 90, + DoPreProcessing = true, }, { Name = "Layered Rock Outcrops in Southwest Candor Chasma", FilePath = "map_datasets/Layered_Rock_Outcrops_in_Southwest_Candor_Chasma_DEM.vrt", + MinimumPixelSize = 90, + DoPreProcessing = true, }, }, HeightMapOverlays = { @@ -113,7 +119,7 @@ return { -- MarsTrail module { Name = "MarsTrail", - Parent = "MarsBarycenter", + Parent = "Sun", Renderable = { Type = "RenderableTrail", Body = "MARS BARYCENTER", diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index cf589d9810..f6720542c5 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -62,7 +62,6 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileioresult.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/asynctilereader.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovidermanager.h - ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileproviderfactory.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/layeredtextureshaderprovider.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/layeredtextures.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/pixelregion.h @@ -114,7 +113,6 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileioresult.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/asynctilereader.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovidermanager.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileproviderfactory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/layeredtextureshaderprovider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/layeredtextures.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/pixelregion.cpp diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index c4bdc00a2b..4b3753c7ff 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -30,8 +30,15 @@ #include #include +#include #include +#include +#include +#include +#include +#include + namespace openspace { @@ -40,28 +47,23 @@ namespace openspace { {} void GlobeBrowsingModule::internalInitialize() { - /* - auto fRenderable = FactoryManager::ref().factory(); - ghoul_assert(fRenderable, "Renderable factory was not created"); - - fRenderable->registerClass("Planet"); - fRenderable->registerClass("RenderableTestPlanet"); - //fRenderable->registerClass("PlanetTestGeometry"); - - auto fPlanetGeometry = FactoryManager::ref().factory(); - ghoul_assert(fPlanetGeometry, "Planet test geometry factory was not created"); - fPlanetGeometry->registerClass("SimpleSphereTest"); - - */ - - - - auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fRenderable, "Renderable factory was not created"); - fRenderable->registerClass("RenderableGlobe"); + + void addFactory(std::unique_ptr factory); + + // add Tile Provider factory + FactoryManager::ref().addFactory( + std::make_unique>()); + + auto fTileProvider = FactoryManager::ref().factory(); + fTileProvider->registerClass("LRUCaching"); + fTileProvider->registerClass("SingleImage"); + fTileProvider->registerClass("Temporal"); + fTileProvider->registerClass("ChunkIndex"); + } } // namespace openspace diff --git a/modules/globebrowsing/tile/tileprovider/cachingtileprovider.cpp b/modules/globebrowsing/tile/tileprovider/cachingtileprovider.cpp index defef66ff3..4e4bd7defb 100644 --- a/modules/globebrowsing/tile/tileprovider/cachingtileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/cachingtileprovider.cpp @@ -38,12 +38,69 @@ namespace { - const std::string _loggerCat = "TileProvider"; + const std::string _loggerCat = "CachingTileProvider"; + + const std::string KeyDoPreProcessing = "DoPreProcessing"; + const std::string KeyMinimumPixelSize = "MinimumPixelSize"; + const std::string KeyFilePath = "FilePath"; + const std::string KeyCacheSize = "CacheSize"; + const std::string KeyFlushInterval = "FlushInterval"; } namespace openspace { + CachingTileProvider::CachingTileProvider(const ghoul::Dictionary& dictionary) + : _framesSinceLastRequestFlush(0) + { + // + std::string name = "Name unspecified"; + dictionary.getValue("Name", name); + std::string _loggerCat = "CachingTileProvider : " + name; + + + // 1. Get required Keys + std::string filePath; + if (!dictionary.getValue(KeyFilePath, filePath)) { + throw std::runtime_error("Must define key '" + KeyFilePath + "'"); + } + + // 2. Initialize default values for any optional Keys + TileDataset::Configuration config; + config.doPreProcessing = false; + config.minimumTilePixelSize = 512; + + // getValue does not work for integers + double minimumPixelSize; + double cacheSize = 512; + double framesUntilRequestFlush = 60; + + // 3. Check for used spcified optional keys + if (dictionary.getValue(KeyDoPreProcessing, config.doPreProcessing)) { + LDEBUG("Default doPreProcessing overridden: " << config.doPreProcessing); + } + if (dictionary.getValue(KeyMinimumPixelSize, minimumPixelSize)) { + LDEBUG("Default minimumPixelSize overridden: " << minimumPixelSize); + config.minimumTilePixelSize = static_cast(minimumPixelSize); + } + if (dictionary.getValue(KeyCacheSize, cacheSize)) { + LDEBUG("Default cacheSize overridden: " << cacheSize); + } + if (dictionary.getValue(KeyFlushInterval, framesUntilRequestFlush)) { + LDEBUG("Default framesUntilRequestFlush overridden: " << framesUntilRequestFlush); + } + + + // Initialize instance variables + auto tileDataset = std::make_shared(filePath, config); + + // only one thread per provider supported atm + auto threadPool = std::make_shared(1); + + _asyncTextureDataProvider = std::make_shared(tileDataset, threadPool); + _tileCache = std::make_shared(cacheSize); + _framesUntilRequestFlush = framesUntilRequestFlush; + } CachingTileProvider::CachingTileProvider(std::shared_ptr tileReader, std::shared_ptr tileCache, diff --git a/modules/globebrowsing/tile/tileprovider/cachingtileprovider.h b/modules/globebrowsing/tile/tileprovider/cachingtileprovider.h index f06c7e774b..5f569793e7 100644 --- a/modules/globebrowsing/tile/tileprovider/cachingtileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/cachingtileprovider.h @@ -25,7 +25,6 @@ #ifndef __CACHING_TILE_PROVIDER_H__ #define __CACHING_TILE_PROVIDER_H__ -#include #include #include // absPath @@ -51,6 +50,7 @@ namespace openspace { class CachingTileProvider : public TileProvider { public: + CachingTileProvider(const ghoul::Dictionary& dictionary); CachingTileProvider( std::shared_ptr tileReader, @@ -101,7 +101,6 @@ namespace openspace { int _framesSinceLastRequestFlush; int _framesUntilRequestFlush; - std::shared_ptr _asyncTextureDataProvider; }; diff --git a/modules/globebrowsing/tile/tileprovider/singleimageprovider.cpp b/modules/globebrowsing/tile/tileprovider/singleimageprovider.cpp index f7d38c0561..b7e8b010f0 100644 --- a/modules/globebrowsing/tile/tileprovider/singleimageprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/singleimageprovider.cpp @@ -38,11 +38,21 @@ namespace { const std::string _loggerCat = "SingleImageProvider"; + + const std::string KeyFilePath = "FilePath"; } namespace openspace { + SingleImageProvider::SingleImageProvider(const ghoul::Dictionary& dictionary) { + // Required input + if (!dictionary.getValue(KeyFilePath, _imagePath)) { + throw std::runtime_error("Must define key '" + KeyFilePath + "'"); + } + + reset(); + } SingleImageProvider::SingleImageProvider(const std::string& imagePath) diff --git a/modules/globebrowsing/tile/tileprovider/singleimageprovider.h b/modules/globebrowsing/tile/tileprovider/singleimageprovider.h index 7b55f9c0f9..dd8143e7b9 100644 --- a/modules/globebrowsing/tile/tileprovider/singleimageprovider.h +++ b/modules/globebrowsing/tile/tileprovider/singleimageprovider.h @@ -51,6 +51,8 @@ namespace openspace { class SingleImageProvider : public TileProvider { public: + + SingleImageProvider(const ghoul::Dictionary& dictionary); SingleImageProvider(const std::string& imagePath); virtual ~SingleImageProvider() { } diff --git a/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp b/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp index 4adaef4a26..567d22572f 100644 --- a/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp @@ -25,7 +25,8 @@ #include #include -#include +#include + #include @@ -46,6 +47,12 @@ namespace { const std::string _loggerCat = "TemporalTileProvider"; + + const std::string KeyDoPreProcessing = "DoPreProcessing"; + const std::string KeyMinimumPixelSize = "MinimumPixelSize"; + const std::string KeyFilePath = "FilePath"; + const std::string KeyCacheSize = "CacheSize"; + const std::string KeyFlushInterval = "FlushInterval"; } @@ -53,16 +60,21 @@ namespace openspace { const std::string TemporalTileProvider::TIME_PLACEHOLDER("${OpenSpaceTimeId}"); - TemporalTileProvider::TemporalTileProvider(const std::string& datasetFile, - const TileProviderInitData& tileProviderInitData) - : _datasetFile(datasetFile) - , _tileProviderInitData(tileProviderInitData) + + TemporalTileProvider::TemporalTileProvider(const ghoul::Dictionary& dictionary) + : _initDict(dictionary) { - std::ifstream in(datasetFile.c_str()); - ghoul_assert(errno == 0, strerror(errno) << std::endl << datasetFile); + + if (!dictionary.getValue(KeyFilePath, _datasetFile)) { + throw std::runtime_error("Must define key '" + KeyFilePath + "'"); + } + + + std::ifstream in(_datasetFile.c_str()); + ghoul_assert(errno == 0, strerror(errno) << std::endl << _datasetFile); // read file - std::string xml( (std::istreambuf_iterator(in)), (std::istreambuf_iterator())); + std::string xml((std::istreambuf_iterator(in)), (std::istreambuf_iterator())); _gdalXmlTemplate = consumeTemporalMetaData(xml); _defaultTile = getTileProvider()->getDefaultTile(); } @@ -185,7 +197,8 @@ namespace openspace { std::shared_ptr TemporalTileProvider::initTileProvider(TimeKey timekey) { std::string gdalDatasetXml = getGdalDatasetXML(timekey); - return TileProviderFactory::ref()->create("LRUCaching", gdalDatasetXml, _tileProviderInitData); + _initDict.setValue(KeyFilePath, gdalDatasetXml); + return std::make_shared(_initDict); } std::string TemporalTileProvider::getGdalDatasetXML(Time t) { diff --git a/modules/globebrowsing/tile/tileprovider/temporaltileprovider.h b/modules/globebrowsing/tile/tileprovider/temporaltileprovider.h index 211becda87..d53ec668f9 100644 --- a/modules/globebrowsing/tile/tileprovider/temporaltileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/temporaltileprovider.h @@ -27,6 +27,7 @@ #include +#include #include #include @@ -102,8 +103,7 @@ namespace openspace { class TemporalTileProvider : public TileProvider { public: - TemporalTileProvider(const std::string& datasetFile, const TileProviderInitData& tileProviderInitData); - + TemporalTileProvider(const ghoul::Dictionary& dictionary); // These methods implements TileProvider @@ -143,16 +143,20 @@ namespace openspace { // Members variables // ////////////////////////////////////////////////////////////////////////////////// - const std::string _datasetFile; + std::string _datasetFile; std::string _gdalXmlTemplate; std::unordered_map > _tileProviderMap; - TileProviderInitData _tileProviderInitData; + + // Used for creation of time specific instances of CachingTileProvider + ghoul::Dictionary _initDict; + Tile _defaultTile; std::shared_ptr _currentTileProvider; + TimeFormat * _timeFormat; TimeQuantizer _timeQuantizer; }; diff --git a/modules/globebrowsing/tile/tileprovider/texttileprovider.h b/modules/globebrowsing/tile/tileprovider/texttileprovider.h index ff7326ada8..363d5c0ea7 100644 --- a/modules/globebrowsing/tile/tileprovider/texttileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.h @@ -56,6 +56,7 @@ namespace openspace { */ class TextTileProvider : public TileProvider { public: + TextTileProvider(const glm::uvec2& textureSize = {512, 512}, size_t fontSize = 48); virtual ~TextTileProvider(); diff --git a/modules/globebrowsing/tile/tileprovider/tileprovider.cpp b/modules/globebrowsing/tile/tileprovider/tileprovider.cpp index 5e73089d24..a35e553b54 100644 --- a/modules/globebrowsing/tile/tileprovider/tileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/tileprovider.cpp @@ -24,6 +24,8 @@ #include +#include + #include @@ -31,9 +33,33 @@ namespace { const std::string _loggerCat = "TileProvider"; + + const std::string KeyType = "Type"; } namespace openspace { +TileProvider* TileProvider::createFromDictionary(const ghoul::Dictionary& dictionary) { + if (!dictionary.hasValue(KeyType)) { + LERROR("TileProvider did not have key '" << KeyType << "'"); + return nullptr; + } + + std::string type; + dictionary.getValue(KeyType, type); + ghoul::TemplateFactory* factory + = FactoryManager::ref().factory(); + TileProvider* result = factory->create(type, dictionary); + + if (result == nullptr) { + LERROR("Failed creating Ephemeris object of type '" << type << "'"); + return nullptr; + } + + return result; +} + +TileProvider::TileProvider(const ghoul::Dictionary& dictionary) { }; + } // namespace openspace diff --git a/modules/globebrowsing/tile/tileprovider/tileprovider.h b/modules/globebrowsing/tile/tileprovider/tileprovider.h index 82f3ca4849..731bd25a20 100644 --- a/modules/globebrowsing/tile/tileprovider/tileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/tileprovider.h @@ -27,6 +27,7 @@ #include // absPath #include +#include #include @@ -41,15 +42,15 @@ namespace openspace { - using namespace ghoul::opengl; - - - - class TileProvider { public: + static TileProvider* createFromDictionary(const ghoul::Dictionary& dictionary); + + TileProvider() {}; + TileProvider(const ghoul::Dictionary& dictionary); + virtual ~TileProvider() { } virtual Tile getTile(const ChunkIndex& chunkIndex) = 0; diff --git a/modules/globebrowsing/tile/tileproviderfactory.cpp b/modules/globebrowsing/tile/tileproviderfactory.cpp deleted file mode 100644 index c50a4d0e9e..0000000000 --- a/modules/globebrowsing/tile/tileproviderfactory.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/***************************************************************************************** -* * -* 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 -#include - -#include -#include -#include -#include - -#include - -#include "cpl_minixml.h" - - -namespace { - const std::string _loggerCat = "TileProviderFactory"; -} - - -namespace openspace { - - std::shared_ptr TileProviderFactory::_ref = nullptr; - - - TileProviderFactory::TileProviderFactory() { - initialize(); - } - - - std::shared_ptr TileProviderFactory::ref() { - if (_ref == nullptr) { - // Need to explicitly use new here, since constructor is private - TileProviderFactory* ptr = new TileProviderFactory(); - _ref = std::shared_ptr(ptr); - } - return _ref; - } - - std::shared_ptr TileProviderFactory::create(const std::string& type, - const std::string& desc, const TileProviderInitData& initData) - { - auto concreteFactoryIterator = _factoryMap.find(type); - - if (concreteFactoryIterator == _factoryMap.end()) { - LERROR("Unknown type: " << type); - return nullptr; - } - - std::shared_ptr tileProvider; - - try { - tileProvider = concreteFactoryIterator->second(desc, initData); - } - catch (const std::exception& e) { - LERROR(e.what()); - } - catch (...) { - LERROR("Could not open dataset:\n" << desc << "\n"); - } - return tileProvider; - } - - void TileProviderFactory::initialize() { - _factoryMap.insert({"LRUCaching", [](const std::string& desc, const TileProviderInitData& initData) { - TileDataset::Configuration config; - config.doPreProcessing = initData.preprocessTiles; - config.minimumTilePixelSize = initData.minimumPixelSize; - - auto tileDataset = std::make_shared(desc, config); - auto threadPool = std::make_shared(1); - auto tileReader = std::make_shared(tileDataset, threadPool); - auto tileCache = std::make_shared(initData.cacheSize); - auto tileProvider = std::make_shared(tileReader, tileCache, initData.framesUntilRequestQueueFlush); - return tileProvider; - }}); - - _factoryMap.insert({ "Temporal", [](const std::string& file, const TileProviderInitData& initData) { - CPLXMLNode * node = CPLParseXMLFile(file.c_str()); - if (!node) { - throw ghoul::RuntimeError("Unable to parse file:\n" + file); - } - if (std::string(node->pszValue) == "OpenSpaceTemporalGDALDataset") { - auto tileProvider = std::make_shared(file, initData); - return tileProvider; - } - }}); - - _factoryMap.insert({ "SingleImage", [](const std::string& file, const TileProviderInitData& initData) { - auto tileProvider = std::make_shared(file); - return tileProvider; - } }); - - _factoryMap.insert({ "ChunkIndex", [](const std::string& file, const TileProviderInitData& initData) { - auto tileProvider = std::make_shared(); - return tileProvider; - } }); - } - - -} // namespace openspace diff --git a/modules/globebrowsing/tile/tileproviderfactory.h b/modules/globebrowsing/tile/tileproviderfactory.h deleted file mode 100644 index d963d42f93..0000000000 --- a/modules/globebrowsing/tile/tileproviderfactory.h +++ /dev/null @@ -1,61 +0,0 @@ -/***************************************************************************************** -* * -* 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_PROVIDER_FACTORY_H__ -#define __TILE_PROVIDER_FACTORY_H__ - - -#include - -#include - -#include -#include -#include - - -namespace openspace { - - class TileProviderFactory { - public: - - static std::shared_ptr ref(); - - std::shared_ptr create(const std::string& type, const std::string& desc, const TileProviderInitData& initData); - - private: - - TileProviderFactory(); - void initialize(); - - typedef std::function(const std::string&, const TileProviderInitData&)> ConcreteFactory; - - std::unordered_map _factoryMap; - - static std::shared_ptr _ref; - }; - - -} // namespace openspace -#endif // __TILE_PROVIDER_FACTORY_H__ \ No newline at end of file diff --git a/modules/globebrowsing/tile/tileprovidermanager.cpp b/modules/globebrowsing/tile/tileprovidermanager.cpp index 5036891244..43dba6486e 100644 --- a/modules/globebrowsing/tile/tileprovidermanager.cpp +++ b/modules/globebrowsing/tile/tileprovidermanager.cpp @@ -22,8 +22,9 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#include + #include -#include #include @@ -133,16 +134,18 @@ namespace openspace { std::string type = "LRUCaching"; // if type is unspecified texDict.getValue("Type", type); - - std::shared_ptr tileProvider = TileProviderFactory::ref()->create(type, path, initData); + + auto tileProviderFactory = FactoryManager::ref().factory(); + TileProvider* tileProvider = tileProviderFactory->create(type, texDict); if (tileProvider == nullptr) { + LERROR("Unable to create TileProvider '" << name << "' of type '" << type << "'"); continue; } bool enabled = false; // defaults to false if unspecified texDict.getValue("Enabled", enabled); - dest.push_back({ name, tileProvider, enabled }); + dest.push_back({ name, std::shared_ptr(tileProvider), enabled }); } } From 41194d33d457ffde91a2ffab211af29ed5c4059e Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Wed, 31 Aug 2016 11:08:16 -0400 Subject: [PATCH 06/12] Add Ellipsoid radii accessor and return const refs instead of copies --- modules/globebrowsing/geometry/ellipsoid.cpp | 11 ++++++++--- modules/globebrowsing/geometry/ellipsoid.h | 8 +++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/globebrowsing/geometry/ellipsoid.cpp b/modules/globebrowsing/geometry/ellipsoid.cpp index 2dc96f427d..9a95047a1b 100644 --- a/modules/globebrowsing/geometry/ellipsoid.cpp +++ b/modules/globebrowsing/geometry/ellipsoid.cpp @@ -115,15 +115,20 @@ namespace openspace { sin(geodetic2.lat)); } - Vec3 Ellipsoid::radiiSquared() const { + const Vec3& Ellipsoid::radii() const { + return _radii; + } + + + const Vec3& Ellipsoid::radiiSquared() const { return _cached._radiiSquared; } - Vec3 Ellipsoid::oneOverRadiiSquared() const { + const Vec3& Ellipsoid::oneOverRadiiSquared() const { return _cached._oneOverRadiiSquared; } - Vec3 Ellipsoid::radiiToTheFourth() const { + const Vec3& Ellipsoid::radiiToTheFourth() const { return _cached._radiiToTheFourth; } diff --git a/modules/globebrowsing/geometry/ellipsoid.h b/modules/globebrowsing/geometry/ellipsoid.h index 041d729ccd..3dd0d23557 100644 --- a/modules/globebrowsing/geometry/ellipsoid.h +++ b/modules/globebrowsing/geometry/ellipsoid.h @@ -76,9 +76,11 @@ public: Vec3 geodeticSurfaceNormalForGeocentricallyProjectedPoint(const Vec3& p) const; Vec3 geodeticSurfaceNormal(Geodetic2 geodetic2) const; - Vec3 radiiSquared() const; - Vec3 oneOverRadiiSquared() const; - Vec3 radiiToTheFourth() const; + const Vec3& radii() const; + const Vec3& radiiSquared() const; + const Vec3& oneOverRadiiSquared() const; + const Vec3& radiiToTheFourth() const; + Scalar minimumRadius() const; Scalar maximumRadius() const; From 4a5dd1dacb0923d905f04ab2789c935e5eb64b33 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Wed, 31 Aug 2016 13:25:33 -0400 Subject: [PATCH 07/12] Add longitudal distance and great circle distance to class Ellipsoid --- modules/globebrowsing/geometry/ellipsoid.cpp | 21 ++++++++++++++++++++ modules/globebrowsing/geometry/ellipsoid.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/modules/globebrowsing/geometry/ellipsoid.cpp b/modules/globebrowsing/geometry/ellipsoid.cpp index 9a95047a1b..6bd4c5a056 100644 --- a/modules/globebrowsing/geometry/ellipsoid.cpp +++ b/modules/globebrowsing/geometry/ellipsoid.cpp @@ -144,6 +144,27 @@ namespace openspace { return (_radii.x + _radii.y + _radii.z) / 3.0; } + Scalar Ellipsoid::longitudalDistance(Scalar lat, Scalar lon1, Scalar lon2) const { + Vec2 ellipseRadii = glm::cos(lat) * _radii.xy(); + // Approximating with the ellipse mean radius + Scalar meanRadius = 0.5 * (ellipseRadii.x + ellipseRadii.y); + return meanRadius * std::abs(lon2 - lon1); + } + + Scalar Ellipsoid::greatCircleDistance(const Geodetic2& p1, const Geodetic2& p2) const{ + // https://en.wikipedia.org/wiki/Meridian_arc + // https://en.wikipedia.org/wiki/Great-circle_distance#Vector_version + + Vec3 n1 = geodeticSurfaceNormal(p1); + Vec3 n2 = geodeticSurfaceNormal(p2); + Scalar centralAngle = glm::atan(glm::length(glm::cross(n1, n2)) / glm::dot(n1, n2)); + + Geodetic2 pMid = (p1 + p2) / 2; + Vec3 centralNormal = cartesianSurfacePosition(pMid); + + return centralAngle * glm::length(centralNormal); + } + Geodetic2 Ellipsoid::cartesianToGeodetic2(const Vec3& p) const { Vec3 normal = geodeticSurfaceNormalForGeocentricallyProjectedPoint(p); diff --git a/modules/globebrowsing/geometry/ellipsoid.h b/modules/globebrowsing/geometry/ellipsoid.h index 3dd0d23557..a65c3d00e8 100644 --- a/modules/globebrowsing/geometry/ellipsoid.h +++ b/modules/globebrowsing/geometry/ellipsoid.h @@ -86,6 +86,9 @@ public: Scalar maximumRadius() const; Scalar averageRadius() const; + Scalar longitudalDistance(Scalar lat, Scalar lon1, Scalar lon2) const; + Scalar greatCircleDistance(const Geodetic2& p1, const Geodetic2& p2) const; + Geodetic2 cartesianToGeodetic2(const Vec3& p) const; Vec3 cartesianSurfacePosition(const Geodetic2& geodetic2) const; Vec3 cartesianPosition(const Geodetic3& geodetic3) const; From b064c5606feaca3f082bd43027d66989b3bd6f37 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Wed, 31 Aug 2016 13:27:36 -0400 Subject: [PATCH 08/12] Add new TileProvider implementation SizeReferenceTileProvider and add to lodMars --- data/scene/lodmars/lodmars.mod | 5 ++ modules/globebrowsing/globebrowsingmodule.cpp | 1 + .../tile/tileprovider/texttileprovider.cpp | 49 ++++++++++++++++++- .../tile/tileprovider/texttileprovider.h | 15 +++++- 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/data/scene/lodmars/lodmars.mod b/data/scene/lodmars/lodmars.mod index b95ebdf89d..15127ad591 100644 --- a/data/scene/lodmars/lodmars.mod +++ b/data/scene/lodmars/lodmars.mod @@ -86,6 +86,11 @@ return { Type = "ChunkIndex", Name = "Indices", }, + { + Type = "SizeReference", + Name = "Size Reference", + Radii = marsEllipsoid, + }, }, HeightMaps = { { diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index 4b3753c7ff..7f511f938b 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -63,6 +63,7 @@ void GlobeBrowsingModule::internalInitialize() { fTileProvider->registerClass("SingleImage"); fTileProvider->registerClass("Temporal"); fTileProvider->registerClass("ChunkIndex"); + fTileProvider->registerClass("SizeReference"); } diff --git a/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp b/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp index 22ca983073..dc516383eb 100644 --- a/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp @@ -53,6 +53,7 @@ namespace openspace { { _font = OsEng.fontManager().font("Mono", _fontSize); + _fontRenderer = std::unique_ptr(FontRenderer::createDefault()); _fontRenderer->setFramebufferSize(textureSize); @@ -142,7 +143,9 @@ namespace openspace { } - + ////////////////////////////////////////////////////////////////////////////////////// + // Chunk Index Tile Provider // + ////////////////////////////////////////////////////////////////////////////////////// void ChunkIndexTileProvider::renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const { fontRenderer.render( @@ -156,8 +159,52 @@ namespace openspace { ); } + ////////////////////////////////////////////////////////////////////////////////////// + // Tile Size Reference Tile Provider // + ////////////////////////////////////////////////////////////////////////////////////// + + namespace { + const std::string KeyRadii = "Radii"; + } + + SizeReferenceTileProvider::SizeReferenceTileProvider(const ghoul::Dictionary& dictionary) { + _fontSize = 64; + _font = OsEng.fontManager().font("Mono", _fontSize); + glm::dvec3 radii(1,1,1); + if (!dictionary.getValue(KeyRadii, radii)) { + throw std::runtime_error("Must define key '" + KeyRadii + "'"); + } + _ellipsoid = Ellipsoid(radii); + } + + 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); + std::string unit = "m"; + if (tileLongitudalLength > 10000) { + tileLongitudalLength *= 0.001; + unit = "km"; + } + + glm::vec2 textPosition; + textPosition.x = 0; + textPosition.y = aboveEquator ? _fontSize / 2 : _textureSize.y - 3 * _fontSize / 2; + glm::vec4 color(1.0, 1.0, 1.0, 1.0); + + fontRenderer.render( + *_font, + textPosition, + color, + " %.0f %s", + tileLongitudalLength, unit.c_str() + ); + } } // namespace openspace diff --git a/modules/globebrowsing/tile/tileprovider/texttileprovider.h b/modules/globebrowsing/tile/tileprovider/texttileprovider.h index 363d5c0ea7..bb40eeaf06 100644 --- a/modules/globebrowsing/tile/tileprovider/texttileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.h @@ -25,6 +25,8 @@ #ifndef __TEXT_TILE_PROVIDER_H__ #define __TEXT_TILE_PROVIDER_H__ +#include + #include #include // absPath #include @@ -37,6 +39,7 @@ #include #include #include +#include ////////////////////////////////////////////////////////////////////////////////////////// @@ -60,7 +63,7 @@ namespace openspace { TextTileProvider(const glm::uvec2& textureSize = {512, 512}, size_t fontSize = 48); virtual ~TextTileProvider(); - // Methods below are implemented in this class + // The TileProvider interface below is implemented in this class virtual Tile getTile(const ChunkIndex& chunkIndex); virtual Tile getDefaultTile(); @@ -72,7 +75,6 @@ namespace openspace { // This method is pure and should be implemented by subclasses - virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const = 0; protected: @@ -97,6 +99,15 @@ namespace openspace { }; + class SizeReferenceTileProvider : public TextTileProvider { + public: + SizeReferenceTileProvider(const ghoul::Dictionary& dictionary); + virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const; + + private: + Ellipsoid _ellipsoid; + }; + } // namespace openspace From c2019570010eb76146cdfd0cb2bd4af925b354ec Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Wed, 31 Aug 2016 14:38:05 -0400 Subject: [PATCH 09/12] SizeReferenceTileProvider renders referred distance next to its text --- data/scene/debugglobe/textures/arrows.png | Bin 0 -> 20377 bytes data/scene/lodmars/lodmars.mod | 1 + .../tile/tileprovider/texttileprovider.cpp | 43 +++++++++++++++++- .../tile/tileprovider/texttileprovider.h | 6 +++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 data/scene/debugglobe/textures/arrows.png diff --git a/data/scene/debugglobe/textures/arrows.png b/data/scene/debugglobe/textures/arrows.png new file mode 100644 index 0000000000000000000000000000000000000000..d10df6684c618aff5de9313b84132b809b60255f GIT binary patch literal 20377 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 literal 0 HcmV?d00001 diff --git a/data/scene/lodmars/lodmars.mod b/data/scene/lodmars/lodmars.mod index 15127ad591..c540ee38c3 100644 --- a/data/scene/lodmars/lodmars.mod +++ b/data/scene/lodmars/lodmars.mod @@ -90,6 +90,7 @@ return { Type = "SizeReference", Name = "Size Reference", Radii = marsEllipsoid, + BackgroundImagePath = "../debugglobe/textures/arrows.png", }, }, HeightMaps = { diff --git a/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp b/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp index dc516383eb..66e8a0d9cf 100644 --- a/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.cpp @@ -100,8 +100,7 @@ namespace openspace { } Tile TextTileProvider::createChunkIndexTile(const ChunkIndex& chunkIndex) { - glm::uvec4 color = { 0, 0, 0, 0 }; - Tile tile = Tile::createPlainTile(_textureSize, color); + Tile tile = backgroundTile(chunkIndex); // Keep track of defaultFBO and viewport to be able to reset state when done GLint defaultFBO; @@ -142,6 +141,11 @@ namespace openspace { return 1337; // unlimited } + Tile TextTileProvider::backgroundTile(const ChunkIndex& chunkIndex) const { + glm::uvec4 color = { 0, 0, 0, 0 }; + return Tile::createPlainTile(_textureSize, color); + } + ////////////////////////////////////////////////////////////////////////////////////// // Chunk Index Tile Provider // @@ -165,16 +169,30 @@ namespace openspace { namespace { const std::string KeyRadii = "Radii"; + const std::string KeyBackgroundImagePath = "BackgroundImagePath"; } SizeReferenceTileProvider::SizeReferenceTileProvider(const ghoul::Dictionary& dictionary) { _fontSize = 64; _font = OsEng.fontManager().font("Mono", _fontSize); + glm::dvec3 radii(1,1,1); if (!dictionary.getValue(KeyRadii, radii)) { throw std::runtime_error("Must define key '" + KeyRadii + "'"); } _ellipsoid = Ellipsoid(radii); + + _backgroundTile.status = Tile::Status::Unavailable; + std::string backgroundImagePath; + if (dictionary.getValue(KeyBackgroundImagePath, backgroundImagePath)) { + using namespace ghoul::io; + std::string imgAbsPath = absPath(backgroundImagePath); + _backgroundTile.texture = TextureReader::ref().loadTexture(imgAbsPath); + _backgroundTile.texture->uploadTexture(); + _backgroundTile.texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + _backgroundTile.status = Tile::Status::OK; + } + } void SizeReferenceTileProvider::renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const { @@ -206,5 +224,26 @@ namespace openspace { ); } + Tile SizeReferenceTileProvider::backgroundTile(const ChunkIndex& chunkIndex) const { + if (_backgroundTile.status == Tile::Status::OK) { + Tile tile; + auto t = _backgroundTile.texture; + void* pixelData = new char[t->expectedPixelDataSize()]; + memcpy(pixelData, t->pixelData(), t->expectedPixelDataSize()); + tile.texture = std::make_shared( + pixelData, t->dimensions(), t->format(), t->internalFormat(), t->dataType(), t->filter(), t->wrapping()); + tile.texture->uploadTexture(); + tile.texture->setDataOwnership(Texture::TakeOwnership::Yes); + tile.status = Tile::Status::OK; + return tile; + } + else { + // use default background + return TextTileProvider::backgroundTile(chunkIndex); + } + } + + + } // namespace openspace diff --git a/modules/globebrowsing/tile/tileprovider/texttileprovider.h b/modules/globebrowsing/tile/tileprovider/texttileprovider.h index bb40eeaf06..79e9f6523a 100644 --- a/modules/globebrowsing/tile/tileprovider/texttileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.h @@ -73,6 +73,9 @@ namespace openspace { virtual void reset(); virtual int maxLevel(); + // 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; // This method is pure and should be implemented by subclasses virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const = 0; @@ -102,10 +105,13 @@ namespace openspace { class SizeReferenceTileProvider : public TextTileProvider { public: SizeReferenceTileProvider(const ghoul::Dictionary& dictionary); + virtual void renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const; + virtual Tile backgroundTile(const ChunkIndex& chunkIndex) const; private: Ellipsoid _ellipsoid; + Tile _backgroundTile; }; } // namespace openspace From b8fb3dcbe66a91fbf22638c4ceaffae8ff5063b5 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Wed, 31 Aug 2016 16:42:48 -0400 Subject: [PATCH 10/12] SizeReferenceTileProvider hashes based on tile sizes instead of chunk indices --- .../tile/tileprovider/texttileprovider.cpp | 36 +++++++++++++++---- .../tile/tileprovider/texttileprovider.h | 9 +++++ 2 files changed, 39 insertions(+), 6 deletions(-) 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; }; From 134ece1293effd59863d72e930a0bb8736f7e7cb Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Wed, 31 Aug 2016 16:43:15 -0400 Subject: [PATCH 11/12] Add size reference for LodEarth --- data/scene/lodearth/lodearth.mod | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/data/scene/lodearth/lodearth.mod b/data/scene/lodearth/lodearth.mod index af0aae94f4..f039f4053e 100644 --- a/data/scene/lodearth/lodearth.mod +++ b/data/scene/lodearth/lodearth.mod @@ -1,3 +1,4 @@ +earthEllipsoid = {6378137.0, 6378137.0, 6356752.314245} -- Earth's radii return { -- Earth barycenter module { @@ -48,7 +49,7 @@ return { }, Renderable = { Type = "RenderableGlobe", - Radii = {6378137.0, 6378137.0, 6356752.314245}, -- Earth's radii + Radii = earthEllipsoid, CameraMinHeight = 300, InteractionDepthBelowEllipsoid = 0, -- Useful when having negative height map values SegmentsPerPatch = 64, @@ -112,6 +113,12 @@ return { Name = "Reference_Labels", FilePath = "map_service_configs/Reference_Labels.xml", }, + { + Type = "SizeReference", + Name = "Size Reference", + Radii = earthEllipsoid, + BackgroundImagePath = "../debugglobe/textures/arrows.png", + }, }, HeightMaps = { { From 1195ff96192c9df48a7e31c76df69c16f28071ff Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Sat, 3 Sep 2016 18:28:47 -0400 Subject: [PATCH 12/12] Remove excessive debug logging in TileDataset --- modules/globebrowsing/tile/tiledataset.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/globebrowsing/tile/tiledataset.cpp b/modules/globebrowsing/tile/tiledataset.cpp index ae4a917138..0b05b027b4 100644 --- a/modules/globebrowsing/tile/tiledataset.cpp +++ b/modules/globebrowsing/tile/tiledataset.cpp @@ -471,7 +471,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(chunkIndex << " | " << preRound.x << ", " << preRound.y << " --> " << io.write.region.numPixels.x << ", " << io.write.region.numPixels.y); } @@ -610,8 +610,8 @@ namespace openspace { } if (depth == 0) { - LDEBUG(indentation << "main rasterIO read: " << io.read.region); - LDEBUG(indentation << "main rasterIO write: " << io.write.region); + //LDEBUG(indentation << "main rasterIO read: " << io.read.region); + //LDEBUG(indentation << "main rasterIO write: " << io.write.region); } else if (worstError > CPLErr::CE_None) {