mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-03 09:20:26 -05:00
Feature/globebrowsingcleanup (#230)
* Initial restructuring of the Globebrowsing branch * Update Ghoul repository Fix include guards * More cleanup * Split texttileprovider subclasses into separate files * Move TileProviders into namespace * Convert static class methods into free functions * Splitting tile subclasses into their own files Remove `using namespace` from header file * Split TileDataSet subclass into separate file Update SGCT reference * Move shader preprocessing data into internal class * More Globebrowsing cleanup * More cleanup Remove unused Convexhull class
This commit is contained in:
@@ -117,7 +117,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
// deallocate sgct c arguments
|
||||
delete[] newArgv;
|
||||
|
||||
|
||||
// Bind functions
|
||||
_sgctEngine->setInitOGLFunction(mainInitFunc);
|
||||
_sgctEngine->setPreSyncFunction(mainPreSyncFunc);
|
||||
|
||||
+1
-1
Submodule ext/sgct updated: b3bf32e8bd...32ca27704f
@@ -33,6 +33,7 @@
|
||||
#ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic3.h>
|
||||
#endif
|
||||
|
||||
#include <list>
|
||||
|
||||
@@ -26,16 +26,22 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
|
||||
set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunk.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunklevelevaluator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunknode.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunklevelevaluator/chunklevelevaluator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunklevelevaluator/availabletiledataevaluator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunklevelevaluator/distanceevaluator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunklevelevaluator/projectedareaevaluator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling/chunkculler.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling/frustumculler.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling/horizonculler.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/aabb.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/angle.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/angle.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/convexhull.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/ellipsoid.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/geodetic2.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/geodetic3.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/geodeticpatch.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunkedlodglobe.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/pointglobe.h
|
||||
@@ -58,24 +64,45 @@ set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/chunkrenderer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpulayermanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layermanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layershadermanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpuchunktile.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpuchunktilepile.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpuheightlayer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpulayer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpulayergroup.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpulayermanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpulayerrendersettings.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gputiledepthtransform.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gputileuvtransform.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layer/layer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layer/layergroup.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layer/layermanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layer/layerrendersettings.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/asynctilereader.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/chunktile.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/pixelregion.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/rawtile.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/textureformat.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tile.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledatalayout.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledataset.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledatatype.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledepthtransform.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tilediskcache.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileindex.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tilemetadata.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileselector.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileuvtransform.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/loadjob/diskcachedtileloadjob.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/loadjob/loadjob.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/loadjob/tileloadjob.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/cachingtileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/singleimageprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/sizereferencetileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/temporaltileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/texttileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/tileindextileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/tileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/tileproviderbyindex.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/tileproviderbylevel.h
|
||||
@@ -83,14 +110,19 @@ set(HEADER_FILES
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunk.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunklevelevaluator.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunknode.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunklevelevaluator/availabletiledataevaluator.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunklevelevaluator/distanceevaluator.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunklevelevaluator/projectedareaevaluator.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling/frustumculler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling/horizonculler.cpp
|
||||
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/aabb.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/convexhull.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/ellipsoid.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/geodetic2.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/geodeticpatch.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunkedlodglobe.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/pointglobe.cpp
|
||||
@@ -106,22 +138,40 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/chunkrenderer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpulayermanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layershadermanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layermanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpuchunktile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpuchunktilepile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpuheightlayer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpulayer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpulayergroup.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpulayermanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gpulayerrendersettings.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gputiledepthtransform.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gpu/gputileuvtransform.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layer/layer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layer/layergroup.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layer/layermanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/layer/layerrendersettings.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/asynctilereader.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/pixelregion.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/rawtile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledatalayout.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledataset.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledatatype.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tilediskcache.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileindex.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tilemetadata.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileselector.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/loadjob/diskcachedtileloadjob.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/loadjob/tileloadjob.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/cachingtileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/singleimageprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/sizereferencetileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/temporaltileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/texttileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/tileindextileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/tileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/tileproviderbyindex.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider/tileproviderbylevel.cpp
|
||||
|
||||
@@ -26,8 +26,9 @@
|
||||
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/rendering/layermanager.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
#include <modules/globebrowsing/tile/tileselector.h>
|
||||
#include <modules/globebrowsing/tile/tilemetadata.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
@@ -58,34 +59,34 @@ bool Chunk::isVisible() const {
|
||||
}
|
||||
|
||||
Chunk::Status Chunk::update(const RenderData& data) {
|
||||
auto savedCamera = _owner.savedCamera();
|
||||
const auto& savedCamera = _owner.savedCamera();
|
||||
const Camera& camRef = savedCamera != nullptr ? *savedCamera : data.camera;
|
||||
RenderData myRenderData = { camRef, data.position, data.doPerformanceMeasurement };
|
||||
|
||||
_isVisible = true;
|
||||
if (_owner.chunkedLodGlobe()->testIfCullable(*this, myRenderData)) {
|
||||
_isVisible = false;
|
||||
return Status::WANT_MERGE;
|
||||
return Status::WantMerge;
|
||||
}
|
||||
|
||||
int desiredLevel = _owner.chunkedLodGlobe()->getDesiredLevel(*this, myRenderData);
|
||||
|
||||
if (desiredLevel < _tileIndex.level) {
|
||||
return Status::WANT_MERGE;
|
||||
return Status::WantMerge;
|
||||
}
|
||||
else if (_tileIndex.level < desiredLevel) {
|
||||
return Status::WANT_SPLIT;
|
||||
return Status::WantSplit;
|
||||
}
|
||||
else {
|
||||
return Status::DO_NOTHING;
|
||||
return Status::DoNothing;
|
||||
}
|
||||
}
|
||||
|
||||
Chunk::BoundingHeights Chunk::getBoundingHeights() const {
|
||||
BoundingHeights boundingHeights;
|
||||
boundingHeights.max = 0;
|
||||
boundingHeights.min = 0;
|
||||
boundingHeights.available = false;
|
||||
BoundingHeights boundingHeights {
|
||||
0.f, 0.f,
|
||||
false
|
||||
};
|
||||
|
||||
// In the future, this should be abstracted away and more easily queryable.
|
||||
// One must also handle how to sample pick one out of multiplte heightmaps
|
||||
@@ -94,48 +95,48 @@ Chunk::BoundingHeights Chunk::getBoundingHeights() const {
|
||||
// The raster of a height map is the first one. We assume that the height map is
|
||||
// a single raster image. If it is not we will just use the first raster
|
||||
// (that is channel 0).
|
||||
size_t HEIGHT_CHANNEL = 0;
|
||||
const size_t HeightChannel = 0;
|
||||
const LayerGroup& heightmaps = layerManager->layerGroup(LayerManager::HeightLayers);
|
||||
std::vector<ChunkTile> chunkTiles = TileSelector::getTilesSortedByHighestResolution(
|
||||
std::vector<ChunkTile> chunkTiles = tileselector::getTilesSortedByHighestResolution(
|
||||
heightmaps, _tileIndex
|
||||
);
|
||||
|
||||
bool lastHadMissingData = true;
|
||||
for (auto chunkTile : chunkTiles) {
|
||||
bool goodTile = chunkTile.tile.status == Tile::Status::OK;
|
||||
bool hastileMetaData = chunkTile.tile.metaData != nullptr;
|
||||
for (const auto& chunkTile : chunkTiles) {
|
||||
bool goodTile = (chunkTile.tile.status == Tile::Status::OK);
|
||||
bool hasTileMetaData = (chunkTile.tile.metaData != nullptr);
|
||||
|
||||
if (goodTile && hastileMetaData) {
|
||||
if (goodTile && hasTileMetaData) {
|
||||
auto tileMetaData = chunkTile.tile.metaData;
|
||||
|
||||
if (!boundingHeights.available) {
|
||||
if (tileMetaData->hasMissingData[HEIGHT_CHANNEL]) {
|
||||
if (tileMetaData->hasMissingData[HeightChannel]) {
|
||||
boundingHeights.min = std::min(
|
||||
DEFAULT_HEIGHT,
|
||||
tileMetaData->minValues[HEIGHT_CHANNEL]
|
||||
tileMetaData->minValues[HeightChannel]
|
||||
);
|
||||
boundingHeights.max = std::max(
|
||||
DEFAULT_HEIGHT,
|
||||
tileMetaData->maxValues[HEIGHT_CHANNEL]
|
||||
tileMetaData->maxValues[HeightChannel]
|
||||
);
|
||||
}
|
||||
else {
|
||||
boundingHeights.min = tileMetaData->minValues[HEIGHT_CHANNEL];
|
||||
boundingHeights.max = tileMetaData->maxValues[HEIGHT_CHANNEL];
|
||||
boundingHeights.min = tileMetaData->minValues[HeightChannel];
|
||||
boundingHeights.max = tileMetaData->maxValues[HeightChannel];
|
||||
}
|
||||
boundingHeights.available = true;
|
||||
}
|
||||
else {
|
||||
boundingHeights.min = std::min(
|
||||
boundingHeights.min,
|
||||
tileMetaData->minValues[HEIGHT_CHANNEL]
|
||||
tileMetaData->minValues[HeightChannel]
|
||||
);
|
||||
boundingHeights.max = std::max(
|
||||
boundingHeights.max,
|
||||
tileMetaData->maxValues[HEIGHT_CHANNEL]
|
||||
tileMetaData->maxValues[HeightChannel]
|
||||
);
|
||||
}
|
||||
lastHadMissingData = tileMetaData->hasMissingData[HEIGHT_CHANNEL];
|
||||
lastHadMissingData = tileMetaData->hasMissingData[HeightChannel];
|
||||
}
|
||||
|
||||
// Allow for early termination
|
||||
@@ -192,7 +193,7 @@ std::vector<glm::dvec4> Chunk::getBoundingPolyhedronCorners() const {
|
||||
double latDiff = latCloseToEquator - pGeodetic.lat;
|
||||
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
Quad q = (Quad)(i % 4);
|
||||
Quad q = static_cast<Quad>(i % 4);
|
||||
double cornerHeight = i < 4 ? minCornerHeight : maxCornerHeight;
|
||||
Geodetic3 cornerGeodetic = { patch.getCorner(q), cornerHeight };
|
||||
|
||||
@@ -204,6 +205,7 @@ std::vector<glm::dvec4> Chunk::getBoundingPolyhedronCorners() const {
|
||||
|
||||
corners[i] = glm::dvec4(ellipsoid.cartesianPosition(cornerGeodetic), 1);
|
||||
}
|
||||
|
||||
return corners;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___CHUNK___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___CHUNK___H__
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/geodeticpatch.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace openspace {
|
||||
@@ -37,7 +38,6 @@ struct RenderData;
|
||||
|
||||
namespace globebrowsing {
|
||||
|
||||
class GeodeticPatch;
|
||||
class RenderableGlobe;
|
||||
struct TileIndex;
|
||||
|
||||
@@ -51,9 +51,9 @@ public:
|
||||
};
|
||||
|
||||
enum class Status {
|
||||
DO_NOTHING,
|
||||
WANT_MERGE,
|
||||
WANT_SPLIT,
|
||||
DoNothing,
|
||||
WantMerge,
|
||||
WantSplit,
|
||||
};
|
||||
|
||||
Chunk(const RenderableGlobe& owner, const TileIndex& tileIndex,
|
||||
@@ -73,8 +73,8 @@ public:
|
||||
Status update(const RenderData& data);
|
||||
|
||||
/**
|
||||
* Returns a convex polyhedron of eight vertices tightly bounding the volume of
|
||||
* the Chunk.
|
||||
* Returns a convex polyhedron of eight vertices tightly bounding the volume of
|
||||
* the Chunk.
|
||||
*/
|
||||
std::vector<glm::dvec4> getBoundingPolyhedronCorners() const;
|
||||
|
||||
@@ -84,13 +84,13 @@ public:
|
||||
bool isVisible() const;
|
||||
|
||||
/**
|
||||
* Returns BoundingHeights that fits the Chunk as tightly as possible.
|
||||
*
|
||||
* If the Chunk uses more than one HightLayer, the BoundingHeights will be set
|
||||
* to cover all HightLayers. If the Chunk has a higher level than its highest
|
||||
* resolution HightLayer Tile, it will base its BoundingHeights on that Tile.
|
||||
* This means that high level Chunks can have BoundingHeights that are not
|
||||
* tightly fitting.
|
||||
* Returns BoundingHeights that fits the Chunk as tightly as possible.
|
||||
*
|
||||
* If the Chunk uses more than one HightLayer, the BoundingHeights will be set
|
||||
* to cover all HeightLayers. If the Chunk has a higher level than its highest
|
||||
* resolution HightLayer Tile, it will base its BoundingHeights on that Tile.
|
||||
* This means that high level Chunks can have BoundingHeights that are not
|
||||
* tightly fitting.
|
||||
*/
|
||||
BoundingHeights getBoundingHeights() const;
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator/availabletiledataevaluator.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layergroup.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
namespace chunklevelevaluator {
|
||||
|
||||
int AvailableTileData::getDesiredLevel(const Chunk& chunk, const RenderData& data) const {
|
||||
auto layerManager = chunk.owner().chunkedLodGlobe()->layerManager();
|
||||
// auto layers = layerManager->layerGroup(LayerManager::HeightLayers).activeLayers();
|
||||
int currLevel = chunk.tileIndex().level;
|
||||
|
||||
for (size_t i = 0; i < LayerManager::NUM_LAYER_GROUPS; ++i) {
|
||||
for (const auto& layer : layerManager->layerGroup(i).activeLayers()) {
|
||||
Tile::Status status = layer->tileProvider()->getTileStatus(chunk.tileIndex());
|
||||
if (status == Tile::Status::OK) {
|
||||
return UnknownDesiredLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return currLevel - 1;
|
||||
}
|
||||
|
||||
} // namespace chunklevelevaluator
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,48 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___AVAILABLETILEDATAEVALUATOR___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___AVAILABLETILEDATAEVALUATOR___H__
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator/chunklevelevaluator.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
namespace chunklevelevaluator {
|
||||
|
||||
/**
|
||||
* If this chunk has available tile data for any LayerGroup on any of its active
|
||||
* Layers it will return an UNKNOWN_DESIRED_LEVEL. If no data is available it will
|
||||
* evaluate to a level that is <code>current level -1</code>.
|
||||
*/
|
||||
class AvailableTileData : public Evaluator {
|
||||
public:
|
||||
int getDesiredLevel(const Chunk& chunk, const RenderData& data) const override;
|
||||
};
|
||||
|
||||
} // namespace chunklevelevaluator
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___AVAILABLETILEDATAEVALUATOR___H__
|
||||
+6
-34
@@ -32,50 +32,22 @@ struct RenderData;
|
||||
namespace globebrowsing {
|
||||
|
||||
class Chunk;
|
||||
|
||||
namespace chunklevelevaluator {
|
||||
|
||||
/**
|
||||
* Abstract class defining an interface for accessing a desired level of a Chunk.
|
||||
* The desired level can be used in the process of determining whether a Chunk should
|
||||
* want to split, merge or do nothing.
|
||||
*/
|
||||
class ChunkLevelEvaluator {
|
||||
class Evaluator {
|
||||
public:
|
||||
static const int UnknownDesiredLevel = -1;
|
||||
|
||||
virtual int getDesiredLevel(const Chunk& chunk, const RenderData& data) const = 0;
|
||||
static const int UNKNOWN_DESIRED_LEVEL = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Evaluate the Chunk level depending on the distance from the Camera to the Chunk.
|
||||
* This evaluation method aims to keep the screen size (horizontal length and not
|
||||
* area) of all chunks constant.
|
||||
*/
|
||||
class EvaluateChunkLevelByDistance : public ChunkLevelEvaluator {
|
||||
public:
|
||||
virtual int getDesiredLevel(const Chunk& chunk, const RenderData& data) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Evaluate the chunk level using the area of the non-heightmapped Chunk projected
|
||||
* on a sphere with the center in the position of the camera. A Chunk near the
|
||||
* horizon will have a small projected area and hence a lower desired level. This
|
||||
* evaluation is more forgiving than EvaluateChunkLevelByDistance, meaning it results
|
||||
* in lower desired levels.
|
||||
*/
|
||||
class EvaluateChunkLevelByProjectedArea : public ChunkLevelEvaluator {
|
||||
public:
|
||||
virtual int getDesiredLevel(const Chunk& chunk, const RenderData& data) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* If this chunk has available tile data for any LayerGroup on any of its active
|
||||
* Layers it will return an UNKNOWN_DESIRED_LEVEL. If no data is available it will
|
||||
* evaluate to a level that is <code>current level -1</code>.
|
||||
*/
|
||||
class EvaluateChunkLevelByAvailableTileData : public ChunkLevelEvaluator {
|
||||
public:
|
||||
virtual int getDesiredLevel(const Chunk& chunk, const RenderData& data) const;
|
||||
};
|
||||
|
||||
} // namespace chunklevelevaluator
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator/distanceevaluator.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
namespace chunklevelevaluator {
|
||||
|
||||
int Distance::getDesiredLevel(const Chunk& chunk, const RenderData& data) const {
|
||||
// Calculations are done in the reference frame of the globe
|
||||
// (model space). Hence, the camera position needs to be transformed
|
||||
// with the inverse model matrix
|
||||
glm::dmat4 inverseModelTransform = chunk.owner().inverseModelTransform();
|
||||
const RenderableGlobe& globe = chunk.owner();
|
||||
const Ellipsoid& ellipsoid = globe.ellipsoid();
|
||||
|
||||
glm::dvec3 cameraPosition =
|
||||
glm::dvec3(inverseModelTransform * glm::dvec4(data.camera.positionVec3(), 1));
|
||||
|
||||
Geodetic2 pointOnPatch = chunk.surfacePatch().closestPoint(
|
||||
ellipsoid.cartesianToGeodetic2(cameraPosition)
|
||||
);
|
||||
glm::dvec3 patchNormal = ellipsoid.geodeticSurfaceNormal(pointOnPatch);
|
||||
glm::dvec3 patchPosition = ellipsoid.cartesianSurfacePosition(pointOnPatch);
|
||||
|
||||
Chunk::BoundingHeights heights = chunk.getBoundingHeights();
|
||||
double heightToChunk = heights.min;
|
||||
|
||||
// Offset position according to height
|
||||
patchPosition += patchNormal * heightToChunk;
|
||||
|
||||
glm::dvec3 cameraToChunk = patchPosition - cameraPosition;
|
||||
|
||||
// Calculate desired level based on distance
|
||||
double distanceToPatch = glm::length(cameraToChunk);
|
||||
double distance = distanceToPatch;
|
||||
|
||||
double scaleFactor =
|
||||
globe.generalProperties().lodScaleFactor * ellipsoid.minimumRadius();
|
||||
double projectedScaleFactor = scaleFactor / distance;
|
||||
int desiredLevel = ceil(log2(projectedScaleFactor));
|
||||
return desiredLevel;
|
||||
}
|
||||
|
||||
} // namespace chunklevelevaluator
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,48 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___DISTANCEEVALUATOR___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___DISTANCEEVALUATOR___H__
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator/chunklevelevaluator.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
namespace chunklevelevaluator {
|
||||
|
||||
/**
|
||||
* Evaluate the Chunk level depending on the distance from the Camera to the Chunk.
|
||||
* This evaluation method aims to keep the screen size (horizontal length and not
|
||||
* area) of all chunks constant.
|
||||
*/
|
||||
class Distance : public Evaluator {
|
||||
public:
|
||||
int getDesiredLevel(const Chunk& chunk, const RenderData& data) const override;
|
||||
};
|
||||
|
||||
} // namespace chunklevelevaluator
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___DISTANCEEVALUATOR___H__
|
||||
+5
-63
@@ -22,58 +22,19 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator.h>
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator/projectedareaevaluator.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <modules/globebrowsing/rendering/layermanager.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
namespace chunklevelevaluator {
|
||||
|
||||
int EvaluateChunkLevelByDistance::getDesiredLevel(const Chunk& chunk,
|
||||
const RenderData& data) const
|
||||
{
|
||||
// Calculations are done in the reference frame of the globe
|
||||
// (model space). Hence, the camera position needs to be transformed
|
||||
// with the inverse model matrix
|
||||
glm::dmat4 inverseModelTransform = chunk.owner().inverseModelTransform();
|
||||
const RenderableGlobe& globe = chunk.owner();
|
||||
const Ellipsoid& ellipsoid = globe.ellipsoid();
|
||||
|
||||
glm::dvec3 cameraPosition =
|
||||
glm::dvec3(inverseModelTransform * glm::dvec4(data.camera.positionVec3(), 1));
|
||||
|
||||
Geodetic2 pointOnPatch = chunk.surfacePatch().closestPoint(
|
||||
ellipsoid.cartesianToGeodetic2(cameraPosition)
|
||||
);
|
||||
glm::dvec3 patchNormal = ellipsoid.geodeticSurfaceNormal(pointOnPatch);
|
||||
glm::dvec3 patchPosition = ellipsoid.cartesianSurfacePosition(pointOnPatch);
|
||||
|
||||
Chunk::BoundingHeights heights = chunk.getBoundingHeights();
|
||||
double heightToChunk = heights.min;
|
||||
|
||||
// Offset position according to height
|
||||
patchPosition += patchNormal * heightToChunk;
|
||||
|
||||
glm::dvec3 cameraToChunk = patchPosition - cameraPosition;
|
||||
|
||||
// Calculate desired level based on distance
|
||||
double distanceToPatch = glm::length(cameraToChunk);
|
||||
double distance = distanceToPatch;
|
||||
|
||||
double scaleFactor =
|
||||
globe.generalProperties().lodScaleFactor * ellipsoid.minimumRadius();
|
||||
double projectedScaleFactor = scaleFactor / distance;
|
||||
int desiredLevel = ceil(log2(projectedScaleFactor));
|
||||
return desiredLevel;
|
||||
}
|
||||
|
||||
int EvaluateChunkLevelByProjectedArea::getDesiredLevel(const Chunk& chunk,
|
||||
const RenderData& data) const
|
||||
{
|
||||
int ProjectedArea::getDesiredLevel(const Chunk& chunk, const RenderData& data) const {
|
||||
// Calculations are done in the reference frame of the globe
|
||||
// (model space). Hence, the camera position needs to be transformed
|
||||
// with the inverse model matrix
|
||||
@@ -163,25 +124,6 @@ int EvaluateChunkLevelByProjectedArea::getDesiredLevel(const Chunk& chunk,
|
||||
return chunk.tileIndex().level + round(scaledArea - 1);
|
||||
}
|
||||
|
||||
int EvaluateChunkLevelByAvailableTileData::getDesiredLevel(const Chunk& chunk,
|
||||
const RenderData& data) const
|
||||
{
|
||||
auto layerManager = chunk.owner().chunkedLodGlobe()->layerManager();
|
||||
auto heightLayers = layerManager->layerGroup(LayerManager::HeightLayers).activeLayers();
|
||||
int currLevel = chunk.tileIndex().level;
|
||||
|
||||
for (size_t i = 0; i < LayerManager::NUM_LAYER_GROUPS; ++i) {
|
||||
for (auto& layer : layerManager->layerGroup(i).activeLayers()) {
|
||||
Tile::Status tileStatus =
|
||||
layer->tileProvider()->getTileStatus(chunk.tileIndex());
|
||||
if (tileStatus == Tile::Status::OK) {
|
||||
return UNKNOWN_DESIRED_LEVEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return currLevel - 1;
|
||||
}
|
||||
|
||||
} // namespace chunklevelevaluator
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,51 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___PROJECTEDAREAEVALUATOR___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___PROJECTEDAREAEVALUATOR___H__
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator/chunklevelevaluator.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
namespace chunklevelevaluator {
|
||||
|
||||
/**
|
||||
* Evaluate the chunk level using the area of the non-heightmapped Chunk projected
|
||||
* on a sphere with the center in the position of the camera. A Chunk near the
|
||||
* horizon will have a small projected area and hence a lower desired level. This
|
||||
* evaluation is more forgiving than EvaluateChunkLevelByDistance, meaning it results
|
||||
* in lower desired levels.
|
||||
*/
|
||||
class ProjectedArea : public Evaluator {
|
||||
public:
|
||||
virtual int getDesiredLevel(const Chunk& chunk, const RenderData& data) const;
|
||||
};
|
||||
|
||||
|
||||
} // namespace chunklevelevaluator
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___PROJECTEDAREAEVALUATOR___H__
|
||||
@@ -32,19 +32,11 @@
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
int ChunkNode::chunkNodeCount = 0;
|
||||
|
||||
ChunkNode::ChunkNode(const Chunk& chunk, ChunkNode* parent)
|
||||
: _chunk(chunk)
|
||||
, _parent(parent)
|
||||
, _children({ nullptr, nullptr, nullptr, nullptr })
|
||||
{
|
||||
chunkNodeCount++;
|
||||
}
|
||||
|
||||
ChunkNode::~ChunkNode() {
|
||||
chunkNodeCount--;
|
||||
}
|
||||
{}
|
||||
|
||||
bool ChunkNode::isRoot() const {
|
||||
return _parent == nullptr;
|
||||
@@ -57,10 +49,10 @@ bool ChunkNode::isLeaf() const {
|
||||
bool ChunkNode::updateChunkTree(const RenderData& data) {
|
||||
if (isLeaf()) {
|
||||
Chunk::Status status = _chunk.update(data);
|
||||
if (status == Chunk::Status::WANT_SPLIT) {
|
||||
if (status == Chunk::Status::WantSplit) {
|
||||
split();
|
||||
}
|
||||
return status == Chunk::Status::WANT_MERGE;
|
||||
return status == Chunk::Status::WantMerge;
|
||||
}
|
||||
else {
|
||||
char requestedMergeMask = 0;
|
||||
@@ -71,7 +63,7 @@ bool ChunkNode::updateChunkTree(const RenderData& data) {
|
||||
}
|
||||
|
||||
bool allChildrenWantsMerge = requestedMergeMask == 0xf;
|
||||
bool thisChunkWantsSplit = _chunk.update(data) == Chunk::Status::WANT_SPLIT;
|
||||
bool thisChunkWantsSplit = _chunk.update(data) == Chunk::Status::WantSplit;
|
||||
|
||||
if (allChildrenWantsMerge && !thisChunkWantsSplit) {
|
||||
merge();
|
||||
@@ -166,7 +158,7 @@ const ChunkNode& ChunkNode::getChild(Quad quad) const {
|
||||
|
||||
void ChunkNode::split(int depth) {
|
||||
if (depth > 0 && isLeaf()) {
|
||||
for (size_t i = 0; i < _children.size(); i++) {
|
||||
for (size_t i = 0; i < _children.size(); ++i) {
|
||||
Chunk chunk(_chunk.owner(), _chunk.tileIndex().child((Quad)i));
|
||||
_children[i] = std::make_unique<ChunkNode>(chunk, this);
|
||||
}
|
||||
|
||||
@@ -39,19 +39,18 @@ class ChunkedLodGlobe;
|
||||
class ChunkNode {
|
||||
public:
|
||||
ChunkNode(const Chunk& chunk, ChunkNode* parent = nullptr);
|
||||
~ChunkNode();
|
||||
|
||||
/**
|
||||
* Recursively split the ChunkNode.
|
||||
*
|
||||
* \param depth defines how deep the recursion should go. If depth == 1 (default),
|
||||
* the ChunkNode will only split once.
|
||||
*/
|
||||
*/
|
||||
void split(int depth = 1);
|
||||
|
||||
/**
|
||||
* Deletes all children of the ChunkNode recursively.
|
||||
*/
|
||||
*/
|
||||
void merge();
|
||||
|
||||
bool isRoot() const;
|
||||
@@ -74,9 +73,7 @@ public:
|
||||
*/
|
||||
bool updateChunkTree(const RenderData& data);
|
||||
|
||||
static int chunkNodeCount;
|
||||
|
||||
private:
|
||||
private:
|
||||
ChunkNode* _parent;
|
||||
std::array<std::unique_ptr<ChunkNode>, 4> _children;
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___CHUNKCULLER___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___CHUNKCULLER___H__
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct RenderData;
|
||||
|
||||
namespace globebrowsing {
|
||||
|
||||
class Chunk;
|
||||
|
||||
namespace culling {
|
||||
|
||||
class ChunkCuller {
|
||||
public:
|
||||
/**
|
||||
* Determine if the Chunk is cullable. That is return true if removing the
|
||||
* Chunk 'culling it' will not have any result on the final rendering. Culling
|
||||
* it will make the rendering faster.
|
||||
*/
|
||||
virtual bool isCullable(const Chunk& chunk, const RenderData& renderData) = 0;
|
||||
};
|
||||
|
||||
} // namespace culling
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___CHUNKCULLER___H__
|
||||
@@ -0,0 +1,63 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/chunk/culling/frustumculler.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
namespace culling {
|
||||
|
||||
FrustumCuller::FrustumCuller(AABB3 viewFrustum)
|
||||
: _viewFrustum(std::move(viewFrustum))
|
||||
{}
|
||||
|
||||
bool FrustumCuller::isCullable(const Chunk& chunk, const RenderData& data) {
|
||||
// Calculate the MVP matrix
|
||||
glm::dmat4 modelTransform = chunk.owner().modelTransform();
|
||||
glm::dmat4 viewTransform = glm::dmat4(data.camera.combinedViewMatrix());
|
||||
glm::dmat4 modelViewProjectionTransform = glm::dmat4(data.camera.projectionMatrix())
|
||||
* viewTransform * modelTransform;
|
||||
|
||||
const std::vector<glm::dvec4>& corners = chunk.getBoundingPolyhedronCorners();
|
||||
|
||||
// Create a bounding box that fits the patch corners
|
||||
AABB3 bounds; // in screen space
|
||||
std::vector<glm::vec4> clippingSpaceCorners(8);
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
glm::dvec4 cornerClippingSpace = modelViewProjectionTransform * corners[i];
|
||||
clippingSpaceCorners[i] = cornerClippingSpace;
|
||||
|
||||
glm::dvec3 ndc = (1.0f / glm::abs(cornerClippingSpace.w)) * cornerClippingSpace;
|
||||
bounds.expand(ndc);
|
||||
}
|
||||
|
||||
return !(_viewFrustum.intersects(bounds));
|
||||
}
|
||||
|
||||
} // namespace culling
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
+25
-35
@@ -22,51 +22,41 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___CONVEX_HULL___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___CONVEX_HULL___H__
|
||||
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___FRUSTUMCULLER___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___FRUSTUMCULLER___H__
|
||||
|
||||
#include <modules/globebrowsing/chunk/culling/chunkculler.h>
|
||||
|
||||
#include <modules/globebrowsing/geometry/aabb.h>
|
||||
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
namespace culling {
|
||||
|
||||
// Implementation based on
|
||||
// http://www.sanfoundry.com/cpp-program-implement-graham-scan-algorithm-find-convex-hull/
|
||||
/**
|
||||
* Culls all chunks that are completely outside the view frustum.
|
||||
*
|
||||
* The frustum culling uses a 2D axis aligned bounding box for the Chunk in
|
||||
* screen space. This is calculated from a bounding polyhedron bounding the
|
||||
* Chunk. Hence the culling will not be 'perfect' but fast and good enough for
|
||||
* culling chunks outside the frustum with some margin.
|
||||
*/
|
||||
class FrustumCuller : public ChunkCuller {
|
||||
public:
|
||||
/**
|
||||
* \param viewFrustum is the view space in normalized device coordinates space.
|
||||
* Hence it is an axis aligned bounding box and not a real frustum.
|
||||
*/
|
||||
FrustumCuller(AABB3 viewFrustum);
|
||||
|
||||
class ConvexHull2 {
|
||||
public:
|
||||
static ConvexHull2 grahamScan_NOT_THREAD_SAFE(std::vector<glm::vec2>& points,
|
||||
int yMinIndex = -1);
|
||||
|
||||
const std::vector<glm::vec2> points() const;
|
||||
|
||||
bool intersects(const ConvexHull2& o) const;
|
||||
|
||||
AABB1 projectedRegion(glm::vec2 direction) const;
|
||||
|
||||
private:
|
||||
bool hasPerpendicularLineWhereProjectedPointsOverlap(const ConvexHull2& other) const;
|
||||
|
||||
static int compare(const void* vp1, const void* vp2);
|
||||
|
||||
static glm::vec2 oneBelowTop(std::stack<glm::vec2>&);
|
||||
static void swap(glm::vec2& p1, glm::vec2& p2);
|
||||
|
||||
// returns 0 = colinear, 1 = clockwise, 2 = counterclockwise
|
||||
static int orientation(const glm::vec2& p, const glm::vec2& q, const glm::vec2& r);
|
||||
static float dist(const glm::vec2& p1, const glm::vec2& p2);
|
||||
bool isCullable(const Chunk& chunk, const RenderData& renderData) override;
|
||||
|
||||
private:
|
||||
static glm::vec2 p0;
|
||||
std::vector<glm::vec2> _points;
|
||||
const AABB3 _viewFrustum;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace culling
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___CONVEX_HULL___H__
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___FRUSTUMCULLER___H__
|
||||
+6
-27
@@ -22,39 +22,14 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/chunk/culling.h>
|
||||
#include <modules/globebrowsing/chunk/culling/horizonculler.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
FrustumCuller::FrustumCuller(const AABB3 viewFrustum) : _viewFrustum(viewFrustum) {}
|
||||
|
||||
bool FrustumCuller::isCullable(const Chunk& chunk, const RenderData& data) {
|
||||
// Calculate the MVP matrix
|
||||
glm::dmat4 modelTransform = chunk.owner().modelTransform();
|
||||
glm::dmat4 viewTransform = glm::dmat4(data.camera.combinedViewMatrix());
|
||||
glm::dmat4 modelViewProjectionTransform = glm::dmat4(data.camera.projectionMatrix())
|
||||
* viewTransform * modelTransform;
|
||||
|
||||
const std::vector<glm::dvec4>& corners = chunk.getBoundingPolyhedronCorners();
|
||||
|
||||
// Create a bounding box that fits the patch corners
|
||||
AABB3 bounds; // in screen space
|
||||
std::vector<glm::vec4> clippingSpaceCorners(8);
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
glm::dvec4 cornerClippingSpace = modelViewProjectionTransform * corners[i];
|
||||
clippingSpaceCorners[i] = cornerClippingSpace;
|
||||
|
||||
glm::dvec3 cornerNDC =
|
||||
(1.0f / glm::abs(cornerClippingSpace.w)) * cornerClippingSpace;
|
||||
bounds.expand(cornerNDC);
|
||||
}
|
||||
|
||||
return !_viewFrustum.intersects(bounds);
|
||||
}
|
||||
namespace culling {
|
||||
|
||||
bool HorizonCuller::isCullable(const Chunk& chunk, const RenderData& data) {
|
||||
// Calculations are done in the reference frame of the globe. Hence, the camera
|
||||
@@ -110,16 +85,20 @@ bool HorizonCuller::isCullable(const glm::dvec3& cameraPosition,
|
||||
double distanceToHorizon =
|
||||
sqrt(pow(length(cameraPosition - globePosition), 2) -
|
||||
pow(minimumGlobeRadius, 2));
|
||||
|
||||
double minimumAllowedDistanceToObjectFromHorizon = sqrt(
|
||||
pow(length(objectPosition - globePosition), 2) -
|
||||
pow(minimumGlobeRadius - objectBoundingSphereRadius, 2));
|
||||
|
||||
// Minimum allowed for the object to be occluded
|
||||
double minimumAllowedDistanceToObjectSquared =
|
||||
pow(distanceToHorizon + minimumAllowedDistanceToObjectFromHorizon, 2)
|
||||
+ pow(objectBoundingSphereRadius, 2);
|
||||
|
||||
double distanceToObjectSquared = pow(length(objectPosition - cameraPosition), 2);
|
||||
return distanceToObjectSquared > minimumAllowedDistanceToObjectSquared;
|
||||
}
|
||||
|
||||
} // namespace culling
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
+9
-41
@@ -22,50 +22,16 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___CULLING___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___CULLING___H__
|
||||
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___HORIZONCULLER___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___HORIZONCULLER___H__
|
||||
|
||||
#include <modules/globebrowsing/geometry/aabb.h>
|
||||
#include <modules/globebrowsing/chunk/culling/chunkculler.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct RenderData;
|
||||
|
||||
namespace globebrowsing {
|
||||
|
||||
class Chunk;
|
||||
|
||||
class ChunkCuller {
|
||||
public:
|
||||
/**
|
||||
* Determine if the Chunk is cullable. That is return true if removing the
|
||||
* Chunk 'culling it' will not have any result on the final rendering. Culling
|
||||
* it will make the rendering faster.
|
||||
*/
|
||||
virtual bool isCullable(const Chunk& chunk, const RenderData& renderData) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Culls all chunks that are completely outside the view frustum.
|
||||
*
|
||||
* The frustum culling uses a 2D axis aligned bounding box for the Chunk in
|
||||
* screen space. This is calculated from a bounding polyhedron bounding the
|
||||
* Chunk. Hence the culling will not be 'perfect' but fast and good enough for
|
||||
* culling chunks outside the frustum with some margin.
|
||||
*/
|
||||
class FrustumCuller : public ChunkCuller {
|
||||
public:
|
||||
/**
|
||||
* \param viewFrustum is the view space in normalized device coordinates space.
|
||||
* Hence it is an axis aligned bounding box and not a real frustum.
|
||||
*/
|
||||
FrustumCuller(const AABB3 viewFrustum);
|
||||
|
||||
bool isCullable(const Chunk& chunk, const RenderData& renderData) override;
|
||||
|
||||
private:
|
||||
const AABB3 _viewFrustum;
|
||||
};
|
||||
namespace culling {
|
||||
|
||||
/**
|
||||
* In this implementation of the horizon culling, the closer the ellipsoid is to a
|
||||
@@ -77,12 +43,14 @@ class HorizonCuller : public ChunkCuller {
|
||||
public:
|
||||
bool isCullable(const Chunk& chunk, const RenderData& renderData) override;
|
||||
|
||||
private:
|
||||
bool isCullable(const glm::dvec3& cameraPosition, const glm::dvec3& globePosition,
|
||||
const glm::dvec3& objectPosition, double objectBoundingSphereRadius,
|
||||
double minimumGlobeRadius);
|
||||
};
|
||||
|
||||
} // namespace culling
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___CULLING___H__
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___HORIZONCULLER___H__
|
||||
@@ -63,17 +63,17 @@ bool AABB1::intersects(const AABB1& o) const {
|
||||
return (min <= o.max) && (o.min <= max);
|
||||
}
|
||||
|
||||
AABBSpatialRelation AABB1::relationTo(const AABB1& o) const {
|
||||
AABB1::AABBSpatialRelation AABB1::relationTo(const AABB1& o) const {
|
||||
if (intersects(o)) {
|
||||
if (contains(o)) {
|
||||
return AABBSpatialRelation::Containing;
|
||||
return AABB1::AABBSpatialRelation::Containing;
|
||||
}
|
||||
if (o.contains(*this)) {
|
||||
return AABBSpatialRelation::Contained;
|
||||
return AABB1::AABBSpatialRelation::Contained;
|
||||
}
|
||||
return AABBSpatialRelation::Intersecting;
|
||||
return AABB1::AABBSpatialRelation::Intersecting;
|
||||
}
|
||||
return AABBSpatialRelation::None;
|
||||
return AABB1::AABBSpatialRelation::None;
|
||||
}
|
||||
|
||||
AABB2::AABB2()
|
||||
@@ -83,9 +83,9 @@ AABB2::AABB2()
|
||||
)
|
||||
{}
|
||||
|
||||
AABB2::AABB2(const glm::vec2& min, const glm::vec2& max)
|
||||
: min(min)
|
||||
, max(max)
|
||||
AABB2::AABB2(glm::vec2 min, glm::vec2 max)
|
||||
: min(std::move(min))
|
||||
, max(std::move(max))
|
||||
{}
|
||||
|
||||
void AABB2::expand(const glm::vec2& p) {
|
||||
@@ -116,17 +116,17 @@ bool AABB2::intersects(const AABB2& o) const {
|
||||
&& (min.y <= o.max.y) && (o.min.y <= max.y);
|
||||
}
|
||||
|
||||
AABBSpatialRelation AABB2::relationTo(const AABB2& o) const {
|
||||
AABB2::AABBSpatialRelation AABB2::relationTo(const AABB2& o) const {
|
||||
if (intersects(o)) {
|
||||
if (contains(o)) {
|
||||
return AABBSpatialRelation::Containing;
|
||||
return AABB2::AABBSpatialRelation::Containing;
|
||||
}
|
||||
if (o.contains(*this)) {
|
||||
return AABBSpatialRelation::Contained;
|
||||
return AABB2::AABBSpatialRelation::Contained;
|
||||
}
|
||||
return AABBSpatialRelation::Intersecting;
|
||||
return AABB2::AABBSpatialRelation::Intersecting;
|
||||
}
|
||||
return AABBSpatialRelation::None;
|
||||
return AABB2::AABBSpatialRelation::None;
|
||||
}
|
||||
|
||||
AABB3::AABB3()
|
||||
@@ -136,9 +136,9 @@ AABB3::AABB3()
|
||||
)
|
||||
{}
|
||||
|
||||
AABB3::AABB3(const glm::vec3& min, const glm::vec3& max)
|
||||
: min(min),
|
||||
max(max)
|
||||
AABB3::AABB3(glm::vec3 min, glm::vec3 max)
|
||||
: min(std::move(min))
|
||||
, max(std::move(max))
|
||||
{}
|
||||
|
||||
void AABB3::expand(const glm::vec3 p) {
|
||||
@@ -172,17 +172,17 @@ bool AABB3::intersects(const AABB3& o) const {
|
||||
&& (min.z <= o.max.z) && (o.min.z <= max.z);
|
||||
}
|
||||
|
||||
AABBSpatialRelation AABB3::relationTo(const AABB3& o) const {
|
||||
AABB3::AABBSpatialRelation AABB3::relationTo(const AABB3& o) const {
|
||||
if (intersects(o)) {
|
||||
if (contains(o)) {
|
||||
return AABBSpatialRelation::Containing;
|
||||
return AABB3::AABBSpatialRelation::Containing;
|
||||
}
|
||||
if (o.contains(*this)) {
|
||||
return AABBSpatialRelation::Contained;
|
||||
return AABB3::AABBSpatialRelation::Contained;
|
||||
}
|
||||
return AABBSpatialRelation::Intersecting;
|
||||
return AABB3::AABBSpatialRelation::Intersecting;
|
||||
}
|
||||
return AABBSpatialRelation::None;
|
||||
return AABB3::AABBSpatialRelation::None;
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
|
||||
@@ -30,14 +30,14 @@
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
enum class AABBSpatialRelation {
|
||||
None,
|
||||
Intersecting,
|
||||
Contained,
|
||||
Containing
|
||||
};
|
||||
|
||||
struct AABB1 {
|
||||
enum class AABBSpatialRelation {
|
||||
None,
|
||||
Intersecting,
|
||||
Contained,
|
||||
Containing
|
||||
};
|
||||
|
||||
AABB1();
|
||||
AABB1(float min, float max);
|
||||
|
||||
@@ -54,8 +54,15 @@ struct AABB1 {
|
||||
};
|
||||
|
||||
struct AABB2 {
|
||||
enum class AABBSpatialRelation {
|
||||
None,
|
||||
Intersecting,
|
||||
Contained,
|
||||
Containing
|
||||
};
|
||||
|
||||
AABB2();
|
||||
AABB2(const glm::vec2& min, const glm::vec2& max);
|
||||
AABB2(glm::vec2 min, glm::vec2 max);
|
||||
|
||||
void expand(const glm::vec2& p);
|
||||
glm::vec2 center() const;
|
||||
@@ -70,8 +77,15 @@ struct AABB2 {
|
||||
};
|
||||
|
||||
struct AABB3 {
|
||||
enum class AABBSpatialRelation {
|
||||
None,
|
||||
Intersecting,
|
||||
Contained,
|
||||
Containing
|
||||
};
|
||||
|
||||
AABB3();
|
||||
AABB3(const glm::vec3& min, const glm::vec3& max);
|
||||
AABB3(glm::vec3 min, glm::vec3 max);
|
||||
|
||||
void expand(const glm::vec3 p);
|
||||
glm::vec3 center() const;
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/geometry/convexhull.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
glm::vec2 ConvexHull2::p0(0,0);
|
||||
|
||||
ConvexHull2 ConvexHull2::grahamScan_NOT_THREAD_SAFE(std::vector<glm::vec2>& points,
|
||||
int yMinIndex)
|
||||
{
|
||||
ConvexHull2 hull;
|
||||
|
||||
if (yMinIndex == -1) {
|
||||
yMinIndex = 0;
|
||||
float ymin = points[0].y;
|
||||
for (int i = 1; i < points.size(); i++) {
|
||||
float y = points[i].y;
|
||||
// Pick the bottom-most or chose the left most point in case of tie
|
||||
if ((y < ymin) || (ymin == y && points[i].x < points[yMinIndex].x)) {
|
||||
ymin = points[i].y;
|
||||
yMinIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Place the bottom-most point at first position
|
||||
swap(points[0], points[yMinIndex]);
|
||||
|
||||
// Sort n-1 points with respect to the first point. A point p1 comes
|
||||
// before p2 in sorted ouput if p2 has larger polar angle (in
|
||||
// counterclockwise direction) than p1
|
||||
hull.p0 = points[0];
|
||||
|
||||
// Replace with std::sort
|
||||
qsort(&(points.data()[1]), points.size()-1, sizeof(glm::vec2), &(hull.compare));
|
||||
|
||||
// Create an empty stack and push first three points to it.
|
||||
std::stack<glm::vec2> S;
|
||||
S.push(points[0]);
|
||||
S.push(points[1]);
|
||||
S.push(points[2]);
|
||||
|
||||
// Process remaining n-3 points
|
||||
for (int i = 3; i < points.size(); i++) {
|
||||
// Keep removing top while the angle formed by points next-to-top,
|
||||
// top, and points[i] makes a non-left turn
|
||||
while (orientation(oneBelowTop(S), S.top(), points[i]) == 1)
|
||||
S.pop();
|
||||
S.push(points[i]);
|
||||
}
|
||||
|
||||
// Now stack has the output points, print contents of stack
|
||||
while (!S.empty()) {
|
||||
glm::vec2 p = S.top();
|
||||
hull._points.push_back(p);
|
||||
S.pop();
|
||||
}
|
||||
|
||||
return hull;
|
||||
}
|
||||
|
||||
bool ConvexHull2::intersects(const ConvexHull2& other) const {
|
||||
// uses Separating Axis Theorem
|
||||
// ref: http://stackoverflow.com/questions/753140/how-do-i-determine-if-two-convex-polygons-intersect
|
||||
return this->hasPerpendicularLineWhereProjectedPointsOverlap(other) ||
|
||||
other.hasPerpendicularLineWhereProjectedPointsOverlap(*this);
|
||||
}
|
||||
|
||||
|
||||
bool ConvexHull2::hasPerpendicularLineWhereProjectedPointsOverlap(const ConvexHull2& other) const {
|
||||
for (size_t i = 1; i < _points.size(); i++) {
|
||||
glm::vec2 dividingAxis = _points[i] - _points[i - 1];
|
||||
// project all points onto the vector perpendicular to the dividing axis
|
||||
glm::vec2 projAxis(glm::normalize(glm::vec2(-dividingAxis.y, dividingAxis.x)));
|
||||
const AABB1& myBounds = projectedRegion(projAxis);
|
||||
const AABB1& otherBounds = other.projectedRegion(projAxis);
|
||||
if (!myBounds.intersects(otherBounds)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// test line defined by last-to-first point
|
||||
glm::vec2 dividingAxis = _points[0] - _points.back();
|
||||
glm::vec2 projAxis(glm::normalize(glm::vec2(-dividingAxis.y, dividingAxis.x)));
|
||||
const AABB1& myBounds = projectedRegion(projAxis);
|
||||
const AABB1& otherBounds = other.projectedRegion(projAxis);
|
||||
if (!myBounds.intersects(otherBounds)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
AABB1 ConvexHull2::projectedRegion(glm::vec2 direction) const {
|
||||
AABB1 projectedRegion;
|
||||
for (const glm::vec2& p : _points) {
|
||||
projectedRegion.expand(glm::dot(p, direction));
|
||||
}
|
||||
//for (size_t i = 0; i < _points.size(); i++) {
|
||||
// projectedRegion.expand(glm::dot(_points[i], direction));
|
||||
//}
|
||||
return projectedRegion;
|
||||
}
|
||||
|
||||
glm::vec2 ConvexHull2::oneBelowTop(std::stack<glm::vec2>& S) {
|
||||
glm::vec2 p = S.top();
|
||||
S.pop();
|
||||
glm::vec2 res = S.top();
|
||||
S.push(p);
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConvexHull2::swap(glm::vec2& p1, glm::vec2& p2) {
|
||||
glm::vec2 temp = p1;
|
||||
p1 = p2;
|
||||
p2 = temp;
|
||||
}
|
||||
|
||||
const std::vector<glm::vec2> ConvexHull2::points() const {
|
||||
return _points;
|
||||
}
|
||||
|
||||
int ConvexHull2::orientation(const glm::vec2& p, const glm::vec2& q, const glm::vec2& r) {
|
||||
float val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
||||
return (val == 0) ? 0 : (val > 0) ? 1 : 2;
|
||||
}
|
||||
|
||||
float ConvexHull2::dist(const glm::vec2& p1, const glm::vec2& p2) {
|
||||
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
|
||||
}
|
||||
|
||||
int ConvexHull2::compare(const void *vp1, const void *vp2) {
|
||||
glm::vec2* p1 = (glm::vec2 *)vp1;
|
||||
glm::vec2* p2 = (glm::vec2 *)vp2;
|
||||
|
||||
// Find orientation
|
||||
int o = orientation(p0, *p1, *p2);
|
||||
if (o == 0) {
|
||||
return (dist(p0, *p2) >= dist(p0, *p1)) ? -1 : 1;
|
||||
}
|
||||
|
||||
return (o == 2) ? -1 : 1;
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -26,6 +26,7 @@
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___ELLIPSOID___H__
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic3.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
#include <modules/globebrowsing/geometry/angle.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
@@ -62,213 +60,5 @@ Geodetic2 Geodetic2::operator/(double scalar) const {
|
||||
return Geodetic2(lat / scalar, lon / scalar);
|
||||
}
|
||||
|
||||
GeodeticPatch::GeodeticPatch(double centerLat, double centerLon, double halfSizeLat,
|
||||
double halfSizeLon)
|
||||
: _center(Geodetic2(centerLat, centerLon))
|
||||
, _halfSize(Geodetic2(halfSizeLat, halfSizeLon))
|
||||
{}
|
||||
|
||||
GeodeticPatch::GeodeticPatch(const Geodetic2& center, const Geodetic2& halfSize)
|
||||
: _center(center)
|
||||
, _halfSize(halfSize)
|
||||
{}
|
||||
|
||||
GeodeticPatch::GeodeticPatch(const GeodeticPatch& patch)
|
||||
: _center(patch._center)
|
||||
, _halfSize(patch._halfSize)
|
||||
{}
|
||||
|
||||
GeodeticPatch::GeodeticPatch(const TileIndex& tileIndex) {
|
||||
double deltaLat = (2 * glm::pi<double>()) / ((double)(1 << tileIndex.level));
|
||||
double deltaLon = (2 * glm::pi<double>()) / ((double)(1 << tileIndex.level));
|
||||
Geodetic2 nwCorner(glm::pi<double>() / 2 - deltaLat * tileIndex.y, -glm::pi<double>() + deltaLon * tileIndex.x);
|
||||
_halfSize = Geodetic2(deltaLat / 2, deltaLon / 2);
|
||||
_center = Geodetic2(nwCorner.lat - _halfSize.lat, nwCorner.lon + _halfSize.lon);
|
||||
}
|
||||
|
||||
void GeodeticPatch::setCenter(const Geodetic2& center) {
|
||||
_center = center;
|
||||
}
|
||||
|
||||
void GeodeticPatch::setHalfSize(const Geodetic2& halfSize) {
|
||||
_halfSize = halfSize;
|
||||
}
|
||||
|
||||
double GeodeticPatch::maximumTileLevel() const {
|
||||
// Numerator is just pi, not 2*pi, since we are dealing with HALF sizes
|
||||
return log2(glm::pi<double>() / glm::min(_halfSize.lat, _halfSize.lon));
|
||||
}
|
||||
|
||||
double GeodeticPatch::minimumTileLevel() const {
|
||||
// Numerator is just pi, not 2*pi, since we are dealing with HALF sizes
|
||||
return log2(glm::pi<double>() / glm::max(_halfSize.lat, _halfSize.lon));
|
||||
}
|
||||
|
||||
const Geodetic2& GeodeticPatch::center() const {
|
||||
return _center;
|
||||
}
|
||||
|
||||
const Geodetic2& GeodeticPatch::halfSize() const {
|
||||
return _halfSize;
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::size() const {
|
||||
return Geodetic2(2 * _halfSize.lat, 2 * _halfSize.lon);
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::getCorner(Quad q) const {
|
||||
switch (q) {
|
||||
case NORTH_WEST: return Geodetic2(maxLat(), minLon());// northWestCorner();
|
||||
case NORTH_EAST: return Geodetic2(maxLat(), maxLon());// northEastCorner();
|
||||
case SOUTH_WEST: return Geodetic2(minLat(), minLon());// southWestCorner();
|
||||
case SOUTH_EAST: return Geodetic2(minLat(), maxLon());// southEastCorner();
|
||||
}
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::getSize() const {
|
||||
return _halfSize * 2;
|
||||
}
|
||||
|
||||
double GeodeticPatch::minLat() const {
|
||||
return _center.lat - _halfSize.lat;
|
||||
}
|
||||
|
||||
double GeodeticPatch::maxLat() const {
|
||||
return _center.lat + _halfSize.lat;
|
||||
}
|
||||
|
||||
double GeodeticPatch::minLon() const {
|
||||
return _center.lon - _halfSize.lon;
|
||||
}
|
||||
|
||||
double GeodeticPatch::maxLon() const {
|
||||
return _center.lon + _halfSize.lon;
|
||||
}
|
||||
|
||||
bool GeodeticPatch::contains(const Geodetic2& p) const {
|
||||
Geodetic2 diff = _center - p;
|
||||
return glm::abs(diff.lat) <= _halfSize.lat && glm::abs(diff.lon) <= _halfSize.lon;
|
||||
}
|
||||
|
||||
double GeodeticPatch::edgeLatitudeNearestEquator() const {
|
||||
return _center.lat + _halfSize.lat * (isNorthern() ? -1 : 1);
|
||||
}
|
||||
|
||||
double GeodeticPatch::isNorthern() const {
|
||||
return _center.lat > 0.0;
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::clamp(const Geodetic2& p) const {
|
||||
using Ang = Angle<double>;
|
||||
|
||||
// Convert to Angles for normalization
|
||||
Ang centerLat = Ang::fromRadians(_center.lat);
|
||||
Ang centerLon = Ang::fromRadians(_center.lon);
|
||||
Ang pointLat = Ang::fromRadians(p.lat);
|
||||
Ang pointLon = Ang::fromRadians(p.lon);
|
||||
|
||||
// Normalize w.r.t. the center in order for the clamping to done correctly
|
||||
//
|
||||
// Example:
|
||||
// centerLat = 0 deg, halfSize.lat = 10 deg, pointLat = 330 deg
|
||||
// --> Just clamping pointLat would be clamp(330, -10, 10) = 10 // WRONG!
|
||||
// Instead, if we first normalize 330 deg around 0, we get -30 deg
|
||||
// --> clamp(-30, -10, 10) = -10 // CORRECT!
|
||||
pointLat.normalizeAround(centerLat);
|
||||
pointLon.normalizeAround(centerLon);
|
||||
|
||||
return Geodetic2(
|
||||
glm::clamp(pointLat.asRadians(), minLat(), maxLat()),
|
||||
glm::clamp(pointLon.asRadians(), minLon(), maxLon())
|
||||
);
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::closestCorner(const Geodetic2& p) const {
|
||||
using Ang = Angle<double>;
|
||||
|
||||
// LatLon vector from patch center to the point
|
||||
Geodetic2 centerToPoint = p - _center;
|
||||
|
||||
// Normalize the difference angles to be centered around 0.
|
||||
Ang latDiff = Ang::fromRadians(centerToPoint.lat).normalizeAround(Ang::ZERO);
|
||||
Ang lonDiff = Ang::fromRadians(centerToPoint.lon).normalizeAround(Ang::ZERO);
|
||||
|
||||
// If latDiff > 0
|
||||
// --> point p is north of the patch center
|
||||
// --> the closest corner to the point must be a northern one
|
||||
// --> set the corner's latitude coordinate to center.lat + halfSize.lat
|
||||
// else
|
||||
// --> set corner's latidude coordinate to center.lat - halfSize.lat
|
||||
double cornerLat = _center.lat + _halfSize.lat * (latDiff > Ang::ZERO ? 1 : -1);
|
||||
|
||||
// We then assigned the corner's longitude coordinate in a similar fashion
|
||||
double cornerLon = _center.lon + _halfSize.lon * (lonDiff > Ang::ZERO ? 1 : -1);
|
||||
|
||||
return Geodetic2(cornerLat, cornerLon);
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::closestPoint(const Geodetic2& p) const {
|
||||
// This method finds the closest point on the patch, to the provided
|
||||
// point p. As we are deali ng with latitude-longitude patches, distance in this
|
||||
// context refers to great-circle distance.
|
||||
// (https://en.wikipedia.org/wiki/Great-circle_distance)
|
||||
//
|
||||
// This uses a simple clamping approach to find the closest point on the
|
||||
// patch. A naive castesian clamp is not sufficient for this purpose,
|
||||
// as illustrated with an example below.
|
||||
|
||||
// Example: (degrees are used for latidude, longitude)
|
||||
// patchCenter = (0,0), patchHalfSize = (45,45), point = (5, 170)
|
||||
// Note, the point and the patch are on opposite sides of the sphere
|
||||
//
|
||||
// cartesian clamp:
|
||||
// --> clampedPointLat = clamp(5, -45, 45) = 5
|
||||
// --> clampedPointLon = clamp(170, -45, 45) = 45
|
||||
// --> result: (5, 45)
|
||||
// --> closest point is actually (45, 45)
|
||||
// --> The error is significant
|
||||
//
|
||||
// This method simply adds an extra clamp on the latitude in these cases. In the
|
||||
// above example, that would be the following:
|
||||
// --> clampedPointLat = clamp(180 - 5, -45, 45) = 45
|
||||
//
|
||||
// Just doing this actually makes points returned from this methods being the
|
||||
// true closest point, great-circle distance-wise.
|
||||
|
||||
|
||||
using Ang = Angle<double>;
|
||||
|
||||
// Convert to Angles for normalization
|
||||
Ang centerLat = Ang::fromRadians(_center.lat);
|
||||
Ang centerLon = Ang::fromRadians(_center.lon);
|
||||
Ang pointLat = Ang::fromRadians(p.lat);
|
||||
Ang pointLon = Ang::fromRadians(p.lon);
|
||||
|
||||
// Normalize point with respect to center. This is done because the point
|
||||
// will later be clamped. See LatLonPatch::clamp(const LatLon&) for explanation
|
||||
pointLat.normalizeAround(centerLat);
|
||||
pointLon.normalizeAround(centerLon);
|
||||
|
||||
// Calculate the longitud difference between center and point. We normalize around
|
||||
// zero because we want the "shortest distance" difference, i.e the difference
|
||||
// should be in the interval [-180 deg, 180 deg]
|
||||
Ang centerToPointLon = (centerLon - pointLon).normalizeAround(Ang::ZERO);
|
||||
|
||||
// Calculate the longitudinal distance to the closest patch edge
|
||||
Ang longitudeDistanceToClosestPatchEdge = centerToPointLon.abs() - Ang::fromRadians(_halfSize.lon);
|
||||
|
||||
// If the longitude distance to the closest patch edge is larger than 90 deg
|
||||
// the latitude will have to be clamped to its closest corner, as explained in
|
||||
// the example above.
|
||||
double clampedLat = longitudeDistanceToClosestPatchEdge > Ang::QUARTER ?
|
||||
clampedLat = glm::clamp((Ang::HALF - pointLat).normalizeAround(centerLat).asRadians(), minLat(), maxLat()) :
|
||||
clampedLat = glm::clamp(pointLat.asRadians(), minLat(), maxLat());
|
||||
|
||||
// Longitude is just clamped normally
|
||||
double clampedLon = glm::clamp(pointLon.asRadians(), minLon(), maxLon());
|
||||
|
||||
return Geodetic2(clampedLat, clampedLon);
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
@@ -25,15 +25,11 @@
|
||||
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___GEODETIC2___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GEODETIC2___H__
|
||||
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class Ellipsoid;
|
||||
|
||||
struct Geodetic2 {
|
||||
Geodetic2(double latitude = 0.0, double longitude = 0.0);
|
||||
Geodetic2(const Geodetic2& src);
|
||||
@@ -55,89 +51,6 @@ struct Geodetic2 {
|
||||
double lon;
|
||||
};
|
||||
|
||||
struct Geodetic3 {
|
||||
Geodetic2 geodetic2;
|
||||
double height;
|
||||
};
|
||||
|
||||
class GeodeticPatch {
|
||||
public:
|
||||
GeodeticPatch(
|
||||
double centerLat,
|
||||
double centerLon,
|
||||
double halfSizeLat,
|
||||
double halfSizeLon);
|
||||
|
||||
GeodeticPatch(
|
||||
const Geodetic2& center,
|
||||
const Geodetic2& halfSize);
|
||||
|
||||
GeodeticPatch(const GeodeticPatch& patch);
|
||||
|
||||
GeodeticPatch(const TileIndex& tileIndex);
|
||||
|
||||
void setCenter(const Geodetic2&);
|
||||
void setHalfSize(const Geodetic2&);
|
||||
|
||||
/**
|
||||
returns the latitude boundary which is closest to the equator
|
||||
*/
|
||||
double edgeLatitudeNearestEquator() const;
|
||||
|
||||
/**
|
||||
Returns true if the center above the equator
|
||||
*/
|
||||
double isNorthern() const;
|
||||
|
||||
Geodetic2 getCorner(Quad q) const;
|
||||
Geodetic2 getSize() const;
|
||||
|
||||
double minLat() const;
|
||||
double maxLat() const;
|
||||
double minLon() const;
|
||||
double maxLon() const;
|
||||
|
||||
/**
|
||||
* returns true if the specified coordinate is contained within the patch
|
||||
*/
|
||||
bool contains(const Geodetic2& p) const;
|
||||
|
||||
|
||||
/**
|
||||
* Clamps a point to the patch region
|
||||
*/
|
||||
Geodetic2 clamp(const Geodetic2& p) const;
|
||||
|
||||
/**
|
||||
* Returns the corner of the patch that is closest to the given point p
|
||||
*/
|
||||
Geodetic2 closestCorner(const Geodetic2& p) const;
|
||||
|
||||
/**
|
||||
* Returns a point on the patch that minimizes the great-circle distance to
|
||||
* the given point p.
|
||||
*/
|
||||
Geodetic2 closestPoint(const Geodetic2& p) const;
|
||||
|
||||
/**
|
||||
* Returns the minimum tile level of the patch (based on largest side)
|
||||
*/
|
||||
double minimumTileLevel() const;
|
||||
|
||||
/**
|
||||
* Returns the maximum level of the patch (based on smallest side)
|
||||
*/
|
||||
double maximumTileLevel() const;
|
||||
|
||||
const Geodetic2& center() const;
|
||||
const Geodetic2& halfSize() const;
|
||||
Geodetic2 size() const;
|
||||
|
||||
private:
|
||||
Geodetic2 _center;
|
||||
Geodetic2 _halfSize;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GEODETIC3___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GEODETIC3___H__
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct Geodetic3 {
|
||||
Geodetic2 geodetic2;
|
||||
double height;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GEODETIC3___H__
|
||||
@@ -0,0 +1,242 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodeticpatch.h>
|
||||
|
||||
#include <modules/globebrowsing/geometry/angle.h>
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
GeodeticPatch::GeodeticPatch(double centerLat, double centerLon, double halfSizeLat,
|
||||
double halfSizeLon)
|
||||
: _center(Geodetic2(centerLat, centerLon))
|
||||
, _halfSize(Geodetic2(halfSizeLat, halfSizeLon))
|
||||
{}
|
||||
|
||||
GeodeticPatch::GeodeticPatch(const Geodetic2& center, const Geodetic2& halfSize)
|
||||
: _center(center)
|
||||
, _halfSize(halfSize)
|
||||
{}
|
||||
|
||||
GeodeticPatch::GeodeticPatch(const GeodeticPatch& patch)
|
||||
: _center(patch._center)
|
||||
, _halfSize(patch._halfSize)
|
||||
{}
|
||||
|
||||
GeodeticPatch::GeodeticPatch(const TileIndex& tileIndex) {
|
||||
double deltaLat = (2 * glm::pi<double>()) / ((double)(1 << tileIndex.level));
|
||||
double deltaLon = (2 * glm::pi<double>()) / ((double)(1 << tileIndex.level));
|
||||
Geodetic2 nwCorner(glm::pi<double>() / 2 - deltaLat * tileIndex.y, -glm::pi<double>() + deltaLon * tileIndex.x);
|
||||
_halfSize = Geodetic2(deltaLat / 2, deltaLon / 2);
|
||||
_center = Geodetic2(nwCorner.lat - _halfSize.lat, nwCorner.lon + _halfSize.lon);
|
||||
}
|
||||
|
||||
void GeodeticPatch::setCenter(const Geodetic2& center) {
|
||||
_center = center;
|
||||
}
|
||||
|
||||
void GeodeticPatch::setHalfSize(const Geodetic2& halfSize) {
|
||||
_halfSize = halfSize;
|
||||
}
|
||||
|
||||
double GeodeticPatch::maximumTileLevel() const {
|
||||
// Numerator is just pi, not 2*pi, since we are dealing with HALF sizes
|
||||
return log2(glm::pi<double>() / glm::min(_halfSize.lat, _halfSize.lon));
|
||||
}
|
||||
|
||||
double GeodeticPatch::minimumTileLevel() const {
|
||||
// Numerator is just pi, not 2*pi, since we are dealing with HALF sizes
|
||||
return log2(glm::pi<double>() / glm::max(_halfSize.lat, _halfSize.lon));
|
||||
}
|
||||
|
||||
const Geodetic2& GeodeticPatch::center() const {
|
||||
return _center;
|
||||
}
|
||||
|
||||
const Geodetic2& GeodeticPatch::halfSize() const {
|
||||
return _halfSize;
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::size() const {
|
||||
return Geodetic2(2 * _halfSize.lat, 2 * _halfSize.lon);
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::getCorner(Quad q) const {
|
||||
switch (q) {
|
||||
case NORTH_WEST: return Geodetic2(maxLat(), minLon());// northWestCorner();
|
||||
case NORTH_EAST: return Geodetic2(maxLat(), maxLon());// northEastCorner();
|
||||
case SOUTH_WEST: return Geodetic2(minLat(), minLon());// southWestCorner();
|
||||
case SOUTH_EAST: return Geodetic2(minLat(), maxLon());// southEastCorner();
|
||||
}
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::getSize() const {
|
||||
return _halfSize * 2;
|
||||
}
|
||||
|
||||
double GeodeticPatch::minLat() const {
|
||||
return _center.lat - _halfSize.lat;
|
||||
}
|
||||
|
||||
double GeodeticPatch::maxLat() const {
|
||||
return _center.lat + _halfSize.lat;
|
||||
}
|
||||
|
||||
double GeodeticPatch::minLon() const {
|
||||
return _center.lon - _halfSize.lon;
|
||||
}
|
||||
|
||||
double GeodeticPatch::maxLon() const {
|
||||
return _center.lon + _halfSize.lon;
|
||||
}
|
||||
|
||||
bool GeodeticPatch::contains(const Geodetic2& p) const {
|
||||
Geodetic2 diff = _center - p;
|
||||
return glm::abs(diff.lat) <= _halfSize.lat && glm::abs(diff.lon) <= _halfSize.lon;
|
||||
}
|
||||
|
||||
double GeodeticPatch::edgeLatitudeNearestEquator() const {
|
||||
return _center.lat + _halfSize.lat * (isNorthern() ? -1 : 1);
|
||||
}
|
||||
|
||||
double GeodeticPatch::isNorthern() const {
|
||||
return _center.lat > 0.0;
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::clamp(const Geodetic2& p) const {
|
||||
using Ang = Angle<double>;
|
||||
|
||||
// Convert to Angles for normalization
|
||||
Ang centerLat = Ang::fromRadians(_center.lat);
|
||||
Ang centerLon = Ang::fromRadians(_center.lon);
|
||||
Ang pointLat = Ang::fromRadians(p.lat);
|
||||
Ang pointLon = Ang::fromRadians(p.lon);
|
||||
|
||||
// Normalize w.r.t. the center in order for the clamping to done correctly
|
||||
//
|
||||
// Example:
|
||||
// centerLat = 0 deg, halfSize.lat = 10 deg, pointLat = 330 deg
|
||||
// --> Just clamping pointLat would be clamp(330, -10, 10) = 10 // WRONG!
|
||||
// Instead, if we first normalize 330 deg around 0, we get -30 deg
|
||||
// --> clamp(-30, -10, 10) = -10 // CORRECT!
|
||||
pointLat.normalizeAround(centerLat);
|
||||
pointLon.normalizeAround(centerLon);
|
||||
|
||||
return Geodetic2(
|
||||
glm::clamp(pointLat.asRadians(), minLat(), maxLat()),
|
||||
glm::clamp(pointLon.asRadians(), minLon(), maxLon())
|
||||
);
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::closestCorner(const Geodetic2& p) const {
|
||||
using Ang = Angle<double>;
|
||||
|
||||
// LatLon vector from patch center to the point
|
||||
Geodetic2 centerToPoint = p - _center;
|
||||
|
||||
// Normalize the difference angles to be centered around 0.
|
||||
Ang latDiff = Ang::fromRadians(centerToPoint.lat).normalizeAround(Ang::ZERO);
|
||||
Ang lonDiff = Ang::fromRadians(centerToPoint.lon).normalizeAround(Ang::ZERO);
|
||||
|
||||
// If latDiff > 0
|
||||
// --> point p is north of the patch center
|
||||
// --> the closest corner to the point must be a northern one
|
||||
// --> set the corner's latitude coordinate to center.lat + halfSize.lat
|
||||
// else
|
||||
// --> set corner's latidude coordinate to center.lat - halfSize.lat
|
||||
double cornerLat = _center.lat + _halfSize.lat * (latDiff > Ang::ZERO ? 1 : -1);
|
||||
|
||||
// We then assigned the corner's longitude coordinate in a similar fashion
|
||||
double cornerLon = _center.lon + _halfSize.lon * (lonDiff > Ang::ZERO ? 1 : -1);
|
||||
|
||||
return Geodetic2(cornerLat, cornerLon);
|
||||
}
|
||||
|
||||
Geodetic2 GeodeticPatch::closestPoint(const Geodetic2& p) const {
|
||||
// This method finds the closest point on the patch, to the provided
|
||||
// point p. As we are deali ng with latitude-longitude patches, distance in this
|
||||
// context refers to great-circle distance.
|
||||
// (https://en.wikipedia.org/wiki/Great-circle_distance)
|
||||
//
|
||||
// This uses a simple clamping approach to find the closest point on the
|
||||
// patch. A naive castesian clamp is not sufficient for this purpose,
|
||||
// as illustrated with an example below.
|
||||
|
||||
// Example: (degrees are used for latidude, longitude)
|
||||
// patchCenter = (0,0), patchHalfSize = (45,45), point = (5, 170)
|
||||
// Note, the point and the patch are on opposite sides of the sphere
|
||||
//
|
||||
// cartesian clamp:
|
||||
// --> clampedPointLat = clamp(5, -45, 45) = 5
|
||||
// --> clampedPointLon = clamp(170, -45, 45) = 45
|
||||
// --> result: (5, 45)
|
||||
// --> closest point is actually (45, 45)
|
||||
// --> The error is significant
|
||||
//
|
||||
// This method simply adds an extra clamp on the latitude in these cases. In the
|
||||
// above example, that would be the following:
|
||||
// --> clampedPointLat = clamp(180 - 5, -45, 45) = 45
|
||||
//
|
||||
// Just doing this actually makes points returned from this methods being the
|
||||
// true closest point, great-circle distance-wise.
|
||||
|
||||
|
||||
using Ang = Angle<double>;
|
||||
|
||||
// Convert to Angles for normalization
|
||||
Ang centerLat = Ang::fromRadians(_center.lat);
|
||||
Ang centerLon = Ang::fromRadians(_center.lon);
|
||||
Ang pointLat = Ang::fromRadians(p.lat);
|
||||
Ang pointLon = Ang::fromRadians(p.lon);
|
||||
|
||||
// Normalize point with respect to center. This is done because the point
|
||||
// will later be clamped. See LatLonPatch::clamp(const LatLon&) for explanation
|
||||
pointLat.normalizeAround(centerLat);
|
||||
pointLon.normalizeAround(centerLon);
|
||||
|
||||
// Calculate the longitud difference between center and point. We normalize around
|
||||
// zero because we want the "shortest distance" difference, i.e the difference
|
||||
// should be in the interval [-180 deg, 180 deg]
|
||||
Ang centerToPointLon = (centerLon - pointLon).normalizeAround(Ang::ZERO);
|
||||
|
||||
// Calculate the longitudinal distance to the closest patch edge
|
||||
Ang longitudeDistanceToClosestPatchEdge = centerToPointLon.abs() - Ang::fromRadians(_halfSize.lon);
|
||||
|
||||
// If the longitude distance to the closest patch edge is larger than 90 deg
|
||||
// the latitude will have to be clamped to its closest corner, as explained in
|
||||
// the example above.
|
||||
double clampedLat = longitudeDistanceToClosestPatchEdge > Ang::QUARTER ?
|
||||
clampedLat = glm::clamp((Ang::HALF - pointLat).normalizeAround(centerLat).asRadians(), minLat(), maxLat()) :
|
||||
clampedLat = glm::clamp(pointLat.asRadians(), minLat(), maxLat());
|
||||
|
||||
// Longitude is just clamped normally
|
||||
double clampedLon = glm::clamp(pointLon.asRadians(), minLon(), maxLon());
|
||||
|
||||
return Geodetic2(clampedLat, clampedLon);
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GEODETICPATCH___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GEODETICPATCH___H__
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/tile/quad.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class TileIndex;
|
||||
|
||||
class GeodeticPatch {
|
||||
public:
|
||||
GeodeticPatch(
|
||||
double centerLat,
|
||||
double centerLon,
|
||||
double halfSizeLat,
|
||||
double halfSizeLon);
|
||||
|
||||
GeodeticPatch(
|
||||
const Geodetic2& center,
|
||||
const Geodetic2& halfSize);
|
||||
|
||||
GeodeticPatch(const GeodeticPatch& patch);
|
||||
|
||||
GeodeticPatch(const TileIndex& tileIndex);
|
||||
|
||||
void setCenter(const Geodetic2&);
|
||||
void setHalfSize(const Geodetic2&);
|
||||
|
||||
/**
|
||||
* Returns the latitude boundary which is closest to the equator
|
||||
*/
|
||||
double edgeLatitudeNearestEquator() const;
|
||||
|
||||
/**
|
||||
* Returns \c true if the center above the equator
|
||||
*/
|
||||
double isNorthern() const;
|
||||
|
||||
Geodetic2 getCorner(Quad q) const;
|
||||
Geodetic2 getSize() const;
|
||||
|
||||
double minLat() const;
|
||||
double maxLat() const;
|
||||
double minLon() const;
|
||||
double maxLon() const;
|
||||
|
||||
/**
|
||||
* Returns \c true if the specified coordinate is contained within the patch
|
||||
*/
|
||||
bool contains(const Geodetic2& p) const;
|
||||
|
||||
|
||||
/**
|
||||
* Clamps a point to the patch region
|
||||
*/
|
||||
Geodetic2 clamp(const Geodetic2& p) const;
|
||||
|
||||
/**
|
||||
* Returns the corner of the patch that is closest to the given point p
|
||||
*/
|
||||
Geodetic2 closestCorner(const Geodetic2& p) const;
|
||||
|
||||
/**
|
||||
* Returns a point on the patch that minimizes the great-circle distance to
|
||||
* the given point p.
|
||||
*/
|
||||
Geodetic2 closestPoint(const Geodetic2& p) const;
|
||||
|
||||
/**
|
||||
* Returns the minimum tile level of the patch (based on largest side)
|
||||
*/
|
||||
double minimumTileLevel() const;
|
||||
|
||||
/**
|
||||
* Returns the maximum level of the patch (based on smallest side)
|
||||
*/
|
||||
double maximumTileLevel() const;
|
||||
|
||||
const Geodetic2& center() const;
|
||||
const Geodetic2& halfSize() const;
|
||||
Geodetic2 size() const;
|
||||
|
||||
private:
|
||||
Geodetic2 _center;
|
||||
Geodetic2 _halfSize;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GEODETICPATCH___H__
|
||||
@@ -28,8 +28,10 @@
|
||||
#include <modules/globebrowsing/other/distanceswitch.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/cachingtileprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/singleimageprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/sizereferencetileprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/temporaltileprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/texttileprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileindextileprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileproviderbylevel.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileproviderbyindex.h>
|
||||
@@ -52,17 +54,17 @@ void GlobeBrowsingModule::internalInitialize() {
|
||||
fRenderable->registerClass<globebrowsing::RenderableGlobe>("RenderableGlobe");
|
||||
|
||||
// add Tile Provider factory
|
||||
auto fTileProvider = std::make_unique<ghoul::TemplateFactory<TileProvider>>();
|
||||
auto fTileProvider = std::make_unique<ghoul::TemplateFactory<tileprovider::TileProvider>>();
|
||||
|
||||
fTileProvider->registerClass<CachingTileProvider>("LRUCaching");
|
||||
fTileProvider->registerClass<SingleImageProvider>("SingleImage");
|
||||
fTileProvider->registerClass<TemporalTileProvider>("Temporal");
|
||||
fTileProvider->registerClass<TileIndexTileProvider>("TileIndex");
|
||||
fTileProvider->registerClass<SizeReferenceTileProvider>("SizeReference");
|
||||
fTileProvider->registerClass<tileprovider::CachingTileProvider>("LRUCaching");
|
||||
fTileProvider->registerClass<tileprovider::SingleImageProvider>("SingleImage");
|
||||
fTileProvider->registerClass<tileprovider::TemporalTileProvider>("Temporal");
|
||||
fTileProvider->registerClass<tileprovider::TileIndexTileProvider>("TileIndex");
|
||||
fTileProvider->registerClass<tileprovider::SizeReferenceTileProvider>("SizeReference");
|
||||
|
||||
// Combining Tile Providers
|
||||
fTileProvider->registerClass<TileProviderByLevel>("ByLevel");
|
||||
fTileProvider->registerClass<TileProviderByIndex>("ByIndex");
|
||||
fTileProvider->registerClass<tileprovider::TileProviderByLevel>("ByLevel");
|
||||
fTileProvider->registerClass<tileprovider::TileProviderByIndex>("ByIndex");
|
||||
|
||||
FactoryManager::ref().addFactory(std::move(fTileProvider));
|
||||
}
|
||||
|
||||
@@ -25,19 +25,26 @@
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator.h>
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator/chunklevelevaluator.h>
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator/availabletiledataevaluator.h>
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator/distanceevaluator.h>
|
||||
#include <modules/globebrowsing/chunk/chunklevelevaluator/projectedareaevaluator.h>
|
||||
#include <modules/globebrowsing/chunk/chunknode.h>
|
||||
#include <modules/globebrowsing/chunk/culling.h>
|
||||
#include <modules/globebrowsing/chunk/culling/chunkculler.h>
|
||||
#include <modules/globebrowsing/chunk/culling/frustumculler.h>
|
||||
#include <modules/globebrowsing/chunk/culling/horizonculler.h>
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <modules/globebrowsing/meshes/skirtedgrid.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
#include <modules/globebrowsing/rendering/chunkrenderer.h>
|
||||
#include <modules/globebrowsing/rendering/layermanager.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layergroup.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
#include <modules/debugging/rendering/debugrenderer.h>
|
||||
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@@ -66,17 +73,17 @@ ChunkedLodGlobe::ChunkedLodGlobe(const RenderableGlobe& owner, size_t segmentsPe
|
||||
TriangleSoup::Normals::No
|
||||
);
|
||||
|
||||
_chunkCullers.push_back(std::make_unique<HorizonCuller>());
|
||||
_chunkCullers.push_back(std::make_unique<FrustumCuller>(
|
||||
_chunkCullers.push_back(std::make_unique<culling::HorizonCuller>());
|
||||
_chunkCullers.push_back(std::make_unique<culling::FrustumCuller>(
|
||||
AABB3(glm::vec3(-1, -1, 0), glm::vec3(1, 1, 1e35)))
|
||||
);
|
||||
|
||||
_chunkEvaluatorByAvailableTiles =
|
||||
std::make_unique<EvaluateChunkLevelByAvailableTileData>();
|
||||
std::make_unique<chunklevelevaluator::AvailableTileData>();
|
||||
_chunkEvaluatorByProjectedArea =
|
||||
std::make_unique<EvaluateChunkLevelByProjectedArea>();
|
||||
std::make_unique<chunklevelevaluator::ProjectedArea>();
|
||||
_chunkEvaluatorByDistance =
|
||||
std::make_unique<EvaluateChunkLevelByDistance>();
|
||||
std::make_unique<chunklevelevaluator::Distance>();
|
||||
|
||||
_renderer = std::make_unique<ChunkRenderer>(geometry, layerManager);
|
||||
}
|
||||
@@ -135,7 +142,7 @@ int ChunkedLodGlobe::getDesiredLevel(
|
||||
int desiredLevelByAvailableData = _chunkEvaluatorByAvailableTiles->getDesiredLevel(
|
||||
chunk, renderData
|
||||
);
|
||||
if (desiredLevelByAvailableData != ChunkLevelEvaluator::UNKNOWN_DESIRED_LEVEL) {
|
||||
if (desiredLevelByAvailableData != chunklevelevaluator::Evaluator::UnknownDesiredLevel) {
|
||||
desiredLevel = glm::min(desiredLevel, desiredLevelByAvailableData);
|
||||
}
|
||||
|
||||
@@ -166,7 +173,7 @@ float ChunkedLodGlobe::getHeight(glm::dvec3 position) const {
|
||||
const auto& heightMapLayers = _layerManager->layerGroup(LayerManager::HeightLayers).activeLayers();
|
||||
|
||||
for (const auto& layer : heightMapLayers) {
|
||||
TileProvider* tileProvider = layer->tileProvider();
|
||||
tileprovider::TileProvider* tileProvider = layer->tileProvider();
|
||||
// Transform the uv coordinates to the current tile texture
|
||||
ChunkTile chunkTile = tileProvider->getChunkTile(tileIndex);
|
||||
const auto& tile = chunkTile.tile;
|
||||
|
||||
@@ -29,15 +29,22 @@
|
||||
|
||||
#include <modules/globebrowsing/geometry/ellipsoid.h>
|
||||
#include <modules/globebrowsing/other/statscollector.h>
|
||||
#include <modules/globebrowsing/geometry/geodeticpatch.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
namespace chunklevelevaluator {
|
||||
class Evaluator;
|
||||
} // namespace chunklevelevaluator
|
||||
|
||||
namespace culling {
|
||||
class ChunkCuller;
|
||||
} // namespace culling
|
||||
|
||||
class Chunk;
|
||||
class ChunkCuller;
|
||||
class ChunkLevelEvaluator;
|
||||
class ChunkNode;
|
||||
class ChunkRenderer;
|
||||
class Geodetic2;
|
||||
@@ -61,13 +68,13 @@ public:
|
||||
* Traverse the chunk tree and find the highest level chunk node.
|
||||
*
|
||||
* \param location is given in geodetic coordinates and must be in the range
|
||||
* latitude [-90. 90] and longitude [-180, 180]. In other words, it must be a
|
||||
* latitude [-90, 90] and longitude [-180, 180]. In other words, it must be a
|
||||
* position defined on the globe in georeferenced coordinates.
|
||||
*/
|
||||
const ChunkNode& findChunkNode(const Geodetic2& location) const;
|
||||
|
||||
/**
|
||||
* Test if a specific chunk can saefely be culled without affecting the rendered
|
||||
* Test if a specific chunk can saf;ely be culled without affecting the rendered
|
||||
* image.
|
||||
*
|
||||
* Goes through all available <code>ChunkCuller</code>s and check if any of them
|
||||
@@ -123,11 +130,11 @@ private:
|
||||
// the patch used for actual rendering
|
||||
std::unique_ptr<ChunkRenderer> _renderer;
|
||||
|
||||
std::vector<std::unique_ptr<ChunkCuller>> _chunkCullers;
|
||||
std::vector<std::unique_ptr<culling::ChunkCuller>> _chunkCullers;
|
||||
|
||||
std::unique_ptr<ChunkLevelEvaluator> _chunkEvaluatorByAvailableTiles;
|
||||
std::unique_ptr<ChunkLevelEvaluator> _chunkEvaluatorByProjectedArea;
|
||||
std::unique_ptr<ChunkLevelEvaluator> _chunkEvaluatorByDistance;
|
||||
std::unique_ptr<chunklevelevaluator::Evaluator> _chunkEvaluatorByAvailableTiles;
|
||||
std::unique_ptr<chunklevelevaluator::Evaluator> _chunkEvaluatorByProjectedArea;
|
||||
std::unique_ptr<chunklevelevaluator::Evaluator> _chunkEvaluatorByDistance;
|
||||
|
||||
std::shared_ptr<LayerManager> _layerManager;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
} }
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include <modules/debugging/rendering/debugrenderer.h>
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/rendering/layermanager.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
|
||||
namespace {
|
||||
const char* keyFrame = "Frame";
|
||||
|
||||
@@ -36,22 +36,22 @@ BasicGrid::BasicGrid(unsigned int xSegments, unsigned int ySegments,
|
||||
: Grid(xSegments, ySegments, usePositions, useTextureCoordinates, useNormals)
|
||||
{
|
||||
_geometry = std::make_unique<TriangleSoup>(
|
||||
CreateElements(xSegments, ySegments),
|
||||
createElements(xSegments, ySegments),
|
||||
usePositions,
|
||||
useTextureCoordinates,
|
||||
useNormals
|
||||
);
|
||||
|
||||
if (usePositions) {
|
||||
_geometry->setVertexPositions(CreatePositions(_xSegments, _ySegments));
|
||||
_geometry->setVertexPositions(createPositions(_xSegments, _ySegments));
|
||||
}
|
||||
if (useTextureCoordinates) {
|
||||
_geometry->setVertexTextureCoordinates(
|
||||
CreateTextureCoordinates(_xSegments, _ySegments)
|
||||
createTextureCoordinates(_xSegments, _ySegments)
|
||||
);
|
||||
}
|
||||
if (useNormals) {
|
||||
_geometry->setVertexNormals(CreateNormals(_xSegments, _ySegments));
|
||||
_geometry->setVertexNormals(createNormals(_xSegments, _ySegments));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ inline size_t BasicGrid::numVertices(int xSegments, int ySegments) {
|
||||
return (xSegments + 1) * (ySegments + 1);
|
||||
}
|
||||
|
||||
std::vector<GLuint> BasicGrid::CreateElements(int xSegments, int ySegments) {
|
||||
std::vector<GLuint> BasicGrid::createElements(int xSegments, int ySegments) {
|
||||
validate(xSegments, ySegments);
|
||||
|
||||
std::vector<GLuint> elements;
|
||||
@@ -111,13 +111,13 @@ std::vector<GLuint> BasicGrid::CreateElements(int xSegments, int ySegments) {
|
||||
return elements;
|
||||
}
|
||||
|
||||
std::vector<glm::vec4> BasicGrid::CreatePositions(int xSegments, int ySegments) {
|
||||
std::vector<glm::vec4> BasicGrid::createPositions(int xSegments, int ySegments) {
|
||||
validate(xSegments, ySegments);
|
||||
std::vector<glm::vec4> positions;
|
||||
positions.reserve(numVertices(xSegments, ySegments));
|
||||
|
||||
// Copy from 2d texture coordinates and use as template to create positions
|
||||
std::vector<glm::vec2> templateTextureCoords = CreateTextureCoordinates(
|
||||
std::vector<glm::vec2> templateTextureCoords = createTextureCoordinates(
|
||||
xSegments, ySegments
|
||||
);
|
||||
for (const glm::vec2& coords : templateTextureCoords) {
|
||||
@@ -133,7 +133,7 @@ std::vector<glm::vec4> BasicGrid::CreatePositions(int xSegments, int ySegments)
|
||||
return positions;
|
||||
}
|
||||
|
||||
std::vector<glm::vec2> BasicGrid::CreateTextureCoordinates(int xSegments, int ySegments) {
|
||||
std::vector<glm::vec2> BasicGrid::createTextureCoordinates(int xSegments, int ySegments) {
|
||||
validate(xSegments, ySegments);
|
||||
std::vector<glm::vec2> textureCoordinates;
|
||||
textureCoordinates.reserve(numVertices(xSegments, ySegments));
|
||||
@@ -149,7 +149,7 @@ std::vector<glm::vec2> BasicGrid::CreateTextureCoordinates(int xSegments, int yS
|
||||
return textureCoordinates;
|
||||
}
|
||||
|
||||
std::vector<glm::vec3> BasicGrid::CreateNormals(int xSegments, int ySegments) {
|
||||
std::vector<glm::vec3> BasicGrid::createNormals(int xSegments, int ySegments) {
|
||||
validate(xSegments, ySegments);
|
||||
std::vector<glm::vec3> normals;
|
||||
normals.reserve(numVertices(xSegments, ySegments));
|
||||
|
||||
@@ -47,18 +47,19 @@ public:
|
||||
* to the GPU.
|
||||
*/
|
||||
BasicGrid(unsigned int xSegments, unsigned int ySegments,
|
||||
TriangleSoup::Positions usePositions,
|
||||
TriangleSoup::TextureCoordinates useTextureCoordinates,
|
||||
TriangleSoup::Normals useNormals);
|
||||
TriangleSoup::Positions usePositions,
|
||||
TriangleSoup::TextureCoordinates useTextureCoordinates,
|
||||
TriangleSoup::Normals useNormals);
|
||||
|
||||
virtual int xSegments() const;
|
||||
virtual int ySegments() const;
|
||||
|
||||
private:
|
||||
virtual std::vector<GLuint> CreateElements(int xRes, int yRes);
|
||||
virtual std::vector<glm::vec4> CreatePositions(int xRes, int yRes);
|
||||
virtual std::vector<glm::vec2> CreateTextureCoordinates(int xRes, int yRes);
|
||||
virtual std::vector<glm::vec3> CreateNormals(int xRes, int yRes);
|
||||
std::vector<GLuint> createElements(int xRes, int yRes) override;
|
||||
std::vector<glm::vec4> createPositions(int xRes, int yRes) override;
|
||||
std::vector<glm::vec2> createTextureCoordinates(int xRes, int yRes)
|
||||
override;
|
||||
std::vector<glm::vec3> createNormals(int xRes, int yRes) override;
|
||||
|
||||
void validate(int xSegments, int ySegments);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
Grid(int xSegments, int ySegments,
|
||||
TriangleSoup::Positions usePositions = TriangleSoup::Positions::No,
|
||||
TriangleSoup::TextureCoordinates useTextures =
|
||||
TriangleSoup::TextureCoordinates::No,
|
||||
TriangleSoup::TextureCoordinates::No,
|
||||
TriangleSoup::Normals useNormals = TriangleSoup::Normals::No);
|
||||
|
||||
virtual ~Grid() = default;
|
||||
@@ -71,14 +71,14 @@ protected:
|
||||
* <code>ySegments</code>. Where the number of vertices in each direction is the number
|
||||
* of segments + 1.
|
||||
*/
|
||||
virtual std::vector<GLuint> CreateElements(int xSegments, int ySegments) = 0;
|
||||
virtual std::vector<GLuint> createElements(int xSegments, int ySegments) = 0;
|
||||
|
||||
/**
|
||||
* Should return the positions of vertices for a grid with size <code>xSegments</code>
|
||||
* * <code>ySegments</code>. Where the number of vertices in each direction is the
|
||||
* number of segments + 1.
|
||||
*/
|
||||
virtual std::vector<glm::vec4> CreatePositions(int xSegments, int ySegments) = 0;
|
||||
virtual std::vector<glm::vec4> createPositions(int xSegments, int ySegments) = 0;
|
||||
|
||||
/**
|
||||
* Should return the texture coordinates of vertices for a grid with size
|
||||
@@ -86,14 +86,14 @@ protected:
|
||||
* each direction is the number of segments + 1.
|
||||
*/
|
||||
virtual std::vector<glm::vec2>
|
||||
CreateTextureCoordinates(int xSegments, int ySegments) = 0;
|
||||
createTextureCoordinates(int xSegments, int ySegments) = 0;
|
||||
|
||||
/**
|
||||
* Should return the normals of vertices for a grid with size <code>xSegments</code> *
|
||||
* <code>ySegments</code>. Where the number of vertices in each direction is the number
|
||||
* of segments + 1.
|
||||
*/
|
||||
virtual std::vector<glm::vec3> CreateNormals(int xSegments, int ySegments) = 0;
|
||||
virtual std::vector<glm::vec3> createNormals(int xSegments, int ySegments) = 0;
|
||||
|
||||
std::unique_ptr<TriangleSoup> _geometry;
|
||||
|
||||
|
||||
@@ -40,20 +40,20 @@ SkirtedGrid::SkirtedGrid(unsigned int xSegments, unsigned int ySegments,
|
||||
: Grid(xSegments, ySegments, usePositions, useTextureCoordinates, useNormals)
|
||||
{
|
||||
_geometry = std::make_unique<TriangleSoup>(
|
||||
CreateElements(xSegments, ySegments),
|
||||
createElements(xSegments, ySegments),
|
||||
usePositions,
|
||||
useTextureCoordinates,
|
||||
useNormals
|
||||
);
|
||||
|
||||
if (usePositions) {
|
||||
_geometry->setVertexPositions(CreatePositions(_xSegments, _ySegments));
|
||||
_geometry->setVertexPositions(createPositions(_xSegments, _ySegments));
|
||||
}
|
||||
if (useTextureCoordinates) {
|
||||
_geometry->setVertexTextureCoordinates(CreateTextureCoordinates(_xSegments, _ySegments));
|
||||
_geometry->setVertexTextureCoordinates(createTextureCoordinates(_xSegments, _ySegments));
|
||||
}
|
||||
if (useNormals) {
|
||||
_geometry->setVertexNormals(CreateNormals(_xSegments, _ySegments));
|
||||
_geometry->setVertexNormals(createNormals(_xSegments, _ySegments));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ inline size_t SkirtedGrid::numVertices(int xSegments, int ySegments) {
|
||||
return (xSegments + 1) * (ySegments + 1);
|
||||
}
|
||||
|
||||
std::vector<GLuint> SkirtedGrid::CreateElements(int xSegments, int ySegments) {
|
||||
std::vector<GLuint> SkirtedGrid::createElements(int xSegments, int ySegments) {
|
||||
validate(xSegments, ySegments);
|
||||
|
||||
std::vector<GLuint> elements;
|
||||
@@ -115,13 +115,13 @@ std::vector<GLuint> SkirtedGrid::CreateElements(int xSegments, int ySegments) {
|
||||
return elements;
|
||||
}
|
||||
|
||||
std::vector<glm::vec4> SkirtedGrid::CreatePositions(int xSegments, int ySegments) {
|
||||
std::vector<glm::vec4> SkirtedGrid::createPositions(int xSegments, int ySegments) {
|
||||
validate(xSegments, ySegments);
|
||||
std::vector<glm::vec4> positions;
|
||||
positions.reserve(numVertices(xSegments, ySegments));
|
||||
|
||||
// Copy from 2d texture coordinates and use as template to create positions
|
||||
std::vector<glm::vec2> templateTextureCoords = CreateTextureCoordinates(
|
||||
std::vector<glm::vec2> templateTextureCoords = createTextureCoordinates(
|
||||
xSegments, ySegments
|
||||
);
|
||||
for (const auto& c : templateTextureCoords) {
|
||||
@@ -137,7 +137,7 @@ std::vector<glm::vec4> SkirtedGrid::CreatePositions(int xSegments, int ySegments
|
||||
return positions;
|
||||
}
|
||||
|
||||
std::vector<glm::vec2> SkirtedGrid::CreateTextureCoordinates(int xSegments, int ySegments)
|
||||
std::vector<glm::vec2> SkirtedGrid::createTextureCoordinates(int xSegments, int ySegments)
|
||||
{
|
||||
validate(xSegments, ySegments);
|
||||
std::vector<glm::vec2> textureCoordinates;
|
||||
@@ -162,7 +162,7 @@ std::vector<glm::vec2> SkirtedGrid::CreateTextureCoordinates(int xSegments, int
|
||||
return textureCoordinates;
|
||||
}
|
||||
|
||||
std::vector<glm::vec3> SkirtedGrid::CreateNormals(int xSegments, int ySegments) {
|
||||
std::vector<glm::vec3> SkirtedGrid::createNormals(int xSegments, int ySegments) {
|
||||
validate(xSegments, ySegments);
|
||||
std::vector<glm::vec3> normals;
|
||||
normals.reserve(numVertices(xSegments + 2, ySegments + 2));
|
||||
|
||||
@@ -61,10 +61,10 @@ public:
|
||||
virtual int ySegments() const;
|
||||
|
||||
private:
|
||||
virtual std::vector<GLuint> CreateElements(int xRes, int yRes);
|
||||
virtual std::vector<glm::vec4> CreatePositions(int xRes, int yRes);
|
||||
virtual std::vector<glm::vec2> CreateTextureCoordinates(int xRes, int yRes);
|
||||
virtual std::vector<glm::vec3> CreateNormals(int xRes, int yRes);
|
||||
std::vector<GLuint> createElements(int xRes, int yRes) override;
|
||||
std::vector<glm::vec4> createPositions(int xRes, int yRes) override;
|
||||
std::vector<glm::vec2> createTextureCoordinates(int xRes, int yRes) override;
|
||||
std::vector<glm::vec3> createNormals(int xRes, int yRes) override;
|
||||
|
||||
void validate(int xSegments, int ySegments);
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
Positions usePositions = Positions::No,
|
||||
TextureCoordinates useTextures = TextureCoordinates::No,
|
||||
Normals useNormals = Normals::No);
|
||||
|
||||
~TriangleSoup();
|
||||
|
||||
// Setters
|
||||
@@ -78,14 +79,13 @@ protected:
|
||||
bool _useTextureCoordinates;
|
||||
bool _useVertexNormals;
|
||||
|
||||
typedef struct {
|
||||
public:
|
||||
struct Vertex {
|
||||
GLfloat position[4];
|
||||
GLfloat texture[2];
|
||||
GLfloat normal[3];
|
||||
private:
|
||||
GLubyte padding[28]; // Pads the struct out to 64 bytes for performance increase
|
||||
} Vertex;
|
||||
};
|
||||
|
||||
// Vertex data
|
||||
std::vector<Vertex> _vertexData;
|
||||
|
||||
@@ -24,9 +24,13 @@
|
||||
|
||||
#include <modules/globebrowsing/other/distanceswitch.h>
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
DistanceSwitch::~DistanceSwitch() {}
|
||||
|
||||
bool DistanceSwitch::initialize() {
|
||||
for (int i = 0; i < _renderables.size(); ++i) {
|
||||
_renderables[i]->initialize();
|
||||
|
||||
@@ -25,13 +25,12 @@
|
||||
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___DISTANCESWITCH___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___DISTANCESWITCH___H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Renderable;
|
||||
struct RenderData;
|
||||
struct UpdateData;
|
||||
|
||||
@@ -43,6 +42,8 @@ namespace globebrowsing {
|
||||
*/
|
||||
class DistanceSwitch {
|
||||
public:
|
||||
~DistanceSwitch();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
|
||||
@@ -46,8 +46,6 @@ public:
|
||||
private:
|
||||
void clean();
|
||||
|
||||
// Member varialbes
|
||||
private:
|
||||
std::list<std::pair<KeyType, ValueType>> _itemList;
|
||||
std::unordered_map<KeyType, decltype(_itemList.begin())> _itemMap;
|
||||
size_t _cacheSize;
|
||||
|
||||
@@ -35,14 +35,6 @@
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
template <typename T>
|
||||
using StatsRecord = std::unordered_map<std::string, T>;
|
||||
|
||||
template <typename T>
|
||||
struct StatsCollection : public std::vector<StatsRecord<T>> {
|
||||
std::set<std::string> keys;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class TemplatedStatsCollector {
|
||||
public:
|
||||
@@ -67,6 +59,14 @@ public:
|
||||
void writeNextRecord(std::ostream& os);
|
||||
|
||||
private:
|
||||
template <typename U>
|
||||
using StatsRecord = std::unordered_map<std::string, U>;
|
||||
|
||||
template <typename U>
|
||||
struct StatsCollection : public std::vector<StatsRecord<U>> {
|
||||
std::set<std::string> keys;
|
||||
};
|
||||
|
||||
StatsCollection<T> _data;
|
||||
T _dummy; // used when disabled
|
||||
bool& _enabled;
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <modules/globebrowsing/meshes/grid.h>
|
||||
#include <modules/globebrowsing/rendering/layershadermanager.h>
|
||||
#include <modules/globebrowsing/rendering/gpulayermanager.h>
|
||||
#include <modules/globebrowsing/rendering/gpu/gpulayermanager.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layergroup.h>
|
||||
|
||||
namespace {
|
||||
const char* keyFrame = "Frame";
|
||||
@@ -82,10 +83,10 @@ ghoul::opengl::ProgramObject* ChunkRenderer::getActivatedProgramWithTileData(
|
||||
{
|
||||
const TileIndex& tileIndex = chunk.tileIndex();
|
||||
|
||||
LayerShaderPreprocessingData layeredTexturePreprocessingData;
|
||||
LayerShaderManager::LayerShaderPreprocessingData layeredTexturePreprocessingData;
|
||||
|
||||
for (size_t i = 0; i < LayerManager::NUM_LAYER_GROUPS; i++) {
|
||||
LayerGroupPreprocessingData layeredTextureInfo;
|
||||
LayerShaderManager::LayerShaderPreprocessingData::LayerGroupPreprocessingData layeredTextureInfo;
|
||||
auto layerGroup = _layerManager->layerGroup(i);
|
||||
layeredTextureInfo.lastLayerIdx = layerGroup.activeLayers().size() - 1;
|
||||
layeredTextureInfo.layerBlendingEnabled = layerGroup.layerBlendingEnabled();
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpuchunktile.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/chunktile.h>
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void GPUChunkTile::setValue(ProgramObject* programObject, const ChunkTile& chunkTile) {
|
||||
gpuTexture.setValue(programObject, chunkTile.tile.texture);
|
||||
gpuTileUvTransform.setValue(programObject, chunkTile.uvTransform);
|
||||
}
|
||||
|
||||
void GPUChunkTile::bind(ProgramObject* programObject, const std::string& nameBase) {
|
||||
gpuTexture.bind(programObject, nameBase + "textureSampler");
|
||||
gpuTileUvTransform.bind(programObject, nameBase + "uvTransform.");
|
||||
}
|
||||
|
||||
void GPUChunkTile::deactivate() {
|
||||
gpuTexture.deactivate();
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,77 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GPUCHUNKTILE___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GPUCHUNKTILE___H__
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gputileuvtransform.h>
|
||||
|
||||
#include <openspace/util/gpudata.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct ChunkTile;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>ChunkTile</code>
|
||||
*/
|
||||
class GPUChunkTile {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>ChunkTile</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
void setValue(ProgramObject* programObject, const ChunkTile& chunkTile);
|
||||
|
||||
/**
|
||||
* Binds GLSL variables with identifiers starting with
|
||||
* nameBase within the provided shader program with this object.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
void bind(ProgramObject* programObject, const std::string& nameBase);
|
||||
|
||||
/**
|
||||
* Deactivates any <code>TextureUnit</code>s assigned by this object.
|
||||
* This method should be called after the OpenGL draw call.
|
||||
*/
|
||||
void deactivate();
|
||||
|
||||
private:
|
||||
GPUTexture gpuTexture;
|
||||
GPUTileUvTransform gpuTileUvTransform;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GPUCHUNKTILE___H__
|
||||
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpuchunktilepile.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void GPUChunkTilePile::setValue(ProgramObject* programObject,
|
||||
const ChunkTilePile& chunkTilePile)
|
||||
{
|
||||
ghoul_assert(
|
||||
gpuChunkTiles.size() == chunkTilePile.size(),
|
||||
"GPU and CPU ChunkTilePile must have same size!"
|
||||
);
|
||||
for (size_t i = 0; i < gpuChunkTiles.size(); ++i) {
|
||||
gpuChunkTiles[i].setValue(programObject, chunkTilePile[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUChunkTilePile::bind(ProgramObject* programObject, const std::string& nameBase,
|
||||
int pileSize)
|
||||
{
|
||||
gpuChunkTiles.resize(pileSize);
|
||||
for (size_t i = 0; i < gpuChunkTiles.size(); ++i) {
|
||||
std::string nameExtension = "chunkTile" + std::to_string(i) + ".";
|
||||
gpuChunkTiles[i].bind(programObject, nameBase + nameExtension);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUChunkTilePile::deactivate() {
|
||||
for (auto& gpuChunkTile : gpuChunkTiles) {
|
||||
gpuChunkTile.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,76 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GPUCHUNKTILEPILE___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GPUCHUNKTILEPILE___H__
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpuchunktile.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/chunktile.h>
|
||||
|
||||
#include <openspace/util/gpudata.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>ChunkTilePile</code>
|
||||
*/
|
||||
class GPUChunkTilePile {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>ChunkTilePile</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
void setValue(ProgramObject* programObject, const ChunkTilePile& chunkTilePile);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
void bind(ProgramObject* programObject, const std::string& nameBase,
|
||||
int pileSize);
|
||||
/**
|
||||
* Deactivates any <code>TextureUnit</code>s assigned by this object.
|
||||
* This method should be called after the OpenGL draw call.
|
||||
*/
|
||||
void deactivate();
|
||||
|
||||
private:
|
||||
std::vector<GPUChunkTile> gpuChunkTiles;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GPUCHUNKTILEPILE___H__
|
||||
@@ -0,0 +1,52 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpuheightlayer.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layer.h>
|
||||
#include <modules/globebrowsing/tile/chunktile.h>
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
#include <modules/globebrowsing/tile/tiledepthtransform.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void GPUHeightLayer::setValue(ProgramObject* programObject, const Layer& layer,
|
||||
const TileIndex& tileIndex, int pileSize)
|
||||
{
|
||||
GPULayer::setValue(programObject, layer, tileIndex, pileSize);
|
||||
gpuDepthTransform.setValue(programObject, layer.tileProvider()->depthTransform());
|
||||
}
|
||||
|
||||
void GPUHeightLayer::bind(ProgramObject* programObject, const Layer& layer,
|
||||
const std::string& nameBase, int pileSize)
|
||||
{
|
||||
GPULayer::bind(programObject, layer, nameBase, pileSize);
|
||||
gpuDepthTransform.bind(programObject, nameBase + "depthTransform.");
|
||||
}
|
||||
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,74 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GPUHEIGHTLAYER___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GPUHEIGHTLAYER___H__
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpulayer.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gputiledepthtransform.h>
|
||||
#include <openspace/util/gpudata.h>
|
||||
#include <string>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class Layer;
|
||||
struct TileIndex;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>Layer</code> representing
|
||||
* a height map.
|
||||
*/
|
||||
class GPUHeightLayer : public GPULayer {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>Layer</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
virtual void setValue(ProgramObject* programObject, const Layer& layer,
|
||||
const TileIndex& tileIndex, int pileSize);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
virtual void bind(ProgramObject* programObject, const Layer& layer,
|
||||
const std::string& nameBase, int pileSize);
|
||||
|
||||
private:
|
||||
GPUTileDepthTransform gpuDepthTransform;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GPUHEIGHTLAYER___H__
|
||||
@@ -0,0 +1,52 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpulayer.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layer.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void GPULayer::setValue(ProgramObject* programObject, const Layer& layer,
|
||||
const TileIndex& tileIndex, int pileSize)
|
||||
{
|
||||
ChunkTilePile chunkTilePile = layer.getChunkTilePile(tileIndex, pileSize);
|
||||
gpuChunkTilePile.setValue(programObject, chunkTilePile);
|
||||
gpuRenderSettings.setValue(programObject, layer.renderSettings());
|
||||
}
|
||||
|
||||
void GPULayer::bind(ProgramObject* programObject, const Layer& layer,
|
||||
const std::string& nameBase, int pileSize)
|
||||
{
|
||||
gpuChunkTilePile.bind(programObject, nameBase + "pile.", pileSize);
|
||||
gpuRenderSettings.bind(programObject, nameBase + "settings.");
|
||||
}
|
||||
|
||||
void GPULayer::deactivate() {
|
||||
gpuChunkTilePile.deactivate();
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,79 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYER___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYER___H__
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpuchunktilepile.h>
|
||||
#include <modules/globebrowsing/rendering/gpu/gpulayerrendersettings.h>
|
||||
#include <openspace/util/gpudata.h>
|
||||
#include <string>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class Layer;
|
||||
struct TileIndex;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>Layer</code>
|
||||
*/
|
||||
class GPULayer {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>Layer</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
virtual void setValue(ProgramObject* programObject, const Layer& layer,
|
||||
const TileIndex& tileIndex, int pileSize);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
virtual void bind(ProgramObject* programObject, const Layer& layer,
|
||||
const std::string& nameBase, int pileSize);
|
||||
|
||||
/**
|
||||
* Deactivates any <code>TextureUnit</code>s assigned by this object.
|
||||
* This method should be called after the OpenGL draw call.
|
||||
*/
|
||||
virtual void deactivate();
|
||||
|
||||
private:
|
||||
GPUChunkTilePile gpuChunkTilePile;
|
||||
GPULayerRenderSettings gpuRenderSettings;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYER___H__
|
||||
@@ -0,0 +1,80 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpulayergroup.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layergroup.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
#include <modules/globebrowsing/rendering/gpu/gpuheightlayer.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void GPULayerGroup::setValue(ProgramObject* programObject, const LayerGroup& layerGroup,
|
||||
const TileIndex& tileIndex)
|
||||
{
|
||||
auto& activeLayers = layerGroup.activeLayers();
|
||||
ghoul_assert(
|
||||
activeLayers.size() == gpuActiveLayers.size(),
|
||||
"GPU and CPU active layers must have same size!"
|
||||
);
|
||||
for (int i = 0; i < activeLayers.size(); ++i) {
|
||||
gpuActiveLayers[i]->setValue(
|
||||
programObject,
|
||||
*activeLayers[i],
|
||||
tileIndex,
|
||||
layerGroup.pileSize()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerGroup::bind(ProgramObject* programObject, const LayerGroup& layerGroup,
|
||||
const std::string& nameBase, int category)
|
||||
{
|
||||
auto activeLayers = layerGroup.activeLayers();
|
||||
gpuActiveLayers.resize(activeLayers.size());
|
||||
int pileSize = layerGroup.pileSize();
|
||||
for (size_t i = 0; i < gpuActiveLayers.size(); ++i) {
|
||||
// should maybe a proper GPULayer factory
|
||||
gpuActiveLayers[i] = (category == LayerManager::HeightLayers) ?
|
||||
std::make_unique<GPUHeightLayer>() :
|
||||
std::make_unique<GPULayer>();
|
||||
std::string nameExtension = "[" + std::to_string(i) + "].";
|
||||
gpuActiveLayers[i]->bind(
|
||||
programObject,
|
||||
*activeLayers[i],
|
||||
nameBase + nameExtension,
|
||||
pileSize
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerGroup::deactivate() {
|
||||
for (size_t i = 0; i < gpuActiveLayers.size(); ++i) {
|
||||
gpuActiveLayers[i]->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,86 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYERGROUP___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYERGROUP___H__
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpulayer.h>
|
||||
#include <modules/globebrowsing/tile/chunktile.h>
|
||||
|
||||
#include <openspace/util/gpudata.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct ChunkTile;
|
||||
class Layer;
|
||||
class LayerRenderSettings;
|
||||
struct TileDepthTransform;
|
||||
struct TileUvTransform;
|
||||
|
||||
class LayerGroup;
|
||||
struct TileIndex;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>LayerGroup</code>
|
||||
*/
|
||||
class GPULayerGroup {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>LayerGroup</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
virtual void setValue(ProgramObject* programObject, const LayerGroup& layerGroup,
|
||||
const TileIndex& tileIndex);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
virtual void bind(ProgramObject* programObject, const LayerGroup& layerGroup,
|
||||
const std::string& nameBase, int category);
|
||||
|
||||
/**
|
||||
* Deactivates any <code>TextureUnit</code>s assigned by this object.
|
||||
* This method should be called after the OpenGL draw call.
|
||||
*/
|
||||
virtual void deactivate();
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<GPULayer>> gpuActiveLayers;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYERGROUP___H__
|
||||
@@ -0,0 +1,65 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpulayermanager.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void GPULayerManager::setValue(ProgramObject* programObject,
|
||||
const LayerManager& layerManager,
|
||||
const TileIndex& tileIndex)
|
||||
{
|
||||
auto layerGroups = layerManager.layerGroups();
|
||||
for (size_t i = 0; i < layerGroups.size(); ++i) {
|
||||
gpuLayerGroups[i]->setValue(programObject, *layerGroups[i], tileIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerManager::bind(ProgramObject* programObject, const LayerManager& layerManager)
|
||||
{
|
||||
auto layerGroups = layerManager.layerGroups();
|
||||
if (gpuLayerGroups.size() != layerGroups.size()) {
|
||||
gpuLayerGroups.resize(layerGroups.size());
|
||||
for (auto& gpuLayerGroup : gpuLayerGroups){
|
||||
gpuLayerGroup = std::make_unique<GPULayerGroup>();
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < layerGroups.size(); ++i) {
|
||||
std::string nameBase = LayerManager::LAYER_GROUP_NAMES[i];
|
||||
gpuLayerGroups[i]->bind(programObject, *layerGroups[i], nameBase, i);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerManager::deactivate() {
|
||||
for (size_t i = 0; i < gpuLayerGroups.size(); ++i) {
|
||||
gpuLayerGroups[i]->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,75 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYERMANAGER___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYERMANAGER___H__
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpulayergroup.h>
|
||||
#include <openspace/util/gpudata.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class LayerManager;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>LayerGroup</code>
|
||||
*/
|
||||
class GPULayerManager {
|
||||
public:
|
||||
/**
|
||||
* Sets the value of <code>LayerGroup</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
virtual void setValue(ProgramObject* programObject, const LayerManager& layerManager,
|
||||
const TileIndex& tileIndex);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
virtual void bind(ProgramObject* programObject, const LayerManager& layerManager);
|
||||
|
||||
/**
|
||||
* Deactivates any <code>TextureUnit</code>s assigned by this object.
|
||||
* This method should be called after the OpenGL draw call.
|
||||
*/
|
||||
virtual void deactivate();
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<GPULayerGroup>> gpuLayerGroups;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYERMANAGER___H__
|
||||
@@ -0,0 +1,49 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gpulayerrendersettings.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layerrendersettings.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void GPULayerRenderSettings::setValue(ProgramObject* programObject,
|
||||
const LayerRenderSettings& layerSettings)
|
||||
{
|
||||
gpuOpacity.setValue(programObject, layerSettings.opacity.value());
|
||||
gpuGamma.setValue(programObject, layerSettings.gamma.value());
|
||||
gpuMultiplier.setValue(programObject, layerSettings.multiplier.value());
|
||||
}
|
||||
|
||||
void GPULayerRenderSettings::bind(ProgramObject* programObject,
|
||||
const std::string& nameBase)
|
||||
{
|
||||
gpuOpacity.bind(programObject, nameBase + "opacity");
|
||||
gpuGamma.bind(programObject, nameBase + "gamma");
|
||||
gpuMultiplier.bind(programObject, nameBase + "multiplier");
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,69 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYERRENDERSETTINGS___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYERRENDERSETTINGS___H__
|
||||
|
||||
#include <openspace/util/gpudata.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class LayerRenderSettings;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>LayerRenderSettings</code>
|
||||
*/
|
||||
class GPULayerRenderSettings{
|
||||
public:
|
||||
/**
|
||||
* Sets the value of <code>LayerRenderSettings</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
void setValue(ProgramObject* programObject, const LayerRenderSettings& layerSettings);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
void bind(ProgramObject* programObject, const std::string& nameBase);
|
||||
|
||||
private:
|
||||
GPUData<float> gpuOpacity;
|
||||
GPUData<float> gpuGamma;
|
||||
GPUData<float> gpuMultiplier;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GPULAYERRENDERSETTINGS___H__
|
||||
@@ -0,0 +1,47 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gputiledepthtransform.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tiledepthtransform.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void GPUTileDepthTransform::setValue(ProgramObject* programObject,
|
||||
const TileDepthTransform& depthTransform)
|
||||
{
|
||||
gpuDepthOffset.setValue(programObject, depthTransform.depthOffset);
|
||||
gpuDepthScale.setValue(programObject, depthTransform.depthScale);
|
||||
}
|
||||
|
||||
void GPUTileDepthTransform::bind(ProgramObject* programObject,
|
||||
const std::string& nameBase)
|
||||
{
|
||||
gpuDepthOffset.bind(programObject, nameBase + "depthOffset");
|
||||
gpuDepthScale.bind(programObject, nameBase + "depthScale");
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,68 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GPUTILEDEPTHTRANSFORM___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GPUTILEDEPTHTRANSFORM___H__
|
||||
|
||||
#include <openspace/util/gpudata.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct TileDepthTransform;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>TileDepthTransform</code>
|
||||
*/
|
||||
class GPUTileDepthTransform {
|
||||
public:
|
||||
/**
|
||||
* Sets the value of <code>TileDepthTransform</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
void setValue(ProgramObject* programObject, const TileDepthTransform& depthTransform);
|
||||
|
||||
/**
|
||||
* Binds GLSL variables with identifiers starting with
|
||||
* nameBase within the provided shader program with this object.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
void bind(ProgramObject* programObject, const std::string& nameBase);
|
||||
|
||||
private:
|
||||
GPUData<float> gpuDepthOffset;
|
||||
GPUData<float> gpuDepthScale;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GPUTILEDEPTHTRANSFORM___H__
|
||||
@@ -0,0 +1,49 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpu/gputileuvtransform.h>
|
||||
|
||||
//#include <modules/globebrowsing/rendering/layermanager.h>
|
||||
//#include <modules/globebrowsing/tile/chunktile.h>
|
||||
//#include <modules/globebrowsing/tile/tile.h>
|
||||
//#include <modules/globebrowsing/tile/tiledepthtransform.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void GPUTileUvTransform::setValue(ProgramObject* programObject,
|
||||
const TileUvTransform& tileUvTransform)
|
||||
{
|
||||
gpuUvOffset.setValue(programObject, tileUvTransform.uvOffset);
|
||||
gpuUvScale.setValue(programObject, tileUvTransform.uvScale);
|
||||
}
|
||||
|
||||
void GPUTileUvTransform::bind(ProgramObject* programObject, const std::string& nameBase) {
|
||||
gpuUvOffset.bind(programObject, nameBase + "uvOffset");
|
||||
gpuUvScale.bind(programObject, nameBase + "uvScale");
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,68 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GPUTILEUVTRANSFORM___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GPUTILEUVTRANSFORM___H__
|
||||
|
||||
#include <openspace/util/gpudata.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct TileUvTransform;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>TileUvTransform</code>
|
||||
*/
|
||||
class GPUTileUvTransform {
|
||||
public:
|
||||
/**
|
||||
* Sets the value of <code>TileUvTransform</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
void setValue(ProgramObject* programObject, const TileUvTransform& uvTransform);
|
||||
|
||||
/**
|
||||
* Binds GLSL variables with identifiers starting with
|
||||
* nameBase within the provided shader program with this object.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
void bind(ProgramObject* programObject, const std::string& nameBase);
|
||||
|
||||
private:
|
||||
GPUData<glm::vec2> gpuUvOffset;
|
||||
GPUData<glm::vec2> gpuUvScale;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GPUTILEUVTRANSFORM___H__
|
||||
@@ -1,232 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/gpulayermanager.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/layermanager.h>
|
||||
#include <modules/globebrowsing/tile/chunktile.h>
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
#include <modules/globebrowsing/tile/tiledepthtransform.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void GPUTileUvTransform::setValue(ProgramObject* programObject,
|
||||
const TileUvTransform& tileUvTransform)
|
||||
{
|
||||
gpuUvOffset.setValue(programObject, tileUvTransform.uvOffset);
|
||||
gpuUvScale.setValue(programObject, tileUvTransform.uvScale);
|
||||
}
|
||||
|
||||
void GPUTileUvTransform::bind(ProgramObject* programObject, const std::string& nameBase) {
|
||||
gpuUvOffset.bind(programObject, nameBase + "uvOffset");
|
||||
gpuUvScale.bind(programObject, nameBase + "uvScale");
|
||||
}
|
||||
|
||||
void GPUTileDepthTransform::setValue(ProgramObject* programObject,
|
||||
const TileDepthTransform& depthTransform)
|
||||
{
|
||||
gpuDepthOffset.setValue(programObject, depthTransform.depthOffset);
|
||||
gpuDepthScale.setValue(programObject, depthTransform.depthScale);
|
||||
}
|
||||
|
||||
void GPUTileDepthTransform::bind(ProgramObject* programObject,
|
||||
const std::string& nameBase)
|
||||
{
|
||||
gpuDepthOffset.bind(programObject, nameBase + "depthOffset");
|
||||
gpuDepthScale.bind(programObject, nameBase + "depthScale");
|
||||
}
|
||||
|
||||
void GPUChunkTile::setValue(ProgramObject* programObject, const ChunkTile& chunkTile) {
|
||||
gpuTexture.setValue(programObject, chunkTile.tile.texture);
|
||||
gpuTileUvTransform.setValue(programObject, chunkTile.uvTransform);
|
||||
}
|
||||
|
||||
void GPUChunkTile::bind(ProgramObject* programObject, const std::string& nameBase) {
|
||||
gpuTexture.bind(programObject, nameBase + "textureSampler");
|
||||
gpuTileUvTransform.bind(programObject, nameBase + "uvTransform.");
|
||||
}
|
||||
|
||||
void GPUChunkTile::deactivate() {
|
||||
gpuTexture.deactivate();
|
||||
}
|
||||
|
||||
void GPUChunkTilePile::setValue(ProgramObject* programObject,
|
||||
const ChunkTilePile& chunkTilePile)
|
||||
{
|
||||
ghoul_assert(
|
||||
gpuChunkTiles.size() == chunkTilePile.chunkTiles.size(),
|
||||
"GPU and CPU ChunkTilePile must have same size!"
|
||||
);
|
||||
for (size_t i = 0; i < gpuChunkTiles.size(); ++i) {
|
||||
gpuChunkTiles[i].setValue(programObject, chunkTilePile.chunkTiles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUChunkTilePile::bind(ProgramObject* programObject, const std::string& nameBase,
|
||||
int pileSize)
|
||||
{
|
||||
gpuChunkTiles.resize(pileSize);
|
||||
for (size_t i = 0; i < gpuChunkTiles.size(); ++i) {
|
||||
std::string nameExtension = "chunkTile" + std::to_string(i) + ".";
|
||||
gpuChunkTiles[i].bind(programObject, nameBase + nameExtension);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUChunkTilePile::deactivate() {
|
||||
for (auto& gpuChunkTile : gpuChunkTiles) {
|
||||
gpuChunkTile.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GPULayerRenderSettings::setValue(ProgramObject* programObject,
|
||||
const LayerRenderSettings& layerSettings)
|
||||
{
|
||||
gpuOpacity.setValue(programObject, layerSettings.opacity.value());
|
||||
gpuGamma.setValue(programObject, layerSettings.gamma.value());
|
||||
gpuMultiplier.setValue(programObject, layerSettings.multiplier.value());
|
||||
}
|
||||
|
||||
void GPULayerRenderSettings::bind(ProgramObject* programObject,
|
||||
const std::string& nameBase)
|
||||
{
|
||||
gpuOpacity.bind(programObject, nameBase + "opacity");
|
||||
gpuGamma.bind(programObject, nameBase + "gamma");
|
||||
gpuMultiplier.bind(programObject, nameBase + "multiplier");
|
||||
}
|
||||
|
||||
void GPULayer::setValue(ProgramObject* programObject, const Layer& layer,
|
||||
const TileIndex& tileIndex, int pileSize)
|
||||
{
|
||||
ChunkTilePile chunkTilePile = layer.getChunkTilePile(tileIndex, pileSize);
|
||||
gpuChunkTilePile.setValue(programObject, chunkTilePile);
|
||||
gpuRenderSettings.setValue(programObject, layer.renderSettings());
|
||||
}
|
||||
|
||||
void GPULayer::bind(ProgramObject* programObject, const Layer& layer,
|
||||
const std::string& nameBase, int pileSize)
|
||||
{
|
||||
gpuChunkTilePile.bind(programObject, nameBase + "pile.", pileSize);
|
||||
gpuRenderSettings.bind(programObject, nameBase + "settings.");
|
||||
}
|
||||
|
||||
void GPULayer::deactivate() {
|
||||
gpuChunkTilePile.deactivate();
|
||||
}
|
||||
|
||||
void GPUHeightLayer::setValue(ProgramObject* programObject, const Layer& layer,
|
||||
const TileIndex& tileIndex, int pileSize)
|
||||
{
|
||||
GPULayer::setValue(programObject, layer, tileIndex, pileSize);
|
||||
gpuDepthTransform.setValue(programObject, layer.tileProvider()->depthTransform());
|
||||
}
|
||||
|
||||
void GPUHeightLayer::bind(ProgramObject* programObject, const Layer& layer,
|
||||
const std::string& nameBase, int pileSize)
|
||||
{
|
||||
GPULayer::bind(programObject, layer, nameBase, pileSize);
|
||||
gpuDepthTransform.bind(programObject, nameBase + "depthTransform.");
|
||||
}
|
||||
|
||||
void GPULayerGroup::setValue(ProgramObject* programObject, const LayerGroup& layerGroup,
|
||||
const TileIndex& tileIndex)
|
||||
{
|
||||
auto& activeLayers = layerGroup.activeLayers();
|
||||
ghoul_assert(
|
||||
activeLayers.size() == gpuActiveLayers.size(),
|
||||
"GPU and CPU active layers must have same size!"
|
||||
);
|
||||
for (int i = 0; i < activeLayers.size(); ++i) {
|
||||
gpuActiveLayers[i]->setValue(
|
||||
programObject,
|
||||
*activeLayers[i],
|
||||
tileIndex,
|
||||
layerGroup.pileSize()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerGroup::bind(ProgramObject* programObject, const LayerGroup& layerGroup,
|
||||
const std::string& nameBase, int category)
|
||||
{
|
||||
auto activeLayers = layerGroup.activeLayers();
|
||||
gpuActiveLayers.resize(activeLayers.size());
|
||||
int pileSize = layerGroup.pileSize();
|
||||
for (size_t i = 0; i < gpuActiveLayers.size(); ++i) {
|
||||
// should maybe a proper GPULayer factory
|
||||
gpuActiveLayers[i] = (category == LayerManager::HeightLayers) ?
|
||||
std::make_unique<GPUHeightLayer>() :
|
||||
std::make_unique<GPULayer>();
|
||||
std::string nameExtension = "[" + std::to_string(i) + "].";
|
||||
gpuActiveLayers[i]->bind(
|
||||
programObject,
|
||||
*activeLayers[i],
|
||||
nameBase + nameExtension,
|
||||
pileSize
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerGroup::deactivate() {
|
||||
for (size_t i = 0; i < gpuActiveLayers.size(); ++i) {
|
||||
gpuActiveLayers[i]->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerManager::setValue(ProgramObject* programObject,
|
||||
const LayerManager& layerManager,
|
||||
const TileIndex& tileIndex)
|
||||
{
|
||||
auto layerGroups = layerManager.layerGroups();
|
||||
for (size_t i = 0; i < layerGroups.size(); ++i) {
|
||||
gpuLayerGroups[i]->setValue(programObject, *layerGroups[i], tileIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerManager::bind(ProgramObject* programObject, const LayerManager& layerManager)
|
||||
{
|
||||
auto layerGroups = layerManager.layerGroups();
|
||||
if (gpuLayerGroups.size() != layerGroups.size()) {
|
||||
gpuLayerGroups.resize(layerGroups.size());
|
||||
for (auto& gpuLayerGroup : gpuLayerGroups){
|
||||
gpuLayerGroup = std::make_unique<GPULayerGroup>();
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < layerGroups.size(); ++i) {
|
||||
std::string nameBase = LayerManager::LAYER_GROUP_NAMES[i];
|
||||
gpuLayerGroups[i]->bind(programObject, *layerGroups[i], nameBase, i);
|
||||
}
|
||||
}
|
||||
|
||||
void GPULayerManager::deactivate() {
|
||||
for (size_t i = 0; i < gpuLayerGroups.size(); ++i) {
|
||||
gpuLayerGroups[i]->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -1,320 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___GPU_LAYER_MANAGER___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___GPU_LAYER_MANAGER___H__
|
||||
|
||||
#include <openspace/util/gpudata.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct ChunkTile;
|
||||
struct ChunkTilePile;
|
||||
class Layer;
|
||||
class LayerRenderSettings;
|
||||
struct TileDepthTransform;
|
||||
struct TileIndex;
|
||||
struct TileUvTransform;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>TileUvTransform</code>
|
||||
*/
|
||||
class GPUTileUvTransform {
|
||||
public:
|
||||
/**
|
||||
* Sets the value of <code>TileUvTransform</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
void setValue(ProgramObject* programObject, const TileUvTransform& uvTransform);
|
||||
|
||||
/**
|
||||
* Binds GLSL variables with identifiers starting with
|
||||
* nameBase within the provided shader program with this object.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
void bind(ProgramObject* programObject, const std::string& nameBase);
|
||||
|
||||
private:
|
||||
GPUData<glm::vec2> gpuUvOffset;
|
||||
GPUData<glm::vec2> gpuUvScale;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>TileDepthTransform</code>
|
||||
*/
|
||||
class GPUTileDepthTransform {
|
||||
public:
|
||||
/**
|
||||
* Sets the value of <code>TileDepthTransform</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
void setValue(ProgramObject* programObject, const TileDepthTransform& depthTransform);
|
||||
|
||||
/**
|
||||
* Binds GLSL variables with identifiers starting with
|
||||
* nameBase within the provided shader program with this object.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
void bind(ProgramObject* programObject, const std::string& nameBase);
|
||||
|
||||
private:
|
||||
GPUData<float> gpuDepthOffset;
|
||||
GPUData<float> gpuDepthScale;
|
||||
};
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>ChunkTile</code>
|
||||
*/
|
||||
class GPUChunkTile {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>ChunkTile</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
void setValue(ProgramObject* programObject, const ChunkTile& chunkTile);
|
||||
|
||||
/**
|
||||
* Binds GLSL variables with identifiers starting with
|
||||
* nameBase within the provided shader program with this object.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
void bind(ProgramObject* programObject, const std::string& nameBase);
|
||||
|
||||
/**
|
||||
* Deactivates any <code>TextureUnit</code>s assigned by this object.
|
||||
* This method should be called after the OpenGL draw call.
|
||||
*/
|
||||
void deactivate();
|
||||
|
||||
private:
|
||||
GPUTexture gpuTexture;
|
||||
GPUTileUvTransform gpuTileUvTransform;
|
||||
};
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>ChunkTilePile</code>
|
||||
*/
|
||||
class GPUChunkTilePile{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>ChunkTilePile</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
void setValue(ProgramObject* programObject, const ChunkTilePile& chunkTilePile);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
void bind(ProgramObject* programObject, const std::string& nameBase,
|
||||
int pileSize);
|
||||
/**
|
||||
* Deactivates any <code>TextureUnit</code>s assigned by this object.
|
||||
* This method should be called after the OpenGL draw call.
|
||||
*/
|
||||
void deactivate();
|
||||
|
||||
private:
|
||||
std::vector<GPUChunkTile> gpuChunkTiles;
|
||||
};
|
||||
|
||||
|
||||
class LayerRenderSettings;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>LayerRenderSettings</code>
|
||||
*/
|
||||
class GPULayerRenderSettings{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>LayerRenderSettings</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
void setValue(ProgramObject* programObject, const LayerRenderSettings& layerSettings);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
void bind(ProgramObject* programObject, const std::string& nameBase);
|
||||
|
||||
private:
|
||||
GPUData<float> gpuOpacity;
|
||||
GPUData<float> gpuGamma;
|
||||
GPUData<float> gpuMultiplier;
|
||||
};
|
||||
|
||||
|
||||
class Layer;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>Layer</code>
|
||||
*/
|
||||
class GPULayer {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>Layer</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
virtual void setValue(ProgramObject* programObject, const Layer& layer,
|
||||
const TileIndex& tileIndex, int pileSize);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
virtual void bind(ProgramObject* programObject, const Layer& layer,
|
||||
const std::string& nameBase, int pileSize);
|
||||
|
||||
/**
|
||||
* Deactivates any <code>TextureUnit</code>s assigned by this object.
|
||||
* This method should be called after the OpenGL draw call.
|
||||
*/
|
||||
virtual void deactivate();
|
||||
|
||||
private:
|
||||
GPUChunkTilePile gpuChunkTilePile;
|
||||
GPULayerRenderSettings gpuRenderSettings;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>Layer</code> representing
|
||||
* a height map.
|
||||
*/
|
||||
class GPUHeightLayer : public GPULayer {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>Layer</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
virtual void setValue(ProgramObject* programObject, const Layer& layer,
|
||||
const TileIndex& tileIndex, int pileSize);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
virtual void bind(ProgramObject* programObject, const Layer& layer,
|
||||
const std::string& nameBase, int pileSize);
|
||||
|
||||
private:
|
||||
GPUTileDepthTransform gpuDepthTransform;
|
||||
};
|
||||
|
||||
class LayerGroup;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>LayerGroup</code>
|
||||
*/
|
||||
class GPULayerGroup{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>LayerGroup</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
virtual void setValue(ProgramObject* programObject, const LayerGroup& layerGroup,
|
||||
const TileIndex& tileIndex);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
virtual void bind(ProgramObject* programObject, const LayerGroup& layerGroup,
|
||||
const std::string& nameBase, int category);
|
||||
|
||||
/**
|
||||
* Deactivates any <code>TextureUnit</code>s assigned by this object.
|
||||
* This method should be called after the OpenGL draw call.
|
||||
*/
|
||||
virtual void deactivate();
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<GPULayer>> gpuActiveLayers;
|
||||
};
|
||||
|
||||
class LayerManager;
|
||||
|
||||
/**
|
||||
* Manages a GPU representation of a <code>LayerGroup</code>
|
||||
*/
|
||||
class GPULayerManager{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Sets the value of <code>LayerGroup</code> to its corresponding
|
||||
* GPU struct. OBS! Users must ensure bind has been
|
||||
* called before setting using this method.
|
||||
*/
|
||||
virtual void setValue(ProgramObject* programObject, const LayerManager& layerManager,
|
||||
const TileIndex& tileIndex);
|
||||
|
||||
/**
|
||||
* Binds this object with GLSL variables with identifiers starting
|
||||
* with nameBase within the provided shader program.
|
||||
* After this method has been called, users may invoke setValue.
|
||||
*/
|
||||
virtual void bind(ProgramObject* programObject, const LayerManager& layerManager);
|
||||
|
||||
/**
|
||||
* Deactivates any <code>TextureUnit</code>s assigned by this object.
|
||||
* This method should be called after the OpenGL draw call.
|
||||
*/
|
||||
virtual void deactivate();
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<GPULayerGroup>> gpuLayerGroups;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___GPU_LAYER_MANAGER___H__
|
||||
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layer.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
Layer::Layer(const ghoul::Dictionary& layerDict)
|
||||
: _enabled(properties::BoolProperty("enabled", "enabled", false))
|
||||
{
|
||||
std::string layerName = "error!";
|
||||
layerDict.getValue("Name", layerName);
|
||||
setName(layerName);
|
||||
|
||||
_tileProvider = std::shared_ptr<tileprovider::TileProvider>(
|
||||
tileprovider::TileProvider::createFromDictionary(layerDict));
|
||||
|
||||
// Something else went wrong and no exception was thrown
|
||||
if (_tileProvider == nullptr) {
|
||||
throw ghoul::RuntimeError("Unable to create TileProvider '" + name() + "'");
|
||||
}
|
||||
|
||||
bool enabled = false; // defaults to false if unspecified
|
||||
layerDict.getValue("Enabled", enabled);
|
||||
_enabled.setValue(enabled);
|
||||
addProperty(_enabled);
|
||||
|
||||
addPropertySubOwner(_renderSettings);
|
||||
}
|
||||
|
||||
ChunkTilePile Layer::getChunkTilePile(const TileIndex& tileIndex, int pileSize) const {
|
||||
return std::move(_tileProvider->getChunkTilePile(tileIndex, pileSize));
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,66 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___LAYER___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___LAYER___H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layerrendersettings.h>
|
||||
#include <modules/globebrowsing/tile/chunktile.h>
|
||||
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
namespace tileprovider {
|
||||
class TileProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple struct which is used to enable/disable <code>TileProvider</code>
|
||||
* and associate is with a name. It also holds layer specific information
|
||||
* which is used in rendering of layer.
|
||||
*/
|
||||
class Layer : public properties::PropertyOwner {
|
||||
public:
|
||||
Layer(const ghoul::Dictionary& layerDict);
|
||||
|
||||
ChunkTilePile getChunkTilePile(const TileIndex& tileIndex, int pileSize) const;
|
||||
|
||||
bool enabled() const { return _enabled.value(); }
|
||||
tileprovider::TileProvider* tileProvider() const { return _tileProvider.get(); }
|
||||
const LayerRenderSettings& renderSettings() const { return _renderSettings; }
|
||||
|
||||
private:
|
||||
properties::BoolProperty _enabled;
|
||||
std::shared_ptr<tileprovider::TileProvider> _tileProvider;
|
||||
LayerRenderSettings _renderSettings;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___LAYER___H__
|
||||
@@ -0,0 +1,85 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layergroup.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
LayerGroup::LayerGroup(std::string name)
|
||||
: _levelBlendingEnabled("blendTileLevels", "blend tile levels", true)
|
||||
{
|
||||
setName(std::move(name));
|
||||
addProperty(_levelBlendingEnabled);
|
||||
}
|
||||
|
||||
LayerGroup::LayerGroup(std::string name, const ghoul::Dictionary& dict)
|
||||
: LayerGroup(std::move(name))
|
||||
{
|
||||
for (size_t i = 0; i < dict.size(); i++) {
|
||||
std::string dictKey = std::to_string(i + 1);
|
||||
ghoul::Dictionary layerDict = dict.value<ghoul::Dictionary>(dictKey);
|
||||
|
||||
try {
|
||||
_layers.push_back(std::make_shared<Layer>(layerDict));
|
||||
}
|
||||
catch (const ghoul::RuntimeError& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
continue;
|
||||
}
|
||||
//_layers.push_back(std::make_shared<Layer>(layerDict));
|
||||
}
|
||||
|
||||
for (const auto& layer : _layers) {
|
||||
addPropertySubOwner(layer.get());
|
||||
}
|
||||
}
|
||||
|
||||
void LayerGroup::update() {
|
||||
_activeLayers.clear();
|
||||
|
||||
for (const auto& layer : _layers) {
|
||||
if (layer->enabled()) {
|
||||
layer->tileProvider()->update();
|
||||
_activeLayers.push_back(layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::shared_ptr<Layer>>& LayerGroup::layers() const {
|
||||
return _layers;
|
||||
}
|
||||
|
||||
const std::vector<std::shared_ptr<Layer>>& LayerGroup::activeLayers() const {
|
||||
return _activeLayers;
|
||||
}
|
||||
|
||||
int LayerGroup::pileSize() const{
|
||||
return _levelBlendingEnabled.value() ? 3 : 1;
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,71 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___LAYERGROUP___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___LAYERGROUP___H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layer.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
namespace tileprovider {
|
||||
class TileProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience class for dealing with multiple <code>Layer</code>s.
|
||||
*/
|
||||
struct LayerGroup : public properties::PropertyOwner {
|
||||
LayerGroup(std::string name);
|
||||
LayerGroup(std::string name, const ghoul::Dictionary& dict);
|
||||
|
||||
/// Updates all layers tile providers within this group
|
||||
void update();
|
||||
|
||||
/// @returns const vector of all layers
|
||||
const std::vector<std::shared_ptr<Layer>>& layers() const;
|
||||
|
||||
/// @returns const vector of all active layers
|
||||
const std::vector<std::shared_ptr<Layer>>& activeLayers() const;
|
||||
|
||||
/// @returns the size of the pile to be used in rendering of this layer
|
||||
int pileSize() const;
|
||||
|
||||
bool layerBlendingEnabled() const { return _levelBlendingEnabled.value(); }
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<Layer>> _layers;
|
||||
std::vector<std::shared_ptr<Layer>> _activeLayers;
|
||||
|
||||
properties::BoolProperty _levelBlendingEnabled;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___LAYERGROUP___H__
|
||||
+2
-92
@@ -22,104 +22,14 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/layermanager.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layergroup.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
LayerRenderSettings::LayerRenderSettings()
|
||||
: opacity(properties::FloatProperty("opacity", "opacity", 1.f, 0.f, 1.f))
|
||||
, gamma(properties::FloatProperty("gamma", "gamma", 1, 0, 5))
|
||||
, multiplier(properties::FloatProperty("multiplier", "multiplier", 1.f, 0.f, 20.f))
|
||||
{
|
||||
setName("settings");
|
||||
|
||||
addProperty(opacity);
|
||||
addProperty(gamma);
|
||||
addProperty(multiplier);
|
||||
}
|
||||
|
||||
Layer::Layer(const ghoul::Dictionary& layerDict)
|
||||
: _enabled(properties::BoolProperty("enabled", "enabled", false))
|
||||
{
|
||||
std::string layerName = "error!";
|
||||
layerDict.getValue("Name", layerName);
|
||||
setName(layerName);
|
||||
|
||||
_tileProvider = std::shared_ptr<TileProvider>(
|
||||
TileProvider::createFromDictionary(layerDict));
|
||||
|
||||
// Something else went wrong and no exception was thrown
|
||||
if (_tileProvider == nullptr) {
|
||||
throw ghoul::RuntimeError("Unable to create TileProvider '" + name() + "'");
|
||||
}
|
||||
|
||||
bool enabled = false; // defaults to false if unspecified
|
||||
layerDict.getValue("Enabled", enabled);
|
||||
_enabled.setValue(enabled);
|
||||
addProperty(_enabled);
|
||||
|
||||
addPropertySubOwner(_renderSettings);
|
||||
}
|
||||
|
||||
ChunkTilePile Layer::getChunkTilePile(const TileIndex& tileIndex, int pileSize) const {
|
||||
return std::move(_tileProvider->getChunkTilePile(tileIndex, pileSize));
|
||||
}
|
||||
|
||||
LayerGroup::LayerGroup(std::string name)
|
||||
: _levelBlendingEnabled("blendTileLevels", "blend tile levels", true)
|
||||
{
|
||||
setName(std::move(name));
|
||||
addProperty(_levelBlendingEnabled);
|
||||
}
|
||||
|
||||
LayerGroup::LayerGroup(std::string name, const ghoul::Dictionary& dict)
|
||||
: LayerGroup(std::move(name))
|
||||
{
|
||||
for (size_t i = 0; i < dict.size(); i++) {
|
||||
std::string dictKey = std::to_string(i + 1);
|
||||
ghoul::Dictionary layerDict = dict.value<ghoul::Dictionary>(dictKey);
|
||||
|
||||
try {
|
||||
_layers.push_back(std::make_shared<Layer>(layerDict));
|
||||
}
|
||||
catch (const ghoul::RuntimeError& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
continue;
|
||||
}
|
||||
//_layers.push_back(std::make_shared<Layer>(layerDict));
|
||||
}
|
||||
|
||||
for (const auto& layer : _layers) {
|
||||
addPropertySubOwner(layer.get());
|
||||
}
|
||||
}
|
||||
|
||||
void LayerGroup::update() {
|
||||
_activeLayers.clear();
|
||||
|
||||
for (const auto& layer : _layers) {
|
||||
if (layer->enabled()) {
|
||||
layer->tileProvider()->update();
|
||||
_activeLayers.push_back(layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::shared_ptr<Layer>>& LayerGroup::layers() const {
|
||||
return _layers;
|
||||
}
|
||||
|
||||
const std::vector<std::shared_ptr<Layer>>& LayerGroup::activeLayers() const {
|
||||
return _activeLayers;
|
||||
}
|
||||
|
||||
int LayerGroup::pileSize() const{
|
||||
return _levelBlendingEnabled.value() ? 3 : 1;
|
||||
}
|
||||
|
||||
const char* LayerManager::LAYER_GROUP_NAMES[NUM_LAYER_GROUPS] = {
|
||||
"HeightLayers",
|
||||
"ColorLayers",
|
||||
+2
-61
@@ -29,69 +29,10 @@
|
||||
|
||||
#include <modules/globebrowsing/tile/chunktile.h>
|
||||
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class TileProvider;
|
||||
|
||||
struct LayerRenderSettings : public properties::PropertyOwner {
|
||||
LayerRenderSettings();
|
||||
properties::FloatProperty opacity;
|
||||
properties::FloatProperty gamma;
|
||||
properties::FloatProperty multiplier;
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple struct which is used to enable/disable <code>TileProvider</code>
|
||||
* and associate is with a name. It also holds layer specific information
|
||||
* which is used in rendering of layer.
|
||||
*/
|
||||
class Layer : public properties::PropertyOwner {
|
||||
public:
|
||||
Layer(const ghoul::Dictionary& layerDict);
|
||||
|
||||
ChunkTilePile getChunkTilePile(const TileIndex& tileIndex, int pileSize) const;
|
||||
|
||||
bool enabled() const { return _enabled.value(); }
|
||||
TileProvider* tileProvider() const { return _tileProvider.get(); }
|
||||
const LayerRenderSettings& renderSettings() const { return _renderSettings; }
|
||||
|
||||
private:
|
||||
properties::BoolProperty _enabled;
|
||||
std::shared_ptr<TileProvider> _tileProvider;
|
||||
LayerRenderSettings _renderSettings;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convenience class for dealing with multiple <code>Layer</code>s.
|
||||
*/
|
||||
struct LayerGroup : public properties::PropertyOwner {
|
||||
LayerGroup(std::string name);
|
||||
LayerGroup(std::string name, const ghoul::Dictionary& dict);
|
||||
|
||||
/// Updates all layers tile providers within this group
|
||||
void update();
|
||||
|
||||
/// @returns const vector of all layers
|
||||
const std::vector<std::shared_ptr<Layer>>& layers() const;
|
||||
|
||||
/// @returns const vector of all active layers
|
||||
const std::vector<std::shared_ptr<Layer>>& activeLayers() const;
|
||||
|
||||
/// @returns the size of the pile to be used in rendering of this layer
|
||||
int pileSize() const;
|
||||
|
||||
bool layerBlendingEnabled() const { return _levelBlendingEnabled.value(); }
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<Layer>> _layers;
|
||||
std::vector<std::shared_ptr<Layer>> _activeLayers;
|
||||
|
||||
properties::BoolProperty _levelBlendingEnabled;
|
||||
};
|
||||
|
||||
class LayerGroup;
|
||||
|
||||
/**
|
||||
* Manages multiple LayerGroups.
|
||||
@@ -0,0 +1,43 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/layer/layerrendersettings.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
LayerRenderSettings::LayerRenderSettings()
|
||||
: opacity(properties::FloatProperty("opacity", "opacity", 1.f, 0.f, 1.f))
|
||||
, gamma(properties::FloatProperty("gamma", "gamma", 1, 0, 5))
|
||||
, multiplier(properties::FloatProperty("multiplier", "multiplier", 1.f, 0.f, 20.f))
|
||||
{
|
||||
setName("settings");
|
||||
|
||||
addProperty(opacity);
|
||||
addProperty(gamma);
|
||||
addProperty(multiplier);
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,45 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___LAYERRENDERSETTINGS___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___LAYERRENDERSETTINGS___H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct LayerRenderSettings : public properties::PropertyOwner {
|
||||
LayerRenderSettings();
|
||||
properties::FloatProperty opacity;
|
||||
properties::FloatProperty gamma;
|
||||
properties::FloatProperty multiplier;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___LAYERRENDERSETTINGS___H__
|
||||
@@ -32,13 +32,13 @@
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
bool LayerGroupPreprocessingData::operator==(
|
||||
bool LayerShaderManager::LayerShaderPreprocessingData::LayerGroupPreprocessingData::operator==(
|
||||
const LayerGroupPreprocessingData& other) const {
|
||||
return lastLayerIdx == other.lastLayerIdx &&
|
||||
layerBlendingEnabled == other.layerBlendingEnabled;
|
||||
}
|
||||
|
||||
bool LayerShaderPreprocessingData::operator==(
|
||||
bool LayerShaderManager::LayerShaderPreprocessingData::operator==(
|
||||
const LayerShaderPreprocessingData& other) const {
|
||||
if (layeredTextureInfo.size() != other.layeredTextureInfo.size() ||
|
||||
keyValuePairs.size() != other.keyValuePairs.size()) {
|
||||
@@ -73,7 +73,7 @@ LayerShaderManager::~LayerShaderManager() {
|
||||
}
|
||||
}
|
||||
|
||||
ProgramObject* LayerShaderManager::programObject(
|
||||
ghoul::opengl::ProgramObject* LayerShaderManager::programObject(
|
||||
LayerShaderPreprocessingData preprocessingData)
|
||||
{
|
||||
_updatedOnLastCall = false;
|
||||
@@ -128,7 +128,7 @@ void LayerShaderManager::recompileShaderProgram(
|
||||
);
|
||||
|
||||
ghoul_assert(_programObject != nullptr, "Failed to initialize programObject!");
|
||||
using IgnoreError = ProgramObject::IgnoreError;
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::ProgramObject::IgnoreError;
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___LAYER_SHADER_MANAGER___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___LAYER_SHADER_MANAGER___H__
|
||||
|
||||
#include <modules/globebrowsing/rendering/layermanager.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
@@ -35,40 +35,41 @@ namespace opengl {
|
||||
class ProgramObject;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
/**
|
||||
* Settings per texture group that contains shader preprocessing information.
|
||||
*/
|
||||
struct LayerGroupPreprocessingData {
|
||||
int lastLayerIdx;
|
||||
bool layerBlendingEnabled;
|
||||
bool operator==(const LayerGroupPreprocessingData& other) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Data needed for shader preprocessing before compiling a layered texture shader
|
||||
* program.
|
||||
*
|
||||
* If a <code>LayerShaderPreprocessingData</code> is compared with another it can
|
||||
* be determined wheter or not a <code>LayerShaderManager</code> needs to
|
||||
* recompile its shader program. For each <code>TextureGroup</code> there is
|
||||
* information about how many layers it has and whether or not to blend the texture
|
||||
* levels.
|
||||
*/
|
||||
struct LayerShaderPreprocessingData {
|
||||
std::array<LayerGroupPreprocessingData, LayerManager::NUM_LAYER_GROUPS>
|
||||
layeredTextureInfo;
|
||||
std::vector<std::pair<std::string, std::string> > keyValuePairs;
|
||||
bool operator==(const LayerShaderPreprocessingData& other) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class has ownership of an updated shader program for rendering tiles.
|
||||
*/
|
||||
class LayerShaderManager {
|
||||
public:
|
||||
/**
|
||||
* Data needed for shader preprocessing before compiling a layered texture shader
|
||||
* program.
|
||||
*
|
||||
* If a <code>LayerShaderPreprocessingData</code> is compared with another it can
|
||||
* be determined wheter or not a <code>LayerShaderManager</code> needs to
|
||||
* recompile its shader program. For each <code>TextureGroup</code> there is
|
||||
* information about how many layers it has and whether or not to blend the texture
|
||||
* levels.
|
||||
*/
|
||||
struct LayerShaderPreprocessingData {
|
||||
/**
|
||||
* Settings per texture group that contains shader preprocessing information.
|
||||
*/
|
||||
struct LayerGroupPreprocessingData {
|
||||
int lastLayerIdx;
|
||||
bool layerBlendingEnabled;
|
||||
bool operator==(const LayerGroupPreprocessingData& other) const;
|
||||
};
|
||||
|
||||
std::array<LayerGroupPreprocessingData, LayerManager::NUM_LAYER_GROUPS>
|
||||
layeredTextureInfo;
|
||||
std::vector<std::pair<std::string, std::string> > keyValuePairs;
|
||||
bool operator==(const LayerShaderPreprocessingData& other) const;
|
||||
};
|
||||
|
||||
LayerShaderManager(
|
||||
const std::string& shaderName,
|
||||
const std::string& vsPath,
|
||||
@@ -82,7 +83,7 @@ public:
|
||||
* from the last time this function was called the shader program will be
|
||||
* recompiled before returned.
|
||||
*/
|
||||
ProgramObject* programObject(
|
||||
ghoul::opengl::ProgramObject* programObject(
|
||||
LayerShaderPreprocessingData preprocessingData);
|
||||
|
||||
bool updatedOnLastCall();
|
||||
@@ -91,7 +92,7 @@ private:
|
||||
|
||||
void recompileShaderProgram(LayerShaderPreprocessingData preprocessingData);
|
||||
|
||||
std::unique_ptr<ProgramObject> _programObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
LayerShaderPreprocessingData _preprocessingData;
|
||||
|
||||
const std::string _shaderName;
|
||||
|
||||
@@ -24,69 +24,13 @@
|
||||
|
||||
#include <modules/globebrowsing/tile/asynctilereader.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/loadjob/tileloadjob.h>
|
||||
#include <modules/globebrowsing/tile/tiledataset.h>
|
||||
#include <modules/globebrowsing/tile/tilediskcache.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void TileLoadJob::execute() {
|
||||
_rawTile = _tileDataset->readTileData(_chunkIndex);
|
||||
}
|
||||
|
||||
std::shared_ptr<RawTile> TileLoadJob::product() const {
|
||||
return _rawTile;
|
||||
}
|
||||
|
||||
DiskCachedTileLoadJob::DiskCachedTileLoadJob(
|
||||
std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const TileIndex& tileIndex,
|
||||
std::shared_ptr<TileDiskCache> tdc,
|
||||
CacheMode m)
|
||||
: TileLoadJob(textureDataProvider, tileIndex)
|
||||
, _tileDiskCache(tdc)
|
||||
, _mode(m)
|
||||
{}
|
||||
|
||||
void DiskCachedTileLoadJob::execute() {
|
||||
_rawTile = nullptr;
|
||||
|
||||
switch (_mode) {
|
||||
case CacheMode::Disabled:
|
||||
_rawTile = _tileDataset->readTileData(_chunkIndex);
|
||||
break;
|
||||
|
||||
case CacheMode::ReadOnly:
|
||||
_rawTile = _tileDiskCache->get(_chunkIndex);
|
||||
if (_rawTile == nullptr) {
|
||||
_rawTile = _tileDataset->readTileData(_chunkIndex);
|
||||
}
|
||||
break;
|
||||
|
||||
case CacheMode::ReadAndWrite:
|
||||
_rawTile = _tileDiskCache->get(_chunkIndex);
|
||||
if (_rawTile == nullptr) {
|
||||
_rawTile = _tileDataset->readTileData(_chunkIndex);
|
||||
_tileDiskCache->put(_chunkIndex, _rawTile);
|
||||
}
|
||||
break;
|
||||
|
||||
case CacheMode::WriteOnly:
|
||||
_rawTile = _tileDataset->readTileData(_chunkIndex);
|
||||
_tileDiskCache->put(_chunkIndex, _rawTile);
|
||||
break;
|
||||
|
||||
case CacheMode::CacheHitsOnly:
|
||||
_rawTile = _tileDiskCache->get(_chunkIndex);
|
||||
if (_rawTile == nullptr) {
|
||||
RawTile res = RawTile::createDefaultRes();
|
||||
res.tileIndex = _chunkIndex;
|
||||
_rawTile = std::make_shared<RawTile>(res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
AsyncTileDataProvider::AsyncTileDataProvider(std::shared_ptr<TileDataset> tileDataset,
|
||||
std::shared_ptr<ThreadPool> pool)
|
||||
: _tileDataset(tileDataset)
|
||||
|
||||
@@ -26,61 +26,17 @@
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___ASYNC_TILE_READER___H__
|
||||
|
||||
#include <modules/globebrowsing/other/concurrentjobmanager.h>
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
|
||||
class RawTile;
|
||||
class TileDataset;
|
||||
|
||||
struct LoadJob : public Job<RawTile> {
|
||||
virtual void execute() = 0;
|
||||
virtual std::shared_ptr<RawTile> product() const = 0;
|
||||
};
|
||||
|
||||
struct TileLoadJob : LoadJob {
|
||||
TileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const TileIndex& tileIndex)
|
||||
: _tileDataset(textureDataProvider)
|
||||
, _chunkIndex(tileIndex)
|
||||
{}
|
||||
|
||||
virtual ~TileLoadJob() = default;
|
||||
|
||||
virtual void execute() override;
|
||||
|
||||
virtual std::shared_ptr<RawTile> product() const override;
|
||||
|
||||
protected:
|
||||
TileIndex _chunkIndex;
|
||||
std::shared_ptr<TileDataset> _tileDataset;
|
||||
std::shared_ptr<RawTile> _rawTile;
|
||||
};
|
||||
|
||||
class TileDiskCache;
|
||||
|
||||
struct DiskCachedTileLoadJob : public TileLoadJob {
|
||||
enum CacheMode {
|
||||
Disabled,
|
||||
ReadOnly,
|
||||
ReadAndWrite,
|
||||
WriteOnly,
|
||||
CacheHitsOnly,
|
||||
};
|
||||
|
||||
DiskCachedTileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const TileIndex& tileIndex, std::shared_ptr<TileDiskCache> tdc,
|
||||
CacheMode cacheMode = CacheMode::ReadOnly);
|
||||
|
||||
void execute() override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<TileDiskCache> _tileDiskCache;
|
||||
CacheMode _mode;
|
||||
};
|
||||
|
||||
class AsyncTileDataProvider {
|
||||
public:
|
||||
AsyncTileDataProvider(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
@@ -101,7 +57,7 @@ protected:
|
||||
private:
|
||||
std::shared_ptr<TileDataset> _tileDataset;
|
||||
ConcurrentJobManager<RawTile> _concurrentJobManager;
|
||||
std::unordered_map<TileHashKey, TileIndex> _enqueuedTileRequests;
|
||||
std::unordered_map<TileIndex::TileHashKey, TileIndex> _enqueuedTileRequests;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
|
||||
@@ -39,9 +39,7 @@ struct ChunkTile {
|
||||
TileDepthTransform depthTransform;
|
||||
};
|
||||
|
||||
struct ChunkTilePile {
|
||||
std::vector<ChunkTile> chunkTiles;
|
||||
};
|
||||
using ChunkTilePile = std::vector<ChunkTile>;
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/tile/loadjob/diskcachedtileloadjob.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/rawtile.h>
|
||||
#include <modules/globebrowsing/tile/tiledataset.h>
|
||||
#include <modules/globebrowsing/tile/tilediskcache.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
DiskCachedTileLoadJob::DiskCachedTileLoadJob(
|
||||
std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const TileIndex& tileIndex,
|
||||
std::shared_ptr<TileDiskCache> tdc,
|
||||
CacheMode m)
|
||||
: TileLoadJob(textureDataProvider, tileIndex)
|
||||
, _tileDiskCache(tdc)
|
||||
, _mode(m)
|
||||
{}
|
||||
|
||||
void DiskCachedTileLoadJob::execute() {
|
||||
_rawTile = nullptr;
|
||||
|
||||
switch (_mode) {
|
||||
case CacheMode::Disabled:
|
||||
_rawTile = _tileDataset->readTileData(_chunkIndex);
|
||||
break;
|
||||
|
||||
case CacheMode::ReadOnly:
|
||||
_rawTile = _tileDiskCache->get(_chunkIndex);
|
||||
if (_rawTile == nullptr) {
|
||||
_rawTile = _tileDataset->readTileData(_chunkIndex);
|
||||
}
|
||||
break;
|
||||
|
||||
case CacheMode::ReadAndWrite:
|
||||
_rawTile = _tileDiskCache->get(_chunkIndex);
|
||||
if (_rawTile == nullptr) {
|
||||
_rawTile = _tileDataset->readTileData(_chunkIndex);
|
||||
_tileDiskCache->put(_chunkIndex, _rawTile);
|
||||
}
|
||||
break;
|
||||
|
||||
case CacheMode::WriteOnly:
|
||||
_rawTile = _tileDataset->readTileData(_chunkIndex);
|
||||
_tileDiskCache->put(_chunkIndex, _rawTile);
|
||||
break;
|
||||
|
||||
case CacheMode::CacheHitsOnly:
|
||||
_rawTile = _tileDiskCache->get(_chunkIndex);
|
||||
if (_rawTile == nullptr) {
|
||||
RawTile res = RawTile::createDefaultRes();
|
||||
res.tileIndex = _chunkIndex;
|
||||
_rawTile = std::make_shared<RawTile>(res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,58 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___DISKCACHEDTILELOADJOB___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___DISKCACHEDTILELOADJOB___H__
|
||||
|
||||
#include <modules/globebrowsing/tile/loadjob/tileloadjob.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class TileDiskCache;
|
||||
|
||||
struct DiskCachedTileLoadJob : public TileLoadJob {
|
||||
enum CacheMode {
|
||||
Disabled,
|
||||
ReadOnly,
|
||||
ReadAndWrite,
|
||||
WriteOnly,
|
||||
CacheHitsOnly,
|
||||
};
|
||||
|
||||
DiskCachedTileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const TileIndex& tileIndex, std::shared_ptr<TileDiskCache> tdc,
|
||||
CacheMode cacheMode = CacheMode::ReadOnly);
|
||||
|
||||
void execute() override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<TileDiskCache> _tileDiskCache;
|
||||
CacheMode _mode;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___DISKCACHEDTILELOADJOB___H__
|
||||
@@ -0,0 +1,45 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___LOADJOB___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___LOADJOB___H__
|
||||
|
||||
#include <modules/globebrowsing/other/concurrentjobmanager.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class RawTile;
|
||||
|
||||
struct LoadJob : public Job<RawTile> {
|
||||
virtual void execute() = 0;
|
||||
virtual std::shared_ptr<RawTile> product() const = 0;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___LOADJOB___H__
|
||||
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/tile/loadjob/tileloadjob.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tiledataset.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void TileLoadJob::execute() {
|
||||
_rawTile = _tileDataset->readTileData(_chunkIndex);
|
||||
}
|
||||
|
||||
std::shared_ptr<RawTile> TileLoadJob::product() const {
|
||||
return _rawTile;
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,61 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___TILELOADJOB___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___TILELOADJOB___H__
|
||||
|
||||
#include <modules/globebrowsing/tile/loadjob/loadjob.h>
|
||||
|
||||
#include <modules/globebrowsing/other/concurrentjobmanager.h>
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class TileDataset;
|
||||
class RawTile;
|
||||
|
||||
struct TileLoadJob : LoadJob {
|
||||
TileLoadJob(std::shared_ptr<TileDataset> textureDataProvider,
|
||||
const TileIndex& tileIndex)
|
||||
: _tileDataset(textureDataProvider)
|
||||
, _chunkIndex(tileIndex)
|
||||
{}
|
||||
|
||||
virtual ~TileLoadJob() = default;
|
||||
|
||||
virtual void execute() override;
|
||||
|
||||
virtual std::shared_ptr<RawTile> product() const override;
|
||||
|
||||
protected:
|
||||
TileIndex _chunkIndex;
|
||||
std::shared_ptr<TileDataset> _tileDataset;
|
||||
std::shared_ptr<RawTile> _rawTile;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___TILELOADJOB___H__
|
||||
@@ -42,18 +42,18 @@ PixelRegion::PixelRegion(const PixelRegion& o)
|
||||
|
||||
void PixelRegion::setSide(Side side, int pos) {
|
||||
switch (side) {
|
||||
case LEFT:
|
||||
setLeft(pos);
|
||||
break;
|
||||
case TOP:
|
||||
setTop(pos);
|
||||
break;
|
||||
case RIGHT:
|
||||
setRight(pos);
|
||||
break;
|
||||
case BOTTOM:
|
||||
setBottom(pos);
|
||||
break;
|
||||
case Side::LEFT:
|
||||
setLeft(pos);
|
||||
break;
|
||||
case Side::TOP:
|
||||
setTop(pos);
|
||||
break;
|
||||
case Side::RIGHT:
|
||||
setRight(pos);
|
||||
break;
|
||||
case Side::BOTTOM:
|
||||
setBottom(pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,18 +77,18 @@ void PixelRegion::setBottom(int y) {
|
||||
|
||||
void PixelRegion::align(Side side, int pos) {
|
||||
switch (side) {
|
||||
case LEFT:
|
||||
alignLeft(pos);
|
||||
break;
|
||||
case TOP:
|
||||
alignTop(pos);
|
||||
break;
|
||||
case RIGHT:
|
||||
alignRight(pos);
|
||||
break;
|
||||
case BOTTOM:
|
||||
alignBottom(pos);
|
||||
break;
|
||||
case Side::LEFT:
|
||||
alignLeft(pos);
|
||||
break;
|
||||
case Side::TOP:
|
||||
alignTop(pos);
|
||||
break;
|
||||
case Side::RIGHT:
|
||||
alignRight(pos);
|
||||
break;
|
||||
case Side::BOTTOM:
|
||||
alignBottom(pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,18 +137,18 @@ void PixelRegion::upscalePow2(int exponent, PixelCoordinate wrt) {
|
||||
|
||||
void PixelRegion::move(Side side, int amount) {
|
||||
switch (side) {
|
||||
case LEFT:
|
||||
start.x -= amount;
|
||||
break;
|
||||
case TOP:
|
||||
start.y -= amount;
|
||||
break;
|
||||
case RIGHT:
|
||||
start.x += amount;
|
||||
break;
|
||||
case BOTTOM:
|
||||
start.y += amount;
|
||||
break;
|
||||
case Side::LEFT:
|
||||
start.x -= amount;
|
||||
break;
|
||||
case Side::TOP:
|
||||
start.y -= amount;
|
||||
break;
|
||||
case Side::RIGHT:
|
||||
start.x += amount;
|
||||
break;
|
||||
case Side::BOTTOM:
|
||||
start.y += amount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,19 +198,19 @@ PixelRegion PixelRegion::globalCut(Side side, int p) {
|
||||
PixelRegion cutOff(*this);
|
||||
int cutSize = 0;
|
||||
switch (side) {
|
||||
case LEFT:
|
||||
case Side::LEFT:
|
||||
setLeft(p);
|
||||
cutOff.setRight(p - cutSize);
|
||||
break;
|
||||
case TOP:
|
||||
case Side::TOP:
|
||||
setTop(p);
|
||||
cutOff.setBottom(p - cutSize);
|
||||
break;
|
||||
case RIGHT:
|
||||
case Side::RIGHT:
|
||||
setRight(p);
|
||||
cutOff.setLeft(p + cutSize);
|
||||
break;
|
||||
case BOTTOM:
|
||||
case Side::BOTTOM:
|
||||
setBottom(p);
|
||||
cutOff.setTop(p + cutSize);
|
||||
break;
|
||||
@@ -233,30 +233,34 @@ int PixelRegion::area() const {
|
||||
|
||||
int PixelRegion::edge(Side side) const {
|
||||
switch (side) {
|
||||
case LEFT: return start.x;
|
||||
case TOP: return start.y;
|
||||
case RIGHT: return start.x + numPixels.x;
|
||||
case BOTTOM: return start.y + numPixels.y;
|
||||
case Side::LEFT:
|
||||
return start.x;
|
||||
case Side::TOP:
|
||||
return start.y;
|
||||
case Side::RIGHT:
|
||||
return start.x + numPixels.x;
|
||||
case Side::BOTTOM:
|
||||
return start.y + numPixels.y;
|
||||
}
|
||||
}
|
||||
|
||||
int PixelRegion::edgeDirectionSign(Side side) const {
|
||||
return side < RIGHT ? -1 : 1;
|
||||
return side < Side::RIGHT ? -1 : 1;
|
||||
}
|
||||
|
||||
PixelCoordinate PixelRegion::end() const {
|
||||
PixelRegion::PixelCoordinate PixelRegion::end() const {
|
||||
return start + numPixels;
|
||||
}
|
||||
|
||||
bool PixelRegion::lineIntersect(Side side, int p) {
|
||||
switch (side) {
|
||||
case PixelRegion::LEFT:
|
||||
case PixelRegion::RIGHT:
|
||||
return start.x <= p && p <= (start.x + numPixels.x);
|
||||
case Side::LEFT:
|
||||
case Side::RIGHT:
|
||||
return start.x <= p && p <= (start.x + numPixels.x);
|
||||
|
||||
case PixelRegion::TOP:
|
||||
case PixelRegion::BOTTOM:
|
||||
return start.y <= p && p <= (start.y + numPixels.y);
|
||||
case Side::TOP:
|
||||
case Side::BOTTOM:
|
||||
return start.y <= p && p <= (start.y + numPixels.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,11 @@
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
using PixelCoordinate = glm::ivec2;
|
||||
using PixelRange= glm::ivec2;
|
||||
|
||||
struct PixelRegion {
|
||||
enum Side {
|
||||
using PixelCoordinate = glm::ivec2;
|
||||
using PixelRange = glm::ivec2;
|
||||
|
||||
enum class Side {
|
||||
LEFT = 0,
|
||||
TOP,
|
||||
RIGHT,
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___QUAD___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___QUAD___H__
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
enum Quad {
|
||||
NORTH_WEST = 0,
|
||||
NORTH_EAST,
|
||||
SOUTH_WEST,
|
||||
SOUTH_EAST
|
||||
};
|
||||
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___QUAD___H__
|
||||
@@ -0,0 +1,96 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/tile/rawtile.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tilemetadata.h>
|
||||
|
||||
#include <gdal_priv.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "Tile";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
RawTile::RawTile()
|
||||
: imageData(nullptr)
|
||||
, dimensions(0, 0, 0)
|
||||
, tileMetaData(nullptr)
|
||||
, tileIndex(0, 0, 0)
|
||||
, error(CE_None)
|
||||
, nBytesImageData(0)
|
||||
{}
|
||||
|
||||
RawTile RawTile::createDefaultRes() {
|
||||
RawTile defaultRes;
|
||||
int w = 8;
|
||||
int h = 8;
|
||||
defaultRes.dimensions = glm::uvec3(w, h, 1);
|
||||
defaultRes.nBytesImageData = w * h * 1 * 3 * 4; // assume max 3 channels, max 4 bytes per pixel
|
||||
defaultRes.imageData = new char[defaultRes.nBytesImageData];
|
||||
std::fill_n((char*)defaultRes.imageData, defaultRes.nBytesImageData, 0);
|
||||
return std::move(defaultRes);
|
||||
}
|
||||
|
||||
void RawTile::serializeMetaData(std::ostream& os) {
|
||||
os << dimensions.x << " " << dimensions.y << " " << dimensions.z << std::endl;
|
||||
os << tileIndex.x << " " << tileIndex.y << " " << tileIndex.level << std::endl;
|
||||
os << error << std::endl;
|
||||
|
||||
// preprocess data
|
||||
os << (tileMetaData != nullptr) << std::endl;
|
||||
if (tileMetaData != nullptr) {
|
||||
tileMetaData->serialize(os);
|
||||
}
|
||||
|
||||
os << nBytesImageData << std::endl;
|
||||
}
|
||||
|
||||
RawTile RawTile::deserializeMetaData(std::istream& is) {
|
||||
RawTile res;
|
||||
is >> res.dimensions.x >> res.dimensions.y >> res.dimensions.z;
|
||||
is >> res.tileIndex.x >> res.tileIndex.y >> res.tileIndex.level;
|
||||
int err; is >> err; res.error = (CPLErr) err;
|
||||
|
||||
res.tileMetaData = nullptr;
|
||||
bool hastileMetaData;
|
||||
is >> hastileMetaData;
|
||||
if (hastileMetaData) {
|
||||
TileMetaData tileMetaData = TileMetaData::deserialize(is);
|
||||
res.tileMetaData = std::make_shared<TileMetaData>(tileMetaData);
|
||||
}
|
||||
|
||||
is >> res.nBytesImageData;
|
||||
|
||||
char binaryDataSeparator;
|
||||
is >> binaryDataSeparator; // not used
|
||||
|
||||
char* buffer = new char[res.nBytesImageData]();
|
||||
return std::move(res);
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,61 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___RAWTILE___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___RAWTILE___H__
|
||||
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <cpl_error.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct TileMetaData;
|
||||
|
||||
struct RawTile {
|
||||
RawTile();
|
||||
|
||||
char* imageData;
|
||||
glm::uvec3 dimensions;
|
||||
std::shared_ptr<TileMetaData> tileMetaData;
|
||||
TileIndex tileIndex;
|
||||
CPLErr error;
|
||||
size_t nBytesImageData;
|
||||
|
||||
void serializeMetaData(std::ostream& s);
|
||||
static RawTile deserializeMetaData(std::istream& s);
|
||||
|
||||
static RawTile createDefaultRes();
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___RAWTILE___H__
|
||||
@@ -0,0 +1,43 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___TEXTUREFORMAT___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___TEXTUREFORMAT___H__
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct TextureFormat {
|
||||
ghoul::opengl::Texture::Format ghoulFormat;
|
||||
GLuint glFormat;
|
||||
};
|
||||
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___TEXTUREFORMAT___H__
|
||||
@@ -33,90 +33,6 @@ namespace {
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
void TileMetaData::serialize(std::ostream& os) {
|
||||
os << maxValues.size() << std::endl;
|
||||
for (float f : maxValues) {
|
||||
os << f << " ";
|
||||
}
|
||||
os << std::endl;
|
||||
for (float f : minValues) {
|
||||
os << f << " ";
|
||||
}
|
||||
os << std::endl;
|
||||
}
|
||||
|
||||
TileMetaData TileMetaData::deserialize(std::istream& is) {
|
||||
TileMetaData res;
|
||||
int n; is >> n;
|
||||
res.maxValues.resize(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
is >> res.maxValues[i];
|
||||
}
|
||||
res.minValues.resize(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
is >> res.minValues[i];
|
||||
}
|
||||
|
||||
return std::move(res);
|
||||
}
|
||||
|
||||
RawTile::RawTile()
|
||||
: imageData(nullptr)
|
||||
, dimensions(0, 0, 0)
|
||||
, tileMetaData(nullptr)
|
||||
, tileIndex(0, 0, 0)
|
||||
, error(CE_None)
|
||||
, nBytesImageData(0)
|
||||
{}
|
||||
|
||||
RawTile RawTile::createDefaultRes() {
|
||||
RawTile defaultRes;
|
||||
int w = 8;
|
||||
int h = 8;
|
||||
defaultRes.dimensions = glm::uvec3(w, h, 1);
|
||||
defaultRes.nBytesImageData = w * h * 1 * 3 * 4; // assume max 3 channels, max 4 bytes per pixel
|
||||
defaultRes.imageData = new char[defaultRes.nBytesImageData];
|
||||
std::fill_n((char*)defaultRes.imageData, defaultRes.nBytesImageData, 0);
|
||||
return std::move(defaultRes);
|
||||
}
|
||||
|
||||
void RawTile::serializeMetaData(std::ostream& os) {
|
||||
os << dimensions.x << " " << dimensions.y << " " << dimensions.z << std::endl;
|
||||
os << tileIndex.x << " " << tileIndex.y << " " << tileIndex.level << std::endl;
|
||||
os << error << std::endl;
|
||||
|
||||
// preprocess data
|
||||
os << (tileMetaData != nullptr) << std::endl;
|
||||
if (tileMetaData != nullptr) {
|
||||
tileMetaData->serialize(os);
|
||||
}
|
||||
|
||||
os << nBytesImageData << std::endl;
|
||||
}
|
||||
|
||||
RawTile RawTile::deserializeMetaData(std::istream& is) {
|
||||
RawTile res;
|
||||
is >> res.dimensions.x >> res.dimensions.y >> res.dimensions.z;
|
||||
is >> res.tileIndex.x >> res.tileIndex.y >> res.tileIndex.level;
|
||||
int err; is >> err; res.error = (CPLErr) err;
|
||||
|
||||
res.tileMetaData = nullptr;
|
||||
bool hastileMetaData;
|
||||
is >> hastileMetaData;
|
||||
if (hastileMetaData) {
|
||||
TileMetaData tileMetaData = TileMetaData::deserialize(is);
|
||||
res.tileMetaData = std::make_shared<TileMetaData>(tileMetaData);
|
||||
}
|
||||
|
||||
is >> res.nBytesImageData;
|
||||
|
||||
char binaryDataSeparator;
|
||||
is >> binaryDataSeparator; // not used
|
||||
|
||||
char* buffer = new char[res.nBytesImageData]();
|
||||
return std::move(res);
|
||||
}
|
||||
|
||||
const Tile Tile::TileUnavailable = {nullptr, nullptr, Tile::Status::Unavailable };
|
||||
|
||||
Tile Tile::createPlainTile(const glm::uvec2& size, const glm::uvec4& color) {
|
||||
@@ -160,7 +76,7 @@ glm::vec2 Tile::compensateSourceTextureSampling(glm::vec2 startOffset, glm::vec2
|
||||
return tileUV;
|
||||
}
|
||||
|
||||
glm::vec2 Tile::TileUvToTextureSamplePosition(const TileUvTransform uvTransform,
|
||||
glm::vec2 Tile::TileUvToTextureSamplePosition(const TileUvTransform& uvTransform,
|
||||
glm::vec2 tileUV, glm::uvec2 resolution)
|
||||
{
|
||||
glm::vec2 uv = uvTransform.uvOffset + uvTransform.uvScale * tileUV;
|
||||
|
||||
@@ -27,57 +27,25 @@
|
||||
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <modules/globebrowsing/tile/tileuvtransform.h>
|
||||
|
||||
#include <cpl_error.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class Texture;
|
||||
}}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct TileMetaData {
|
||||
std::vector<float> maxValues;
|
||||
std::vector<float> minValues;
|
||||
std::vector<bool> hasMissingData;
|
||||
|
||||
void serialize(std::ostream& s);
|
||||
static TileMetaData deserialize(std::istream& s);
|
||||
};
|
||||
|
||||
struct TextureFormat {
|
||||
ghoul::opengl::Texture::Format ghoulFormat;
|
||||
GLuint glFormat;
|
||||
};
|
||||
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
struct RawTile {
|
||||
RawTile();
|
||||
|
||||
char* imageData;
|
||||
glm::uvec3 dimensions;
|
||||
std::shared_ptr<TileMetaData> tileMetaData;
|
||||
TileIndex tileIndex;
|
||||
CPLErr error;
|
||||
size_t nBytesImageData;
|
||||
|
||||
void serializeMetaData(std::ostream& s);
|
||||
static RawTile deserializeMetaData(std::istream& s);
|
||||
|
||||
static RawTile createDefaultRes();
|
||||
};
|
||||
|
||||
struct TileUvTransform {
|
||||
glm::vec2 uvOffset;
|
||||
glm::vec2 uvScale;
|
||||
};
|
||||
struct TileMetaData;
|
||||
struct TileUvTransform;
|
||||
|
||||
/**
|
||||
* Defines a status and may have a Texture and TileMetaData
|
||||
*/
|
||||
struct Tile {
|
||||
std::shared_ptr<Texture> texture;
|
||||
std::shared_ptr<ghoul::opengl::Texture> texture;
|
||||
std::shared_ptr<TileMetaData> metaData;
|
||||
|
||||
/**
|
||||
@@ -126,7 +94,7 @@ struct Tile {
|
||||
static glm::vec2 compensateSourceTextureSampling(glm::vec2 startOffset,
|
||||
glm::vec2 sizeDiff, glm::uvec2 resolution, glm::vec2 tileUV);
|
||||
|
||||
static glm::vec2 TileUvToTextureSamplePosition(const TileUvTransform uvTransform,
|
||||
static glm::vec2 TileUvToTextureSamplePosition(const TileUvTransform& uvTransform,
|
||||
glm::vec2 tileUV, glm::uvec2 resolution);
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/tile/tiledatalayout.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <ogr_featurestyle.h>
|
||||
#include <ogr_spatialref.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h> // abspath
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
|
||||
|
||||
#include <modules/globebrowsing/geometry/angle.h>
|
||||
|
||||
#include <float.h>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <gdal_priv.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <ghoul/filesystem/file.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/misc/threadpool.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
#include <modules/globebrowsing/tile/tiledatatype.h>
|
||||
#include <modules/globebrowsing/tile/tiledepthtransform.h>
|
||||
#include <modules/globebrowsing/tile/pixelregion.h>
|
||||
#include <modules/globebrowsing/tile/rawtile.h>
|
||||
#include <modules/globebrowsing/tile/tilemetadata.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/geodeticpatch.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TileDataset";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
TileDataLayout::TileDataLayout() {}
|
||||
|
||||
TileDataLayout::TileDataLayout(GDALDataset* dataSet, GLuint preferredGlType) {
|
||||
// Assume all raster bands have the same data type
|
||||
gdalType =preferredGlType != 0 ?
|
||||
tiledatatype::getGdalDataType(preferredGlType) :
|
||||
dataSet->GetRasterBand(1)->GetRasterDataType();
|
||||
|
||||
glType = tiledatatype::getOpenGLDataType(gdalType);
|
||||
numRasters = dataSet->GetRasterCount();
|
||||
bytesPerDatum = tiledatatype::numberOfBytes(gdalType);
|
||||
bytesPerPixel = bytesPerDatum * numRasters;
|
||||
textureFormat = tiledatatype::getTextureFormat(numRasters, gdalType);
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,57 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___TILEDATALAYOUT___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___TILEDATALAYOUT___H__
|
||||
|
||||
#include <modules/globebrowsing/tile/textureformat.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
#include <gdal.h>
|
||||
|
||||
class GDALDataset;
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct TileDataLayout {
|
||||
TileDataLayout();
|
||||
TileDataLayout(GDALDataset* dataSet, GLuint preferredGlType);
|
||||
|
||||
GDALDataType gdalType;
|
||||
GLuint glType;
|
||||
|
||||
size_t bytesPerDatum;
|
||||
size_t numRasters;
|
||||
size_t bytesPerPixel;
|
||||
|
||||
TextureFormat textureFormat;
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___TILEDATALAYOUT___H__
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include <modules/globebrowsing/tile/tiledataset.h>
|
||||
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <ogr_featurestyle.h>
|
||||
@@ -62,8 +61,10 @@
|
||||
#include <modules/globebrowsing/tile/tiledatatype.h>
|
||||
#include <modules/globebrowsing/tile/tiledepthtransform.h>
|
||||
#include <modules/globebrowsing/tile/pixelregion.h>
|
||||
#include <modules/globebrowsing/tile/rawtile.h>
|
||||
#include <modules/globebrowsing/tile/tilemetadata.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodeticpatch.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TileDataset";
|
||||
@@ -81,17 +82,17 @@ TileDataLayout::TileDataLayout() {}
|
||||
TileDataLayout::TileDataLayout(GDALDataset* dataSet, GLuint preferredGlType) {
|
||||
// Assume all raster bands have the same data type
|
||||
gdalType =preferredGlType != 0 ?
|
||||
TileDataType::getGdalDataType(preferredGlType) :
|
||||
tiledatatype::getGdalDataType(preferredGlType) :
|
||||
dataSet->GetRasterBand(1)->GetRasterDataType();
|
||||
|
||||
glType = TileDataType::getOpenGLDataType(gdalType);
|
||||
glType = tiledatatype::getOpenGLDataType(gdalType);
|
||||
numRasters = dataSet->GetRasterCount();
|
||||
bytesPerDatum = TileDataType::numberOfBytes(gdalType);
|
||||
bytesPerDatum = tiledatatype::numberOfBytes(gdalType);
|
||||
bytesPerPixel = bytesPerDatum * numRasters;
|
||||
textureFormat = TileDataType::getTextureFormat(numRasters, gdalType);
|
||||
textureFormat = tiledatatype::getTextureFormat(numRasters, gdalType);
|
||||
}
|
||||
|
||||
IODescription IODescription::cut(PixelRegion::Side side, int pos) {
|
||||
TileDataset::IODescription TileDataset::IODescription::cut(PixelRegion::Side side, int pos) {
|
||||
PixelRegion readPreCut = read.region;
|
||||
PixelRegion writePreCut = write.region;
|
||||
|
||||
@@ -106,8 +107,8 @@ IODescription IODescription::cut(PixelRegion::Side side, int pos) {
|
||||
IODescription whatCameOff = *this;
|
||||
whatCameOff.read.region = read.region.globalCut(side, pos);
|
||||
|
||||
PixelRange cutSize = whatCameOff.read.region.numPixels;
|
||||
PixelRange localWriteCutSize = ratio * glm::dvec2(cutSize);
|
||||
PixelRegion::PixelRange cutSize = whatCameOff.read.region.numPixels;
|
||||
PixelRegion::PixelRange localWriteCutSize = ratio * glm::dvec2(cutSize);
|
||||
|
||||
if (cutSize.x == 0 || cutSize.y == 0) {
|
||||
ghoul_assert(
|
||||
@@ -120,7 +121,8 @@ IODescription IODescription::cut(PixelRegion::Side side, int pos) {
|
||||
);
|
||||
}
|
||||
|
||||
int localWriteCutPos = (side % 2 == 0) ? localWriteCutSize.x : localWriteCutSize.y;
|
||||
int localWriteCutPos = (side == PixelRegion::Side::LEFT || side == PixelRegion::Side::RIGHT)
|
||||
? localWriteCutSize.x : localWriteCutSize.y;
|
||||
whatCameOff.write.region = write.region.localCut(side, localWriteCutPos);
|
||||
|
||||
return whatCameOff;
|
||||
@@ -321,7 +323,10 @@ std::shared_ptr<RawTile> TileDataset::readTileData(TileIndex tileIndex) {
|
||||
|
||||
std::shared_ptr<RawTile> TileDataset::defaultTileData() {
|
||||
ensureInitialized();
|
||||
PixelRegion pixelRegion = { PixelCoordinate(0, 0), PixelRange(16, 16) };
|
||||
PixelRegion pixelRegion = {
|
||||
PixelRegion::PixelCoordinate(0, 0),
|
||||
PixelRegion::PixelRange(16, 16)
|
||||
};
|
||||
std::shared_ptr<RawTile> rawTile = std::make_shared<RawTile>();
|
||||
rawTile->tileIndex = { 0, 0, 0 };
|
||||
rawTile->dimensions = glm::uvec3(pixelRegion.numPixels, 1);
|
||||
@@ -385,7 +390,7 @@ TileDepthTransform TileDataset::calculateTileDepthTransform() {
|
||||
bool isFloat =
|
||||
(_dataLayout.gdalType == GDT_Float32 || _dataLayout.gdalType == GDT_Float64);
|
||||
double maximumValue =
|
||||
isFloat ? 1.0 : TileDataType::getMaximumValue(_dataLayout.gdalType);
|
||||
isFloat ? 1.0 : tiledatatype::getMaximumValue(_dataLayout.gdalType);
|
||||
|
||||
TileDepthTransform transform;
|
||||
transform.depthOffset = firstBand->GetOffset();
|
||||
@@ -397,7 +402,7 @@ bool TileDataset::gdalHasOverviews() const {
|
||||
return _dataset->GetRasterBand(1)->GetOverviewCount() > 0;
|
||||
}
|
||||
|
||||
int TileDataset::gdalOverview(const PixelRange& regionSizeOverviewZero) const {
|
||||
int TileDataset::gdalOverview(const PixelRegion::PixelRange& regionSizeOverviewZero) const {
|
||||
GDALRasterBand* firstBand = _dataset->GetRasterBand(1);
|
||||
|
||||
int minNumPixels0 = glm::min(regionSizeOverviewZero.x, regionSizeOverviewZero.y);
|
||||
@@ -441,8 +446,8 @@ PixelRegion TileDataset::gdalPixelRegion(GDALRasterBand* rasterBand) const {
|
||||
PixelRegion TileDataset::gdalPixelRegion(const GeodeticPatch& geodeticPatch) const {
|
||||
Geodetic2 nwCorner = geodeticPatch.getCorner(Quad::NORTH_WEST);
|
||||
Geodetic2 swCorner = geodeticPatch.getCorner(Quad::SOUTH_EAST);
|
||||
PixelCoordinate pixelStart = geodeticToPixel(nwCorner);
|
||||
PixelCoordinate pixelEnd = geodeticToPixel(swCorner);
|
||||
PixelRegion::PixelCoordinate pixelStart = geodeticToPixel(nwCorner);
|
||||
PixelRegion::PixelCoordinate pixelEnd = geodeticToPixel(swCorner);
|
||||
PixelRegion gdalRegion(pixelStart, pixelEnd - pixelStart);
|
||||
return gdalRegion;
|
||||
}
|
||||
@@ -474,7 +479,7 @@ std::array<double, 6> TileDataset::getGeoTransform() const {
|
||||
return padfTransform;
|
||||
}
|
||||
|
||||
PixelCoordinate TileDataset::geodeticToPixel(const Geodetic2& geo) const {
|
||||
PixelRegion::PixelCoordinate TileDataset::geodeticToPixel(const Geodetic2& geo) const {
|
||||
std::array<double, 6> padfTransform = getGeoTransform();
|
||||
|
||||
double Y = Angle<double>::fromRadians(geo.lat).asDegrees();
|
||||
@@ -505,10 +510,10 @@ PixelCoordinate TileDataset::geodeticToPixel(const Geodetic2& geo) const {
|
||||
ghoul_assert(abs(X - Xp) < 1e-10, "inverse should yield X as before");
|
||||
ghoul_assert(abs(Y - Yp) < 1e-10, "inverse should yield Y as before");
|
||||
|
||||
return PixelCoordinate(glm::round(P), glm::round(L));
|
||||
return PixelRegion::PixelCoordinate(glm::round(P), glm::round(L));
|
||||
}
|
||||
|
||||
Geodetic2 TileDataset::pixelToGeodetic(const PixelCoordinate& p) const {
|
||||
Geodetic2 TileDataset::pixelToGeodetic(const PixelRegion::PixelCoordinate& p) const {
|
||||
std::array<double, 6> padfTransform = getGeoTransform();
|
||||
Geodetic2 geodetic;
|
||||
// Should be using radians and not degrees?
|
||||
@@ -517,7 +522,7 @@ Geodetic2 TileDataset::pixelToGeodetic(const PixelCoordinate& p) const {
|
||||
return geodetic;
|
||||
}
|
||||
|
||||
IODescription TileDataset::getIODescription(const TileIndex& tileIndex) const {
|
||||
TileDataset::IODescription TileDataset::getIODescription(const TileIndex& tileIndex) const {
|
||||
IODescription io;
|
||||
io.read.region = gdalPixelRegion(tileIndex);
|
||||
|
||||
@@ -541,14 +546,14 @@ IODescription TileDataset::getIODescription(const TileIndex& tileIndex) const {
|
||||
|
||||
// For correct sampling in height dataset, we need to pad the texture tile
|
||||
io.write.region.pad(padding);
|
||||
PixelRange preRound = io.write.region.numPixels;
|
||||
PixelRegion::PixelRange preRound = io.write.region.numPixels;
|
||||
io.write.region.roundDownToQuadratic();
|
||||
io.write.region.roundUpNumPixelToNearestMultipleOf(2);
|
||||
if (preRound != io.write.region.numPixels) {
|
||||
LDEBUG(tileIndex << " | " << preRound.x << ", " << preRound.y << " --> " << io.write.region.numPixels.x << ", " << io.write.region.numPixels.y);
|
||||
}
|
||||
|
||||
io.write.region.start = PixelCoordinate(0, 0); // write region starts in origin
|
||||
io.write.region.start = PixelRegion::PixelCoordinate(0, 0); // write region starts in origin
|
||||
io.write.bytesPerLine = _dataLayout.bytesPerPixel * io.write.region.numPixels.x;
|
||||
io.write.totalNumBytes = io.write.bytesPerLine * io.write.region.numPixels.y;
|
||||
|
||||
@@ -705,7 +710,7 @@ CPLErr TileDataset::rasterIO(GDALRasterBand* rasterBand, const IODescription& io
|
||||
"Invalid write region"
|
||||
);
|
||||
|
||||
PixelCoordinate end = io.write.region.end();
|
||||
PixelRegion::PixelCoordinate end = io.write.region.end();
|
||||
size_t largestIndex =
|
||||
(end.y - 1) * io.write.bytesPerLine + (end.x - 1) * _dataLayout.bytesPerPixel;
|
||||
ghoul_assert(largestIndex <= io.write.totalNumBytes, "Invalid write region");
|
||||
@@ -765,7 +770,7 @@ std::shared_ptr<TileMetaData> TileDataset::getTileMetaData(
|
||||
for (size_t x = 0; x < region.numPixels.x; x++) {
|
||||
for (size_t c = 0; c < _dataLayout.numRasters; c++) {
|
||||
float noDataValue = _dataset->GetRasterBand(c + 1)->GetNoDataValue();
|
||||
float val = TileDataType::interpretFloat(
|
||||
float val = tiledatatype::interpretFloat(
|
||||
_dataLayout.gdalType,
|
||||
&(rawTile->imageData[yi + i])
|
||||
);
|
||||
@@ -818,7 +823,7 @@ CPLErr TileDataset::postProcessErrorCheck(std::shared_ptr<const RawTile> rawTile
|
||||
return CE_Fatal;
|
||||
}
|
||||
// ugly test for heightmap overlay
|
||||
if (_dataLayout.textureFormat.ghoulFormat == Texture::Format::RG) {
|
||||
if (_dataLayout.textureFormat.ghoulFormat == ghoul::opengl::Texture::Format::RG) {
|
||||
// check the alpha
|
||||
if (rawTile->tileMetaData->maxValues[1] == 0.0
|
||||
&& rawTile->tileMetaData->minValues[1] == 0.0)
|
||||
|
||||
@@ -25,13 +25,16 @@
|
||||
#ifndef __OPENSPACE_MODULE_GLOBEBROWSING___TILE_DATASET___H__
|
||||
#define __OPENSPACE_MODULE_GLOBEBROWSING___TILE_DATASET___H__
|
||||
|
||||
#include <modules/globebrowsing/tile/textureformat.h>
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
#include <modules/globebrowsing/tile/tiledepthtransform.h>
|
||||
#include <modules/globebrowsing/tile/tiledatalayout.h>
|
||||
#include <modules/globebrowsing/tile/tiledataset.h>
|
||||
#include <modules/globebrowsing/tile/pixelregion.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <gdal.h>
|
||||
#include <string>
|
||||
@@ -42,37 +45,9 @@ class GDALRasterBand;
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
class RawTile;
|
||||
class GeodeticPatch;
|
||||
|
||||
struct TileDataLayout {
|
||||
TileDataLayout();
|
||||
TileDataLayout(GDALDataset* dataSet, GLuint preferredGlType);
|
||||
|
||||
GDALDataType gdalType;
|
||||
GLuint glType;
|
||||
|
||||
size_t bytesPerDatum;
|
||||
size_t numRasters;
|
||||
size_t bytesPerPixel;
|
||||
|
||||
TextureFormat textureFormat;
|
||||
};
|
||||
|
||||
struct IODescription {
|
||||
struct ReadData {
|
||||
int overview;
|
||||
PixelRegion region;
|
||||
} read;
|
||||
|
||||
struct WriteData {
|
||||
PixelRegion region;
|
||||
size_t bytesPerLine;
|
||||
size_t totalNumBytes;
|
||||
} write;
|
||||
|
||||
IODescription cut(PixelRegion::Side side, int pos);
|
||||
};
|
||||
|
||||
class TileDataset {
|
||||
public:
|
||||
struct Configuration {
|
||||
@@ -113,6 +88,21 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
struct IODescription {
|
||||
struct ReadData {
|
||||
int overview;
|
||||
PixelRegion region;
|
||||
} read;
|
||||
|
||||
struct WriteData {
|
||||
PixelRegion region;
|
||||
size_t bytesPerLine;
|
||||
size_t totalNumBytes;
|
||||
} write;
|
||||
|
||||
IODescription cut(PixelRegion::Side side, int pos);
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// Initialization //
|
||||
@@ -132,7 +122,7 @@ private:
|
||||
void setGdalProxyConfiguration();
|
||||
GDALDataset* gdalDataset(const std::string& gdalDatasetDesc);
|
||||
bool gdalHasOverviews() const;
|
||||
int gdalOverview(const PixelRange& baseRegionSize) const;
|
||||
int gdalOverview(const PixelRegion::PixelRange& baseRegionSize) const;
|
||||
int gdalOverview(const TileIndex& tileIndex) const;
|
||||
int gdalVirtualOverview(const TileIndex& tileIndex) const;
|
||||
PixelRegion gdalPixelRegion(const GeodeticPatch& geodeticPatch) const;
|
||||
@@ -153,8 +143,8 @@ private:
|
||||
*/
|
||||
std::array<double, 6> getGeoTransform() const;
|
||||
|
||||
PixelCoordinate geodeticToPixel(const Geodetic2& geo) const;
|
||||
Geodetic2 pixelToGeodetic(const PixelCoordinate& p) const;
|
||||
PixelRegion::PixelCoordinate geodeticToPixel(const Geodetic2& geo) const;
|
||||
Geodetic2 pixelToGeodetic(const PixelRegion::PixelCoordinate& p) const;
|
||||
IODescription getIODescription(const TileIndex& tileIndex) const;
|
||||
char* readImageData(IODescription& io, CPLErr& worstError) const;
|
||||
CPLErr rasterIO(GDALRasterBand* rasterBand, const IODescription& io, char* dst) const;
|
||||
|
||||
@@ -44,8 +44,9 @@ namespace {
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
namespace tiledatatype {
|
||||
|
||||
float TileDataType::interpretFloat(GDALDataType gdalType, const char* src) {
|
||||
float interpretFloat(GDALDataType gdalType, const char* src) {
|
||||
switch (gdalType) {
|
||||
case GDT_Byte:
|
||||
return static_cast<float>(*reinterpret_cast<const GLubyte*>(src));
|
||||
@@ -66,7 +67,7 @@ float TileDataType::interpretFloat(GDALDataType gdalType, const char* src) {
|
||||
}
|
||||
}
|
||||
|
||||
size_t TileDataType::numberOfBytes(GDALDataType gdalType) {
|
||||
size_t numberOfBytes(GDALDataType gdalType) {
|
||||
switch (gdalType) {
|
||||
case GDT_Byte:
|
||||
return sizeof(GLubyte);
|
||||
@@ -88,7 +89,7 @@ size_t TileDataType::numberOfBytes(GDALDataType gdalType) {
|
||||
}
|
||||
}
|
||||
|
||||
size_t TileDataType::getMaximumValue(GDALDataType gdalType) {
|
||||
size_t getMaximumValue(GDALDataType gdalType) {
|
||||
switch (gdalType) {
|
||||
case GDT_Byte:
|
||||
return 1 << 8;
|
||||
@@ -106,14 +107,12 @@ size_t TileDataType::getMaximumValue(GDALDataType gdalType) {
|
||||
}
|
||||
}
|
||||
|
||||
TextureFormat TileDataType::getTextureFormat(
|
||||
int rasterCount, GDALDataType gdalType)
|
||||
{
|
||||
TextureFormat getTextureFormat(int rasterCount, GDALDataType gdalType) {
|
||||
TextureFormat format;
|
||||
|
||||
switch (rasterCount) {
|
||||
case 1: // Red
|
||||
format.ghoulFormat = Texture::Format::Red;
|
||||
format.ghoulFormat = ghoul::opengl::Texture::Format::Red;
|
||||
switch (gdalType) {
|
||||
case GDT_Byte:
|
||||
format.glFormat = GL_R8;
|
||||
@@ -142,7 +141,7 @@ TextureFormat TileDataType::getTextureFormat(
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
format.ghoulFormat = Texture::Format::RG;
|
||||
format.ghoulFormat = ghoul::opengl::Texture::Format::RG;
|
||||
switch (gdalType) {
|
||||
case GDT_Byte:
|
||||
format.glFormat = GL_RG8;
|
||||
@@ -170,7 +169,7 @@ TextureFormat TileDataType::getTextureFormat(
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
format.ghoulFormat = Texture::Format::RGB;
|
||||
format.ghoulFormat = ghoul::opengl::Texture::Format::RGB;
|
||||
switch (gdalType) {
|
||||
case GDT_Byte:
|
||||
format.glFormat = GL_RGB8;
|
||||
@@ -199,7 +198,7 @@ TextureFormat TileDataType::getTextureFormat(
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
format.ghoulFormat = Texture::Format::RGBA;
|
||||
format.ghoulFormat = ghoul::opengl::Texture::Format::RGBA;
|
||||
switch (gdalType) {
|
||||
case GDT_Byte:
|
||||
format.glFormat = GL_RGBA8;
|
||||
@@ -234,7 +233,7 @@ TextureFormat TileDataType::getTextureFormat(
|
||||
return format;
|
||||
}
|
||||
|
||||
GLuint TileDataType::getOpenGLDataType(GDALDataType gdalType) {
|
||||
GLuint getOpenGLDataType(GDALDataType gdalType) {
|
||||
switch (gdalType) {
|
||||
case GDT_Byte:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
@@ -256,7 +255,7 @@ GLuint TileDataType::getOpenGLDataType(GDALDataType gdalType) {
|
||||
}
|
||||
}
|
||||
|
||||
GDALDataType TileDataType::getGdalDataType(GLuint glType) {
|
||||
GDALDataType getGdalDataType(GLuint glType) {
|
||||
switch (glType) {
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return GDT_Byte;
|
||||
@@ -278,5 +277,6 @@ GDALDataType TileDataType::getGdalDataType(GLuint glType) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace tiledatatype
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
@@ -27,27 +27,29 @@
|
||||
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/textureformat.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
#include <gdal.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
namespace tiledatatype {
|
||||
|
||||
struct TileDataType {
|
||||
static GLuint getOpenGLDataType(GDALDataType gdalType);
|
||||
GLuint getOpenGLDataType(GDALDataType gdalType);
|
||||
|
||||
static GDALDataType getGdalDataType(GLuint glType);
|
||||
GDALDataType getGdalDataType(GLuint glType);
|
||||
|
||||
static TextureFormat getTextureFormat(int rasterCount, GDALDataType gdalType);
|
||||
TextureFormat getTextureFormat(int rasterCount, GDALDataType gdalType);
|
||||
|
||||
static size_t getMaximumValue(GDALDataType gdalType);
|
||||
size_t getMaximumValue(GDALDataType gdalType);
|
||||
|
||||
static size_t numberOfBytes(GDALDataType gdalType);
|
||||
size_t numberOfBytes(GDALDataType gdalType);
|
||||
|
||||
static float interpretFloat(GDALDataType gdalType, const char* src);
|
||||
};
|
||||
float interpretFloat(GDALDataType gdalType, const char* src);
|
||||
|
||||
} // namespace tiledatatype
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <modules/globebrowsing/tile/tilediskcache.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/rawtile.h>
|
||||
#include <modules/globebrowsing/tile/tile.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
@@ -54,7 +54,6 @@ private:
|
||||
std::string getFilePath(const TileIndex& tileIndex) const;
|
||||
ghoul::filesystem::File getMetaDataFile(const TileIndex& tileIndex) const;
|
||||
ghoul::filesystem::File getDataFile(const TileIndex& tileIndex) const;
|
||||
|
||||
};
|
||||
|
||||
} // namespace globebrowsing
|
||||
|
||||
@@ -122,7 +122,7 @@ Creates a hash which can be used as key in hash maps.
|
||||
+-------+------------+-------+------------+
|
||||
|
||||
*/
|
||||
TileHashKey TileIndex::hashKey() const {
|
||||
TileIndex::TileHashKey TileIndex::hashKey() const {
|
||||
TileHashKey key = 0LL;
|
||||
key |= level;
|
||||
key |= x << 5;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user