From eb40b8945bdcf93c907fd92b915fd541842bab15 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Thu, 28 Apr 2016 17:54:51 -0400 Subject: [PATCH] Change TwmsTileProvider to TileProvider --- modules/globebrowsing/CMakeLists.txt | 16 +++++++------- modules/globebrowsing/globes/chunklodglobe.h | 2 +- modules/globebrowsing/globes/chunknode.cpp | 2 +- .../globebrowsing/other/texturetileset.cpp | 12 +++++----- modules/globebrowsing/other/texturetileset.h | 12 +++++----- ...{twmstileprovider.cpp => tileprovider.cpp} | 22 +++++++++---------- .../{twmstileprovider.h => tileprovider.h} | 16 +++++++------- .../globebrowsing/rendering/patchrenderer.cpp | 9 ++++---- .../globebrowsing/rendering/patchrenderer.h | 8 +++---- tests/test_texturetileset.inl | 10 ++++----- tests/test_twmstileprovider.inl | 4 ++-- 11 files changed, 57 insertions(+), 56 deletions(-) rename modules/globebrowsing/other/{twmstileprovider.cpp => tileprovider.cpp} (92%) rename modules/globebrowsing/other/{twmstileprovider.h => tileprovider.h} (93%) diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index b5d0b7aa0c..a03274e78d 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -39,16 +39,16 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/meshes/clipmapgrid.h - ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/geodetic2.h - ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/angle.h - ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/ellipsoid.h + ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/geodetic2.h + ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/angle.h + ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/ellipsoid.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/patchrenderer.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/frustumculler.h ${CMAKE_CURRENT_SOURCE_DIR}/other/distanceswitch.h ${CMAKE_CURRENT_SOURCE_DIR}/other/texturetileset.h - ${CMAKE_CURRENT_SOURCE_DIR}/other/twmstileprovider.h + ${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.h ${CMAKE_CURRENT_SOURCE_DIR}/other/gdaldataconverter.h ${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.h ${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.h @@ -70,16 +70,16 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/meshes/clipmapgrid.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/geodetic2.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/angle.inl - ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/ellipsoid.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/geodetic2.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/angle.inl + ${CMAKE_CURRENT_SOURCE_DIR}/geodetics/ellipsoid.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/patchrenderer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/frustumculler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/other/distanceswitch.cpp ${CMAKE_CURRENT_SOURCE_DIR}/other/texturetileset.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/other/twmstileprovider.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/other/gdaldataconverter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.inl ${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.inl diff --git a/modules/globebrowsing/globes/chunklodglobe.h b/modules/globebrowsing/globes/chunklodglobe.h index b5350a2385..207548ee03 100644 --- a/modules/globebrowsing/globes/chunklodglobe.h +++ b/modules/globebrowsing/globes/chunklodglobe.h @@ -41,7 +41,7 @@ #include #include #include -#include +#include namespace ghoul { namespace opengl { diff --git a/modules/globebrowsing/globes/chunknode.cpp b/modules/globebrowsing/globes/chunknode.cpp index 11cb3c0b68..14507683d7 100644 --- a/modules/globebrowsing/globes/chunknode.cpp +++ b/modules/globebrowsing/globes/chunknode.cpp @@ -120,7 +120,7 @@ bool ChunkNode::internalUpdateChunkTree(const RenderData& data, ChunkIndex& trav void ChunkNode::internalRender(const RenderData& data, ChunkIndex& traverseData) { if (isLeaf()) { if (_isVisible) { - TileIndex ti = { traverseData.x, traverseData.y, traverseData.level }; + GeodeticTileIndex ti = { traverseData.x, traverseData.y, traverseData.level }; LatLonPatchRenderer& patchRenderer = _owner.getPatchRenderer(); diff --git a/modules/globebrowsing/other/texturetileset.cpp b/modules/globebrowsing/other/texturetileset.cpp index 8e1548307f..e361ae25ef 100644 --- a/modules/globebrowsing/other/texturetileset.cpp +++ b/modules/globebrowsing/other/texturetileset.cpp @@ -94,7 +94,7 @@ namespace openspace { } - TileIndex TextureTileSet::getTileIndex(GeodeticPatch patch) { + GeodeticTileIndex TextureTileSet::getTileIndex(const GeodeticPatch& patch) { // Calculate the level of the index depanding on the size of the incoming patch. // The level is as big as possible (as far down as possible) but it can't be // too big since at maximum four tiles should be used to cover a patch @@ -115,20 +115,20 @@ namespace openspace { tileIndexXY.y *= -1; // Create the tileindex - TileIndex tileIndex = { tileIndexXY.x, tileIndexXY.y, level }; + GeodeticTileIndex tileIndex = { tileIndexXY.x, tileIndexXY.y, level }; return tileIndex; } - std::shared_ptr TextureTileSet::getTile(GeodeticPatch patch) { + std::shared_ptr TextureTileSet::getTile(const GeodeticPatch& patch) { return getTile(getTileIndex(patch)); } - std::shared_ptr TextureTileSet::getTile(const TileIndex& tileIndex) { + std::shared_ptr TextureTileSet::getTile(const GeodeticTileIndex& tileIndex) { return _testTexture; } GeodeticPatch TextureTileSet::getTilePositionAndScale( - const TileIndex& tileIndex) { + const GeodeticTileIndex& tileIndex) { Geodetic2 tileSize = Geodetic2( _sizeLevel0.lat / pow(2, tileIndex.level), _sizeLevel0.lon / pow(2, tileIndex.level)); @@ -143,7 +143,7 @@ namespace openspace { glm::mat3 TextureTileSet::getUvTransformationPatchToTile( GeodeticPatch patch, - const TileIndex& tileIndex) + const GeodeticTileIndex& tileIndex) { GeodeticPatch tile = getTilePositionAndScale(tileIndex); return getUvTransformationPatchToTile(patch, tile); diff --git a/modules/globebrowsing/other/texturetileset.h b/modules/globebrowsing/other/texturetileset.h index 10837dc592..2df976ac2b 100644 --- a/modules/globebrowsing/other/texturetileset.h +++ b/modules/globebrowsing/other/texturetileset.h @@ -30,7 +30,7 @@ #include #include -#include +#include ////////////////////////////////////////////////////////////////////////////////////////// @@ -56,26 +56,26 @@ namespace openspace { Without the tile being smaller than the patch in lat-lon space. The tile is at least as big as the patch. */ - TileIndex getTileIndex(GeodeticPatch patch); + GeodeticTileIndex getTileIndex(const GeodeticPatch& patch); /** Returns a texture that can be used for the specified patch */ - std::shared_ptr getTile(GeodeticPatch patch); + std::shared_ptr getTile(const GeodeticPatch& patch); /** Returns the texture for the given tile index. The indices reaches from left to right and top to bottom while the texture coordinates and the latlon coordinates reaches from left to right and bottom to top. */ - std::shared_ptr getTile(const TileIndex& tileIndex); + std::shared_ptr getTile(const GeodeticTileIndex& tileIndex); /** A tile can be defined with a tile index or a LatLonPatch which defines the position and the size of the tile. */ GeodeticPatch getTilePositionAndScale( - const TileIndex& tileIndex); + const GeodeticTileIndex& tileIndex); /** A transformation (translation and scaling) from the texture space of a patch @@ -83,7 +83,7 @@ namespace openspace { */ glm::mat3 getUvTransformationPatchToTile( GeodeticPatch patch, - const TileIndex& tileIndex); + const GeodeticTileIndex& tileIndex); /** Overloaded function diff --git a/modules/globebrowsing/other/twmstileprovider.cpp b/modules/globebrowsing/other/tileprovider.cpp similarity index 92% rename from modules/globebrowsing/other/twmstileprovider.cpp rename to modules/globebrowsing/other/tileprovider.cpp index ef4b63fad7..48d84186f3 100644 --- a/modules/globebrowsing/other/twmstileprovider.cpp +++ b/modules/globebrowsing/other/tileprovider.cpp @@ -23,7 +23,7 @@ ****************************************************************************************/ -#include +#include #include @@ -43,9 +43,8 @@ namespace { namespace openspace { - TwmsTileProvider::TwmsTileProvider() - : _tileCache(5000) // setting cache size - //, _fileFutureCache(5000) // setting cache size + TileProvider::TileProvider(int tileCacheSize) + : _tileCache(tileCacheSize) // setting cache size { int downloadApplicationVersion = 1; if (!DownloadManager::isInitialized()) { @@ -54,12 +53,12 @@ namespace openspace { } - TwmsTileProvider::~TwmsTileProvider(){ + TileProvider::~TileProvider(){ } - void TwmsTileProvider::prerender() { + void TileProvider::prerender() { // Remove filefutures that are inactive auto it = _fileFutureMap.begin(); @@ -81,6 +80,7 @@ namespace openspace { // Move finished texture tiles to cache + /* while (_concurrentJobManager.numFinishedJobs() > 0) { auto finishedJob = _concurrentJobManager.popFinishedJob(); @@ -99,11 +99,11 @@ namespace openspace { _tileCache.put(hashkey, texture); _fileFutureMap.erase(hashkey); } - + */ } - std::shared_ptr TwmsTileProvider::getTile(const TileIndex& tileIndex) { + std::shared_ptr TileProvider::getTile(const GeodeticTileIndex& tileIndex) { HashKey hashkey = tileIndex.hashKey(); if (_tileCache.exist(hashkey)) { @@ -126,7 +126,7 @@ namespace openspace { //_concurrentJobManager.enqueueJob(job); } } - else if(_fileFutureMap.size() < 50){ + else if(_fileFutureMap.size() < 100){ std::shared_ptr fileFuture = requestTile(tileIndex); _fileFutureMap.insert_or_assign(hashkey, fileFuture); @@ -134,7 +134,7 @@ namespace openspace { return nullptr; } - std::shared_ptr TwmsTileProvider::loadAndInitTextureDisk(std::string filePath) { + std::shared_ptr TileProvider::loadAndInitTextureDisk(std::string filePath) { auto textureReader = ghoul::io::TextureReader::ref(); std::shared_ptr texture = std::move(textureReader.loadTexture(absPath(filePath))); @@ -147,7 +147,7 @@ namespace openspace { - std::shared_ptr TwmsTileProvider::requestTile(const TileIndex& tileIndex) { + std::shared_ptr TileProvider::requestTile(const GeodeticTileIndex& tileIndex) { // download tile std::stringstream ss; //std::string baseUrl = "https://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi?TIME=2016-04-17&layer=MODIS_Terra_CorrectedReflectance_TrueColor&tilematrixset=EPSG4326_250m&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fjpeg"; diff --git a/modules/globebrowsing/other/twmstileprovider.h b/modules/globebrowsing/other/tileprovider.h similarity index 93% rename from modules/globebrowsing/other/twmstileprovider.h rename to modules/globebrowsing/other/tileprovider.h index fe1f15caa6..de843344b6 100644 --- a/modules/globebrowsing/other/twmstileprovider.h +++ b/modules/globebrowsing/other/tileprovider.h @@ -45,7 +45,7 @@ namespace openspace { using HashKey = unsigned long; - struct TileIndex { + struct GeodeticTileIndex { int x, y, level; HashKey hashKey() const { @@ -100,26 +100,26 @@ namespace openspace { namespace openspace { using namespace ghoul::opengl; - class TwmsTileProvider - { + class TileProvider { public: - TwmsTileProvider(); - ~TwmsTileProvider(); + TileProvider(int tileCacheSize); + ~TileProvider(); - std::shared_ptr getTile(const TileIndex& tileIndex); + std::shared_ptr getTile(const GeodeticTileIndex& tileIndex); void prerender(); private: - std::shared_ptr requestTile(const TileIndex&); + std::shared_ptr requestTile(const GeodeticTileIndex&); std::shared_ptr loadAndInitTextureDisk(std::string filePath); LRUCache> _tileCache; std::unordered_map> _fileFutureMap; + //LRUCache> _fileFutureCache; - ConcurrentJobManager _concurrentJobManager; + //ConcurrentJobManager _concurrentJobManager; }; } // namespace openspace diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index 496f7fe2cf..17827fe080 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -77,6 +77,7 @@ namespace openspace { LatLonPatchRenderer::LatLonPatchRenderer(shared_ptr grid) : PatchRenderer() , _grid(grid) + , tileProvider(5000) { _programObject = OsEng.renderEngine().buildRenderProgram( "LatLonSphereMappingProgram", @@ -97,7 +98,7 @@ namespace openspace { { // Get the textures that should be used for rendering - TileIndex ti = _tileSet.getTileIndex(patch); + GeodeticTileIndex ti = _tileSet.getTileIndex(patch); renderPatch(patch, data, ellipsoid, ti); } @@ -106,7 +107,7 @@ namespace openspace { const GeodeticPatch& patch, const RenderData& data, const Ellipsoid& ellipsoid, - const TileIndex& tileIndex) + const GeodeticTileIndex& tileIndex) { using namespace glm; @@ -128,7 +129,7 @@ namespace openspace { // Get the textures that should be used for rendering std::shared_ptr tile00; bool usingTile = true; - TileIndex ti; + GeodeticTileIndex ti; ti.level =tileIndex.level; ti.x = tileIndex.y; ti.y = tileIndex.x; @@ -226,7 +227,7 @@ namespace openspace { // Get the textures that should be used for rendering - TileIndex tileIndex = _tileSet.getTileIndex(newPatch); + GeodeticTileIndex tileIndex = _tileSet.getTileIndex(newPatch); GeodeticPatch tilePatch = _tileSet.getTilePositionAndScale(tileIndex); std::shared_ptr tile00 = _tileSet.getTile(tileIndex); glm::mat3 uvTransform = _tileSet.getUvTransformationPatchToTile(newPatch, tileIndex); diff --git a/modules/globebrowsing/rendering/patchrenderer.h b/modules/globebrowsing/rendering/patchrenderer.h index 196cb96b63..e9f9a121f8 100644 --- a/modules/globebrowsing/rendering/patchrenderer.h +++ b/modules/globebrowsing/rendering/patchrenderer.h @@ -86,13 +86,13 @@ namespace openspace { const GeodeticPatch& patch, const RenderData& data, const Ellipsoid& ellipsoid, - const TileIndex& ti); + const GeodeticTileIndex& ti); private: - TwmsTileProvider tileProvider; + TileProvider tileProvider; shared_ptr _grid; }; @@ -105,8 +105,8 @@ namespace openspace { void renderPatch( const Geodetic2& patchSize, const RenderData& data, - const Ellipsoid& ellipsoid); - private: + const Ellipsoid& ellipsoid); + private: shared_ptr _grid; }; diff --git a/tests/test_texturetileset.inl b/tests/test_texturetileset.inl index de7fabcf3a..cc5b4dfa65 100644 --- a/tests/test_texturetileset.inl +++ b/tests/test_texturetileset.inl @@ -40,7 +40,7 @@ TEST_F(TextureTileSetTest, getTileIndexLevel) { TextureTileSet tileSet(Geodetic2(M_PI, M_PI * 2), Geodetic2(M_PI / 2, - M_PI), 0); GeodeticPatch patch(Geodetic2(0, 0), Geodetic2(M_PI / 16, M_PI / 8)); - TileIndex tileIndex0 = tileSet.getTileIndex(patch); + GeodeticTileIndex tileIndex0 = tileSet.getTileIndex(patch); // Maximum level is 0 ASSERT_EQ(tileIndex0.level, 0); @@ -59,7 +59,7 @@ TEST_F(TextureTileSetTest, getTileIndexLevel) { // An edge case tile that covers a fourth of the latlon space GeodeticPatch patchEdgeCase(Geodetic2(0, 0), Geodetic2(M_PI / 4, M_PI / 2)); - TileIndex tileIndex1 = tileSetDepth10.getTileIndex(patchEdgeCase); + GeodeticTileIndex tileIndex1 = tileSetDepth10.getTileIndex(patchEdgeCase); // Now it can go up a level ASSERT_EQ(tileIndex1.level, 1); @@ -79,7 +79,7 @@ TEST_F(TextureTileSetTest, getTileIndexXY) { TextureTileSet tileSet(Geodetic2(M_PI, M_PI * 2), Geodetic2(M_PI / 2, - M_PI), 0); GeodeticPatch patch(Geodetic2(0, 0), Geodetic2(M_PI / 16, M_PI / 8)); - TileIndex tileIndex0 = tileSet.getTileIndex(patch); + GeodeticTileIndex tileIndex0 = tileSet.getTileIndex(patch); // Maximum level is 0 so the x y indices should also be 0 ASSERT_EQ(tileIndex0.x, 0); @@ -100,7 +100,7 @@ TEST_F(TextureTileSetTest, getTileIndexXY) { // A tile that covers a fourth of the latlon space GeodeticPatch patchEdgeCase(Geodetic2(0, 0), Geodetic2(M_PI / 4, M_PI / 2)); - TileIndex tileIndex1 = tileSetDepth10.getTileIndex(patchEdgeCase); + GeodeticTileIndex tileIndex1 = tileSetDepth10.getTileIndex(patchEdgeCase); // Now it can go up a level (1) // Since the position is 0, 0 it has 0, 0, in x, y index @@ -110,7 +110,7 @@ TEST_F(TextureTileSetTest, getTileIndexXY) { // A smaller edge case tile GeodeticPatch patchEdgeCase2(Geodetic2(0, 0), Geodetic2(M_PI / 8, M_PI / 4)); - TileIndex tileIndex11 = tileSetDepth10.getTileIndex(patchEdgeCase2); + GeodeticTileIndex tileIndex11 = tileSetDepth10.getTileIndex(patchEdgeCase2); // Now it can go up two levels (2) // Since the position is 0, 0 it now has 1, 1, in x, y index diff --git a/tests/test_twmstileprovider.inl b/tests/test_twmstileprovider.inl index ce63f9d32d..7896f5fd4f 100644 --- a/tests/test_twmstileprovider.inl +++ b/tests/test_twmstileprovider.inl @@ -38,9 +38,9 @@ using namespace openspace; TEST_F(TWMSTileProviderTest, Simple) { - TwmsTileProvider* tileProvider = new TwmsTileProvider(); + TileProvider* tileProvider = new TileProvider(); - TileIndex tileIndex = { 0, 0, 0 }; + GeodeticTileIndex tileIndex = { 0, 0, 0 }; tileProvider->getTile(tileIndex); using namespace std::chrono_literals;