From eaaa3eb4c412db1189db2e3a470e73d53ea0b8c3 Mon Sep 17 00:00:00 2001 From: Lionel Heng Date: Wed, 20 Oct 2010 22:49:51 +0200 Subject: [PATCH] Cleaned up 3D imagery code. --- src/ui/map3D/Imagery.cc | 312 ++++++++++++++++++++++-------------------- src/ui/map3D/Imagery.h | 69 ++++++++-- src/ui/map3D/Q3DWidget.cc | 261 ++++++++++++++++++----------------- src/ui/map3D/Q3DWidget.h | 28 ++-- src/ui/map3D/QMap3DWidget.cc | 14 +- src/ui/map3D/QMap3DWidget.h | 12 +- src/ui/map3D/Texture.cc | 31 +++++ src/ui/map3D/Texture.h | 31 +++++ src/ui/map3D/TextureCache.cc | 31 +++++ src/ui/map3D/TextureCache.h | 31 +++++ src/ui/map3D/WebImage.cc | 33 ++++- src/ui/map3D/WebImage.h | 31 +++++ src/ui/map3D/WebImageCache.cc | 36 ++++- src/ui/map3D/WebImageCache.h | 31 +++++ 14 files changed, 633 insertions(+), 318 deletions(-) diff --git a/src/ui/map3D/Imagery.cc b/src/ui/map3D/Imagery.cc index 7a768f1..714fb65 100644 --- a/src/ui/map3D/Imagery.cc +++ b/src/ui/map3D/Imagery.cc @@ -1,3 +1,34 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the class Imagery. + * + * @author Lionel Heng + * + */ + #include "Imagery.h" #include @@ -33,45 +64,29 @@ Imagery::prefetch2D(double windowWidth, double windowHeight, double viewXOffset, double viewYOffset, const QString& utmZone) { - double minX = xOrigin + viewXOffset - windowWidth / 2.0 / zoom; - double minY = yOrigin + viewYOffset - windowHeight / 2.0 / zoom; - double centerX = xOrigin + viewXOffset; - double centerY = yOrigin + viewYOffset; - double maxX = xOrigin + viewXOffset + windowWidth / 2.0 / zoom; - double maxY = yOrigin + viewYOffset + windowHeight / 2.0 / zoom; - - double imageResolution; + double tileResolution; if (currentImageryType == SATELLITE) { - imageResolution = 1.0; - while (imageResolution * 3.0 / 2.0 < 1.0 / zoom) + tileResolution = 1.0; + while (tileResolution * 3.0 / 2.0 < 1.0 / zoom) { - imageResolution *= 2.0; + tileResolution *= 2.0; } - if (imageResolution > 512.0) + if (tileResolution > 512.0) { - imageResolution = 512.0; + tileResolution = 512.0; } } - int32_t minTileX, minTileY, centerTileX, centerTileY, maxTileX, maxTileY; + int32_t minTileX, minTileY, maxTileX, maxTileY; int32_t zoomLevel; - UTMtoTile(minX, minY, utmZone, imageResolution, - minTileX, maxTileY, zoomLevel); - UTMtoTile(centerX, centerY, utmZone, imageResolution, - centerTileX, centerTileY, zoomLevel); - UTMtoTile(maxX, maxY, utmZone, imageResolution, - maxTileX, minTileY, zoomLevel); - if (maxTileX - minTileX + 1 > 14) - { - minTileX = centerTileX - 7; - maxTileX = centerTileX + 6; - } - if (maxTileY - minTileY + 1 > 14) - { - minTileY = centerTileY - 7; - maxTileY = centerTileY + 6; - } + + tileBounds(tileResolution, + xOrigin + viewXOffset - windowWidth / 2.0 / zoom, + yOrigin + viewYOffset - windowHeight / 2.0 / zoom, + xOrigin + viewXOffset + windowWidth / 2.0 / zoom, + yOrigin + viewYOffset + windowHeight / 2.0 / zoom, utmZone, + minTileX, minTileY, maxTileX, maxTileY, zoomLevel); for (int32_t r = minTileY; r <= maxTileY; ++r) { @@ -90,45 +105,29 @@ Imagery::draw2D(double windowWidth, double windowHeight, double viewXOffset, double viewYOffset, const QString& utmZone) { - double minX = xOrigin + viewXOffset - windowWidth / 2.0 / zoom * 1.5; - double minY = yOrigin + viewYOffset - windowHeight / 2.0 / zoom * 1.5; - double centerX = xOrigin + viewXOffset; - double centerY = yOrigin + viewYOffset; - double maxX = xOrigin + viewXOffset + windowWidth / 2.0 / zoom * 1.5; - double maxY = yOrigin + viewYOffset + windowHeight / 2.0 / zoom * 1.5; - - double imageResolution; + double tileResolution; if (currentImageryType == SATELLITE) { - imageResolution = 1.0; - while (imageResolution * 3.0 / 2.0 < 1.0 / zoom) + tileResolution = 1.0; + while (tileResolution * 3.0 / 2.0 < 1.0 / zoom) { - imageResolution *= 2.0; + tileResolution *= 2.0; } - if (imageResolution > 512.0) + if (tileResolution > 512.0) { - imageResolution = 512.0; + tileResolution = 512.0; } } - int32_t minTileX, minTileY, centerTileX, centerTileY, maxTileX, maxTileY; + int32_t minTileX, minTileY, maxTileX, maxTileY; int32_t zoomLevel; - UTMtoTile(minX, minY, utmZone, imageResolution, - minTileX, maxTileY, zoomLevel); - UTMtoTile(centerX, centerY, utmZone, imageResolution, - centerTileX, centerTileY, zoomLevel); - UTMtoTile(maxX, maxY, utmZone, imageResolution, - maxTileX, minTileY, zoomLevel); - if (maxTileX - minTileX + 1 > 14) - { - minTileX = centerTileX - 7; - maxTileX = centerTileX + 6; - } - if (maxTileY - minTileY + 1 > 14) - { - minTileY = centerTileY - 7; - maxTileY = centerTileY + 6; - } + + tileBounds(tileResolution, + xOrigin + viewXOffset - windowWidth / 2.0 / zoom * 1.5, + yOrigin + viewYOffset - windowHeight / 2.0 / zoom * 1.5, + xOrigin + viewXOffset + windowWidth / 2.0 / zoom * 1.5, + yOrigin + viewYOffset + windowHeight / 2.0 / zoom * 1.5, utmZone, + minTileX, minTileY, maxTileX, maxTileY, zoomLevel); for (int32_t r = minTileY; r <= maxTileY; ++r) { @@ -137,7 +136,7 @@ Imagery::draw2D(double windowWidth, double windowHeight, QString tileURL = getTileURL(c, r, zoomLevel); double x1, y1, x2, y2, x3, y3, x4, y4; - imageBounds(c, r, imageResolution, x1, y1, x2, y2, x3, y3, x4, y4); + imageBounds(c, r, tileResolution, x1, y1, x2, y2, x3, y3, x4, y4); TexturePtr t = textureCache->get(tileURL); if (!t.isNull()) @@ -152,36 +151,20 @@ Imagery::draw2D(double windowWidth, double windowHeight, } void -Imagery::prefetch3D(double radius, double imageResolution, +Imagery::prefetch3D(double radius, double tileResolution, double xOrigin, double yOrigin, double viewXOffset, double viewYOffset, const QString& utmZone) { - double minX = xOrigin + viewXOffset - radius; - double minY = yOrigin + viewYOffset - radius; - double centerX = xOrigin + viewXOffset; - double centerY = yOrigin + viewYOffset; - double maxX = xOrigin + viewXOffset + radius; - double maxY = yOrigin + viewYOffset + radius; - - int32_t minTileX, minTileY, centerTileX, centerTileY, maxTileX, maxTileY; + int32_t minTileX, minTileY, maxTileX, maxTileY; int32_t zoomLevel; - UTMtoTile(minX, minY, utmZone, imageResolution, - minTileX, maxTileY, zoomLevel); - UTMtoTile(centerX, centerY, utmZone, imageResolution, - centerTileX, centerTileY, zoomLevel); - UTMtoTile(maxX, maxY, utmZone, imageResolution, - maxTileX, minTileY, zoomLevel); - if (maxTileX - minTileX + 1 > 14) - { - minTileX = centerTileX - 7; - maxTileX = centerTileX + 6; - } - if (maxTileY - minTileY + 1 > 14) - { - minTileY = centerTileY - 7; - maxTileY = centerTileY + 6; - } + + tileBounds(tileResolution, + xOrigin + viewXOffset - radius, + yOrigin + viewYOffset - radius, + xOrigin + viewXOffset + radius, + yOrigin + viewYOffset + radius, utmZone, + minTileX, minTileY, maxTileX, maxTileY, zoomLevel); for (int32_t r = minTileY; r <= maxTileY; ++r) { @@ -195,38 +178,20 @@ Imagery::prefetch3D(double radius, double imageResolution, } void -Imagery::draw3D(double radius, double imageResolution, +Imagery::draw3D(double radius, double tileResolution, double xOrigin, double yOrigin, double viewXOffset, double viewYOffset, const QString& utmZone) { - - double minX = xOrigin + viewXOffset - radius; - double minY = yOrigin + viewYOffset - radius; - double centerX = xOrigin + viewXOffset; - double centerY = yOrigin + viewYOffset; - double maxX = xOrigin + viewXOffset + radius; - double maxY = yOrigin + viewYOffset + radius; - - int32_t minTileX, minTileY, centerTileX, centerTileY, maxTileX, maxTileY; + int32_t minTileX, minTileY, maxTileX, maxTileY; int32_t zoomLevel; - UTMtoTile(minX, minY, utmZone, imageResolution, - minTileX, maxTileY, zoomLevel); - UTMtoTile(centerX, centerY, utmZone, imageResolution, - centerTileX, centerTileY, zoomLevel); - UTMtoTile(maxX, maxY, utmZone, imageResolution, - maxTileX, minTileY, zoomLevel); - if (maxTileX - minTileX + 1 > 14) - { - minTileX = centerTileX - 7; - maxTileX = centerTileX + 6; - } - if (maxTileY - minTileY + 1 > 14) - { - minTileY = centerTileY - 7; - maxTileY = centerTileY + 6; - } + tileBounds(tileResolution, + xOrigin + viewXOffset - radius, + yOrigin + viewYOffset - radius, + xOrigin + viewXOffset + radius, + yOrigin + viewYOffset + radius, utmZone, + minTileX, minTileY, maxTileX, maxTileY, zoomLevel); for (int32_t r = minTileY; r <= maxTileY; ++r) { @@ -235,7 +200,7 @@ Imagery::draw3D(double radius, double imageResolution, QString tileURL = getTileURL(c, r, zoomLevel); double x1, y1, x2, y2, x3, y3, x4, y4; - imageBounds(c, r, imageResolution, x1, y1, x2, y2, x3, y3, x4, y4); + imageBounds(c, r, tileResolution, x1, y1, x2, y2, x3, y3, x4, y4); TexturePtr t = textureCache->get(tileURL); @@ -259,66 +224,108 @@ Imagery::update(void) } void -Imagery::imageBounds(int32_t x, int32_t y, double imageResolution, +Imagery::imageBounds(int32_t tileX, int32_t tileY, double tileResolution, double& x1, double& y1, double& x2, double& y2, - double& x3, double& y3, double& x4, double& y4) + double& x3, double& y3, double& x4, double& y4) const { - int32_t zoomLevel = MAX_ZOOM_LEVEL - static_cast(rint(log2(imageResolution))); + int32_t zoomLevel = MAX_ZOOM_LEVEL - static_cast(rint(log2(tileResolution))); int32_t numTiles = static_cast(exp2(static_cast(zoomLevel))); - double lon1 = 360.0 * (static_cast(x) - / static_cast(numTiles)) - 180; - double lon2 = 360.0 * ((static_cast(x + 1)) - / static_cast(numTiles)) - 180; + double lon1 = tileXToLongitude(tileX, numTiles); + double lon2 = tileXToLongitude(tileX + 1, numTiles); - double lat1 = tileYToLatitude((static_cast(y + 1) - / static_cast(numTiles)) - * 2.0 * M_PI - M_PI); - double lat2 = tileYToLatitude((static_cast(y) - / static_cast(numTiles)) - * 2.0 * M_PI - M_PI); + double lat1 = tileYToLatitude(tileY, numTiles); + double lat2 = tileYToLatitude(tileY + 1, numTiles); QString utmZone; - LLtoUTM(lat2, lon1, x1, y1, utmZone); - LLtoUTM(lat2, lon2, x2, y2, utmZone); - LLtoUTM(lat1, lon2, x3, y3, utmZone); - LLtoUTM(lat1, lon1, x4, y4, utmZone); + LLtoUTM(lat1, lon1, x1, y1, utmZone); + LLtoUTM(lat1, lon2, x2, y2, utmZone); + LLtoUTM(lat2, lon2, x3, y3, utmZone); + LLtoUTM(lat2, lon1, x4, y4, utmZone); +} + +void +Imagery::tileBounds(double tileResolution, + double minUtmX, double minUtmY, + double maxUtmX, double maxUtmY, const QString& utmZone, + int32_t& minTileX, int32_t& minTileY, + int32_t& maxTileX, int32_t& maxTileY, + int32_t& zoomLevel) const +{ + double centerUtmX = (maxUtmX - minUtmX) / 2.0 + minUtmX; + double centerUtmY = (maxUtmY - minUtmY) / 2.0 + minUtmY; + + int32_t centerTileX, centerTileY; + + UTMtoTile(minUtmX, minUtmY, utmZone, tileResolution, + minTileX, maxTileY, zoomLevel); + UTMtoTile(centerUtmX, centerUtmY, utmZone, tileResolution, + centerTileX, centerTileY, zoomLevel); + UTMtoTile(maxUtmX, maxUtmY, utmZone, tileResolution, + maxTileX, minTileY, zoomLevel); + + if (maxTileX - minTileX + 1 > 14) + { + minTileX = centerTileX - 7; + maxTileX = centerTileX + 6; + } + if (maxTileY - minTileY + 1 > 14) + { + minTileY = centerTileY - 7; + maxTileY = centerTileY + 6; + } } double -Imagery::tileYToLatitude(double y) +Imagery::tileXToLongitude(int32_t tileX, int32_t numTiles) const { - double rad = 2.0 * atan(exp(y)) - M_PI / 2.0; - return -rad * 180.0 / M_PI; + return 360.0 * (static_cast(tileX) + / static_cast(numTiles)) - 180.0; } double -Imagery::latitudeToTileY(double latitude) +Imagery::tileYToLatitude(int32_t tileY, int32_t numTiles) const +{ + double unnormalizedRad = + (static_cast(tileY) / static_cast(numTiles)) + * 2.0 * M_PI - M_PI; + double rad = 2.0 * atan(exp(unnormalizedRad)) - M_PI / 2.0; + return -rad * 180.0 / M_PI; +} + +int32_t +Imagery::longitudeToTileX(double longitude, int32_t numTiles) const +{ + return static_cast((longitude / 180.0 + 1.0) / 2.0 * numTiles); +} + +int32_t +Imagery::latitudeToTileY(double latitude, int32_t numTiles) const { double rad = latitude * M_PI / 180.0; - return -log(tan(rad) + 1.0 / cos(rad)); + double normalizedRad = -log(tan(rad) + 1.0 / cos(rad)); + return static_cast((normalizedRad + M_PI) + / (2.0 * M_PI) * numTiles); } void Imagery::UTMtoTile(double northing, double easting, const QString& utmZone, - double imageResolution, int32_t& tileX, int32_t& tileY, - int32_t& zoomLevel) + double tileResolution, int32_t& tileX, int32_t& tileY, + int32_t& zoomLevel) const { double latitude, longitude; UTMtoLL(northing, easting, utmZone, latitude, longitude); - zoomLevel = MAX_ZOOM_LEVEL - static_cast(rint(log2(imageResolution))); + zoomLevel = MAX_ZOOM_LEVEL - static_cast(rint(log2(tileResolution))); int32_t numTiles = static_cast(exp2(static_cast(zoomLevel))); - double x = longitude / 180.0; - double y = latitudeToTileY(latitude); - tileX = static_cast((x + 1.0) / 2.0 * numTiles); - tileY = static_cast((y + M_PI) / (2.0 * M_PI) * numTiles); + tileX = longitudeToTileX(longitude, numTiles); + tileY = latitudeToTileY(latitude, numTiles); } QChar -Imagery::UTMLetterDesignator(double latitude) +Imagery::UTMLetterDesignator(double latitude) const { // This routine determines the correct UTM letter designator for the given latitude // returns 'Z' if latitude is outside the UTM limits of 84N to 80S @@ -351,8 +358,9 @@ Imagery::UTMLetterDesignator(double latitude) } void -Imagery::LLtoUTM(const double latitude, const double longitude, - double& utmNorthing, double& utmEasting, QString& utmZone) +Imagery::LLtoUTM(double latitude, double longitude, + double& utmNorthing, double& utmEasting, + QString& utmZone) const { // converts lat/long to UTM coords. Equations from USGS Bulletin 1532 // East Longitudes are positive, West longitudes are negative. @@ -432,8 +440,8 @@ Imagery::LLtoUTM(const double latitude, const double longitude, } void -Imagery::UTMtoLL(const double utmNorthing, const double utmEasting, - const QString& utmZone, double& latitude, double& longitude) +Imagery::UTMtoLL(double utmNorthing, double utmEasting, const QString& utmZone, + double& latitude, double& longitude) const { // converts UTM coords to lat/long. Equations from USGS Bulletin 1532 // East Longitudes are positive, West longitudes are negative. @@ -505,19 +513,19 @@ Imagery::UTMtoLL(const double utmNorthing, const double utmEasting, } QString -Imagery::getTileURL(int32_t x, int32_t y, int32_t zoomLevel) +Imagery::getTileURL(int32_t tileX, int32_t tileY, int32_t zoomLevel) const { std::ostringstream oss; switch (currentImageryType) { case MAP: - oss << "http://mt0.google.com/vt/lyrs=m@120&x=" << x << "&y=" << y - << "&z=" << zoomLevel; + oss << "http://mt0.google.com/vt/lyrs=m@120&x=" << tileX + << "&y=" << tileY << "&z=" << zoomLevel; break; case SATELLITE: - oss << "http://khm.google.com/vt/lbw/lyrs=y&x=" << x << "&y=" << y - << "&z=" << zoomLevel; + oss << "http://khm.google.com/vt/lbw/lyrs=y&x=" << tileX + << "&y=" << tileY << "&z=" << zoomLevel; break; default: {}; diff --git a/src/ui/map3D/Imagery.h b/src/ui/map3D/Imagery.h index 67c535f..bcfe10b 100644 --- a/src/ui/map3D/Imagery.h +++ b/src/ui/map3D/Imagery.h @@ -1,3 +1,34 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the class Imagery. + * + * @author Lionel Heng + * + */ + #ifndef IMAGERY_H #define IMAGERY_H @@ -28,11 +59,11 @@ public: double viewXOffset, double viewYOffset, const QString& utmZone); - void prefetch3D(double radius, double imageResolution, + void prefetch3D(double radius, double tileResolution, double xOrigin, double yOrigin, double viewXOffset, double viewYOffset, const QString& utmZone); - void draw3D(double radius, double imageResolution, + void draw3D(double radius, double tileResolution, double xOrigin, double yOrigin, double viewXOffset, double viewYOffset, const QString& utmZone); @@ -40,28 +71,36 @@ public: bool update(void); private: - void imageBounds(int32_t x, int32_t y, double imageResolution, + void imageBounds(int32_t tileX, int32_t tileY, double tileResolution, double& x1, double& y1, double& x2, double& y2, - double& x3, double& y3, double& x4, double& y4); + double& x3, double& y3, double& x4, double& y4) const; + + void tileBounds(double tileResolution, + double minUtmX, double minUtmY, + double maxUtmX, double maxUtmY, const QString& utmZone, + int32_t& minTileX, int32_t& minTileY, + int32_t& maxTileX, int32_t& maxTileY, + int32_t& zoomLevel) const; - double tileYToLatitude(double y); - double latitudeToTileY(double latitude); + double tileXToLongitude(int32_t tileX, int32_t numTiles) const; + double tileYToLatitude(int32_t tileY, int32_t numTiles) const; + int32_t longitudeToTileX(double longitude, int32_t numTiles) const; + int32_t latitudeToTileY(double latitude, int32_t numTiles) const; void UTMtoTile(double northing, double easting, const QString& utmZone, - double imageResolution, int32_t& tileX, int32_t& tileY, - int32_t& zoomLevel); + double tileResolution, int32_t& tileX, int32_t& tileY, + int32_t& zoomLevel) const; - QChar UTMLetterDesignator(double latitude); + QChar UTMLetterDesignator(double latitude) const; - void LLtoUTM(const double latitude, const double longitude, + void LLtoUTM(double latitude, double longitude, double& utmNorthing, double& utmEasting, - QString& utmZone); + QString& utmZone) const; - void UTMtoLL(const double utmNorthing, const double utmEasting, - const QString& utmZone, - double& latitude, double& longitude); + void UTMtoLL(double utmNorthing, double utmEasting, const QString& utmZone, + double& latitude, double& longitude) const; - QString getTileURL(int32_t x, int32_t y, int32_t zoomLevel); + QString getTileURL(int32_t tileX, int32_t tileY, int32_t zoomLevel) const; ImageryType currentImageryType; diff --git a/src/ui/map3D/Q3DWidget.cc b/src/ui/map3D/Q3DWidget.cc index a6c9fe6..ec730d3 100755 --- a/src/ui/map3D/Q3DWidget.cc +++ b/src/ui/map3D/Q3DWidget.cc @@ -474,13 +474,13 @@ Q3DWidget::setDisplayMode3D() } float -Q3DWidget::r2d(float angle) +Q3DWidget::r2d(float angle) const { return angle * 57.295779513082320876f; } float -Q3DWidget::d2r(float angle) +Q3DWidget::d2r(float angle) const { return angle * 0.0174532925199432957692f; } @@ -866,160 +866,173 @@ Q3DWidget::closeEvent(QCloseEvent *) // exit application } -void Q3DWidget::wireSphere(double radius, int slices, int stacks) +void +Q3DWidget::wireSphere(double radius, int slices, int stacks) const { - static GLUquadricObj* quadObj; + static GLUquadricObj* quadObj; // Make sure quad object exists - if(!quadObj) quadObj = gluNewQuadric(); - gluQuadricDrawStyle(quadObj, GLU_LINE); - gluQuadricNormals(quadObj, GLU_SMOOTH); - /* If we ever changed/used the texture or orientation state - of quadObj, we'd need to change it to the defaults here - with gluQuadricTexture and/or gluQuadricOrientation. */ - gluSphere(quadObj, radius, slices, stacks); + if (!quadObj) quadObj = gluNewQuadric(); + gluQuadricDrawStyle(quadObj, GLU_LINE); + gluQuadricNormals(quadObj, GLU_SMOOTH); + /* If we ever changed/used the texture or orientation state + of quadObj, we'd need to change it to the defaults here + with gluQuadricTexture and/or gluQuadricOrientation. */ + gluSphere(quadObj, radius, slices, stacks); } -void Q3DWidget::solidSphere(double radius, int slices, int stacks) +void +Q3DWidget::solidSphere(double radius, int slices, int stacks) const { - static GLUquadricObj* quadObj; + static GLUquadricObj* quadObj; // Make sure quad object exists - if(!quadObj) quadObj = gluNewQuadric(); - gluQuadricDrawStyle(quadObj, GLU_FILL); - gluQuadricNormals(quadObj, GLU_SMOOTH); - /* If we ever changed/used the texture or orientation state - of quadObj, we'd need to change it to the defaults here - with gluQuadricTexture and/or gluQuadricOrientation. */ - gluSphere(quadObj, radius, slices, stacks); + if (!quadObj) quadObj = gluNewQuadric(); + gluQuadricDrawStyle(quadObj, GLU_FILL); + gluQuadricNormals(quadObj, GLU_SMOOTH); + /* If we ever changed/used the texture or orientation state + of quadObj, we'd need to change it to the defaults here + with gluQuadricTexture and/or gluQuadricOrientation. */ + gluSphere(quadObj, radius, slices, stacks); } -void Q3DWidget::wireCone(double base, double height, int slices, int stacks) +void +Q3DWidget::wireCone(double base, double height, int slices, int stacks) const { - static GLUquadricObj* quadObj; + static GLUquadricObj* quadObj; // Make sure quad object exists - if(!quadObj) quadObj = gluNewQuadric(); - gluQuadricDrawStyle(quadObj, GLU_LINE); - gluQuadricNormals(quadObj, GLU_SMOOTH); - /* If we ever changed/used the texture or orientation state - of quadObj, we'd need to change it to the defaults here - with gluQuadricTexture and/or gluQuadricOrientation. */ - gluCylinder(quadObj, base, 0.0, height, slices, stacks); + if (!quadObj) quadObj = gluNewQuadric(); + gluQuadricDrawStyle(quadObj, GLU_LINE); + gluQuadricNormals(quadObj, GLU_SMOOTH); + /* If we ever changed/used the texture or orientation state + of quadObj, we'd need to change it to the defaults here + with gluQuadricTexture and/or gluQuadricOrientation. */ + gluCylinder(quadObj, base, 0.0, height, slices, stacks); } -void Q3DWidget::solidCone(double base, double height, int slices, int stacks) +void +Q3DWidget::solidCone(double base, double height, int slices, int stacks) const { static GLUquadricObj* quadObj; // Make sure quad object exists - if(!quadObj) quadObj = gluNewQuadric(); - gluQuadricDrawStyle(quadObj, GLU_FILL); - gluQuadricNormals(quadObj, GLU_SMOOTH); - /* If we ever changed/used the texture or orientation state - of quadObj, we'd need to change it to the defaults here - with gluQuadricTexture and/or gluQuadricOrientation. */ - gluCylinder(quadObj, base, 0.0, height, slices, stacks); + if (!quadObj) quadObj = gluNewQuadric(); + gluQuadricDrawStyle(quadObj, GLU_FILL); + gluQuadricNormals(quadObj, GLU_SMOOTH); + /* If we ever changed/used the texture or orientation state + of quadObj, we'd need to change it to the defaults here + with gluQuadricTexture and/or gluQuadricOrientation. */ + gluCylinder(quadObj, base, 0.0, height, slices, stacks); } -void Q3DWidget::drawBox(float size, GLenum type) +void +Q3DWidget::drawBox(float size, GLenum type) const { - static GLfloat n[6][3] = - { - {-1.0, 0.0, 0.0}, - {0.0, 1.0, 0.0}, - {1.0, 0.0, 0.0}, - {0.0, -1.0, 0.0}, - {0.0, 0.0, 1.0}, - {0.0, 0.0, -1.0} - }; - static GLint faces[6][4] = - { - {0, 1, 2, 3}, - {3, 2, 6, 7}, - {7, 6, 5, 4}, - {4, 5, 1, 0}, - {5, 6, 2, 1}, - {7, 4, 0, 3} - }; - GLfloat v[8][3]; - GLint i; - - v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2; - v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2; - v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2; - v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2; - v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2; - v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2; - - for (i = 5; i >= 0; i--) { - glBegin(type); - glNormal3fv(&n[i][0]); - glVertex3fv(&v[faces[i][0]][0]); - glVertex3fv(&v[faces[i][1]][0]); - glVertex3fv(&v[faces[i][2]][0]); - glVertex3fv(&v[faces[i][3]][0]); - glEnd(); - } + static GLfloat n[6][3] = + { + {-1.0, 0.0, 0.0}, + {0.0, 1.0, 0.0}, + {1.0, 0.0, 0.0}, + {0.0, -1.0, 0.0}, + {0.0, 0.0, 1.0}, + {0.0, 0.0, -1.0} + }; + static GLint faces[6][4] = + { + {0, 1, 2, 3}, + {3, 2, 6, 7}, + {7, 6, 5, 4}, + {4, 5, 1, 0}, + {5, 6, 2, 1}, + {7, 4, 0, 3} + }; + GLfloat v[8][3]; + GLint i; + + v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2; + v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2; + v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2; + v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2; + v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2; + v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2; + + for (i = 5; i >= 0; i--) + { + glBegin(type); + glNormal3fv(&n[i][0]); + glVertex3fv(&v[faces[i][0]][0]); + glVertex3fv(&v[faces[i][1]][0]); + glVertex3fv(&v[faces[i][2]][0]); + glVertex3fv(&v[faces[i][3]][0]); + glEnd(); + } } -void Q3DWidget::wireCube(double size) +void +Q3DWidget::wireCube(double size) const { - drawBox(size, GL_LINE_LOOP); + drawBox(size, GL_LINE_LOOP); } -void Q3DWidget::solidCube(double size) +void +Q3DWidget::solidCube(double size) const { - drawBox(size, GL_QUADS); + drawBox(size, GL_QUADS); } -void Q3DWidget::doughnut(float r, float R, int nsides, int rings) +void +Q3DWidget::doughnut(float r, float R, int nsides, int rings) const { - int i, j; - GLfloat theta, phi, theta1; - GLfloat cosTheta, sinTheta; - GLfloat cosTheta1, sinTheta1; - GLfloat ringDelta, sideDelta; - - ringDelta = 2.0 * M_PI / rings; - sideDelta = 2.0 * M_PI / nsides; - - theta = 0.0; - cosTheta = 1.0; - sinTheta = 0.0; - for (i = rings - 1; i >= 0; i--) { - theta1 = theta + ringDelta; - cosTheta1 = cos(theta1); - sinTheta1 = sin(theta1); - glBegin(GL_QUAD_STRIP); - phi = 0.0; - for (j = nsides; j >= 0; j--) { - GLfloat cosPhi, sinPhi, dist; - - phi += sideDelta; - cosPhi = cos(phi); - sinPhi = sin(phi); - dist = R + r * cosPhi; - - glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); - glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); - glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); - glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); + int i, j; + GLfloat theta, phi, theta1; + GLfloat cosTheta, sinTheta; + GLfloat cosTheta1, sinTheta1; + GLfloat ringDelta, sideDelta; + + ringDelta = 2.0 * M_PI / rings; + sideDelta = 2.0 * M_PI / nsides; + + theta = 0.0; + cosTheta = 1.0; + sinTheta = 0.0; + for (i = rings - 1; i >= 0; i--) + { + theta1 = theta + ringDelta; + cosTheta1 = cos(theta1); + sinTheta1 = sin(theta1); + glBegin(GL_QUAD_STRIP); + phi = 0.0; + for (j = nsides; j >= 0; j--) + { + GLfloat cosPhi, sinPhi, dist; + + phi += sideDelta; + cosPhi = cos(phi); + sinPhi = sin(phi); + dist = R + r * cosPhi; + + glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); + glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); + glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); + glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); + } + glEnd(); + theta = theta1; + cosTheta = cosTheta1; + sinTheta = sinTheta1; } - glEnd(); - theta = theta1; - cosTheta = cosTheta1; - sinTheta = sinTheta1; - } } -void Q3DWidget::wireTorus(double innerRadius, double outerRadius, - int nsides, int rings) +void +Q3DWidget::wireTorus(double innerRadius, double outerRadius, + int nsides, int rings) const { - glPushAttrib(GL_POLYGON_BIT); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - doughnut(innerRadius, outerRadius, nsides, rings); - glPopAttrib(); + glPushAttrib(GL_POLYGON_BIT); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + doughnut(innerRadius, outerRadius, nsides, rings); + glPopAttrib(); } -void Q3DWidget::solidTorus(double innerRadius, double outerRadius, - int nsides, int rings) +void +Q3DWidget::solidTorus(double innerRadius, double outerRadius, + int nsides, int rings) const { - doughnut(innerRadius, outerRadius, nsides, rings); + doughnut(innerRadius, outerRadius, nsides, rings); } diff --git a/src/ui/map3D/Q3DWidget.h b/src/ui/map3D/Q3DWidget.h index 5658c64..947deef 100644 --- a/src/ui/map3D/Q3DWidget.h +++ b/src/ui/map3D/Q3DWidget.h @@ -162,19 +162,21 @@ protected: void switchTo3DMode(void); void setDisplayMode3D(void); - float r2d(float angle); - float d2r(float angle); - - void wireSphere(double radius, int slices, int stacks); - void solidSphere(double radius, int slices, int stacks); - void wireCone(double base, double height, int slices, int stacks); - void solidCone(double base, double height, int slices, int stacks); - void drawBox(float size, GLenum type); - void wireCube(double size); - void solidCube(double size); - void doughnut(float r, float R, int nsides, int rings); - void wireTorus(double innerRadius, double outerRadius, int nsides, int rings); - void solidTorus(double innerRadius, double outerRadius, int nsides, int rings); + float r2d(float angle) const; + float d2r(float angle) const; + + void wireSphere(double radius, int slices, int stacks) const; + void solidSphere(double radius, int slices, int stacks) const; + void wireCone(double base, double height, int slices, int stacks) const; + void solidCone(double base, double height, int slices, int stacks) const; + void drawBox(float size, GLenum type) const; + void wireCube(double size) const; + void solidCube(double size) const; + void doughnut(float r, float R, int nsides, int rings) const; + void wireTorus(double innerRadius, double outerRadius, + int nsides, int rings) const; + void solidTorus(double innerRadius, double outerRadius, + int nsides, int rings) const; GLUquadricObj* quadObj; diff --git a/src/ui/map3D/QMap3DWidget.cc b/src/ui/map3D/QMap3DWidget.cc index e57db05..97b3505 100644 --- a/src/ui/map3D/QMap3DWidget.cc +++ b/src/ui/map3D/QMap3DWidget.cc @@ -266,7 +266,7 @@ QMap3DWidget::displayHandler(void) &painter); } -void QMap3DWidget::drawWaypoints() +void QMap3DWidget::drawWaypoints(void) const { if (uas) { @@ -391,7 +391,9 @@ QMap3DWidget::drawLegend(void) &painter); } -void QMap3DWidget::paintText(QString text, QColor color, float fontSize, float refX, float refY, QPainter* painter) +void +QMap3DWidget::paintText(QString text, QColor color, float fontSize, + float refX, float refY, QPainter* painter) const { QPen prevPen = painter->pen(); @@ -590,7 +592,7 @@ QMap3DWidget::toggleLockCamera(int32_t state) } void -QMap3DWidget::drawPlatform(float roll, float pitch, float yaw) +QMap3DWidget::drawPlatform(float roll, float pitch, float yaw) const { glPushMatrix(); @@ -627,7 +629,7 @@ QMap3DWidget::drawPlatform(float roll, float pitch, float yaw) } void -QMap3DWidget::drawGrid(void) +QMap3DWidget::drawGrid(void) const { float radius = 10.0f; float resolution = 0.25f; @@ -660,7 +662,7 @@ QMap3DWidget::drawGrid(void) void QMap3DWidget::drawImagery(double originX, double originY, const QString& zone, - bool prefetch) + bool prefetch) const { glPushMatrix(); glEnable(GL_BLEND); @@ -763,7 +765,7 @@ QMap3DWidget::drawTrail(float x, float y, float z) } void -QMap3DWidget::drawTarget(float x, float y, float z) +QMap3DWidget::drawTarget(float x, float y, float z) const { static double radius = 0.2; static bool expand = true; diff --git a/src/ui/map3D/QMap3DWidget.h b/src/ui/map3D/QMap3DWidget.h index e0d2a9d..b4aea81 100644 --- a/src/ui/map3D/QMap3DWidget.h +++ b/src/ui/map3D/QMap3DWidget.h @@ -80,16 +80,16 @@ private slots: protected: UASInterface* uas; void paintText(QString text, QColor color, float fontSize, - float refX, float refY, QPainter* painter); - void drawWaypoints(); + float refX, float refY, QPainter* painter) const; + void drawWaypoints(void) const; private: - void drawPlatform(float roll, float pitch, float yaw); - void drawGrid(void); + void drawPlatform(float roll, float pitch, float yaw) const; + void drawGrid(void) const; void drawImagery(double originX, double originY, const QString& zone, - bool prefetch); + bool prefetch) const; void drawTrail(float x, float y, float z); - void drawTarget(float x, float y, float z); + void drawTarget(float x, float y, float z) const; void drawLegend(void); diff --git a/src/ui/map3D/Texture.cc b/src/ui/map3D/Texture.cc index 82574bb..184f44f 100644 --- a/src/ui/map3D/Texture.cc +++ b/src/ui/map3D/Texture.cc @@ -1,3 +1,34 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the class Texture. + * + * @author Lionel Heng + * + */ + #include "Texture.h" Texture::Texture() diff --git a/src/ui/map3D/Texture.h b/src/ui/map3D/Texture.h index d4c8395..4b81617 100644 --- a/src/ui/map3D/Texture.h +++ b/src/ui/map3D/Texture.h @@ -1,3 +1,34 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the class Texture. + * + * @author Lionel Heng + * + */ + #ifndef TEXTURE_H #define TEXTURE_H diff --git a/src/ui/map3D/TextureCache.cc b/src/ui/map3D/TextureCache.cc index 5fb2103..477c2b7 100644 --- a/src/ui/map3D/TextureCache.cc +++ b/src/ui/map3D/TextureCache.cc @@ -1,3 +1,34 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the class TextureCache. + * + * @author Lionel Heng + * + */ + #include "TextureCache.h" TextureCache::TextureCache(uint32_t _cacheSize) diff --git a/src/ui/map3D/TextureCache.h b/src/ui/map3D/TextureCache.h index 7368441..25be665 100644 --- a/src/ui/map3D/TextureCache.h +++ b/src/ui/map3D/TextureCache.h @@ -1,3 +1,34 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the class TextureCache. + * + * @author Lionel Heng + * + */ + #ifndef TEXTURECACHE_H #define TEXTURECACHE_H diff --git a/src/ui/map3D/WebImage.cc b/src/ui/map3D/WebImage.cc index bfcdc9c..be97fa3 100644 --- a/src/ui/map3D/WebImage.cc +++ b/src/ui/map3D/WebImage.cc @@ -1,3 +1,34 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the class WebImage. + * + * @author Lionel Heng + * + */ + #include "WebImage.h" #include @@ -6,7 +37,7 @@ WebImage::WebImage() : state(WebImage::UNINITIALIZED) , sourceURL("") - , image(new QImage) + , image(0) , lastReference(0) , syncFlag(false) { diff --git a/src/ui/map3D/WebImage.h b/src/ui/map3D/WebImage.h index 2796878..ac601dc 100644 --- a/src/ui/map3D/WebImage.h +++ b/src/ui/map3D/WebImage.h @@ -1,3 +1,34 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the class WebImage. + * + * @author Lionel Heng + * + */ + #ifndef WEBIMAGE_H #define WEBIMAGE_H diff --git a/src/ui/map3D/WebImageCache.cc b/src/ui/map3D/WebImageCache.cc index ce85266..9074832 100644 --- a/src/ui/map3D/WebImageCache.cc +++ b/src/ui/map3D/WebImageCache.cc @@ -1,3 +1,34 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the class WebImageCache. + * + * @author Lionel Heng + * + */ + #include "WebImageCache.h" #include @@ -100,7 +131,10 @@ WebImageCache::at(int32_t index) const void WebImageCache::downloadFinished(QNetworkReply* reply) { - if (reply->error() != QNetworkReply::NoError) { + reply->deleteLater(); + + if (reply->error() != QNetworkReply::NoError) + { return; } QVariant attribute = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); diff --git a/src/ui/map3D/WebImageCache.h b/src/ui/map3D/WebImageCache.h index 5c4dd86..d482d71 100644 --- a/src/ui/map3D/WebImageCache.h +++ b/src/ui/map3D/WebImageCache.h @@ -1,3 +1,34 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the class WebImageCache. + * + * @author Lionel Heng + * + */ + #ifndef WEBIMAGECACHE_H #define WEBIMAGECACHE_H