summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Rahn <[email protected]>2016-07-09 13:16:08 +0200
committerTorsten Rahn <[email protected]>2016-07-09 13:19:34 +0200
commitde4cf8886c7aba7565881c219c84bbe4e788cf13 (patch)
tree17d00303bbe58fa421dad4d100882f59421965e4
parent88534cb92a081b9f620eeeab05ca614f311c5929 (diff)
Adding initial version of the Sentinel-Bathymetry-Merge-Tool
-rw-r--r--tools/CMakeLists.txt1
-rw-r--r--tools/sentineltile/sentineltile.cpp56
-rw-r--r--tools/sentineltile/tileprocessor.cpp121
-rw-r--r--tools/sentineltile/tileprocessor.h46
4 files changed, 224 insertions, 0 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 9abb7c0..a0c7134 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -19,6 +19,7 @@ add_subdirectory( maptheme-previewimage )
add_subdirectory( mapreproject )
add_subdirectory( speaker-files )
add_subdirectory( stars )
+add_subdirectory( sentineltile )
find_package(Protobuf)
find_package(ZLIB)
diff --git a/tools/sentineltile/sentineltile.cpp b/tools/sentineltile/sentineltile.cpp
new file mode 100644
index 0000000..77faf9c
--- /dev/null
+++ b/tools/sentineltile/sentineltile.cpp
@@ -0,0 +1,56 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2016 Torsten Rahn <[email protected]>
+//
+
+
+#include <QApplication>
+#include <QFileSystemModel>
+#include <QDebug>
+
+#include <tileprocessor.h>
+
+
+int main(int argc, char *argv[])
+{
+ QString sourcefile;
+ QString targetfile;
+
+ QApplication app(argc, argv);
+
+ qDebug( " sentineltile -o targetfile sourcefile" );
+ qDebug( " Syntax: pntreplace -d tileleveldirectory -m maskfile -b bathymetryfile " );
+ qDebug( " e.g. sentineltile -d /home/tackat/tilefab/sentinel2/14 " );
+ qDebug( " -m /home/tackat/bathymetry/coastline_mask.png " );
+ qDebug( " -b /home/tackat/bathymetry/bathymetry_equirect.jpg" );
+ // /home/tackat/tilefab/sentinel2/14
+ QString tileDirPath;
+ int tileDirIndex = app.arguments().indexOf("-d");
+ if (tileDirIndex > 0 && tileDirIndex + 1 < argc )
+ tileDirPath = app.arguments().at( tileDirIndex + 1 );
+
+ // /home/tackat/bathymetry/coastline_mask.png
+ QString coastLineMaskPath;
+ int maskIndex = app.arguments().indexOf("-m");
+ if (maskIndex > 0 && maskIndex + 1 < argc )
+ coastLineMaskPath = app.arguments().at( maskIndex + 1 );
+
+ // /home/tackat/bathymetry/bathymetry_equirect.jpg
+ QString bathymetryPath;
+ int bathymetryIndex = app.arguments().indexOf("-b");
+ if (bathymetryIndex > 0 && bathymetryIndex + 1 < argc )
+ bathymetryPath = app.arguments().at( bathymetryIndex + 1 );
+
+ TileProcessor * tileProc = new TileProcessor();
+
+ tileProc->parseFileList(tileDirPath);
+ tileProc->loadReferenceImages(coastLineMaskPath, bathymetryPath);
+ tileProc->process();
+
+ app.exit();
+}
diff --git a/tools/sentineltile/tileprocessor.cpp b/tools/sentineltile/tileprocessor.cpp
new file mode 100644
index 0000000..c7c737e
--- /dev/null
+++ b/tools/sentineltile/tileprocessor.cpp
@@ -0,0 +1,121 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2016 Torsten Rahn <[email protected]>
+//
+
+#include "tileprocessor.h"
+
+#include <QFile>
+#include <QTextStream>
+#include <QPainter>
+#include <QDebug>
+#include <QFileInfo>
+#include <QDir>
+
+#include <cmath>
+
+int TileProcessor::progress = 0;
+
+TileProcessor::TileProcessor(QObject *parent) : QObject(parent),
+ m_tileLevel(14)
+{
+
+}
+
+void TileProcessor::parseFileList(const QString& fileListUrl) {
+
+ m_fileList.clear();
+
+ QDir rootDir(fileListUrl);
+
+ QStringList dirList = rootDir.entryList(QStringList(), QDir::AllDirs | QDir::NoDotAndDotDot);
+
+ for (int i = 0; i < dirList.length(); ++i) {
+ QString urlPath = fileListUrl + "/" + dirList.at(i);
+ QDir columnDir = QDir(urlPath);
+ QStringList files = columnDir.entryList(QStringList() << "*.jpg", QDir::Files);
+ for (int j = 0; j < files.length(); ++j) {
+ QString filePath = urlPath + "/" + files.at(j);
+ m_fileList << filePath;
+ }
+ }
+ qDebug() << "Total file count: " << m_fileList.length();
+}
+
+void TileProcessor::loadReferenceImages(const QString& maskPath, const QString& bathymetryPath) {
+ qDebug() << "Loading mask from" << maskPath;
+ bool success = m_mask.load(maskPath);
+ if (!success) qDebug() << "Loading mask failed: " << maskPath;
+ qDebug() << "Loading bathymetry from" << bathymetryPath;
+ success = m_bathymetry.load(bathymetryPath);
+ if (!success) qDebug() << "Loading bathymetry failed: " << bathymetryPath;
+ qDebug() << "Reference images loaded.";
+
+ if (m_mask.width() != m_bathymetry.width() || m_mask.height() != m_bathymetry.height()) {
+ qDebug() << "Mask and bathymetry geometries don't match:";
+ qDebug() << "Mask: " << m_mask.width() << "x" << m_mask.height();
+ qDebug() << "Bathymetry: " << m_bathymetry.width() << "x" << m_bathymetry.height();
+ }
+}
+
+void TileProcessor::process() {
+ for (int i = 0; i < m_fileList.length(); ++i) {
+ QFileInfo fileInfo(m_fileList.at(i));
+ if (fileInfo.isFile()) {
+ colorForFile(m_fileList.at(i));
+ }
+ }
+}
+
+void TileProcessor::colorForFile(const QString& filePath){
+ ++progress;
+
+ int tileCount = pow(2, m_tileLevel);
+
+ int x = m_mask.width() * (filePath.section('/', -2, -2).toDouble()/ (double)tileCount);
+
+ int ypos = filePath.section('/', -1).section(".",0, 0).toDouble();
+
+ qreal lat_rad = atan(sinh(M_PI * (1 - 2 * ypos / (double)tileCount)));
+ qreal yreal = m_mask.height() * (-lat_rad + M_PI/2) / M_PI;
+
+ int y = (int)yreal;
+
+ int maskValue = qRed(m_mask.pixel(x, y));
+
+ if (maskValue != 0) { // for all areas which are not black
+ QColor bathymetryColor = QColor(m_bathymetry.pixel(x, y));
+
+ QImage tile(256, 256, QImage::Format_RGB32);
+ tile.fill(bathymetryColor);
+
+ QImage origTile;
+ bool success = origTile.load(filePath);
+
+ if (!success) qDebug() << "Loading tile failed: " << filePath;
+
+ QPainter painter;
+ painter.begin(&tile);
+ qreal opacity = 1.0 - (double)(maskValue)/255.0;
+ painter.setOpacity(opacity);
+ painter.drawImage(0, 0, origTile);
+ painter.end();
+
+ QString modFilePath = filePath;
+// modFilePath = modFilePath.replace(".", "_mod.");
+
+ tile.save(modFilePath, "JPG", 85);
+ if (opacity > 0.0) {
+ qDebug() << progress << filePath.section('/', -2, -2) << filePath.section('/', -1).section(".",0, 0);
+ qDebug() << maskValue << modFilePath;
+ }
+ }
+ else {
+// qDebug() << maskValue;
+ }
+}
diff --git a/tools/sentineltile/tileprocessor.h b/tools/sentineltile/tileprocessor.h
new file mode 100644
index 0000000..739417f
--- /dev/null
+++ b/tools/sentineltile/tileprocessor.h
@@ -0,0 +1,46 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2016 Torsten Rahn <[email protected]>
+//
+
+#ifndef TILEPROCESSOR_H
+#define TILEPROCESSOR_H
+
+#include <QObject>
+#include <QColor>
+#include <QImage>
+
+
+class TileProcessor : public QObject
+{
+ Q_OBJECT
+public:
+ explicit TileProcessor(QObject *parent = 0);
+
+public:
+
+ void parseFileList(const QString& fileListUrl);
+
+ void loadReferenceImages(const QString& maskPath, const QString& bathymetryPath);
+
+ void process();
+
+private:
+ void colorForFile(const QString& filePath);
+
+ QStringList m_fileList;
+
+ QImage m_mask;
+ QImage m_bathymetry;
+
+ int m_tileLevel;
+ static int progress;
+
+};
+
+#endif // TILEPROCESSOR_H