Commit eff1df53 authored by Lionel Heng's avatar Lionel Heng

Minor changes to 3D imagery code

parent 6ab24659
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include <cmath> #include <cmath>
#include <sstream> #include <sstream>
#include <QNetworkReply>
#include <QPixmap>
//for street-maps to: //for street-maps to:
//http://mt1.google.com/mt?&x=%d&y=%d&z=%d //http://mt1.google.com/mt?&x=%d&y=%d&z=%d
...@@ -13,9 +15,12 @@ ...@@ -13,9 +15,12 @@
const double WGS84_A = 6378137.0; const double WGS84_A = 6378137.0;
const double WGS84_ECCSQ = 0.00669437999013; 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 void
...@@ -62,6 +67,8 @@ Imagery::prefetch2D(double windowWidth, double windowHeight, ...@@ -62,6 +67,8 @@ Imagery::prefetch2D(double windowWidth, double windowHeight,
imageResolution = 512.0; imageResolution = 512.0;
} }
} }
// networkManager->get(QNetworkRequest(QUrl("")));
} }
void void
...@@ -98,61 +105,20 @@ Imagery::update(void) ...@@ -98,61 +105,20 @@ Imagery::update(void)
} }
void void
Imagery::drawTexture3D(const TexturePtr& t, Imagery::downloadFinished(QNetworkReply* reply)
float x1, float y1, float x2, float y2,
bool smooth)
{ {
if (t.isNull() == 0) if (reply->error() != QNetworkReply::NoError) {
{
return; return;
} }
QVariant attribute = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (t->getState() == Texture::REQUESTED) 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; return;
} }
glEnable(GL_TEXTURE_2D); QByteArray jpegData = reply->readAll();
glBindTexture(GL_TEXTURE_2D, t->getTextureId()); QPixmap pixmap;
pixmap.loadFromData(jpegData);
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);
} }
void void
......
...@@ -3,13 +3,17 @@ ...@@ -3,13 +3,17 @@
#include <inttypes.h> #include <inttypes.h>
#include <string> #include <string>
#include <QNetworkAccessManager>
#include <QObject>
#include "Texture.h" #include "Texture.h"
class Imagery class Imagery : public QObject
{ {
// Q_OBJECT
public: public:
Imagery(); explicit Imagery(QObject* parent);
enum ImageryType enum ImageryType
{ {
...@@ -41,11 +45,10 @@ public: ...@@ -41,11 +45,10 @@ public:
bool update(void); bool update(void);
private: private slots:
void drawTexture3D(const TexturePtr& t, void downloadFinished(QNetworkReply* reply);
float x1, float y1, float x2, float y2,
bool smooth);
private:
void UTMtoTile(double northing, double easting, const std::string& utmZone, void UTMtoTile(double northing, double easting, const std::string& utmZone,
double imageResolution, int32_t& tileX, int32_t& tileY, double imageResolution, int32_t& tileX, int32_t& tileY,
int32_t& zoomLevel); int32_t& zoomLevel);
...@@ -61,6 +64,8 @@ private: ...@@ -61,6 +64,8 @@ private:
double& latitude, double& longitude); double& latitude, double& longitude);
ImageryType currentImageryType; ImageryType currentImageryType;
QScopedPointer<QNetworkAccessManager> networkManager;
}; };
#endif // IMAGERY_H #endif // IMAGERY_H
...@@ -5,50 +5,54 @@ Texture::Texture() ...@@ -5,50 +5,54 @@ Texture::Texture()
} }
Texture::State void
Texture::getState(void) const Texture::draw(float x1, float y1, float x2, float y2,
{ bool smoothInterpolation) const
return state; {
} if (state == REQUESTED)
{
GLuint glBegin(GL_LINE_LOOP);
Texture::getTextureId(void) const glColor3f(0.0f, 0.0f, 1.0f);
{ glVertex2f(x1, y1);
return textureId; glVertex2f(x2, y1);
} glVertex2f(x2, y2);
glVertex2f(x1, y2);
int32_t glEnd();
Texture::getTextureWidth(void) const return;
{ }
return textureWidth;
} glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureId);
int32_t
Texture::getTextureHeight(void) const float dx, dy;
{ if (smoothInterpolation)
return textureHeight; {
} glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
int32_t dx = 1.0f / (2.0f * textureWidth);
Texture::getImageWidth(void) const dy = 1.0f / (2.0f * textureHeight);
{ }
return imageWidth; else
} {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
int32_t glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Texture::getImageHeight(void) const dx = 0.0f;
{ dy = 0.0f;
return imageHeight; }
}
glColor3f(1.0f, 1.0f, 1.0f);
float glBegin(GL_QUADS);
Texture::getMaxU(void) const
{ glTexCoord2f(dx, maxV - dy);
return maxU; glVertex2f(x1, y1);
} glTexCoord2f(maxU - dx, maxV - dy);
glVertex2f(x2, y1);
float glTexCoord2f(maxU - dx, dy);
Texture::getMaxV(void) const glVertex2f(x2, y2);
{ glTexCoord2f(dx, dy);
return maxV; glVertex2f(x1, y2);
glEnd();
glDisable(GL_TEXTURE_2D);
} }
...@@ -9,6 +9,10 @@ class Texture ...@@ -9,6 +9,10 @@ class Texture
public: public:
Texture(); Texture();
void draw(float x1, float y1, float x2, float y2,
bool smoothInterpolation) const;
private:
enum State enum State
{ {
UNINITIALIZED = 0, UNINITIALIZED = 0,
...@@ -16,16 +20,6 @@ public: ...@@ -16,16 +20,6 @@ public:
READY = 2 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; State state;
GLuint textureId; GLuint textureId;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment