mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-10 07:18:46 -05:00
Change TwmsTileProvider to TileProvider
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
#include <modules/globebrowsing/geodetics/ellipsoid.h>
|
||||
#include <modules/globebrowsing/globes/chunknode.h>
|
||||
#include <modules/globebrowsing/rendering/patchrenderer.h>
|
||||
#include <modules/globebrowsing/other/twmstileprovider.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<Texture> TextureTileSet::getTile(GeodeticPatch patch) {
|
||||
std::shared_ptr<Texture> TextureTileSet::getTile(const GeodeticPatch& patch) {
|
||||
return getTile(getTileIndex(patch));
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> TextureTileSet::getTile(const TileIndex& tileIndex) {
|
||||
std::shared_ptr<Texture> 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);
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/geodetics/ellipsoid.h>
|
||||
#include <modules/globebrowsing/other/twmstileprovider.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -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<Texture> getTile(GeodeticPatch patch);
|
||||
std::shared_ptr<Texture> 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<Texture> getTile(const TileIndex& tileIndex);
|
||||
std::shared_ptr<Texture> 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
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
****************************************************************************************/
|
||||
|
||||
|
||||
#include <modules/globebrowsing/other/twmstileprovider.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
|
||||
#include <openspace/engine/downloadmanager.h>
|
||||
|
||||
@@ -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<Texture> TwmsTileProvider::getTile(const TileIndex& tileIndex) {
|
||||
std::shared_ptr<Texture> 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<DownloadManager::FileFuture> fileFuture = requestTile(tileIndex);
|
||||
_fileFutureMap.insert_or_assign(hashkey, fileFuture);
|
||||
@@ -134,7 +134,7 @@ namespace openspace {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> TwmsTileProvider::loadAndInitTextureDisk(std::string filePath) {
|
||||
std::shared_ptr<Texture> TileProvider::loadAndInitTextureDisk(std::string filePath) {
|
||||
auto textureReader = ghoul::io::TextureReader::ref();
|
||||
std::shared_ptr<Texture> texture = std::move(textureReader.loadTexture(absPath(filePath)));
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace openspace {
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<DownloadManager::FileFuture> TwmsTileProvider::requestTile(const TileIndex& tileIndex) {
|
||||
std::shared_ptr<DownloadManager::FileFuture> 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";
|
||||
@@ -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<Texture> getTile(const TileIndex& tileIndex);
|
||||
std::shared_ptr<Texture> getTile(const GeodeticTileIndex& tileIndex);
|
||||
|
||||
void prerender();
|
||||
|
||||
|
||||
private:
|
||||
std::shared_ptr<DownloadManager::FileFuture> requestTile(const TileIndex&);
|
||||
std::shared_ptr<DownloadManager::FileFuture> requestTile(const GeodeticTileIndex&);
|
||||
std::shared_ptr<Texture> loadAndInitTextureDisk(std::string filePath);
|
||||
|
||||
LRUCache<HashKey, std::shared_ptr<Texture>> _tileCache;
|
||||
std::unordered_map<HashKey, std::shared_ptr<DownloadManager::FileFuture>> _fileFutureMap;
|
||||
|
||||
//LRUCache<HashKey, std::shared_ptr<DownloadManager::FileFuture>> _fileFutureCache;
|
||||
|
||||
ConcurrentJobManager<Texture> _concurrentJobManager;
|
||||
//ConcurrentJobManager<Texture> _concurrentJobManager;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
@@ -77,6 +77,7 @@ namespace openspace {
|
||||
LatLonPatchRenderer::LatLonPatchRenderer(shared_ptr<Grid> 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<ghoul::opengl::Texture> 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<ghoul::opengl::Texture> tile00 = _tileSet.getTile(tileIndex);
|
||||
glm::mat3 uvTransform = _tileSet.getUvTransformationPatchToTile(newPatch, tileIndex);
|
||||
|
||||
@@ -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> _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<ClipMapGrid> _grid;
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user