diff --git a/src/ui/map3D/Imagery.cc b/src/ui/map3D/Imagery.cc index 7095b83b0c8f3967fdc8b29d945261b3bc45a6ab..39079cbbe6d607ab8e713da4bd974e035d54f364 100644 --- a/src/ui/map3D/Imagery.cc +++ b/src/ui/map3D/Imagery.cc @@ -2,6 +2,8 @@ #include #include +#include +#include //for street-maps to: //http://mt1.google.com/mt?&x=%d&y=%d&z=%d @@ -13,9 +15,12 @@ const double WGS84_A = 6378137.0; const double WGS84_ECCSQ = 0.00669437999013; -Imagery::Imagery() +Imagery::Imagery(QObject* parent) + : QObject(parent) + , networkManager(new QNetworkAccessManager) { - +// connect(networkManager.data(), SIGNAL(finished(QNetworkReply*)), +// this, SLOT(downloadFinished(QNetworkReply*))); } void @@ -62,6 +67,8 @@ Imagery::prefetch2D(double windowWidth, double windowHeight, imageResolution = 512.0; } } + +// networkManager->get(QNetworkRequest(QUrl(""))); } void @@ -98,61 +105,20 @@ Imagery::update(void) } void -Imagery::drawTexture3D(const TexturePtr& t, - float x1, float y1, float x2, float y2, - bool smooth) +Imagery::downloadFinished(QNetworkReply* reply) { - if (t.isNull() == 0) - { + if (reply->error() != QNetworkReply::NoError) { return; } - - if (t->getState() == Texture::REQUESTED) + QVariant attribute = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (attribute.isValid()) { - glBegin(GL_LINE_LOOP); - glColor3f(0.0f, 0.0f, 1.0f); - glVertex2f(x1, y1); - glVertex2f(x2, y1); - glVertex2f(x2, y2); - glVertex2f(x1, y2); - glEnd(); return; } - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, t->getTextureId()); - - float dx, dy; - if (smooth) - { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - dx = 1.0f / (2.0f * t->getTextureWidth()); - dy = 1.0f / (2.0f * t->getTextureHeight()); - } - else - { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - dx = 0.0f; - dy = 0.0f; - } - - glColor3f(1.0f, 1.0f, 1.0f); - glBegin(GL_QUADS); - - glTexCoord2f(dx, t->getMaxV() - dy); - glVertex2f(x1, y1); - glTexCoord2f(t->getMaxU() - dx, t->getMaxV() - dy); - glVertex2f(x2, y1); - glTexCoord2f(t->getMaxU() - dx, dy); - glVertex2f(x2, y2); - glTexCoord2f(dx, dy); - glVertex2f(x1, y2); - - glEnd(); - - glDisable(GL_TEXTURE_2D); + QByteArray jpegData = reply->readAll(); + QPixmap pixmap; + pixmap.loadFromData(jpegData); } void diff --git a/src/ui/map3D/Imagery.h b/src/ui/map3D/Imagery.h index 1f0cf514c59b6d86a19ede574224fea74882d796..09495c33cc9e05dc43e5c6142c4ea39fc5c5f106 100644 --- a/src/ui/map3D/Imagery.h +++ b/src/ui/map3D/Imagery.h @@ -3,13 +3,17 @@ #include #include +#include +#include #include "Texture.h" -class Imagery +class Imagery : public QObject { +// Q_OBJECT + public: - Imagery(); + explicit Imagery(QObject* parent); enum ImageryType { @@ -41,11 +45,10 @@ public: bool update(void); -private: - void drawTexture3D(const TexturePtr& t, - float x1, float y1, float x2, float y2, - bool smooth); +private slots: + void downloadFinished(QNetworkReply* reply); +private: void UTMtoTile(double northing, double easting, const std::string& utmZone, double imageResolution, int32_t& tileX, int32_t& tileY, int32_t& zoomLevel); @@ -61,6 +64,8 @@ private: double& latitude, double& longitude); ImageryType currentImageryType; + + QScopedPointer networkManager; }; #endif // IMAGERY_H diff --git a/src/ui/map3D/Texture.cc b/src/ui/map3D/Texture.cc index 882a5ae59463fad7704947a7e02e5ddf2afafedc..36bed2cfcfd8e9a558a90867ec7b1a456c33e9af 100644 --- a/src/ui/map3D/Texture.cc +++ b/src/ui/map3D/Texture.cc @@ -5,50 +5,54 @@ Texture::Texture() } -Texture::State -Texture::getState(void) const -{ - return state; -} - -GLuint -Texture::getTextureId(void) const -{ - return textureId; -} - -int32_t -Texture::getTextureWidth(void) const -{ - return textureWidth; -} - -int32_t -Texture::getTextureHeight(void) const -{ - return textureHeight; -} - -int32_t -Texture::getImageWidth(void) const -{ - return imageWidth; -} - -int32_t -Texture::getImageHeight(void) const -{ - return imageHeight; -} - -float -Texture::getMaxU(void) const -{ - return maxU; -} - -float -Texture::getMaxV(void) const -{ - return maxV; +void +Texture::draw(float x1, float y1, float x2, float y2, + bool smoothInterpolation) const +{ + if (state == REQUESTED) + { + glBegin(GL_LINE_LOOP); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex2f(x1, y1); + glVertex2f(x2, y1); + glVertex2f(x2, y2); + glVertex2f(x1, y2); + glEnd(); + return; + } + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, textureId); + + float dx, dy; + if (smoothInterpolation) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + dx = 1.0f / (2.0f * textureWidth); + dy = 1.0f / (2.0f * textureHeight); + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + dx = 0.0f; + dy = 0.0f; + } + + glColor3f(1.0f, 1.0f, 1.0f); + glBegin(GL_QUADS); + + glTexCoord2f(dx, maxV - dy); + glVertex2f(x1, y1); + glTexCoord2f(maxU - dx, maxV - dy); + glVertex2f(x2, y1); + glTexCoord2f(maxU - dx, dy); + glVertex2f(x2, y2); + glTexCoord2f(dx, dy); + glVertex2f(x1, y2); + + glEnd(); + + glDisable(GL_TEXTURE_2D); } diff --git a/src/ui/map3D/Texture.h b/src/ui/map3D/Texture.h index 77a631ffd59e68aaaa75593e0a0ab450eb6c6286..b575fa6c2086a34fa71c4ebf8d908ea3541d2405 100644 --- a/src/ui/map3D/Texture.h +++ b/src/ui/map3D/Texture.h @@ -9,6 +9,10 @@ class Texture public: Texture(); + void draw(float x1, float y1, float x2, float y2, + bool smoothInterpolation) const; + +private: enum State { UNINITIALIZED = 0, @@ -16,16 +20,6 @@ public: READY = 2 }; - State getState(void) const; - GLuint getTextureId(void) const; - int32_t getTextureWidth(void) const; - int32_t getTextureHeight(void) const; - int32_t getImageWidth(void) const; - int32_t getImageHeight(void) const; - float getMaxU(void) const; - float getMaxV(void) const; - -private: State state; GLuint textureId;