mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-06 19:39:56 -05:00
No-overview datasets use virtual overview to downsample write region. Ensure tiles have even number of pixels
This commit is contained in:
@@ -23,8 +23,8 @@ return {
|
||||
Frame = "IAU_EARTH",
|
||||
Body = "EARTH",
|
||||
--Radii = {6378137.0, 6378137.0, 6356752.314245}, -- Earth's radii
|
||||
Radii = {1738100, 1738100, 1736000}, -- Moon's radii
|
||||
--Radii = {3396190.0, 3396190.0, 3376200.0}, -- Mars' radii
|
||||
--Radii = {1738100, 1738100, 1736000}, -- Moon's radii
|
||||
Radii = {3396190.0, 3396190.0, 3376200.0}, -- Mars' radii
|
||||
--Radii = {2439700.0, 2439700.0, 2439700.0},
|
||||
CameraMinHeight = 1000,
|
||||
InteractionDepthBelowEllipsoid = 10000, -- Useful when having negative height map values
|
||||
@@ -49,27 +49,27 @@ return {
|
||||
--[[{
|
||||
Type = "Temporal",
|
||||
Name = "Temporal MODIS Aqua CorrectedRecflectance TrueColor",
|
||||
FilePath = "map_service_configs/Temporal_MODIS_Aqua_CorrectedReflectance_TrueColor.xml",
|
||||
FilePath = "map_service_configs/earth/Temporal_MODIS_Aqua_CorrectedReflectance_TrueColor.xml",
|
||||
},
|
||||
{
|
||||
Name = "MODIS_Terra_CorrectedReflectance_TrueColor",
|
||||
FilePath = "map_service_configs/MODIS_Terra_CorrectedReflectance_TrueColor.xml",
|
||||
FilePath = "map_service_configs/earth/MODIS_Terra_CorrectedReflectance_TrueColor.xml",
|
||||
},
|
||||
{
|
||||
Name = "ESRI Imagery World 2D",
|
||||
FilePath = "map_service_configs/ESRI_Imagery_World_2D.wms",
|
||||
--Enabled = true,
|
||||
},
|
||||
{
|
||||
Name = "MARS_Viking_MDIM21",
|
||||
FilePath = "map_service_configs/MARS_Viking_MDIM21.xml",
|
||||
FilePath = "map_service_configs/earth/ESRI_Imagery_World_2D.wms",
|
||||
--Enabled = true,
|
||||
},]]
|
||||
{
|
||||
Name = "Mars Viking Clr",
|
||||
FilePath = "textures/Mars_Viking_ClrMosaic_global_925m_longlat.cub",
|
||||
Name = "MARS_Viking_MDIM21",
|
||||
FilePath = "map_service_configs/mars/MARS_Viking_MDIM21.xml",
|
||||
--Enabled = true,
|
||||
},
|
||||
{
|
||||
Name = "Mars Viking Clr",
|
||||
FilePath = "textures/Mars_Viking_ClrMosaic_global_925m_longlat_full.vrt",
|
||||
Enabled = true,
|
||||
},
|
||||
--[[
|
||||
{
|
||||
Name = "On Mercury Color",
|
||||
@@ -89,7 +89,7 @@ return {
|
||||
{
|
||||
Name = "On Moon Color",
|
||||
FilePath = "map_service_configs/moon/OnMoonColor.xml",
|
||||
Enabled = true,
|
||||
--Enabled = true,
|
||||
},
|
||||
},
|
||||
NightTextures = {
|
||||
@@ -112,7 +112,7 @@ return {
|
||||
{
|
||||
Name = "On Moon Height",
|
||||
FilePath = "map_service_configs/moon/OnMoonHeight.xml",
|
||||
Enabled = true,
|
||||
--Enabled = true,
|
||||
},
|
||||
{
|
||||
Name = "On Mercury Height",
|
||||
|
||||
@@ -235,7 +235,7 @@ vec4 calculateGrayScaleOverlay(
|
||||
levelWeights.w2 * getTexVal(grayscaleOverlayTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(grayscaleOverlayTilesParent2[#{i}], uv);
|
||||
|
||||
colorSample = vec4(colorSample.r, colorSample.r, colorSample.r, 1);
|
||||
colorSample = vec4(colorSample.r, colorSample.r, colorSample.r, colorSample.g);
|
||||
colorGrayScale = blendOver(colorGrayScale, colorSample);
|
||||
}
|
||||
#endfor
|
||||
|
||||
@@ -135,18 +135,22 @@ namespace openspace {
|
||||
scale(glm::dvec2(s));
|
||||
}
|
||||
|
||||
void PixelRegion::downscalePow2(int exponent) {
|
||||
void PixelRegion::downscalePow2(int exponent, PixelCoordinate wrt) {
|
||||
start += wrt;
|
||||
start.x >>= exponent;
|
||||
start.y >>= exponent;
|
||||
numPixels.x >>= exponent;
|
||||
numPixels.y >>= exponent;
|
||||
start -= wrt;
|
||||
}
|
||||
|
||||
void PixelRegion::upscalePow2(int exponent) {
|
||||
void PixelRegion::upscalePow2(int exponent, PixelCoordinate wrt) {
|
||||
start += wrt;
|
||||
start.x <<= exponent;
|
||||
start.y <<= exponent;
|
||||
numPixels.x <<= exponent;
|
||||
numPixels.y <<= exponent;
|
||||
start -= wrt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ namespace openspace {
|
||||
|
||||
void scale(const glm::dvec2& s);
|
||||
void scale(double s);
|
||||
void downscalePow2(int exponent);
|
||||
void upscalePow2(int exponent);
|
||||
void downscalePow2(int exponent, PixelCoordinate wrt = {0,0});
|
||||
void upscalePow2(int exponent, PixelCoordinate wrt = { 0,0 });
|
||||
|
||||
void move(Side side, int amount);
|
||||
void pad(const PixelRegion& padding);
|
||||
|
||||
@@ -135,6 +135,7 @@ namespace openspace {
|
||||
_dataLayout = TileDataLayout(_dataset, dataType);
|
||||
_depthTransform = calculateTileDepthTransform();
|
||||
_tileLevelDifference = calculateTileLevelDifference(minimumPixelSize);
|
||||
_description = gdalDatasetDesc;
|
||||
|
||||
LDEBUG(gdalDatasetDesc << " - " << _tileLevelDifference);
|
||||
}
|
||||
@@ -240,7 +241,7 @@ namespace openspace {
|
||||
return _dataset->GetRasterBand(1)->GetOverviewCount() > 0;
|
||||
}
|
||||
|
||||
int TileDataset::gdalOverview(const PixelCoordinate& regionSizeOverviewZero) const {
|
||||
int TileDataset::gdalOverview(const PixelRange& regionSizeOverviewZero) const {
|
||||
GDALRasterBand* firstBand = _dataset->GetRasterBand(1);
|
||||
|
||||
int minNumPixels0 = glm::min(regionSizeOverviewZero.x, regionSizeOverviewZero.y);
|
||||
@@ -264,6 +265,13 @@ namespace openspace {
|
||||
return glm::clamp(ov, 0, overviews - 1);
|
||||
}
|
||||
|
||||
|
||||
int TileDataset::gdalVirtualOverview(const ChunkIndex& chunkIndex) const {
|
||||
int overviews = _dataset->GetRasterBand(1)->GetOverviewCount();
|
||||
int ov = overviews - (chunkIndex.level + _tileLevelDifference + 1);
|
||||
return ov;
|
||||
}
|
||||
|
||||
PixelRegion TileDataset::gdalPixelRegion(GDALRasterBand* rasterBand) const {
|
||||
PixelRegion gdalRegion;
|
||||
gdalRegion.start.x = 0;
|
||||
@@ -284,7 +292,10 @@ namespace openspace {
|
||||
|
||||
GDALRasterBand* TileDataset::gdalRasterBand(int overview, int raster) const {
|
||||
GDALRasterBand* rasterBand = _dataset->GetRasterBand(raster);
|
||||
return gdalHasOverviews() ? rasterBand->GetOverview(overview) : rasterBand;
|
||||
int numberOfOverviews = rasterBand->GetOverviewCount();
|
||||
rasterBand = gdalHasOverviews() ? rasterBand->GetOverview(overview) : rasterBand;
|
||||
ghoul_assert(rasterBand != nullptr, "Rasterband is null");
|
||||
return rasterBand;
|
||||
}
|
||||
|
||||
|
||||
@@ -334,40 +345,36 @@ namespace openspace {
|
||||
}
|
||||
|
||||
IODescription TileDataset::getIODescription(const ChunkIndex& chunkIndex) const {
|
||||
// Calculate suitable overview and corresponding pixel region
|
||||
int overview = gdalOverview(chunkIndex);
|
||||
PixelRegion region = gdalPixelRegion(chunkIndex); // pixel region at overview zero
|
||||
region.downscalePow2(overview + 1); // pixel region at suitable overview
|
||||
|
||||
// Create an IORegion based on that overview pixel region
|
||||
IODescription io;
|
||||
io.read.overview = overview;
|
||||
io.read.region = region;
|
||||
io.write.region = region;
|
||||
io.read.region = gdalPixelRegion(chunkIndex);
|
||||
|
||||
// Handle the case where the dataset does not have overviews
|
||||
if (!gdalHasOverviews()) {
|
||||
io.read.region.upscalePow2(overview + 1);
|
||||
io.read.overview = 0; // no overview
|
||||
//Geodetic2 halfSize = Geodetic2(dAngle::HALF.asRadians(), dAngle::QUARTER.asRadians());
|
||||
//PixelRegion fullRegion = gdalPixelRegion(GeodeticPatch(Geodetic2(0, 0), Geodetic2(dAngle::HALF)))
|
||||
|
||||
|
||||
if (gdalHasOverviews()) {
|
||||
int overview = gdalOverview(chunkIndex);
|
||||
io.read.overview = overview;
|
||||
io.read.region.downscalePow2(overview + 1);
|
||||
io.write.region = io.read.region;
|
||||
}
|
||||
else {
|
||||
io.read.overview = 0;
|
||||
io.write.region = io.read.region;
|
||||
int virtualOverview = gdalVirtualOverview(chunkIndex);
|
||||
io.write.region.downscalePow2(virtualOverview + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// For correct sampling in height dataset, we need to pad the texture tile
|
||||
io.read.region.pad(padding);
|
||||
io.write.region.pad(padding);
|
||||
|
||||
io.write.region.numPixels.x += (io.write.region.numPixels.x % 2);
|
||||
io.write.region.numPixels.y += (io.write.region.numPixels.y % 2);
|
||||
|
||||
io.write.region.start = PixelCoordinate(0, 0); // write region starts in origin
|
||||
|
||||
|
||||
|
||||
// Doing this may cause invalid regions, i.e. having negative pixel coordinates
|
||||
// or being too large etc. For now, just clamp
|
||||
PixelRegion overviewRegion = gdalPixelRegion(gdalRasterBand(overview));
|
||||
|
||||
//if (chunkIndex.level < 3) {
|
||||
// io.read.region.clampTo(overviewRegion);
|
||||
// io.write.region.clampTo(overviewRegion);
|
||||
//}
|
||||
|
||||
|
||||
io.write.bytesPerLine = _dataLayout.bytesPerPixel * io.write.region.numPixels.x;
|
||||
io.write.totalNumBytes = io.write.bytesPerLine * io.write.region.numPixels.y;
|
||||
|
||||
@@ -381,7 +388,7 @@ namespace openspace {
|
||||
// Read the data (each rasterband is a separate channel)
|
||||
for (size_t i = 0; i < _dataLayout.numRasters; i++) {
|
||||
GDALRasterBand* rasterBand = gdalRasterBand(io.read.overview, i + 1);
|
||||
|
||||
|
||||
// The final destination pointer is offsetted by one datum byte size
|
||||
// for every raster (or data channel, i.e. R in RGB)
|
||||
char* dataDestination = imageData + (i * _dataLayout.bytesPerDatum);
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace openspace {
|
||||
|
||||
struct WriteData {
|
||||
PixelRegion region;
|
||||
size_t bytesPerLine;
|
||||
size_t bytesPerLine;
|
||||
size_t totalNumBytes;
|
||||
} write;
|
||||
};
|
||||
@@ -124,8 +124,9 @@ namespace openspace {
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool gdalHasOverviews() const;
|
||||
int gdalOverview(const PixelCoordinate& baseRegionSize) const;
|
||||
int gdalOverview(const PixelRange& baseRegionSize) const;
|
||||
int gdalOverview(const ChunkIndex& chunkIndex) const;
|
||||
int gdalVirtualOverview(const ChunkIndex& chunkIndex) const;
|
||||
PixelRegion gdalPixelRegion(const GeodeticPatch& geodeticPatch) const;
|
||||
PixelRegion gdalPixelRegion(GDALRasterBand* rasterBand) const;
|
||||
GDALRasterBand* gdalRasterBand(int overview, int raster = 1) const;
|
||||
@@ -152,7 +153,8 @@ namespace openspace {
|
||||
|
||||
int _maxLevel;
|
||||
double _tileLevelDifference;
|
||||
|
||||
|
||||
std::string _description;
|
||||
TileDepthTransform _depthTransform;
|
||||
|
||||
GDALDataset* _dataset;
|
||||
|
||||
Reference in New Issue
Block a user