Commit 6302dedf authored by Lionel Heng's avatar Lionel Heng

Restored imagery feature. Not yet running.

parent 8464b4ce
......@@ -63,10 +63,6 @@ This file is part of the QGROUNDCONTROL project
#include "HSIDisplay.h"
#include "QGCDataPlot2D.h"
#include "QGCRemoteControlView.h"
#ifdef QGC_OSG_ENABLED
//#include "Q3DWidget.h"
#include "QMap3D.h"
#endif
#include "LogCompressor.h"
......
This diff is collapsed.
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of the class Imagery.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef IMAGERY_H
#define IMAGERY_H
#include <QScopedPointer>
#include <QString>
#include "TextureCache.h"
class Imagery
{
public:
enum ImageryType
{
GOOGLE_MAP = 0,
GOOGLE_SATELLITE = 1,
SWISSTOPO_SATELLITE = 2,
SWISSTOPO_SATELLITE_3D = 3
};
Imagery();
void setImageryType(ImageryType type);
void setOffset(double xOffset, double yOffset);
void prefetch2D(double windowWidth, double windowHeight,
double zoom, double xOrigin, double yOrigin,
double viewXOffset, double viewYOffset,
const QString& utmZone);
void draw2D(double windowWidth, double windowHeight,
double zoom, double xOrigin, double yOrigin,
double viewXOffset, double viewYOffset,
const QString& utmZone);
void prefetch3D(double radius, double tileResolution,
double xOrigin, double yOrigin,
double viewXOffset, double viewYOffset,
const QString& utmZone, bool useHeightModel);
void draw3D(double radius, double tileResolution,
double xOrigin, double yOrigin,
double viewXOffset, double viewYOffset,
const QString& utmZone, bool useHeightModel);
bool update(void);
private:
void imageBounds(int tileX, int tileY, double tileResolution,
double& x1, double& y1, double& x2, double& y2,
double& x3, double& y3, double& x4, double& y4) const;
void tileBounds(double tileResolution,
double minUtmX, double minUtmY,
double maxUtmX, double maxUtmY, const QString& utmZone,
int& minTileX, int& minTileY,
int& maxTileX, int& maxTileY,
int& zoomLevel) const;
double tileXToLongitude(int tileX, int numTiles) const;
double tileYToLatitude(int tileY, int numTiles) const;
int longitudeToTileX(double longitude, int numTiles) const;
int latitudeToTileY(double latitude, int numTiles) const;
void UTMtoTile(double northing, double easting, const QString& utmZone,
double tileResolution, int& tileX, int& tileY,
int& zoomLevel) const;
QChar UTMLetterDesignator(double latitude) const;
void LLtoUTM(double latitude, double longitude,
double& utmNorthing, double& utmEasting,
QString& utmZone) const;
void UTMtoLL(double utmNorthing, double utmEasting, const QString& utmZone,
double& latitude, double& longitude) const;
QString getTileLocation(int tileX, int tileY, int zoomLevel,
double tileResolution) const;
QScopedPointer<TextureCache> textureCache;
ImageryType currentImageryType;
double xOffset;
double yOffset;
};
#endif // IMAGERY_H
......@@ -29,12 +29,22 @@ This file is part of the QGROUNDCONTROL project
*
*/
#include <osg/LineWidth>
#include "Texture.h"
Texture::Texture()
: _is3D(false)
{
texture2D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST);
texture2D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST);
GLuint id;
glGenTextures(1, &id);
t->setID(id);
glBindTexture(GL_TEXTURE_2D, id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
const QString&
......@@ -44,9 +54,9 @@ Texture::getSourceURL(void) const
}
void
Texture::setID(GLuint id)
Texture::setId(unsigned int _id)
{
this->id = id;
id = _id;
}
void
......@@ -87,6 +97,10 @@ Texture::sync(const WebImagePtr& image)
maxV = static_cast<double>(imageHeight)
/ static_cast<double>(textureHeight);
osg::ref_ptr<osg::Image> image;
image->setImage(textureWidth, textureHeight, 8, 3, GL_RGBA, GL_UNSIGNED_BYTES, NULL, osg::Image::USE_NEW_DELETE);
texture2D->
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, 3, textureWidth, textureHeight,
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
......@@ -100,46 +114,56 @@ Texture::sync(const WebImagePtr& image)
}
}
void
osg::ref_ptr<osg::Geometry>
Texture::draw(float x1, float y1, float x2, float y2,
bool smoothInterpolation) const
{
draw(x1, y1, x2, y1, x2, y2, x1, y2, smoothInterpolation);
return draw(x1, y1, x2, y1, x2, y2, x1, y2, smoothInterpolation);
}
void
osg::ref_ptr<osg::Geometry>
Texture::draw(float x1, float y1, float x2, float y2,
float x3, float y3, float x4, float y4,
bool smoothInterpolation) const
{
osg::ref_ptr<osg::Geometry> geometry(new osg::Geometry);
osg::ref_ptr<osg::StateSet> stateset(new osg::StateSet);
if (state == REQUESTED)
{
glBegin(GL_LINE_LOOP);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(x1, y1);
glVertex2f(x2, y2);
glVertex2f(x3, y3);
glVertex2f(x4, y4);
glEnd();
return;
osg::ref_ptr<osg::Vec2Array> vertices(new osg::Vec2Array);
vertices->push_back(osg::Vec2(x1, y1));
vertices->push_back(osg::Vec2(x2, y2));
vertices->push_back(osg::Vec2(x3, y3));
vertices->push_back(osg::Vec2(x4, y4));
geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,
0, vertices->size()));
geometry->setVertexArray(vertices);
osg::ref_ptr<osg::Vec4Array> color(new osg::Vec4Array);
color->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
geometry->setColorArray(color);
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
return geometry;
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, id);
stateset->setTextureAttributeAndModes(id, texture2D);
float dx, dy;
if (smoothInterpolation)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
texture2D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
texture2D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
dx = 1.0f / (2.0f * textureWidth);
dy = 1.0f / (2.0f * textureHeight);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
texture2D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST);
texture2D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST);
dx = 0.0f;
dy = 0.0f;
}
......@@ -147,6 +171,14 @@ Texture::draw(float x1, float y1, float x2, float y2,
glColor3f(1.0f, 1.0f, 1.0f);
if (!_is3D)
{
osg::ref_ptr<osg::Vec2Array> tc = new osg::Vec2Array;
geometry->setTexCoordArray(id, tc);
tc->push_back(osg::Vec2(dx, maxV - dy));
tc->push_back(osg::Vec2(maxU - dx, maxV - dy));
tc->push_back(osg::Vec2(maxU - dx, dy));
tc->push_back(osg::Vec2(dx, dy));
glBegin(GL_QUADS);
glTexCoord2f(dx, maxV - dy);
glVertex3f(x1, y1, 0.0f);
......@@ -210,8 +242,6 @@ Texture::draw(float x1, float y1, float x2, float y2,
}
}
}
glDisable(GL_TEXTURE_2D);
}
bool
......
......@@ -38,6 +38,8 @@ This file is part of the QGROUNDCONTROL project
#include <GL/gl.h>
#endif
#include <inttypes.h>
#include <osg/ref_ptr>
#include <osg/Geometry>
#include <QSharedPointer>
#include "WebImage.h"
......@@ -49,15 +51,15 @@ public:
const QString& getSourceURL(void) const;
void setID(GLuint id);
void setId(unsigned int _id);
void sync(const WebImagePtr& image);
void draw(float x1, float y1, float x2, float y2,
bool smoothInterpolation) const;
void draw(float x1, float y1, float x2, float y2,
float x3, float y3, float x4, float y4,
bool smoothInterpolation) const;
osg::ref_ptr<osg::Geometry> draw(float x1, float y1, float x2, float y2,
bool smoothInterpolation) const;
osg::ref_ptr<osg::Geometry> draw(float x1, float y1, float x2, float y2,
float x3, float y3, float x4, float y4,
bool smoothInterpolation) const;
bool is3D(void) const;
......@@ -71,7 +73,8 @@ private:
State state;
QString sourceURL;
GLuint id;
unsigned int id;
osg::ref_ptr<osg::Texture2D> texture2D;
int32_t textureWidth;
int32_t textureHeight;
......
......@@ -38,14 +38,7 @@ TextureCache::TextureCache(uint32_t _cacheSize)
for (uint32_t i = 0; i < cacheSize; ++i)
{
TexturePtr t(new Texture);
GLuint id;
glGenTextures(1, &id);
t->setID(id);
glBindTexture(GL_TEXTURE_2D, id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
t->setId(i);
textures.push_back(t);
}
......
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