Commit 9adfc8dc authored by Lionel Heng's avatar Lionel Heng

Disabled culling of imagery tiles.

parent ee74c2c3
......@@ -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
......
......@@ -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;
......
......@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
* @file
* @brief Definition of the class Texture.
*
* @author Lionel Heng <hengli@student.ethz.ch>
* @author Lionel Heng <hengli@inf.ethz.ch>
*
*/
......@@ -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<osg::Image> image = new osg::Image;
texture2D->setImage(image);
mTexture2D->setImage(image);
osg::ref_ptr<osg::Vec3dArray> vertices(new osg::Vec3dArray(4));
geometry->setVertexArray(vertices);
mGeometry->setVertexArray(vertices);
osg::ref_ptr<osg::Vec2Array> 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<osg::Vec4Array> 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<osg::LineWidth> 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<State>(image->getState());
mState = static_cast<State>(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<osg::Vec3dArray*>(geometry->getVertexArray());
static_cast<osg::Vec3dArray*>(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<osg::DrawArrays*>(geometry->getPrimitiveSet(0));
static_cast<osg::DrawArrays*>(mGeometry->getPrimitiveSet(0));
osg::Vec4Array* colors =
static_cast<osg::Vec4Array*>(geometry->getColorArray());
static_cast<osg::Vec4Array*>(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;
}
......@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
* @file
* @brief Definition of the class Texture.
*
* @author Lionel Heng <hengli@student.ethz.ch>
* @author Lionel Heng <hengli@inf.ethz.ch>
*
*/
......@@ -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<osg::Texture2D> texture2D;
osg::ref_ptr<osg::Geometry> geometry;
State mState;
QString mSourceURL;
quint64 mId;
osg::ref_ptr<osg::Texture2D> mTexture2D;
osg::ref_ptr<osg::Geometry> mGeometry;
};
typedef QSharedPointer<Texture> TexturePtr;
......
......@@ -25,34 +25,37 @@ This file is part of the QGROUNDCONTROL project
* @file
* @brief Definition of the class TextureCache.
*
* @author Lionel Heng <hengli@student.ethz.ch>
* @author Lionel Heng <hengli@inf.ethz.ch>
*
*/
#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<TexturePtr, int32_t> p1 = lookup(tileURL);
if (!p1.first.isNull()) {
QPair<TexturePtr, int> p1 = lookup(tileURL);
if (!p1.first.isNull())
{
return p1.first;
}
QPair<WebImagePtr, int32_t> p2 = imageCache->lookup(tileURL);
if (!p2.first.isNull()) {
textures[p2.second]->sync(p2.first);
QPair<WebImagePtr, int> 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<TexturePtr, int32_t>
QPair<TexturePtr, int>
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;
}
}
......
......@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
* @file
* @brief Definition of the class TextureCache.
*
* @author Lionel Heng <hengli@student.ethz.ch>
* @author Lionel Heng <hengli@inf.ethz.ch>
*
*/
......@@ -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<TexturePtr> textures;
int mCacheSize;
QVector<TexturePtr> mTextures;
QScopedPointer<WebImageCache> imageCache;
QScopedPointer<WebImageCache> mImageCache;
};
#endif // TEXTURECACHE_H
......@@ -35,11 +35,11 @@ This file is part of the QGROUNDCONTROL project
#include <QGLWidget>
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;
}
......@@ -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<QImage> image;
ulong lastReference;
bool syncFlag;
State mState;
QString mSourceURL;
QScopedPointer<QImage> mImage;
quint64 mLastReference;
bool mSyncFlag;
};
typedef QSharedPointer<WebImage> WebImagePtr;
......
......@@ -25,102 +25,129 @@ This file is part of the QGROUNDCONTROL project
* @file
* @brief Definition of the class WebImageCache.
*
* @author Lionel Heng <hengli@student.ethz.ch>
* @author Lionel Heng <hengli@inf.ethz.ch>
*
*/
#include "WebImageCache.h"
#include <cstdio>
#include <QNetworkReply>
#include <QPixmap>
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<WebImagePtr, int32_t>
QPair<WebImagePtr, int>
WebImageCache::lookup(const QString& url)
{
QPair<WebImagePtr, int32_t> cacheEntry;
QPair<WebImagePtr, int> 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);
......
......@@ -25,7 +25,7 @@ This file is part of the QGROUNDCONTROL project
* @file
* @brief Definition of the class WebImageCache.
*
* @author Lionel Heng <hengli@student.ethz.ch>
* @author Lionel Heng <hengli@inf.ethz.ch>
*
*/
......@@ -43,22 +43,22 @@ class WebImageCache : public QObject
Q_OBJECT
public:
WebImageCache(QObject* parent, uint32_t cacheSize);
WebImageCache(QObject* parent, int cacheSize);
QPair<WebImagePtr, int32_t> lookup(const QString& url);
QPair<WebImagePtr, int> 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<WebImagePtr> webImages;
uint64_t currentReference;
QVector<WebImagePtr> mWebImages;
quint64 mCurrentReference;
QScopedPointer<QNetworkAccessManager> networkManager;
QScopedPointer<QNetworkAccessManager> mNetworkManager;
};
#endif // WEBIMAGECACHE_H
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