diff --git a/src/ui/map3D/Imagery.cc b/src/ui/map3D/Imagery.cc index 030419f27331ff64a949a4da111f6b9ea0b45696..d5c39740dea255305a3204af82c07190ce238548 100644 --- a/src/ui/map3D/Imagery.cc +++ b/src/ui/map3D/Imagery.cc @@ -42,13 +42,13 @@ const double WGS84_ECCSQ = 0.00669437999013; const int MAX_ZOOM_LEVEL = 20; Imagery::Imagery() - : mTextureCache(new TextureCache(500)) + : mTextureCache(new TextureCache(1000)) , mImageryType(Imagery::BLANK_MAP) , mXOffset(0.0) , mYOffset(0.0) , mZOffset(0.0) { - + setCullingActive(false); } Imagery::Type diff --git a/src/ui/map3D/Pixhawk3DWidget.cc b/src/ui/map3D/Pixhawk3DWidget.cc index 0a1a483e6bb8ba0afd6106f6afba807f910a8b7c..182459cd6fad9dcfbc8f7764a0354c423a1f8da9 100644 --- a/src/ui/map3D/Pixhawk3DWidget.cc +++ b/src/ui/map3D/Pixhawk3DWidget.cc @@ -2053,9 +2053,9 @@ Pixhawk3DWidget::updateImagery(double originX, double originY, } double viewingRadius = m3DWidget->cameraManipulator()->getDistance() * 10.0; - if (viewingRadius < 100.0) + if (viewingRadius < 200.0) { - viewingRadius = 100.0; + viewingRadius = 200.0; } double minResolution = 0.25; diff --git a/src/ui/map3D/Texture.cc b/src/ui/map3D/Texture.cc index 77691888a1ef7be3cc7006ea4e50edb7df6df87c..e7dc3c741b5ea7fe967a303a63897ac42a803f50 100644 --- a/src/ui/map3D/Texture.cc +++ b/src/ui/map3D/Texture.cc @@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project * @file * @brief Definition of the class Texture. * - * @author Lionel Heng + * @author Lionel Heng * */ @@ -33,77 +33,86 @@ This file is part of the QGROUNDCONTROL project #include "Texture.h" -Texture::Texture(unsigned int _id) - : id(_id) - , texture2D(new osg::Texture2D) - , geometry(new osg::Geometry) +Texture::Texture(quint64 id) + : mId(id) + , mTexture2D(new osg::Texture2D) + , mGeometry(new osg::Geometry) { - texture2D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST); - texture2D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST); + mTexture2D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST); + mTexture2D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST); - texture2D->setDataVariance(osg::Object::DYNAMIC); - texture2D->setResizeNonPowerOfTwoHint(false); + mTexture2D->setDataVariance(osg::Object::DYNAMIC); + mTexture2D->setResizeNonPowerOfTwoHint(false); osg::ref_ptr image = new osg::Image; - texture2D->setImage(image); + mTexture2D->setImage(image); osg::ref_ptr vertices(new osg::Vec3dArray(4)); - geometry->setVertexArray(vertices); + mGeometry->setVertexArray(vertices); osg::ref_ptr textureCoords = new osg::Vec2Array; textureCoords->push_back(osg::Vec2(0.0f, 1.0f)); textureCoords->push_back(osg::Vec2(1.0f, 1.0f)); textureCoords->push_back(osg::Vec2(1.0f, 0.0f)); textureCoords->push_back(osg::Vec2(0.0f, 0.0f)); - geometry->setTexCoordArray(0, textureCoords); + mGeometry->setTexCoordArray(0, textureCoords); - geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, + mGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, 4)); osg::ref_ptr colors(new osg::Vec4Array); colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f)); - geometry->setColorArray(colors); - geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + mGeometry->setColorArray(colors); + mGeometry->setColorBinding(osg::Geometry::BIND_OVERALL); - geometry->setUseDisplayList(false); + mGeometry->setUseDisplayList(false); osg::ref_ptr linewidth(new osg::LineWidth); linewidth->setWidth(2.0f); - geometry->getOrCreateStateSet()-> + mGeometry->getOrCreateStateSet()-> setAttributeAndModes(linewidth, osg::StateAttribute::ON); - geometry->getOrCreateStateSet()-> + mGeometry->getOrCreateStateSet()-> setMode(GL_LIGHTING, osg::StateAttribute::OFF); } const QString& Texture::getSourceURL(void) const { - return sourceURL; + return mSourceURL; +} + +void +Texture::setId(quint64 id) +{ + mId = id; } void Texture::sync(const WebImagePtr& image) { - state = static_cast(image->getState()); + mState = static_cast(image->getState()); if (image->getState() != WebImage::UNINITIALIZED && - sourceURL != image->getSourceURL()) { - sourceURL = image->getSourceURL(); + mSourceURL != image->getSourceURL()) + { + mSourceURL = image->getSourceURL(); } - if (image->getState() == WebImage::READY && image->getSyncFlag()) { + if (image->getState() == WebImage::READY && image->getSyncFlag()) + { image->setSyncFlag(false); - if (texture2D->getImage() != NULL) { - texture2D->getImage()->setImage(image->getWidth(), - image->getHeight(), - 1, - GL_RGBA, - GL_RGBA, - GL_UNSIGNED_BYTE, - image->getImageData(), - osg::Image::NO_DELETE); - texture2D->getImage()->dirty(); + if (mTexture2D->getImage() != NULL) + { + mTexture2D->getImage()->setImage(image->getWidth(), + image->getHeight(), + 1, + GL_RGBA, + GL_RGBA, + GL_UNSIGNED_BYTE, + image->getImageData(), + osg::Image::NO_DELETE); + mTexture2D->getImage()->dirty(); } } } @@ -123,40 +132,44 @@ Texture::draw(double x1, double y1, double x2, double y2, bool smoothInterpolation) const { osg::Vec3dArray* vertices = - static_cast(geometry->getVertexArray()); + static_cast(mGeometry->getVertexArray()); (*vertices)[0].set(x1, y1, z); (*vertices)[1].set(x2, y2, z); (*vertices)[2].set(x3, y3, z); (*vertices)[3].set(x4, y4, z); osg::DrawArrays* drawarrays = - static_cast(geometry->getPrimitiveSet(0)); + static_cast(mGeometry->getPrimitiveSet(0)); osg::Vec4Array* colors = - static_cast(geometry->getColorArray()); + static_cast(mGeometry->getColorArray()); - if (state == REQUESTED) { + if (mState == REQUESTED) + { drawarrays->set(osg::PrimitiveSet::LINE_LOOP, 0, 4); (*colors)[0].set(0.0f, 0.0f, 1.0f, 1.0f); - geometry->getOrCreateStateSet()-> - setTextureAttributeAndModes(0, texture2D, osg::StateAttribute::OFF); + mGeometry->getOrCreateStateSet()-> + setTextureAttributeAndModes(0, mTexture2D, osg::StateAttribute::OFF); - return geometry; + return mGeometry; } - if (smoothInterpolation) { - texture2D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); - texture2D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); - } else { - texture2D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST); - texture2D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST); + if (smoothInterpolation) + { + mTexture2D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); + mTexture2D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); + } + else + { + mTexture2D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST); + mTexture2D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST); } drawarrays->set(osg::PrimitiveSet::POLYGON, 0, 4); (*colors)[0].set(1.0f, 1.0f, 1.0f, 1.0f); - geometry->getOrCreateStateSet()-> - setTextureAttributeAndModes(0, texture2D, osg::StateAttribute::ON); + mGeometry->getOrCreateStateSet()-> + setTextureAttributeAndModes(0, mTexture2D, osg::StateAttribute::ON); - return geometry; + return mGeometry; } diff --git a/src/ui/map3D/Texture.h b/src/ui/map3D/Texture.h index b953849674d39cde17d50d64820915d50186d477..b1250aa5a6267675064739eac235dd4205c29a2b 100644 --- a/src/ui/map3D/Texture.h +++ b/src/ui/map3D/Texture.h @@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project * @file * @brief Definition of the class Texture. * - * @author Lionel Heng + * @author Lionel Heng * */ @@ -43,11 +43,11 @@ This file is part of the QGROUNDCONTROL project class Texture { public: - explicit Texture(unsigned int _id); + explicit Texture(quint64 id); const QString& getSourceURL(void) const; - void setId(unsigned int _id); + void setId(quint64 id); void sync(const WebImagePtr& image); @@ -60,17 +60,18 @@ public: bool smoothInterpolation) const; private: - enum State { + enum State + { UNINITIALIZED = 0, REQUESTED = 1, READY = 2 }; - State state; - QString sourceURL; - unsigned int id; - osg::ref_ptr texture2D; - osg::ref_ptr geometry; + State mState; + QString mSourceURL; + quint64 mId; + osg::ref_ptr mTexture2D; + osg::ref_ptr mGeometry; }; typedef QSharedPointer TexturePtr; diff --git a/src/ui/map3D/TextureCache.cc b/src/ui/map3D/TextureCache.cc index 8681c6811cb5d7787d429f49598f5b8af871500d..6b9ebc9e9e3a5ccaa6eb7117397b51d106900e89 100644 --- a/src/ui/map3D/TextureCache.cc +++ b/src/ui/map3D/TextureCache.cc @@ -25,34 +25,37 @@ This file is part of the QGROUNDCONTROL project * @file * @brief Definition of the class TextureCache. * - * @author Lionel Heng + * @author Lionel Heng * */ #include "TextureCache.h" -TextureCache::TextureCache(uint32_t _cacheSize) - : cacheSize(_cacheSize) - , imageCache(new WebImageCache(0, cacheSize)) +TextureCache::TextureCache(int cacheSize) + : mCacheSize(cacheSize) + , mImageCache(new WebImageCache(0, cacheSize)) { - for (uint32_t i = 0; i < cacheSize; ++i) { + for (int i = 0; i < mCacheSize; ++i) + { TexturePtr t(new Texture(i)); - textures.push_back(t); + mTextures.push_back(t); } } TexturePtr TextureCache::get(const QString& tileURL) { - QPair p1 = lookup(tileURL); - if (!p1.first.isNull()) { + QPair p1 = lookup(tileURL); + if (!p1.first.isNull()) + { return p1.first; } - QPair p2 = imageCache->lookup(tileURL); - if (!p2.first.isNull()) { - textures[p2.second]->sync(p2.first); + QPair p2 = mImageCache->lookup(tileURL); + if (!p2.first.isNull()) + { + mTextures[p2.second]->sync(p2.first); p1 = lookup(tileURL); return p1.first; @@ -64,19 +67,23 @@ TextureCache::get(const QString& tileURL) void TextureCache::sync(void) { - if (requireSync()) { - for (int32_t i = 0; i < textures.size(); ++i) { - textures[i]->sync(imageCache->at(i)); + if (requireSync()) + { + for (int i = 0; i < mTextures.size(); ++i) + { + mTextures[i]->sync(mImageCache->at(i)); } } } -QPair +QPair TextureCache::lookup(const QString& tileURL) { - for (int32_t i = 0; i < textures.size(); ++i) { - if (textures[i]->getSourceURL() == tileURL) { - return qMakePair(textures[i], i); + for (int i = 0; i < mTextures.size(); ++i) + { + if (mTextures[i]->getSourceURL() == tileURL) + { + return qMakePair(mTextures[i], i); } } @@ -86,8 +93,10 @@ TextureCache::lookup(const QString& tileURL) bool TextureCache::requireSync(void) const { - for (uint32_t i = 0; i < cacheSize; ++i) { - if (imageCache->at(i)->getSyncFlag()) { + for (int i = 0; i < mCacheSize; ++i) + { + if (mImageCache->at(i)->getSyncFlag()) + { return true; } } diff --git a/src/ui/map3D/TextureCache.h b/src/ui/map3D/TextureCache.h index 25be665b90f82560549d35237e17688566432a53..14597b23415085707d5a511788639a12a27473f1 100644 --- a/src/ui/map3D/TextureCache.h +++ b/src/ui/map3D/TextureCache.h @@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project * @file * @brief Definition of the class TextureCache. * - * @author Lionel Heng + * @author Lionel Heng * */ @@ -40,7 +40,7 @@ This file is part of the QGROUNDCONTROL project class TextureCache { public: - explicit TextureCache(uint32_t cacheSize); + explicit TextureCache(int cacheSize); TexturePtr get(const QString& tileURL); @@ -51,10 +51,10 @@ private: bool requireSync(void) const; - uint32_t cacheSize; - QVector textures; + int mCacheSize; + QVector mTextures; - QScopedPointer imageCache; + QScopedPointer mImageCache; }; #endif // TEXTURECACHE_H diff --git a/src/ui/map3D/WebImage.cc b/src/ui/map3D/WebImage.cc index d09f96dd0c335e09255a2441687fba45f2e45a11..c638b811fa9b32f71a7e1b420dd6f53e8b84a911 100644 --- a/src/ui/map3D/WebImage.cc +++ b/src/ui/map3D/WebImage.cc @@ -35,11 +35,11 @@ This file is part of the QGROUNDCONTROL project #include WebImage::WebImage() - : state(WebImage::UNINITIALIZED) - , sourceURL("") - , image(0) - , lastReference(0) - , syncFlag(false) + : mState(WebImage::UNINITIALIZED) + , mSourceURL("") + , mImage(0) + , mLastReference(0) + , mSyncFlag(false) { } @@ -47,54 +47,58 @@ WebImage::WebImage() void WebImage::clear(void) { - image.reset(); - sourceURL.clear(); - state = WebImage::UNINITIALIZED; - lastReference = 0; + mImage.reset(); + mSourceURL.clear(); + mState = WebImage::UNINITIALIZED; + mLastReference = 0; } WebImage::State WebImage::getState(void) const { - return state; + return mState; } void WebImage::setState(State state) { - this->state = state; + mState = state; } const QString& WebImage::getSourceURL(void) const { - return sourceURL; + return mSourceURL; } void WebImage::setSourceURL(const QString& url) { - sourceURL = url; + mSourceURL = url; } uchar* WebImage::getImageData(void) const { - return image->scanLine(0); + return mImage->scanLine(0); } bool WebImage::setData(const QByteArray& data) { QImage tempImage; - if (tempImage.loadFromData(data)) { - if (image.isNull()) { - image.reset(new QImage); + if (tempImage.loadFromData(data)) + { + if (mImage.isNull()) + { + mImage.reset(new QImage); } - *image = QGLWidget::convertToGLFormat(tempImage); + *mImage = QGLWidget::convertToGLFormat(tempImage); return true; - } else { + } + else + { return false; } } @@ -103,14 +107,18 @@ bool WebImage::setData(const QString& filename) { QImage tempImage; - if (tempImage.load(filename)) { - if (image.isNull()) { - image.reset(new QImage); + if (tempImage.load(filename)) + { + if (mImage.isNull()) + { + mImage.reset(new QImage); } - *image = QGLWidget::convertToGLFormat(tempImage); + *mImage = QGLWidget::convertToGLFormat(tempImage); return true; - } else { + } + else + { return false; } } @@ -118,41 +126,41 @@ WebImage::setData(const QString& filename) int WebImage::getWidth(void) const { - return image->width(); + return mImage->width(); } int WebImage::getHeight(void) const { - return image->height(); + return mImage->height(); } int WebImage::getByteCount(void) const { - return image->byteCount(); + return mImage->byteCount(); } -ulong +quint64 WebImage::getLastReference(void) const { - return lastReference; + return mLastReference; } void -WebImage::setLastReference(ulong value) +WebImage::setLastReference(quint64 value) { - lastReference = value; + mLastReference = value; } bool WebImage::getSyncFlag(void) const { - return syncFlag; + return mSyncFlag; } void WebImage::setSyncFlag(bool onoff) { - syncFlag = onoff; + mSyncFlag = onoff; } diff --git a/src/ui/map3D/WebImage.h b/src/ui/map3D/WebImage.h index 15c122b21a0dd7276ebf183660525838c72bc9db..6b317dce1d2cb39fde402c05af3a5f9657386a36 100644 --- a/src/ui/map3D/WebImage.h +++ b/src/ui/map3D/WebImage.h @@ -64,18 +64,18 @@ public: int getHeight(void) const; int getByteCount(void) const; - ulong getLastReference(void) const; - void setLastReference(ulong value); + quint64 getLastReference(void) const; + void setLastReference(quint64 value); bool getSyncFlag(void) const; void setSyncFlag(bool onoff); private: - State state; - QString sourceURL; - QScopedPointer image; - ulong lastReference; - bool syncFlag; + State mState; + QString mSourceURL; + QScopedPointer mImage; + quint64 mLastReference; + bool mSyncFlag; }; typedef QSharedPointer WebImagePtr; diff --git a/src/ui/map3D/WebImageCache.cc b/src/ui/map3D/WebImageCache.cc index 0ad66fe7254cc0e06de787722eda286267d79257..42efc5bc59e375f10e5d8a3cd6f6f44575083779 100644 --- a/src/ui/map3D/WebImageCache.cc +++ b/src/ui/map3D/WebImageCache.cc @@ -25,102 +25,129 @@ This file is part of the QGROUNDCONTROL project * @file * @brief Definition of the class WebImageCache. * - * @author Lionel Heng + * @author Lionel Heng * */ #include "WebImageCache.h" +#include #include #include -WebImageCache::WebImageCache(QObject* parent, uint32_t _cacheSize) +WebImageCache::WebImageCache(QObject* parent, int cacheSize) : QObject(parent) - , cacheSize(_cacheSize) - , currentReference(0) - , networkManager(new QNetworkAccessManager) + , mCacheSize(cacheSize) + , mCurrentReference(0) + , mNetworkManager(new QNetworkAccessManager) { - for (uint32_t i = 0; i < cacheSize; ++i) { + for (int i = 0; i < mCacheSize; ++i) + { WebImagePtr image(new WebImage); - webImages.push_back(image); + mWebImages.push_back(image); } - connect(networkManager.data(), SIGNAL(finished(QNetworkReply*)), + connect(mNetworkManager.data(), SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*))); } -QPair +QPair WebImageCache::lookup(const QString& url) { - QPair cacheEntry; + QPair cacheEntry; - for (int32_t i = 0; i < webImages.size(); ++i) { - if (webImages[i]->getState() != WebImage::UNINITIALIZED && - webImages[i]->getSourceURL() == url) { - cacheEntry.first = webImages[i]; + for (int i = 0; i < mWebImages.size(); ++i) + { + WebImagePtr& image = mWebImages[i]; + + if (image->getState() != WebImage::UNINITIALIZED && + image->getSourceURL() == url) + { + cacheEntry.first = image; cacheEntry.second = i; break; } } - if (cacheEntry.first.isNull()) { - for (int32_t i = 0; i < webImages.size(); ++i) { + if (cacheEntry.first.isNull()) + { + for (int i = 0; i < mWebImages.size(); ++i) + { + WebImagePtr& image = mWebImages[i]; + // get uninitialized image - if (webImages[i]->getState() == WebImage::UNINITIALIZED) { - cacheEntry.first = webImages[i]; + if (image->getState() == WebImage::UNINITIALIZED) + { + cacheEntry.first = image; cacheEntry.second = i; break; } // get oldest image - else if (webImages[i]->getState() == WebImage::READY && + else if (image->getState() == WebImage::READY && (cacheEntry.first.isNull() || - webImages[i]->getLastReference() < - cacheEntry.first->getLastReference())) { - cacheEntry.first = webImages[i]; + image->getLastReference() < + cacheEntry.first->getLastReference())) + { + cacheEntry.first = image; cacheEntry.second = i; } } - if (cacheEntry.first.isNull()) { - return qMakePair(WebImagePtr(), -1); - } else { - if (cacheEntry.first->getState() == WebImage::READY) { + if (cacheEntry.first.isNull()) + { + return qMakePair(WebImagePtr(), -1); + } + else + { + if (cacheEntry.first->getState() == WebImage::READY) + { cacheEntry.first->clear(); } cacheEntry.first->setSourceURL(url); - cacheEntry.first->setLastReference(currentReference); - ++currentReference; + cacheEntry.first->setLastReference(mCurrentReference); + ++mCurrentReference; cacheEntry.first->setState(WebImage::REQUESTED); - if (url.left(4).compare("http") == 0) { - networkManager->get(QNetworkRequest(QUrl(url))); - } else { - if (cacheEntry.first->setData(url)) { + if (url.left(4).compare("http") == 0) + { + mNetworkManager->get(QNetworkRequest(QUrl(url))); + } + else + { + if (cacheEntry.first->setData(url)) + { cacheEntry.first->setSyncFlag(true); cacheEntry.first->setState(WebImage::READY); - } else { + } + else + { cacheEntry.first->setState(WebImage::UNINITIALIZED); } } return cacheEntry; } - } else { - if (cacheEntry.first->getState() == WebImage::READY) { - cacheEntry.first->setLastReference(currentReference); - ++currentReference; + } + else + { + if (cacheEntry.first->getState() == WebImage::READY) + { + cacheEntry.first->setLastReference(mCurrentReference); + ++mCurrentReference; return cacheEntry; - } else { + } + else + { return qMakePair(WebImagePtr(), -1); } } } WebImagePtr -WebImageCache::at(int32_t index) const +WebImageCache::at(int index) const { - return webImages[index]; + return mWebImages[index]; } void @@ -128,17 +155,21 @@ WebImageCache::downloadFinished(QNetworkReply* reply) { reply->deleteLater(); - if (reply->error() != QNetworkReply::NoError) { + if (reply->error() != QNetworkReply::NoError) + { return; } QVariant attribute = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); - if (attribute.isValid()) { + if (attribute.isValid()) + { return; } WebImagePtr image; - foreach(image, webImages) { - if (reply->url().toString() == image->getSourceURL()) { + foreach(image, mWebImages) + { + if (reply->url().toString() == image->getSourceURL()) + { image->setData(reply->readAll()); image->setSyncFlag(true); image->setState(WebImage::READY); diff --git a/src/ui/map3D/WebImageCache.h b/src/ui/map3D/WebImageCache.h index d482d717a60b2338e5a2f20e1e8beda680211759..136800a5545dcb653b69beea6f2841e3c0e32aaf 100644 --- a/src/ui/map3D/WebImageCache.h +++ b/src/ui/map3D/WebImageCache.h @@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project * @file * @brief Definition of the class WebImageCache. * - * @author Lionel Heng + * @author Lionel Heng * */ @@ -43,22 +43,22 @@ class WebImageCache : public QObject Q_OBJECT public: - WebImageCache(QObject* parent, uint32_t cacheSize); + WebImageCache(QObject* parent, int cacheSize); - QPair lookup(const QString& url); + QPair lookup(const QString& url); - WebImagePtr at(int32_t index) const; + WebImagePtr at(int index) const; private Q_SLOTS: void downloadFinished(QNetworkReply* reply); private: - uint32_t cacheSize; + int mCacheSize; - QVector webImages; - uint64_t currentReference; + QVector mWebImages; + quint64 mCurrentReference; - QScopedPointer networkManager; + QScopedPointer mNetworkManager; }; #endif // WEBIMAGECACHE_H