Commit eff1df53 authored by Lionel Heng's avatar Lionel Heng

Minor changes to 3D imagery code

parent 6ab24659
......@@ -2,6 +2,8 @@
#include <cmath>
#include <sstream>
#include <QNetworkReply>
#include <QPixmap>
//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
......
......@@ -3,13 +3,17 @@
#include <inttypes.h>
#include <string>
#include <QNetworkAccessManager>
#include <QObject>
#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<QNetworkAccessManager> networkManager;
};
#endif // IMAGERY_H
......@@ -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);
}
......@@ -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;
......
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