mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-13 06:49:05 -05:00
Changed gdaldataconverter to TextureDataProvider. Clean up public interface and added skeleton interface for async data fetching
This commit is contained in:
@@ -52,7 +52,7 @@ set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/texturetileset.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/patchcoverageprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/gdaldataconverter.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/texturedataprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.h
|
||||
@@ -89,7 +89,7 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/texturetileset.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/patchcoverageprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/gdaldataconverter.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/texturedataprovider.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.cpp
|
||||
|
||||
+56
-20
@@ -31,6 +31,7 @@
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/other/threadpool.h>
|
||||
|
||||
#include "gdal_priv.h"
|
||||
|
||||
@@ -40,7 +41,7 @@
|
||||
namespace openspace {
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
struct UninitializedTextureTile {
|
||||
struct TextureData {
|
||||
|
||||
struct TextureFormat
|
||||
{
|
||||
@@ -48,12 +49,8 @@ namespace openspace {
|
||||
GLuint glFormat;
|
||||
};
|
||||
|
||||
UninitializedTextureTile(
|
||||
void* data,
|
||||
glm::uvec3 dims,
|
||||
TextureFormat format,
|
||||
GLuint glType,
|
||||
const ChunkIndex& chunkIndex)
|
||||
TextureData(void* data, glm::uvec3 dims, TextureFormat format,
|
||||
GLuint glType, const ChunkIndex& chunkIndex)
|
||||
: imageData(data)
|
||||
, dimensions(dims)
|
||||
, texFormat(format)
|
||||
@@ -70,32 +67,71 @@ namespace openspace {
|
||||
const ChunkIndex chunkIndex;
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
class GdalDataConverter
|
||||
class TextureDataProvider
|
||||
{
|
||||
public:
|
||||
|
||||
GdalDataConverter();
|
||||
~GdalDataConverter();
|
||||
TextureDataProvider();
|
||||
~TextureDataProvider();
|
||||
|
||||
std::shared_ptr<UninitializedTextureTile> getUninitializedTextureTile(
|
||||
GDALDataset * dataSet,
|
||||
ChunkIndex chunkIndex,
|
||||
int tileLevelDifference);
|
||||
|
||||
UninitializedTextureTile::TextureFormat getTextureFormat(
|
||||
int rasterCount,
|
||||
GDALDataType gdalType);
|
||||
GLuint getGlDataTypeFromGdalDataType(GDALDataType gdalType);
|
||||
std::shared_ptr<TextureData> getTextureData(
|
||||
GDALDataset * dataSet, ChunkIndex chunkIndex, int tileLevelDifference);
|
||||
|
||||
|
||||
|
||||
struct async {
|
||||
public:
|
||||
void request(GDALDataset * dataSet, ChunkIndex chunkIndex, int tileLevelDifference);
|
||||
void updateRequests();
|
||||
bool hasTextureTileData() const;
|
||||
std::shared_ptr<TextureData> nextTextureTile();
|
||||
|
||||
private:
|
||||
std::queue<std::shared_ptr<TextureData>> loadedTextureTiles;
|
||||
std::set<GDALAsyncReader*> asyncReaders;
|
||||
};
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// HELPER STRUCTS //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
struct GdalRequestParams {
|
||||
glm::uvec2 pixelStart;
|
||||
glm::uvec2 numPixels;
|
||||
GDALDataType dataType;
|
||||
int pixelSpacing;
|
||||
int lineSpacing;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// HELPER FUNCTIONS //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
glm::uvec2 geodeticToPixel(GDALDataset* dataSet, const Geodetic2& geo);
|
||||
|
||||
};
|
||||
GLuint getGlDataTypeFromGdalDataType(GDALDataType gdalType);
|
||||
|
||||
|
||||
TextureData::TextureFormat getTextureFormat(
|
||||
int rasterCount,
|
||||
GDALDataType gdalType);
|
||||
|
||||
|
||||
};
|
||||
} // namespace openspace
|
||||
|
||||
#include <modules/globebrowsing/other/texturedataprovider.inl>
|
||||
|
||||
|
||||
#include <modules/globebrowsing/other/gdaldataconverter.inl>
|
||||
|
||||
#endif // __GDALDATACONVERTER_H__
|
||||
+49
-14
@@ -23,7 +23,7 @@
|
||||
****************************************************************************************/
|
||||
|
||||
|
||||
#include <modules/globebrowsing/other/gdaldataconverter.h>
|
||||
#include <modules/globebrowsing/other/texturedataprovider.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
#include <modules/globebrowsing/geodetics/angle.h>
|
||||
|
||||
@@ -31,20 +31,22 @@
|
||||
namespace openspace {
|
||||
|
||||
template<class T>
|
||||
GdalDataConverter<T>::GdalDataConverter()
|
||||
TextureDataProvider<T>::TextureDataProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
GdalDataConverter<T>::~GdalDataConverter()
|
||||
TextureDataProvider<T>::~TextureDataProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<UninitializedTextureTile> GdalDataConverter<T>::getUninitializedTextureTile(
|
||||
std::shared_ptr<TextureData> TextureDataProvider<T>::getTextureData(
|
||||
GDALDataset* dataSet,
|
||||
ChunkIndex chunkIndex,
|
||||
int tileLevelDifference)
|
||||
@@ -94,6 +96,9 @@ namespace openspace {
|
||||
// GDAL reads image data top to bottom
|
||||
T* imageData = new T[numPixels.x * numPixels.y * nRasters];
|
||||
|
||||
int pixelSpacing = sizeof(T) * nRasters;
|
||||
int lineSpacing = pixelSpacing * numPixels.x;
|
||||
|
||||
// Read the data (each rasterband is a separate channel)
|
||||
for (size_t i = 0; i < nRasters; i++) {
|
||||
GDALRasterBand* rasterBand = dataSet->GetRasterBand(i + 1)->GetOverview(ov);
|
||||
@@ -101,6 +106,7 @@ namespace openspace {
|
||||
int xSize = rasterBand->GetXSize();
|
||||
int ySize = rasterBand->GetYSize();
|
||||
|
||||
|
||||
CPLErr err = rasterBand->RasterIO(
|
||||
GF_Read,
|
||||
pixelStart.x, // Begin read x
|
||||
@@ -111,8 +117,8 @@ namespace openspace {
|
||||
numPixels.x, // width to write x in destination
|
||||
numPixels.y, // width to write y in destination
|
||||
gdalType, // Type
|
||||
sizeof(T) * nRasters, // Pixel spacing
|
||||
0); // Line spacing
|
||||
pixelSpacing, // Pixel spacing
|
||||
lineSpacing); // Line spacing
|
||||
|
||||
if (err != CE_None) {
|
||||
;//LERROR("There was a IO error (" << err << ") for: " << dataSet->GetDescription());
|
||||
@@ -130,22 +136,22 @@ namespace openspace {
|
||||
delete[] imageData;
|
||||
|
||||
glm::uvec3 dims(numPixels.x, numPixels.y, 1);
|
||||
UninitializedTextureTile::TextureFormat textureFormat =
|
||||
TextureData::TextureFormat textureFormat =
|
||||
getTextureFormat(nRasters, gdalType);
|
||||
GLuint glType = getGlDataTypeFromGdalDataType(gdalType);
|
||||
UninitializedTextureTile* uninitedTexPtr = new UninitializedTextureTile(
|
||||
TextureData* uninitedTexPtr = new TextureData(
|
||||
imageDataYflipped,
|
||||
dims,
|
||||
textureFormat,
|
||||
glType,
|
||||
chunkIndex);
|
||||
std::shared_ptr<UninitializedTextureTile> uninitedTex =
|
||||
std::shared_ptr<UninitializedTextureTile>(uninitedTexPtr);
|
||||
std::shared_ptr<TextureData> uninitedTex =
|
||||
std::shared_ptr<TextureData>(uninitedTexPtr);
|
||||
return uninitedTex;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
glm::uvec2 GdalDataConverter<T>::geodeticToPixel(GDALDataset* dataSet, const Geodetic2& geo) {
|
||||
glm::uvec2 TextureDataProvider<T>::geodeticToPixel(GDALDataset* dataSet, const Geodetic2& geo) {
|
||||
double padfTransform[6];
|
||||
CPLErr err = dataSet->GetGeoTransform(padfTransform);
|
||||
|
||||
@@ -183,11 +189,11 @@ namespace openspace {
|
||||
}
|
||||
|
||||
template<class T>
|
||||
UninitializedTextureTile::TextureFormat GdalDataConverter<T>::getTextureFormat(
|
||||
TextureData::TextureFormat TextureDataProvider<T>::getTextureFormat(
|
||||
int rasterCount,
|
||||
GDALDataType gdalType)
|
||||
{
|
||||
UninitializedTextureTile::TextureFormat format;
|
||||
TextureData::TextureFormat format;
|
||||
|
||||
switch (rasterCount)
|
||||
{
|
||||
@@ -323,7 +329,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
template<class T>
|
||||
GLuint GdalDataConverter<T>::getGlDataTypeFromGdalDataType(GDALDataType gdalType)
|
||||
GLuint TextureDataProvider<T>::getGlDataTypeFromGdalDataType(GDALDataType gdalType)
|
||||
{
|
||||
switch (gdalType)
|
||||
{
|
||||
@@ -354,4 +360,33 @@ namespace openspace {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void TextureDataProvider<T>::async::request(GDALDataset * dataSet, ChunkIndex chunkIndex, int tileLevelDifference) {
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void TextureDataProvider<T>::async::updateRequests() {
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool TextureDataProvider<T>::async::hasTextureTileData() const {
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<TextureData> TextureDataProvider<T>::async::nextTextureTile() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void asyncRequest(GDALDataset * dataSet, ChunkIndex chunkIndex, int tileLevelDifference);
|
||||
void updateAsyncRequests();
|
||||
std::shared_ptr<TextureData> nextTextureTile();
|
||||
|
||||
*/
|
||||
|
||||
} // namespace openspace
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <modules/globebrowsing/other/texturetileset.h>
|
||||
|
||||
#include <modules/globebrowsing/geodetics/ellipsoid.h>
|
||||
#include <modules/globebrowsing/other/gdaldataconverter.h>
|
||||
#include <modules/globebrowsing/other/texturedataprovider.h>
|
||||
|
||||
#include <ghoul/opengl/texturemanager.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
@@ -67,7 +67,7 @@ namespace openspace {
|
||||
poDataset = (GDALDataset *)GDALOpen(testFile.c_str(), GA_ReadOnly);
|
||||
|
||||
assert(poDataset != nullptr, "Unable to read dataset" << testFile);
|
||||
GdalDataConverter conv;
|
||||
TextureDataProvider conv;
|
||||
|
||||
GeodeticTileIndex ti(0, 0, 0);
|
||||
|
||||
|
||||
@@ -101,6 +101,9 @@ namespace openspace {
|
||||
|
||||
_depthTransform.depthOffset = firstBand->GetOffset();
|
||||
_depthTransform.depthScale = firstBand->GetScale() * maximumValue;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
TileProvider::~TileProvider(){
|
||||
@@ -120,7 +123,7 @@ namespace openspace {
|
||||
void TileProvider::initTexturesFromLoadedData() {
|
||||
while (_tileLoadManager.numFinishedJobs() > 0) {
|
||||
auto finishedJob = _tileLoadManager.popFinishedJob();
|
||||
std::shared_ptr<UninitializedTextureTile> uninitedTex =
|
||||
std::shared_ptr<TextureData> uninitedTex =
|
||||
finishedJob->product();
|
||||
HashKey key = uninitedTex->chunkIndex.hashKey();
|
||||
std::shared_ptr<Texture> texture = initializeTexture(uninitedTex);
|
||||
@@ -228,7 +231,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<UninitializedTextureTile> TileProvider::getUninitializedTextureTile(
|
||||
std::shared_ptr<TextureData> TileProvider::getTextureData(
|
||||
const ChunkIndex& chunkIndex) {
|
||||
|
||||
// We assume here that all rasterbands have the same data type
|
||||
@@ -237,44 +240,44 @@ namespace openspace {
|
||||
switch (gdalType)
|
||||
{
|
||||
case GDT_Byte:
|
||||
return _uByteConverter.getUninitializedTextureTile(
|
||||
return _uByteTextureTileDataProvider.getTextureData(
|
||||
_gdalDataSet,
|
||||
chunkIndex,
|
||||
_tileLevelDifference);
|
||||
break;
|
||||
case GDT_UInt16:
|
||||
return _uShortConverter.getUninitializedTextureTile(
|
||||
return _uShortTextureDataProvider.getTextureData(
|
||||
_gdalDataSet,
|
||||
chunkIndex,
|
||||
_tileLevelDifference);
|
||||
break;
|
||||
case GDT_Int16:
|
||||
return _shortConverter.getUninitializedTextureTile(
|
||||
return _shortTextureDataProvider.getTextureData(
|
||||
_gdalDataSet,
|
||||
chunkIndex,
|
||||
_tileLevelDifference);
|
||||
break;
|
||||
case GDT_UInt32:
|
||||
return _uIntConverter.getUninitializedTextureTile(
|
||||
return _uIntTextureDataProvider.getTextureData(
|
||||
_gdalDataSet,
|
||||
chunkIndex,
|
||||
_tileLevelDifference);
|
||||
break;
|
||||
case GDT_Int32:
|
||||
return _intConverter.getUninitializedTextureTile(
|
||||
return _intTextureDataProvider.getTextureData(
|
||||
_gdalDataSet,
|
||||
chunkIndex,
|
||||
_tileLevelDifference);
|
||||
break;
|
||||
case GDT_Float32:
|
||||
return _floatConverter.getUninitializedTextureTile(
|
||||
return _floatTextureDataProvider.getTextureData(
|
||||
_gdalDataSet,
|
||||
chunkIndex,
|
||||
_tileLevelDifference);
|
||||
|
||||
break;
|
||||
case GDT_Float64:
|
||||
return _doubleConverter.getUninitializedTextureTile(
|
||||
return _doubleTextureDataProvider.getTextureData(
|
||||
_gdalDataSet,
|
||||
chunkIndex,
|
||||
_tileLevelDifference);
|
||||
@@ -287,7 +290,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> TileProvider::initializeTexture(
|
||||
std::shared_ptr<UninitializedTextureTile> uninitedTexture) {
|
||||
std::shared_ptr<TextureData> uninitedTexture) {
|
||||
Texture* tex = new Texture(
|
||||
uninitedTexture->imageData,
|
||||
uninitedTexture->dimensions,
|
||||
@@ -299,7 +302,6 @@ namespace openspace {
|
||||
|
||||
// The texture should take ownership of the data
|
||||
std::shared_ptr<Texture> texture = std::shared_ptr<Texture>(tex);
|
||||
|
||||
texture->uploadTexture();
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/other/lrucache.h>
|
||||
#include <modules/globebrowsing/other/concurrentjobmanager.h>
|
||||
#include <modules/globebrowsing/other/gdaldataconverter.h>
|
||||
#include <modules/globebrowsing/other/texturedataprovider.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TILE PROVIDER //
|
||||
@@ -99,14 +99,14 @@ namespace openspace {
|
||||
/**
|
||||
Fetches all the needeed texture data from the GDAL dataset.
|
||||
*/
|
||||
std::shared_ptr<UninitializedTextureTile> getUninitializedTextureTile(
|
||||
std::shared_ptr<TextureData> getTextureData(
|
||||
const ChunkIndex& chunkIndex);
|
||||
|
||||
/**
|
||||
Creates an OpenGL texture and pushes the data to the GPU.
|
||||
*/
|
||||
std::shared_ptr<Texture> initializeTexture(
|
||||
std::shared_ptr<UninitializedTextureTile> uninitedTexture);
|
||||
std::shared_ptr<TextureData> uninitedTexture);
|
||||
|
||||
bool enqueueTileRequest(const ChunkIndex& ci);
|
||||
|
||||
@@ -133,15 +133,15 @@ namespace openspace {
|
||||
GDALDataset* _gdalDataSet;
|
||||
|
||||
// Converters are needed for all different data types since they are templated.
|
||||
GdalDataConverter<GLubyte> _uByteConverter;
|
||||
GdalDataConverter<GLushort> _uShortConverter;
|
||||
GdalDataConverter<GLshort> _shortConverter;
|
||||
GdalDataConverter<GLuint> _uIntConverter;
|
||||
GdalDataConverter<GLint> _intConverter;
|
||||
GdalDataConverter<GLfloat> _floatConverter;
|
||||
GdalDataConverter<GLdouble> _doubleConverter;
|
||||
TextureDataProvider<GLubyte> _uByteTextureTileDataProvider;
|
||||
TextureDataProvider<GLushort> _uShortTextureDataProvider;
|
||||
TextureDataProvider<GLshort> _shortTextureDataProvider;
|
||||
TextureDataProvider<GLuint> _uIntTextureDataProvider;
|
||||
TextureDataProvider<GLint> _intTextureDataProvider;
|
||||
TextureDataProvider<GLfloat> _floatTextureDataProvider;
|
||||
TextureDataProvider<GLdouble> _doubleTextureDataProvider;
|
||||
|
||||
ConcurrentJobManager<UninitializedTextureTile> _tileLoadManager;
|
||||
ConcurrentJobManager<TextureData> _tileLoadManager;
|
||||
|
||||
std::shared_ptr<Texture> _defaultTexture;
|
||||
int _tileLevelDifference;
|
||||
@@ -150,11 +150,19 @@ namespace openspace {
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
struct TextureTileLoadJob : public Job<UninitializedTextureTile> {
|
||||
struct TextureTileLoadJob : public Job<TextureData> {
|
||||
TextureTileLoadJob(TileProvider * tileProvider, const ChunkIndex& chunkIndex)
|
||||
: _tileProvider(tileProvider)
|
||||
, _chunkIndex(chunkIndex) {
|
||||
@@ -164,11 +172,11 @@ namespace openspace {
|
||||
virtual ~TextureTileLoadJob() { }
|
||||
|
||||
virtual void execute() {
|
||||
_uninitedTexture = _tileProvider->getUninitializedTextureTile(_chunkIndex);
|
||||
_uninitedTexture = _tileProvider->getTextureData(_chunkIndex);
|
||||
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<UninitializedTextureTile> product() {
|
||||
virtual std::shared_ptr<TextureData> product() {
|
||||
return _uninitedTexture;
|
||||
}
|
||||
|
||||
@@ -176,7 +184,7 @@ namespace openspace {
|
||||
private:
|
||||
ChunkIndex _chunkIndex;
|
||||
TileProvider * _tileProvider;
|
||||
std::shared_ptr<UninitializedTextureTile> _uninitedTexture;
|
||||
std::shared_ptr<TextureData> _uninitedTexture;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ Fragment getFragment() {
|
||||
colorTiles[#{i}].uvTransform.uvScale * fs_uv +
|
||||
colorTiles[#{i}].uvTransform.uvOffset;
|
||||
vec4 colorSample = texture(colorTiles[#{i}].textureSampler, samplePos);
|
||||
frag.color = blendOver(frag.color, colorSample);
|
||||
frag.color = blendAdd(frag.color, colorSample);
|
||||
}
|
||||
#endfor
|
||||
|
||||
@@ -54,7 +54,7 @@ Fragment getFragment() {
|
||||
//frag.color = frag.color * 0.9 + 0.2*vec4(samplePos, 0, 1);
|
||||
|
||||
// Border overlay
|
||||
//frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02);
|
||||
frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02);
|
||||
|
||||
frag.depth = fs_position.w;
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ Fragment getFragment() {
|
||||
//frag.color = frag.color * 0.9 + 0.2*vec4(samplePos, 0, 1);
|
||||
|
||||
// Border overlay
|
||||
//frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02);
|
||||
frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02);
|
||||
|
||||
frag.depth = fs_position.w;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user