Commit c6c4ef05 authored by hengli's avatar hengli

Latest working version of 3D imagery overlay. Unresolved errors with Google...

Latest working version of 3D imagery overlay. Unresolved errors with Google URLs for satellite imagery.
parent 17f43c41
...@@ -7,6 +7,7 @@ const double WGS84_A = 6378137.0; ...@@ -7,6 +7,7 @@ const double WGS84_A = 6378137.0;
const double WGS84_ECCSQ = 0.00669437999013; const double WGS84_ECCSQ = 0.00669437999013;
Imagery::Imagery() Imagery::Imagery()
: textureCache(new TextureCache(1000))
{ {
} }
...@@ -137,10 +138,13 @@ Imagery::draw2D(double windowWidth, double windowHeight, ...@@ -137,10 +138,13 @@ Imagery::draw2D(double windowWidth, double windowHeight,
imageBounds(c, r, imageResolution, x1, y1, x2, y2, x3, y3, x4, y4); imageBounds(c, r, imageResolution, x1, y1, x2, y2, x3, y3, x4, y4);
TexturePtr t = textureCache->get(tileURL); TexturePtr t = textureCache->get(tileURL);
t->draw(x1 - xOrigin, y1 - yOrigin, if (!t.isNull())
x2 - xOrigin, y2 - yOrigin, {
x3 - xOrigin, y3 - yOrigin, t->draw(x1 - xOrigin, y1 - yOrigin,
x4 - xOrigin, y4 - yOrigin, true); x2 - xOrigin, y2 - yOrigin,
x3 - xOrigin, y3 - yOrigin,
x4 - xOrigin, y4 - yOrigin, true);
}
} }
} }
} }
...@@ -231,10 +235,13 @@ Imagery::draw3D(double radius, double imageResolution, ...@@ -231,10 +235,13 @@ Imagery::draw3D(double radius, double imageResolution,
imageBounds(c, r, imageResolution, x1, y1, x2, y2, x3, y3, x4, y4); imageBounds(c, r, imageResolution, x1, y1, x2, y2, x3, y3, x4, y4);
TexturePtr t = textureCache->get(tileURL); TexturePtr t = textureCache->get(tileURL);
t->draw(x1 - xOrigin, y1 - yOrigin, if (!t.isNull())
x2 - xOrigin, y2 - yOrigin, {
x3 - xOrigin, y3 - yOrigin, t->draw(x1 - xOrigin, y1 - yOrigin,
x4 - xOrigin, y4 - yOrigin, true); x2 - xOrigin, y2 - yOrigin,
x3 - xOrigin, y3 - yOrigin,
x4 - xOrigin, y4 - yOrigin, true);
}
} }
} }
} }
...@@ -499,18 +506,18 @@ Imagery::getTileURL(int32_t x, int32_t y, int32_t zoomLevel) ...@@ -499,18 +506,18 @@ Imagery::getTileURL(int32_t x, int32_t y, int32_t zoomLevel)
switch (currentImageryType) switch (currentImageryType)
{ {
case MAP: case MAP:
oss << "http://mt1.google.com/mt?&x=" << x << "&y=" << y << oss << "http://mt0.google.com/vt/lyrs=m@120&x=" << x << "&y=" << y
"&z=" << zoomLevel; << "&z=" << zoomLevel;
break; break;
case SATELLITE: case SATELLITE:
oss << "http://khm.google.com/kh?&x=" << x << "&y=" << y << oss << "http://khm.google.com/vt/lbw/lyrs=y&x=" << x << "&y=" << y
"&zoom=" << zoomLevel; << "&z=" << zoomLevel;
break; break;
default: default:
{}; {};
} }
QString url; QString url(oss.str().c_str());
return url; return url;
} }
...@@ -45,11 +45,13 @@ QMap3DWidget::QMap3DWidget(QWidget* parent) ...@@ -45,11 +45,13 @@ QMap3DWidget::QMap3DWidget(QWidget* parent)
, uas(NULL) , uas(NULL)
, lastRedrawTime(0.0) , lastRedrawTime(0.0)
, displayGrid(true) , displayGrid(true)
, displayImagery(false)
, displayTrail(false) , displayTrail(false)
, lockCamera(true) , lockCamera(true)
, updateLastUnlockedPose(true) , updateLastUnlockedPose(true)
, displayTarget(false) , displayTarget(false)
, displayWaypoints(true) , displayWaypoints(true)
, imagery(new Imagery)
{ {
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
...@@ -88,6 +90,14 @@ QMap3DWidget::buildLayout(void) ...@@ -88,6 +90,14 @@ QMap3DWidget::buildLayout(void)
waypointsCheckBox->setText("Waypoints"); waypointsCheckBox->setText("Waypoints");
waypointsCheckBox->setChecked(displayWaypoints); waypointsCheckBox->setChecked(displayWaypoints);
QLabel* imageryLabel = new QLabel(this);
imageryLabel->setText("Imagery");
QComboBox* imageryComboBox = new QComboBox(this);
imageryComboBox->addItem("None");
imageryComboBox->addItem("Map (Google)");
imageryComboBox->addItem("Satellite (Google)");
QPushButton* recenterButton = new QPushButton(this); QPushButton* recenterButton = new QPushButton(this);
recenterButton->setText("Recenter Camera"); recenterButton->setText("Recenter Camera");
...@@ -105,18 +115,23 @@ QMap3DWidget::buildLayout(void) ...@@ -105,18 +115,23 @@ QMap3DWidget::buildLayout(void)
layout->addWidget(trailCheckBox, 1, 1); layout->addWidget(trailCheckBox, 1, 1);
layout->addWidget(waypointsCheckBox, 1, 2); layout->addWidget(waypointsCheckBox, 1, 2);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding), 1, 3); layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding), 1, 3);
layout->addWidget(recenterButton, 1, 4); layout->addWidget(imageryLabel, 1, 4);
layout->addWidget(lockCameraCheckBox, 1, 5); layout->addWidget(imageryComboBox, 1, 5);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding), 1, 6);
layout->addWidget(recenterButton, 1, 7);
layout->addWidget(lockCameraCheckBox, 1, 8);
layout->setRowStretch(0, 100); layout->setRowStretch(0, 100);
layout->setRowStretch(1, 1); layout->setRowStretch(1, 1);
//layout->setColumnStretch(0, 1); layout->setColumnStretch(3, 50);
layout->setColumnStretch(2, 50); layout->setColumnStretch(6, 50);
setLayout(layout); setLayout(layout);
connect(gridCheckBox, SIGNAL(stateChanged(int)), connect(gridCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(showGrid(int))); this, SLOT(showGrid(int)));
connect(trailCheckBox, SIGNAL(stateChanged(int)), connect(trailCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(showTrail(int))); this, SLOT(showTrail(int)));
connect(imageryComboBox, SIGNAL(currentIndexChanged(const QString &)),
this, SLOT(showImagery(const QString &)));
connect(recenterButton, SIGNAL(clicked()), this, SLOT(recenterCamera())); connect(recenterButton, SIGNAL(clicked()), this, SLOT(recenterCamera()));
connect(lockCameraCheckBox, SIGNAL(stateChanged(int)), connect(lockCameraCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(toggleLockCamera(int))); this, SLOT(toggleLockCamera(int)));
...@@ -206,6 +221,11 @@ QMap3DWidget::displayHandler(void) ...@@ -206,6 +221,11 @@ QMap3DWidget::displayHandler(void)
drawWaypoints(); drawWaypoints();
} }
if (displayImagery)
{
drawImagery(robotX, robotY, "32N", true);
}
glPopMatrix(); glPopMatrix();
// switch to 2D // switch to 2D
...@@ -441,6 +461,28 @@ QMap3DWidget::showGrid(int32_t state) ...@@ -441,6 +461,28 @@ QMap3DWidget::showGrid(int32_t state)
} }
} }
void
QMap3DWidget::showImagery(const QString& text)
{
if (text.compare("None") == 0)
{
displayImagery = false;
}
else
{
if (text.compare("Map (Google)") == 0)
{
imagery->setImageryType(Imagery::MAP);
}
else if (text.compare("Satellite (Google)") == 0)
{
imagery->setImageryType(Imagery::SATELLITE);
}
displayImagery = true;
}
}
void void
QMap3DWidget::showTrail(int32_t state) QMap3DWidget::showTrail(int32_t state)
{ {
...@@ -549,6 +591,56 @@ QMap3DWidget::drawGrid(void) ...@@ -549,6 +591,56 @@ QMap3DWidget::drawGrid(void)
glPopMatrix(); glPopMatrix();
} }
void
QMap3DWidget::drawImagery(double originX, double originY, const QString& zone,
bool prefetch)
{
glPushMatrix();
glEnable(GL_BLEND);
CameraPose camPose = getCameraPose();
double viewingRadius = camPose.distance / 4000.0 * 3000.0;
if (viewingRadius < 100.0)
{
viewingRadius = 100.0;
}
double minResolution = 0.25;
double centerResolution = camPose.distance / 160.0 * 0.25;
double maxResolution = 2.0;
double resolution = minResolution;
while (resolution * 2.0 < centerResolution)
{
resolution *= 2.0;
}
if (resolution > maxResolution)
{
resolution = maxResolution;
}
imagery->draw3D(viewingRadius, resolution, originX, originY, camPose.yOffset, camPose.xOffset, zone);
if (prefetch)
{
if (resolution / 2.0 >= minResolution)
{
imagery->prefetch3D(viewingRadius / 2.0, resolution / 2.0,
originX, originY,
camPose.yOffset, camPose.xOffset, zone);
}
if (resolution * 2.0 <= maxResolution)
{
imagery->prefetch3D(viewingRadius * 2.0, resolution * 2.0,
originX, originY,
camPose.yOffset, camPose.xOffset, zone);
}
}
glDisable(GL_BLEND);
glPopMatrix();
}
void void
QMap3DWidget::drawTrail(float x, float y, float z) QMap3DWidget::drawTrail(float x, float y, float z)
{ {
......
...@@ -34,6 +34,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -34,6 +34,7 @@ This file is part of the QGROUNDCONTROL project
#include <QLabel> #include <QLabel>
#include "Imagery.h"
#include "Q3DWidget.h" #include "Q3DWidget.h"
class CheetahModel; class CheetahModel;
...@@ -72,23 +73,28 @@ public slots: ...@@ -72,23 +73,28 @@ public slots:
private slots: private slots:
void showGrid(int state); void showGrid(int state);
void showTrail(int state); void showTrail(int state);
void showImagery(const QString& text);
void recenterCamera(void); void recenterCamera(void);
void toggleLockCamera(int state); void toggleLockCamera(int state);
protected: protected:
UASInterface* uas; UASInterface* uas;
void paintText(QString text, QColor color, float fontSize, float refX, float refY, QPainter* painter); void paintText(QString text, QColor color, float fontSize,
float refX, float refY, QPainter* painter);
void drawWaypoints(); void drawWaypoints();
private: private:
void drawPlatform(float roll, float pitch, float yaw); void drawPlatform(float roll, float pitch, float yaw);
void drawGrid(void); void drawGrid(void);
void drawImagery(double originX, double originY, const QString& zone,
bool prefetch);
void drawTrail(float x, float y, float z); void drawTrail(float x, float y, float z);
void drawTarget(float x, float y, float z); void drawTarget(float x, float y, float z);
double lastRedrawTime; double lastRedrawTime;
bool displayGrid; bool displayGrid;
bool displayImagery;
bool displayTrail; bool displayTrail;
typedef struct typedef struct
...@@ -110,6 +116,7 @@ private: ...@@ -110,6 +116,7 @@ private:
Pose3D targetPosition; Pose3D targetPosition;
QScopedPointer<CheetahModel> cheetahModel; QScopedPointer<CheetahModel> cheetahModel;
QScopedPointer<Imagery> imagery;
}; };
#endif // QMAP3DWIDGET_H #endif // QMAP3DWIDGET_H
...@@ -5,8 +5,8 @@ Texture::Texture() ...@@ -5,8 +5,8 @@ Texture::Texture()
} }
QString const QString&
Texture::getSourceURL(void) Texture::getSourceURL(void) const
{ {
return sourceURL; return sourceURL;
} }
......
...@@ -16,7 +16,7 @@ class Texture ...@@ -16,7 +16,7 @@ class Texture
public: public:
Texture(); Texture();
QString getSourceURL(void); const QString& getSourceURL(void) const;
void setID(GLuint id); void setID(GLuint id);
......
...@@ -4,10 +4,9 @@ TextureCache::TextureCache(uint32_t _cacheSize) ...@@ -4,10 +4,9 @@ TextureCache::TextureCache(uint32_t _cacheSize)
: cacheSize(_cacheSize) : cacheSize(_cacheSize)
, imageCache(new WebImageCache(0, cacheSize)) , imageCache(new WebImageCache(0, cacheSize))
{ {
textures.resize(cacheSize); for (uint32_t i = 0; i < cacheSize; ++i)
TexturePtr t;
foreach(t, textures)
{ {
TexturePtr t(new Texture);
GLuint id; GLuint id;
glGenTextures(1, &id); glGenTextures(1, &id);
t->setID(id); t->setID(id);
...@@ -15,6 +14,8 @@ TextureCache::TextureCache(uint32_t _cacheSize) ...@@ -15,6 +14,8 @@ TextureCache::TextureCache(uint32_t _cacheSize)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
textures.push_back(t);
} }
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
WebImage::WebImage() WebImage::WebImage()
: state(WebImage::UNINITIALIZED) : state(WebImage::UNINITIALIZED)
, sourceURL("")
, image(new QImage)
, lastReference(0) , lastReference(0)
, syncFlag(false) , syncFlag(false)
{ {
...@@ -29,7 +31,7 @@ WebImage::setState(State state) ...@@ -29,7 +31,7 @@ WebImage::setState(State state)
this->state = state; this->state = state;
} }
QString const QString&
WebImage::getSourceURL(void) const WebImage::getSourceURL(void) const
{ {
return sourceURL; return sourceURL;
...@@ -47,6 +49,12 @@ WebImage::getData(void) const ...@@ -47,6 +49,12 @@ WebImage::getData(void) const
return image->bits(); return image->bits();
} }
void
WebImage::setData(const QByteArray& data)
{
image->loadFromData(data);
}
int32_t int32_t
WebImage::getWidth(void) const WebImage::getWidth(void) const
{ {
......
...@@ -22,10 +22,12 @@ public: ...@@ -22,10 +22,12 @@ public:
State getState(void) const; State getState(void) const;
void setState(State state); void setState(State state);
QString getSourceURL(void) const; const QString& getSourceURL(void) const;
void setSourceURL(const QString& url); void setSourceURL(const QString& url);
const uint8_t* getData(void) const; const uint8_t* getData(void) const;
void setData(const QByteArray& data);
int32_t getWidth(void) const; int32_t getWidth(void) const;
int32_t getHeight(void) const; int32_t getHeight(void) const;
......
...@@ -9,7 +9,12 @@ WebImageCache::WebImageCache(QObject* parent, uint32_t _cacheSize) ...@@ -9,7 +9,12 @@ WebImageCache::WebImageCache(QObject* parent, uint32_t _cacheSize)
, currentReference(0) , currentReference(0)
, networkManager(new QNetworkAccessManager) , networkManager(new QNetworkAccessManager)
{ {
webImages.resize(cacheSize); for (uint32_t i = 0; i < cacheSize; ++i)
{
WebImagePtr image(new WebImage);
webImages.push_back(image);
}
connect(networkManager.data(), SIGNAL(finished(QNetworkReply*)), connect(networkManager.data(), SIGNAL(finished(QNetworkReply*)),
this, SLOT(downloadFinished(QNetworkReply*))); this, SLOT(downloadFinished(QNetworkReply*)));
...@@ -104,9 +109,16 @@ WebImageCache::downloadFinished(QNetworkReply* reply) ...@@ -104,9 +109,16 @@ WebImageCache::downloadFinished(QNetworkReply* reply)
return; return;
} }
QByteArray imageData = reply->readAll(); WebImagePtr image;
QPixmap pixmap; foreach(image, webImages)
pixmap.loadFromData(imageData); {
if (reply->url().toString() == image->getSourceURL())
{
image->setData(reply->readAll());
image->setSyncFlag(true);
image->setState(WebImage::READY);
// set image, needsSync to true, and state to READY return;
}
}
} }
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