Commit 25187e60 authored by Don Gagne's avatar Don Gagne

Local 3d View no longer supported

Only QtLocation based mapping supported in future
parent 0dbb002d
#include "CameraParams.h"
CameraParams::CameraParams()
: mMinZoomRange(2.0f)
, mFov(30.0f)
, mMinClipRange(1.0f)
, mMaxClipRange(10000.0f)
{
}
float&
CameraParams::minZoomRange(void)
{
return mMinZoomRange;
}
float
CameraParams::minZoomRange(void) const
{
return mMinZoomRange;
}
float&
CameraParams::fov(void)
{
return mFov;
}
float
CameraParams::fov(void) const
{
return mFov;
}
float&
CameraParams::minClipRange(void)
{
return mMinClipRange;
}
float
CameraParams::minClipRange(void) const
{
return mMinClipRange;
}
float&
CameraParams::maxClipRange(void)
{
return mMaxClipRange;
}
float
CameraParams::maxClipRange(void) const
{
return mMaxClipRange;
}
#ifndef CAMERAPARAMS_H
#define CAMERAPARAMS_H
class CameraParams
{
public:
CameraParams();
float& minZoomRange(void);
float minZoomRange(void) const;
float& fov(void);
float fov(void) const;
float& minClipRange(void);
float minClipRange(void) const;
float& maxClipRange(void);
float maxClipRange(void) const;
private:
float mMinZoomRange;
float mFov;
float mMinClipRange;
float mMaxClipRange;
};
#endif // CAMERAPARAMS_H
/*=====================================================================
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 GCManipulator.
*
* @author Lionel Heng <hengli@inf.ethz.ch>
*
*/
#include "GCManipulator.h"
#include <osg/Version>
GCManipulator::GCManipulator()
{
_moveSensitivity = 0.05;
_zoomSensitivity = 1.0;
_minZoomRange = 2.0;
}
void
GCManipulator::setMinZoomRange(double minZoomRange)
{
_minZoomRange = minZoomRange;
}
void
GCManipulator::move(double dx, double dy, double dz)
{
_center += osg::Vec3d(dx, dy, dz);
}
bool
GCManipulator::handle(const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& us)
{
using namespace osgGA;
switch (ea.getEventType()) {
case GUIEventAdapter::PUSH: {
flushMouseEventStack();
addMouseEvent(ea);
if (calcMovement()) {
us.requestRedraw();
}
us.requestContinuousUpdate(false);
_thrown = false;
return true;
}
case GUIEventAdapter::RELEASE: {
if (ea.getButtonMask() == 0) {
if (isMouseMoving()) {
if (calcMovement()) {
us.requestRedraw();
us.requestContinuousUpdate(false);
_thrown = false;
}
} else {
flushMouseEventStack();
addMouseEvent(ea);
if (calcMovement()) {
us.requestRedraw();
}
us.requestContinuousUpdate(false);
_thrown = false;
}
} else {
flushMouseEventStack();
addMouseEvent(ea);
if (calcMovement()) {
us.requestRedraw();
}
us.requestContinuousUpdate(false);
_thrown = false;
}
return true;
}
case GUIEventAdapter::DRAG: {
addMouseEvent(ea);
if (calcMovement()) {
us.requestRedraw();
}
us.requestContinuousUpdate(false);
_thrown = false;
return true;
}
case GUIEventAdapter::SCROLL: {
// zoom model
double scale = 1.0;
if (ea.getScrollingMotion() == GUIEventAdapter::SCROLL_UP) {
scale -= _zoomSensitivity * 0.1;
} else {
scale += _zoomSensitivity * 0.1;
}
if (_distance * scale > _minZoomRange) {
_distance *= scale;
}
return true;
}
case GUIEventAdapter::KEYDOWN:
// pan model
switch (ea.getKey()) {
case GUIEventAdapter::KEY_Space: {
flushMouseEventStack();
_thrown = false;
home(ea,us);
us.requestRedraw();
us.requestContinuousUpdate(false);
return true;
}
case GUIEventAdapter::KEY_Left: {
double scale = -_moveSensitivity * _distance;
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate(_rotation);
osg::Vec3d dv(scale, 0.0, 0.0);
_center += dv * rotation_matrix;
return true;
}
case GUIEventAdapter::KEY_Right: {
double scale = _moveSensitivity * _distance;
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate(_rotation);
osg::Vec3d dv(scale, 0.0, 0.0);
_center += dv * rotation_matrix;
return true;
}
case GUIEventAdapter::KEY_Up: {
double scale = _moveSensitivity * _distance;
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate(_rotation);
osg::Vec3d dv(0.0, scale, 0.0);
_center += dv * rotation_matrix;
return true;
}
case GUIEventAdapter::KEY_Down: {
double scale = -_moveSensitivity * _distance;
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate(_rotation);
osg::Vec3d dv(0.0, scale, 0.0);
_center += dv * rotation_matrix;
return true;
}
return false;
}
case GUIEventAdapter::FRAME:
if (_thrown) {
if (calcMovement()) {
us.requestRedraw();
}
}
return false;
default:
return false;
}
}
bool
GCManipulator::calcMovement(void)
{
using namespace osgGA;
// return if less then two events have been added.
if (_ga_t0.get() == NULL || _ga_t1.get() == NULL) {
return false;
}
double dx = _ga_t0->getXnormalized() - _ga_t1->getXnormalized();
double dy = _ga_t0->getYnormalized() - _ga_t1->getYnormalized();
// return if there is no movement.
if (dx == 0.0 && dy == 0.0) {
return false;
}
unsigned int buttonMask = _ga_t1->getButtonMask();
if (buttonMask == GUIEventAdapter::LEFT_MOUSE_BUTTON) {
// rotate camera
#if ((OPENSCENEGRAPH_MAJOR_VERSION == 2) & (OPENSCENEGRAPH_MINOR_VERSION > 8)) | (OPENSCENEGRAPH_MAJOR_VERSION > 2)
osg::Vec3d axis;
#else
osg::Vec3 axis;
#endif
float angle;
float px0 = _ga_t0->getXnormalized();
float py0 = _ga_t0->getYnormalized();
float px1 = _ga_t1->getXnormalized();
float py1 = _ga_t1->getYnormalized();
trackball(axis, angle, px1, py1, px0, py0);
osg::Quat new_rotate;
new_rotate.makeRotate(angle, axis);
_rotation = _rotation * new_rotate;
return true;
} else if (buttonMask == GUIEventAdapter::MIDDLE_MOUSE_BUTTON ||
buttonMask == (GUIEventAdapter::LEFT_MOUSE_BUTTON |
GUIEventAdapter::RIGHT_MOUSE_BUTTON)) {
// pan model
double scale = -_moveSensitivity * _distance;
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate(_rotation);
osg::Vec3d dv(dx * scale, dy * scale, 0.0);
_center += dv * rotation_matrix;
return true;
} else if (buttonMask == GUIEventAdapter::RIGHT_MOUSE_BUTTON) {
// zoom model
double scale = 1.0 + dy * _zoomSensitivity;
if (_distance * scale > _minZoomRange) {
_distance *= scale;
}
return true;
}
return false;
}
/*=====================================================================
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 GCManipulator.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef GCMANIPULATOR_H
#define GCMANIPULATOR_H
#include <osgGA/TrackballManipulator>
class GCManipulator : public osgGA::TrackballManipulator
{
public:
GCManipulator();
void setMinZoomRange(double minZoomRange);
virtual void move(double dx, double dy, double dz);
/**
* @brief Handle events.
* @return True if event is handled; false otherwise.
*/
virtual bool handle(const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& us);
protected:
bool calcMovement(void);
double _moveSensitivity;
double _zoomSensitivity;
double _minZoomRange;
};
#endif // GCMANIPULATOR_H
This diff is collapsed.
#ifndef GLOVERLAYGEODE_H
#define GLOVERLAYGEODE_H
#include <mavlink_protobuf_manager.hpp>
#include <osg/Geode>
#include <QtGlobal>
class GLOverlayGeode : public osg::Geode
{
public:
GLOverlayGeode();
void setOverlay(px::GLOverlay& overlay);
px::GLOverlay::CoordinateFrameType coordinateFrameType(void) const;
void setMessageTimestamp(qreal timestamp);
qreal messageTimestamp(void) const;
private:
class GLOverlayDrawable : public osg::Drawable
{
public:
GLOverlayDrawable();
GLOverlayDrawable(const GLOverlayDrawable& drawable,
const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
void setOverlay(px::GLOverlay& overlay);
META_Object(GLOverlayDrawableApp, GLOverlayDrawable)
virtual void drawImplementation(osg::RenderInfo&) const;
virtual osg::BoundingBox computeBound() const;
private:
float getFloatValue(const std::string& data, size_t& mark) const;
px::GLOverlay mOverlay;
osg::BoundingBox mBBox;
};
osg::ref_ptr<GLOverlayDrawable> mDrawable;
px::GLOverlay::CoordinateFrameType mCoordinateFrameType;
qreal mMessageTimestamp;
};
#endif // GLOVERLAYGEODE_H
#include "GlobalViewParams.h"
#include <QStringList>
GlobalViewParams::GlobalViewParams()
: mDisplayTerrain(true)
, mDisplayWorldGrid(true)
, mImageryType(Imagery::BLANK_MAP)
, mFollowCameraId(-1)
, mFrame(MAV_FRAME_LOCAL_NED)
{
}
bool&
GlobalViewParams::displayTerrain(void)
{
return mDisplayTerrain;
}
bool
GlobalViewParams::displayTerrain(void) const
{
return mDisplayTerrain;
}
bool&
GlobalViewParams::displayWorldGrid(void)
{
return mDisplayWorldGrid;
}
bool
GlobalViewParams::displayWorldGrid(void) const
{
return mDisplayWorldGrid;
}
QVector3D&
GlobalViewParams::imageryOffset(void)
{
return mImageryOffset;
}
QVector3D
GlobalViewParams::imageryOffset(void) const
{
return mImageryOffset;
}
QString&
GlobalViewParams::imageryPath(void)
{
return mImageryPath;
}
QString
GlobalViewParams::imageryPath(void) const
{
return mImageryPath;
}
Imagery::Type&
GlobalViewParams::imageryType(void)
{
return mImageryType;
}
Imagery::Type
GlobalViewParams::imageryType(void) const
{
return mImageryType;
}
int&
GlobalViewParams::followCameraId(void)
{
return mFollowCameraId;
}
int
GlobalViewParams::followCameraId(void) const
{
return mFollowCameraId;
}
MAV_FRAME&
GlobalViewParams::frame(void)
{
return mFrame;
}
MAV_FRAME
GlobalViewParams::frame(void) const
{
return mFrame;
}
void
GlobalViewParams::signalImageryParamsChanged(void)
{
emit imageryParamsChanged();
}
QVector3D&
GlobalViewParams::terrainPositionOffset(void)
{
return mTerrainPositionOffset;
}
QVector3D
GlobalViewParams::terrainPositionOffset(void) const
{
return mTerrainPositionOffset;
}
QVector3D&
GlobalViewParams::terrainAttitudeOffset(void)
{
return mTerrainAttitudeOffset;
}
QVector3D
GlobalViewParams::terrainAttitudeOffset(void) const
{
return mTerrainAttitudeOffset;
}
void
GlobalViewParams::followCameraChanged(const QString& text)
{
int followCameraId = -1;
if (text.compare("None") == 0)
{
followCameraId = -1;
}
else
{
QStringList list = text.split(" ", QString::SkipEmptyParts);
followCameraId = list.back().toInt();
}
if (followCameraId != mFollowCameraId)
{
mFollowCameraId = followCameraId;
emit followCameraChanged(mFollowCameraId);
}
}
void
GlobalViewParams::frameChanged(const QString& text)
{
if (text.compare("Global") == 0)
{
mFrame = MAV_FRAME_GLOBAL;
}
else if (text.compare("Local") == 0)
{
mFrame = MAV_FRAME_LOCAL_NED;
}
}
void
GlobalViewParams::toggleWorldGrid(int state)
{
if (state == Qt::Checked)
{
mDisplayWorldGrid = true;
}
else
{
mDisplayWorldGrid = false;
}
}
void
GlobalViewParams::toggleTerrain(int state)
{
if (state == Qt::Checked)
{
mDisplayTerrain = true;
}
else
{
mDisplayTerrain = false;
}
}
#ifndef GLOBALVIEWPARAMS_H
#define GLOBALVIEWPARAMS_H
#include <QObject>
#include <QString>
#include <QVector3D>
#include "QGCMAVLink.h"
#include "Imagery.h"
class GlobalViewParams : public QObject
{
Q_OBJECT
public:
GlobalViewParams();
bool& displayTerrain(void);
bool displayTerrain(void) const;
bool& displayWorldGrid(void);
bool displayWorldGrid(void) const;
QVector3D& imageryOffset(void);
QVector3D imageryOffset(void) const;
QString& imageryPath(void);
QString imageryPath(void) const;
Imagery::Type& imageryType(void);
Imagery::Type imageryType(void) const;
int& followCameraId(void);
int followCameraId(void) const;
MAV_FRAME& frame(void);
MAV_FRAME frame(void) const;
void signalImageryParamsChanged(void);
QVector3D& terrainPositionOffset(void);
QVector3D terrainPositionOffset(void) const;
QVector3D& terrainAttitudeOffset(void);
QVector3D terrainAttitudeOffset(void) const;
public slots:
void followCameraChanged(const QString& text);
void frameChanged(const QString &text);
void toggleTerrain(int state);
void toggleWorldGrid(int state);
signals:
void followCameraChanged(int systemId);
void imageryParamsChanged(void);
private:
bool mDisplayTerrain;
bool mDisplayWorldGrid;
QVector3D mImageryOffset;
QString mImageryPath;
Imagery::Type mImageryType;
int mFollowCameraId;
MAV_FRAME mFrame;
QVector3D mTerrainPositionOffset;
QVector3D mTerrainAttitudeOffset;
};
typedef QSharedPointer<GlobalViewParams> GlobalViewParamsPtr;
#endif // GLOBALVIEWPARAMS_H
/*=====================================================================
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 HUDScaleGeode.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#include "HUDScaleGeode.h"
#include <osg/Geometry>
#include <osg/LineWidth>
HUDScaleGeode::HUDScaleGeode()
{
}
void
HUDScaleGeode::init(osg::ref_ptr<osgText::Font>& font)
{
osg::ref_ptr<osg::Vec2Array> outlineVertices(new osg::Vec2Array);
outlineVertices->push_back(osg::Vec2(20.0f, 50.0f));
outlineVertices->push_back(osg::Vec2(20.0f, 70.0f));
outlineVertices->push_back(osg::Vec2(20.0f, 60.0f));
outlineVertices->push_back(osg::Vec2(100.0f, 60.0f));
outlineVertices->push_back(osg::Vec2(100.0f, 50.0f));
outlineVertices->push_back(osg::Vec2(100.0f, 70.0f));
osg::ref_ptr<osg::Geometry> outlineGeometry(new osg::Geometry);
outlineGeometry->setVertexArray(outlineVertices);
osg::ref_ptr<osg::Vec4Array> outlineColor(new osg::Vec4Array);
outlineColor->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
outlineGeometry->setColorArray(outlineColor);
outlineGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
outlineGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,
0, 6));
osg::ref_ptr<osg::LineWidth> outlineWidth(new osg::LineWidth());
outlineWidth->setWidth(4.0f);
outlineGeometry->getOrCreateStateSet()->
setAttributeAndModes(outlineWidth, osg::StateAttribute::ON);
addDrawable(outlineGeometry);
osg::ref_ptr<osg::Vec2Array> markerVertices(new osg::Vec2Array);
markerVertices->push_back(osg::Vec2(20.0f, 50.0f));
markerVertices->push_back(osg::Vec2(20.0f, 70.0f));
markerVertices->push_back(osg::Vec2(20.0f, 60.0f));
markerVertices->push_back(osg::Vec2(100.0f, 60.0f));
markerVertices->push_back(osg::Vec2(100.0f, 50.0f));
markerVertices->push_back(osg::Vec2(100.0f, 70.0f));
osg::ref_ptr<osg::Geometry> markerGeometry(new osg::Geometry);
markerGeometry->setVertexArray(markerVertices);
osg::ref_ptr<osg::Vec4Array> markerColor(new osg::Vec4Array);
markerColor->push_back(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
markerGeometry->setColorArray(markerColor);
markerGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
markerGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,
0, 6));
osg::ref_ptr<osg::LineWidth> markerWidth(new osg::LineWidth());
markerWidth->setWidth(1.5f);
markerGeometry->getOrCreateStateSet()->
setAttributeAndModes(markerWidth, osg::StateAttribute::ON);
addDrawable(markerGeometry);
text = new osgText::Text;
text->setCharacterSize(11);
text->setFont(font);
text->setAxisAlignment(osgText::Text::SCREEN);
text->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
text->setPosition(osg::Vec3(40.0f, 45.0f, -1.5f));
addDrawable(text);
}
void
HUDScaleGeode::update(int windowHeight, float cameraFov, float cameraDistance,
bool darkBackground)
{
float f = static_cast<float>(windowHeight) / 2.0f
/ tanf(cameraFov / 180.0f * M_PI / 2.0f);
float dist = cameraDistance / f * 80.0f;
if (darkBackground) {
text->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
} else {
text->setColor(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
}
text->setText(QString("%1 m").arg(dist, 0, 'f', 2).toStdString());
}
/*=====================================================================
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 HUDScaleGeode.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef HUDSCALEGEODE_H
#define HUDSCALEGEODE_H
#include <osg/Geode>
#include <osgText/Text>
#include <QString>
class HUDScaleGeode : public osg::Geode
{
public:
HUDScaleGeode();
void init(osg::ref_ptr<osgText::Font>& font);
void update(int windowHeight, float cameraFov, float cameraDistance,
bool darkBackground);
private:
osg::ref_ptr<osgText::Text> text;
};
#endif // HUDSCALEGEODE_H
///*=====================================================================
//
//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 ImageWindowGeode.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#include "ImageWindowGeode.h"
ImageWindowGeode::ImageWindowGeode()
: mBorder(5)
, mImage(new osg::Image)
{
}
void
ImageWindowGeode::init(const QString& caption, const osg::Vec4& backgroundColor,
osg::ref_ptr<osgText::Font>& font)
{
// image
osg::ref_ptr<osg::Geometry> imageGeometry = new osg::Geometry;
mImageVertices = new osg::Vec3Array(4);
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));
osg::ref_ptr<osg::Vec4Array> imageColors(new osg::Vec4Array);
imageColors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
imageGeometry->setColorArray(imageColors);
imageGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
imageGeometry->setVertexArray(mImageVertices);
imageGeometry->setTexCoordArray(0, textureCoords);
imageGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,
0, mImageVertices->size()));
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC);
texture->setImage(mImage);
texture->setResizeNonPowerOfTwoHint(false);
imageGeometry->getOrCreateStateSet()->
setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
imageGeometry->setUseDisplayList(false);
// background
osg::ref_ptr<osg::Geometry> backgroundGeometry = new osg::Geometry;
mBackgroundVertices = new osg::Vec3Array(4);
backgroundGeometry->setVertexArray(mBackgroundVertices);
backgroundGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,
0, mBackgroundVertices->size()));
osg::ref_ptr<osg::Vec4Array> backgroundColors(new osg::Vec4Array);
backgroundColors->push_back(backgroundColor);
backgroundGeometry->setColorArray(backgroundColors);
backgroundGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
backgroundGeometry->setUseDisplayList(false);
// caption
mText = new osgText::Text;
mText->setText(caption.toStdString().c_str());
mText->setCharacterSize(11);
mText->setFont(font);
mText->setAxisAlignment(osgText::Text::SCREEN);
mText->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
addDrawable(imageGeometry);
addDrawable(backgroundGeometry);
addDrawable(mText);
setAttributes(0, 0, 0, 0);
}
void
ImageWindowGeode::setAttributes(int x, int y, int width, int height)
{
int imageWidth = width - mBorder * 2;
int imageHeight = height - mBorder * 2 - 15;
int imageXPosition = x + mBorder;
int imageYPosition = y + mBorder;
mImageVertices->at(0) = osg::Vec3(imageXPosition, imageYPosition, 0);
mImageVertices->at(1) = osg::Vec3(imageXPosition + imageWidth, imageYPosition, 0);
mImageVertices->at(2) = osg::Vec3(imageXPosition + imageWidth, imageYPosition + imageHeight, 0);
mImageVertices->at(3) = osg::Vec3(imageXPosition, imageYPosition + imageHeight, 0);
mText->setPosition(osg::Vec3(imageXPosition, imageYPosition + imageHeight + 5, 0));
mBackgroundVertices->at(0) = osg::Vec3(x, y, -1);
mBackgroundVertices->at(1) = osg::Vec3(x + width, y, -1);
mBackgroundVertices->at(2) = osg::Vec3(x + width, y + height, -1);
mBackgroundVertices->at(3) = osg::Vec3(x, y + height, -1);
}
osg::ref_ptr<osg::Image>&
ImageWindowGeode::image(void)
{
return mImage;
}
///*=====================================================================
//
//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 ImageWindowGeode.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef IMAGEWINDOWGEODE_H
#define IMAGEWINDOWGEODE_H
#include <osg/Geode>
#include <osg/Geometry>
#include <osgText/Text>
#include <QString>
class ImageWindowGeode : public osg::Geode
{
public:
ImageWindowGeode();
void init(const QString& caption, const osg::Vec4& backgroundColor,
osg::ref_ptr<osgText::Font>& font);
void setAttributes(int x, int y, int width, int height);
osg::ref_ptr<osg::Image>& image(void);
private:
int mBorder;
osg::ref_ptr<osg::Image> mImage;
osg::ref_ptr<osg::Vec3Array> mImageVertices;
osg::ref_ptr<osg::Vec3Array> mBackgroundVertices;
osg::ref_ptr<osgText::Text> mText;
};
#endif // IMAGEWINDOWGEODE_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 <osg/Geode>
#include <QScopedPointer>
#include <QString>
#include "TextureCache.h"
class Imagery : public osg::Geode
{
public:
enum Type
{
BLANK_MAP = 0,
GOOGLE_MAP = 1,
GOOGLE_SATELLITE = 2,
OFFLINE_SATELLITE = 3
};
Imagery();
Type getImageryType(void) const;
void setImageryType(Type type);
void setOffset(double xOffset, double yOffset, double zOffset = 0.0);
void setPath(const QString& path);
void prefetch2D(double windowWidth, double windowHeight,
double zoom, double xOrigin, double yOrigin,
const QString& utmZone);
void draw2D(double windowWidth, double windowHeight,
double zoom, double xOrigin, double yOrigin,
const QString& utmZone);
void prefetch3D(double radius, double tileResolution,
double xOrigin, double yOrigin,
const QString& utmZone);
void draw3D(double radius, double tileResolution,
double xOrigin, double yOrigin,
double xOffset, double yOffset,
const QString& utmZone);
bool update(void);
static void LLtoUTM(double latitude, double longitude,
double& utmNorthing, double& utmEasting,
QString& utmZone);
static void UTMtoLL(double utmNorthing, double utmEasting, const QString& utmZone,
double& latitude, double& longitude);
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;
static QChar UTMLetterDesignator(double latitude);
QString getTileLocation(int tileX, int tileY, int zoomLevel,
double tileResolution) const;
QScopedPointer<TextureCache> mTextureCache;
Type mImageryType;
std::string mImageryPath;
double mXOffset;
double mYOffset;
double mZOffset;
};
#endif // IMAGERY_H
#include "ImageryParamDialog.h"
#include <QStandardPaths>
#include <QFormLayout>
#include <QGroupBox>
#include <QPushButton>
#include "QGCFileDialog.h"
ImageryParamDialog::ImageryParamDialog(QWidget* parent)
: QDialog(parent)
{
QVBoxLayout* layout = new QVBoxLayout;
setLayout(layout);
setWindowTitle(tr("Imagery Parameters"));
setModal(true);
buildLayout(layout);
}
void
ImageryParamDialog::getImageryParams(GlobalViewParamsPtr &globalViewParams)
{
ImageryParamDialog dialog;
switch (globalViewParams->imageryType())
{
case Imagery::BLANK_MAP:
dialog.mImageryTypeComboBox->setCurrentIndex(0);
break;
case Imagery::GOOGLE_MAP:
dialog.mImageryTypeComboBox->setCurrentIndex(1);
break;
case Imagery::GOOGLE_SATELLITE:
dialog.mImageryTypeComboBox->setCurrentIndex(2);
break;
case Imagery::OFFLINE_SATELLITE:
dialog.mImageryTypeComboBox->setCurrentIndex(3);
break;
}
dialog.mPathLineEdit->setText(globalViewParams->imageryPath());
QVector3D& imageryOffset = globalViewParams->imageryOffset();
dialog.mXOffsetSpinBox->setValue(imageryOffset.x());
dialog.mYOffsetSpinBox->setValue(imageryOffset.y());
dialog.mZOffsetSpinBox->setValue(imageryOffset.z());
if (dialog.exec() == QDialog::Accepted)
{
switch (dialog.mImageryTypeComboBox->currentIndex())
{
case 0:
globalViewParams->imageryType() = Imagery::BLANK_MAP;
break;
case 1:
globalViewParams->imageryType() = Imagery::GOOGLE_MAP;
break;
case 2:
globalViewParams->imageryType() = Imagery::GOOGLE_SATELLITE;
break;
case 3:
globalViewParams->imageryType() = Imagery::OFFLINE_SATELLITE;
break;
}
globalViewParams->imageryPath() = dialog.mPathLineEdit->text();
imageryOffset.setX(dialog.mXOffsetSpinBox->value());
imageryOffset.setY(dialog.mYOffsetSpinBox->value());
imageryOffset.setZ(dialog.mZOffsetSpinBox->value());
globalViewParams->signalImageryParamsChanged();
}
}
void
ImageryParamDialog::selectPath(void)
{
QString filename = QGCFileDialog::getExistingDirectory(this, "Imagery path",
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
if (filename.isNull())
{
return;
}
else
{
mPathLineEdit->setText(filename);
}
}
void
ImageryParamDialog::closeWithSaving(void)
{
done(QDialog::Accepted);
}
void
ImageryParamDialog::closeWithoutSaving(void)
{
done(QDialog::Rejected);
}
void
ImageryParamDialog::buildLayout(QVBoxLayout* layout)
{
QFormLayout* formLayout = new QFormLayout;
mImageryTypeComboBox = new QComboBox(this);
mImageryTypeComboBox->addItem("None");
mImageryTypeComboBox->addItem("Map (Google)");
mImageryTypeComboBox->addItem("Satellite (Google)");
mImageryTypeComboBox->addItem("Satellite (Offline)");
mPathLineEdit = new QLineEdit(this);
mPathLineEdit->setReadOnly(true);
QPushButton* pathButton = new QPushButton(this);
pathButton->setText(tr(".."));
QHBoxLayout* pathLayout = new QHBoxLayout;
pathLayout->addWidget(mPathLineEdit);
pathLayout->addWidget(pathButton);
formLayout->addRow(tr("Imagery Type"), mImageryTypeComboBox);
formLayout->addRow(tr("Path"), pathLayout);
layout->addLayout(formLayout);
QGroupBox* offsetGroupBox = new QGroupBox(tr("Offset"), this);
mXOffsetSpinBox = new QDoubleSpinBox(this);
mXOffsetSpinBox->setDecimals(1);
mXOffsetSpinBox->setRange(-1000.0, 1000.0);
mXOffsetSpinBox->setValue(0.0);
mYOffsetSpinBox = new QDoubleSpinBox(this);
mYOffsetSpinBox->setDecimals(1);
mYOffsetSpinBox->setRange(-1000.0, 1000.0);
mYOffsetSpinBox->setValue(0.0);
mZOffsetSpinBox = new QDoubleSpinBox(this);
mZOffsetSpinBox->setDecimals(1);
mZOffsetSpinBox->setRange(-1000.0, 1000.0);
mZOffsetSpinBox->setValue(0.0);
formLayout = new QFormLayout;
formLayout->addRow(tr("x (m)"), mXOffsetSpinBox);
formLayout->addRow(tr("y (m)"), mYOffsetSpinBox);
formLayout->addRow(tr("z (m)"), mZOffsetSpinBox);
offsetGroupBox->setLayout(formLayout);
layout->addWidget(offsetGroupBox);
layout->addItem(new QSpacerItem(10, 0, QSizePolicy::Expanding, QSizePolicy::Expanding));
QPushButton* cancelButton = new QPushButton(this);
cancelButton->setText("Cancel");
QPushButton* saveButton = new QPushButton(this);
saveButton->setText("Save");
QHBoxLayout* buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(cancelButton);
buttonLayout->addItem(new QSpacerItem(10, 0, QSizePolicy::Expanding, QSizePolicy::Expanding));
buttonLayout->addWidget(saveButton);
layout->addLayout(buttonLayout);
connect(pathButton, SIGNAL(clicked()), this, SLOT(selectPath()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(closeWithoutSaving()));
connect(saveButton, SIGNAL(clicked()), this, SLOT(closeWithSaving()));
}
#ifndef IMAGERYPARAMDIALOG_H
#define IMAGERYPARAMDIALOG_H
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QDialog>
#include <QLineEdit>
#include <QVBoxLayout>
#include "GlobalViewParams.h"
class ImageryParamDialog : public QDialog
{
Q_OBJECT
public:
ImageryParamDialog(QWidget* parent = 0);
static void getImageryParams(GlobalViewParamsPtr& globalViewParams);
private slots:
void selectPath(void);
void closeWithSaving(void);
void closeWithoutSaving(void);
private:
void buildLayout(QVBoxLayout* layout);
QComboBox* mImageryTypeComboBox;
QLineEdit* mPathLineEdit;
QDoubleSpinBox* mXOffsetSpinBox;
QDoubleSpinBox* mYOffsetSpinBox;
QDoubleSpinBox* mZOffsetSpinBox;
};
#endif // IMAGERYPARAMDIALOG_H
/*=====================================================================
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 ObstacleGroupNode.
*
* @author Lionel Heng <hengli@inf.ethz.ch>
*
*/
#include "ObstacleGroupNode.h"
#include <limits>
#include <osg/PositionAttitudeTransform>
#include <osg/ShapeDrawable>
#include "gpl.h"
#include "Imagery.h"
ObstacleGroupNode::ObstacleGroupNode()
{
}
void
ObstacleGroupNode::init(void)
{
}
void
ObstacleGroupNode::clear(void)
{
if (getNumChildren() > 0)
{
removeChild(0, getNumChildren());
}
}
void
ObstacleGroupNode::update(double robotX, double robotY, double robotZ,
const px::ObstacleList& obstacleList)
{
clear();
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
// find minimum and maximum height
float zMin = std::numeric_limits<float>::max();
float zMax = std::numeric_limits<float>::min();
for (int i = 0; i < obstacleList.obstacles_size(); ++i)
{
const px::Obstacle& obs = obstacleList.obstacles(i);
float z = robotZ - obs.z();
if (zMin > z)
{
zMin = z;
}
if (zMax < z)
{
zMax = z;
}
}
for (int i = 0; i < obstacleList.obstacles_size(); ++i)
{
const px::Obstacle& obs = obstacleList.obstacles(i);
osg::Vec3d obsPos(obs.y() - robotY, obs.x() - robotX, robotZ - obs.z());
osg::ref_ptr<osg::Box> box =
new osg::Box(obsPos, obs.width(), obs.width(), obs.height());
osg::ref_ptr<osg::ShapeDrawable> sd = new osg::ShapeDrawable(box);
int idx = (obsPos.z() - zMin) / (zMax - zMin) * 127.0f;
float r, g, b;
qgc::colormap("jet", idx, r, g, b);
sd->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
sd->setColor(osg::Vec4(r, g, b, 1.0f));
sd->setUseDisplayList(false);
geode->addDrawable(sd);
}
addChild(geode);
}
/*=====================================================================
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 ObstacleGroupNode.
*
* @author Lionel Heng <hengli@inf.ethz.ch>
*
*/
#ifndef OBSTACLEGROUPNODE_H
#define OBSTACLEGROUPNODE_H
#include <osg/Group>
#include "UASInterface.h"
class ObstacleGroupNode : public osg::Group
{
public:
ObstacleGroupNode();
void init(void);
void clear(void);
void update(double robotX, double robotY, double robotZ,
const px::ObstacleList& obstacleList);
};
#endif // OBSTACLEGROUPNODE_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 Pixhawk3DWidget.
*
* @author Lionel Heng <hengli@inf.ethz.ch>
*
*/
#ifndef PIXHAWK3DWIDGET_H
#define PIXHAWK3DWIDGET_H
#include <osgText/Text>
#include "HUDScaleGeode.h"
#include "Imagery.h"
#include "Q3DWidget.h"
#include "SystemContainer.h"
#include "ViewParamWidget.h"
class UASInterface;
/**
* @brief A 3D View widget which displays vehicle-centric information.
**/
class Pixhawk3DWidget : public QWidget
{
Q_OBJECT
public:
explicit Pixhawk3DWidget(QWidget* parent = 0);
~Pixhawk3DWidget();
public slots:
void activeSystemChanged(UASInterface* uas);
void systemCreated(UASInterface* uas);
void localPositionChanged(UASInterface* uas, int component, double x, double y, double z, quint64 time);
void localPositionChanged(UASInterface* uas, double x, double y, double z, quint64 time);
void attitudeChanged(UASInterface* uas, int component, double roll, double pitch, double yaw, quint64 time);
void attitudeChanged(UASInterface* uas, double roll, double pitch, double yaw, quint64 time);
void homePositionChanged(int uasId, double lat, double lon, double alt);
void setpointChanged(int uasId, float x, float y, float z, float yaw);
signals:
void systemCreatedSignal(UASInterface* uas);
void overlayCreatedSignal(int systemId, const QString& name);
private slots:
void clearData(void);
void showTerrainParamWindow(void);
void showViewParamWindow(void);
void followCameraChanged(int systemId);
void imageryParamsChanged(void);
void recenterActiveCamera(void);
void modelChanged(int systemId, int index);
void setBirdEyeView(void);
void loadTerrainModel(void);
void selectTargetHeading(void);
void selectTarget(void);
void setTarget(void);
void insertWaypoint(void);
void moveWaypointPosition(void);
void moveWaypointHeading(void);
void deleteWaypoint(void);
void setWaypointAltitude(void);
void clearAllWaypoints(void);
void moveImagery(void);
void moveTerrain(void);
void rotateTerrain(void);
void sizeChanged(int width, int height);
void updateWidget(void);
protected:
void addModels(QVector< osg::ref_ptr<osg::Node> >& models,
const QColor& systemColor);
void buildLayout(void);
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
void showEvent(QShowEvent* event);
void hideEvent(QHideEvent* event);
signals:
void visibilityChanged(bool visible);
private:
void initializeSystem(int systemId, const QColor& systemColor);
void getPose(UASInterface* uas,
MAV_FRAME frame,
double& x, double& y, double& z,
double& roll, double& pitch, double& yaw,
QString& utmZone) const;
void getPose(UASInterface* uas,
MAV_FRAME frame,
double& x, double& y, double& z,
double& roll, double& pitch, double& yaw) const;
void getPosition(UASInterface* uas,
MAV_FRAME frame,
double& x, double& y, double& z,
QString& utmZone) const;
void getPosition(UASInterface* uas,
MAV_FRAME frame,
double& x, double& y, double& z) const;
osg::ref_ptr<osg::Geode> createLocalGrid(void);
osg::ref_ptr<osg::Geode> createWorldGrid(void);
osg::ref_ptr<osg::Geometry> createTrail(const osg::Vec4& color);
osg::ref_ptr<osg::Geometry> createLink(const QColor& color);
osg::ref_ptr<Imagery> createImagery(void);
osg::ref_ptr<osg::Geode> createPointCloud(void);
osg::ref_ptr<osg::Node> createTarget(const QColor& color);
void setupHUD(void);
void resizeHUD(int width, int height);
void updateHUD(UASInterface* uas, MAV_FRAME frame);
void updateImagery(double originX, double originY,
const QString& zone, MAV_FRAME frame);
void updateTarget(UASInterface* uas, MAV_FRAME frame,
double robotX, double robotY, double robotZ,
QVector4D& target,
osg::ref_ptr<osg::Node>& targetNode);
void updateTrails(double robotX, double robotY, double robotZ,
osg::ref_ptr<osg::Geode>& trailNode,
osg::ref_ptr<osg::Group>& orientationNode,
QMap<int, QVector<osg::Vec3d> >& trailMap,
QMap<int, int>& trailIndexMap);
void updateWaypoints(UASInterface* uas, MAV_FRAME frame,
osg::ref_ptr<WaypointGroupNode>& waypointGroupNode);
int findWaypoint(const QPoint& mousePos);
bool findTarget(int mouseX, int mouseY);
bool findTerrain(const QPoint& mousePos);
void showInsertWaypointMenu(const QPoint& cursorPos);
void showEditWaypointMenu(const QPoint& cursorPos);
void showTerrainMenu(const QPoint& cursorPos);
const qreal kMessageTimeout; // message timeout in seconds
enum Mode {
DEFAULT_MODE,
MOVE_WAYPOINT_POSITION_MODE,
MOVE_WAYPOINT_HEADING_MODE,
SELECT_TARGET_HEADING_MODE,
MOVE_TERRAIN_MODE,
ROTATE_TERRAIN_MODE,
MOVE_IMAGERY_MODE
};
Mode mMode;
int mSelectedWpIndex;
int mActiveSystemId;
UASInterface* mActiveUAS;
GlobalViewParamsPtr mGlobalViewParams;
// maps system id to system-specific view parameters
QMap<int, SystemViewParamsPtr> mSystemViewParamMap;
// maps system id to system-specific data
QMap<int, SystemContainer> mSystemContainerMap;
osg::ref_ptr<osg::Geometry> mHudBackgroundGeometry;
osg::ref_ptr<Imagery> mImageryNode;
osg::ref_ptr<HUDScaleGeode> mScaleGeode;
osg::ref_ptr<osgText::Text> mStatusText;
osg::ref_ptr<osg::Node> mTerrainNode;
osg::ref_ptr<osg::PositionAttitudeTransform> mTerrainPAT;
osg::ref_ptr<osg::Geode> mWorldGridNode;
QPoint mCachedMousePos;
int mFollowCameraId;
QVector3D mCameraPos;
bool mInitCameraPos;
Q3DWidget* m3DWidget;
ViewParamWidget* mViewParamWidget;
};
#endif // PIXHAWK3DWIDGET_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 PixhawkCheetahNode.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef PIXHAWKCHEETAHNODE_H_
#define PIXHAWKCHEETAHNODE_H_
#include <osg/Geode>
#include <QColor>
/**
* @brief The PixhawkCheetahNode class.
* Generates an OpenSceneGraph node which renders a Pixhawk Cheetah MAV.
**/
class PixhawkCheetahNode
{
public:
/**
* Constructor.
*/
PixhawkCheetahNode();
/**
* Get a single instance of the node.
*/
static osg::ref_ptr<osg::Node> instance(void);
/**
* @brief Creates an OpenSceneGraph node which renders a Pixhawk Cheetah MAV.
* @param red Red intensity of the MAV model.
* @param green Green intensity of the MAV model.
* @param blue Blue intensity of the MAV model.
*
* @return A smart pointer to the node.
**/
static osg::ref_ptr<osg::Node> create(const QColor& color);
private:
static osg::ref_ptr<osg::Node> mInstance;
};
#endif
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 Q3DWidget.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef Q3DWIDGET_H
#define Q3DWIDGET_H
#include <QtOpenGL>
#include <inttypes.h>
#include <osg/LineSegment>
#include <osg/PositionAttitudeTransform>
#include <osgGA/TrackballManipulator>
#include <osgText/Font>
// OpenSceneGraph has overloaded virtuals defined, since third party code we silence the warnings when the
// headers are used.
#ifndef Q_OS_WIN
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
#endif
#include <osgViewer/Viewer>
#ifndef Q_OS_WIN
#pragma GCC diagnostic pop
#endif
#include "CameraParams.h"
#include "GCManipulator.h"
#include "SystemGroupNode.h"
/**
* @brief Definition of the class Q3DWidget.
* The Q3DWidget widget uses the OpenSceneGraph framework to render
* user-defined objects in 3D. The world coordinate system in OSG is defined:
* - x-axis points to the east
* - y-axis points to the north
* - z-axis points upwards
*/
class Q3DWidget : public QGLWidget, public osgViewer::Viewer
{
Q_OBJECT
public:
/**
* Constructor.
* @param parent Parent widget.
*/
Q3DWidget(QWidget* parent = 0);
/**
* Destructor.
*/
virtual ~Q3DWidget();
/**
* @brief Initializes the widget.
* @param fps Frames per second.
*/
void init(float fps);
/**
* @brief Sets the camera parameters.
* @param minZoomRange Minimum distance from the viewer to the camera.
* @param cameraFov Camera field of view.
* @param minClipRange Distance from the viewer to the near clipping range.
* @param maxClipRange Distance from the viewer to the far clipping range.
*/
void setCameraParams(float minZoomRange, float cameraFov,
float minClipRange, float maxClipRange);
/**
* @brief Moves the camera by [dx,dy,dz].
* @param dx Translation along the x-axis in meters.
* @param dy Translation along the y-axis in meters.
* @param dz Translation along the z-axis in meters.
*/
void moveCamera(double dx, double dy, double dz);
/**
* @brief Recenters the camera at (x,y,z).
*/
void recenterCamera(double x, double y, double z);
/**
* @brief Rotates the camera.
*/
void rotateCamera(double roll, double pitch, double yaw);
/**
* @brief Sets the camera distance.
*/
void setCameraDistance(double distance);
/**
* @brief Sets up 3D display mode.
*/
void setDisplayMode3D(void);
osg::ref_ptr<osg::Switch>& hudGroup(void);
/**
* @brief Get screen coordinates of mouse cursor.
* @return screen coordinates of mouse cursor.
*/
QPoint mouseCursorCoords(void);
/**
* @brief Gets the world 3D coordinates of the cursor.
* The function projects the 2D cursor position to a line in world space
* and returns the intersection of that line and the horizontal plane
* which contains the point (0, 0, z);
* @param cursorX x-coordinate of the cursor.
* @param cursorY y-coordinate of the cursor.
* @param worldZ z-coordinate of the point in the plane.
* @return World (x,y) cursor coordinates.
*/
QPointF worldCursorPosition(const QPoint& cursorPos, double worldZ) const;
CameraParams& cameraParams(void);
osg::ref_ptr<GCManipulator>& cameraManipulator(void);
osg::ref_ptr<osgText::Font>& font(void);
osg::ref_ptr<osg::Switch>& worldMap(void);
osg::ref_ptr<SystemGroupNode>& systemGroup(int systemId);
bool& handleDeviceEvents(void);
void handleKeyPressEvent(QKeyEvent* event);
void handleKeyReleaseEvent(QKeyEvent* event);
void handleMousePressEvent(QMouseEvent* event);
void handleMouseReleaseEvent(QMouseEvent* event);
void handleMouseMoveEvent(QMouseEvent* event);
void handleWheelEvent(QWheelEvent* event);
protected slots:
/**
* @brief Updates the widget.
*/
void redraw(void);
signals:
void sizeChanged(int width, int height);
void updateWidget(void);
protected:
/**
* @brief Handle widget resize event.
* @param width New width of widget.
* @param height New height of widget.
*/
virtual void resizeGL(int width, int height);
/**
* @brief Processes key press events.
* @param event Key press event.
*/
virtual void keyPressEvent(QKeyEvent* event);
/**
* @brief Processes key release events.
* @param event Key release event.
*/
virtual void keyReleaseEvent(QKeyEvent* event);
/**
* @brief Processes mouse press events.
* @param event Mouse press event.
*/
virtual void mousePressEvent(QMouseEvent* event);
/**
* @brief Processes mouse release events.
* @param event Mouse release event.
*/
virtual void mouseReleaseEvent(QMouseEvent* event);
/**
* @brief Processes mouse move events.
* @param event Mouse move event.
*/
virtual void mouseMoveEvent(QMouseEvent* event);
/**
* @brief Processes mouse wheel events.
* @param event Mouse wheel event.
*/
virtual void wheelEvent(QWheelEvent* event);
/** @brief Start widget updating */
void showEvent(QShowEvent* event);
/** @brief Stop widget updating */
void hideEvent(QHideEvent* event);
/**
* @brief Get base HUD geode.
* @return Smart pointer to the geode.
*/
osg::ref_ptr<osg::Node> createHUD(void);
/**
* @brief Handle widget paint event.
*/
virtual void paintGL(void);
/**
* @brief Converts Qt-defined key to OSG-defined key.
* @param key Qt-defined key.
* @return OSG-defined key.
*/
osgGA::GUIEventAdapter::KeySymbol convertKey(int key) const;
/**
* @brief Computes intersection of line and plane.
* @param plane Vector which represents the plane.
* @param line Line representation.
* @return 3D point which lies at the intersection of the line and plane.
*/
bool planeLineIntersection(const osg::Vec4d& plane,
const osg::LineSegment& line,
osg::Vec3d& isect) const;
bool mHandleDeviceEvents;
osg::ref_ptr<osg::Group> mRoot; /**< Root node of scene graph. */
osg::ref_ptr<osg::Switch> mWorldMap;
QMap<int, osg::ref_ptr<SystemGroupNode> > mSystemGroups;
osg::ref_ptr<osg::Switch> mHudGroup; /**< A group which contains renderable HUD objects. */
osg::ref_ptr<osg::Projection> mHudProjectionMatrix; /**< An orthographic projection matrix for HUD display. */
osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> mOsgGW; /**< A class which manages OSG graphics windows and events. */
osg::ref_ptr<GCManipulator> mCameraManipulator; /**< Camera manipulator. */
QTimer mTimer; /**< Timer which draws graphics based on specified fps. */
CameraParams mCameraParams; /**< Struct representing camera parameters. */
float mFps;
osg::ref_ptr<osgText::Font> mFont;
};
#endif // Q3DWIDGET_H
/*=====================================================================
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 Q3DWidgetFactory.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#include "Q3DWidgetFactory.h"
#include "Pixhawk3DWidget.h"
#ifdef QGC_OSGEARTH_ENABLED
#include "QMap3D.h"
#endif
QPointer<QWidget>
Q3DWidgetFactory::get(const std::string& type, QWidget* parent)
{
if (type == "PIXHAWK") {
return QPointer<QWidget>(new Pixhawk3DWidget(parent));
}
else {
return QPointer<QWidget>(new Q3DWidget(parent));
}
}
/*=====================================================================
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 Q3DWidgetFactory.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef Q3DWIDGETFACTORY_H
#define Q3DWIDGETFACTORY_H
#include <QPointer>
#include "Q3DWidget.h"
/**
* @brief A factory which creates project-specific 3D widgets without
* specifying the exact widget class.
*/
class Q3DWidgetFactory
{
public:
/**
* @brief Returns a Q3DWidget instance of the appropriate type.
* @param type String specifying the required type name.
* @return A smart pointer to the Q3DWidget instance.
*/
static QPointer<QWidget> get(const std::string& type, QWidget* parent);
};
#endif // Q3DWIDGETFACTORY_H
This diff is collapsed.
#include "QGCWebPage.h"
#include <QDebug>
QGCWebPage::QGCWebPage(QObject *parent) :
QWebPage(parent)
{
}
void QGCWebPage::javaScriptConsoleMessage ( const QString & message, int lineNumber, const QString & sourceID )
{
qDebug() << "JAVASCRIPT: " << lineNumber << sourceID << message;
}
#ifdef Q_OS_MAC64
QString QGCWebPage::userAgentForUrl ( const QUrl & url ) const
{
Q_UNUSED(url);
return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_0) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari";
}
#endif
#ifndef QGCWEBPAGE_H
#define QGCWEBPAGE_H
#include <QWebPage>
class QGCWebPage : public QWebPage
{
Q_OBJECT
public:
explicit QGCWebPage(QObject *parent = 0);
signals:
public slots:
protected:
void javaScriptConsoleMessage ( const QString & message, int lineNumber, const QString & sourceID );
#ifdef Q_OS_MAC
QString userAgentForUrl ( const QUrl & url ) const;
#endif
};
#endif // QGCWEBPAGE_H
/*=====================================================================
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 QMap3D.h
*
* @author James Goppert <james.goppert@gmail.com>
*
*/
#ifdef QGC_OSGEARTH_ENABLED
#ifndef QMAP3D_H
#define QMAP3D_H
#include "QOSGWidget.h"
#include "ui_QMap3D.h"
namespace Ui
{
class QMap3D;
}
class QMap3D : public QWidget, private Ui::QMap3D
{
Q_OBJECT
public:
QMap3D(QWidget * parent = 0, const char * name = 0, WindowFlags f = 0);
~QMap3D();
public slots:
void on_pushButton_map_clicked();
void on_pushButton_vehicle_clicked();
};
#endif // QMAP3D_H
#endif
#include "SystemContainer.h"
#include <osg/PositionAttitudeTransform>
SystemContainer::SystemContainer()
{
}
QVector3D&
SystemContainer::gpsLocalOrigin(void)
{
return mGPSLocalOrigin;
}
QVector4D&
SystemContainer::target(void)
{
return mTarget;
}
QVector< osg::ref_ptr<osg::Node> >&
SystemContainer::models(void)
{
return mModels;
}
QMap<int, QVector<osg::Vec3d> >&
SystemContainer::trailMap(void)
{
return mTrailMap;
}
QMap<int, int>&
SystemContainer::trailIndexMap(void)
{
return mTrailIndexMap;
}
osg::ref_ptr<ImageWindowGeode>&
SystemContainer::depthImageNode(void)
{
return mDepthImageNode;
}
osg::ref_ptr<osg::Geode>&
SystemContainer::localGridNode(void)
{
return mLocalGridNode;
}
osg::ref_ptr<osg::Node>&
SystemContainer::modelNode(void)
{
return mModelNode;
}
osg::ref_ptr<osg::Group>&
SystemContainer::orientationNode(void)
{
return mOrientationNode;
}
osg::ref_ptr<osg::Geode>&
SystemContainer::pointCloudNode(void)
{
return mPointCloudNode;
}
osg::ref_ptr<ImageWindowGeode>&
SystemContainer::rgbImageNode(void)
{
return mRGBImageNode;
}
osg::ref_ptr<osg::Group>&
SystemContainer::setpointGroupNode(void)
{
return mSetpointGroupNode;
}
osg::ref_ptr<osg::Node>&
SystemContainer::targetNode(void)
{
return mTargetNode;
}
osg::ref_ptr<osg::Geode>&
SystemContainer::trailNode(void)
{
return mTrailNode;
}
osg::ref_ptr<WaypointGroupNode>&
SystemContainer::waypointGroupNode(void)
{
return mWaypointGroupNode;
}
#ifndef SYSTEMCONTAINER_H
#define SYSTEMCONTAINER_H
#include <osg/Geode>
#include <QMap>
#include <QVarLengthArray>
#include <QVector3D>
#include <QVector4D>
#include "ImageWindowGeode.h"
#include "WaypointGroupNode.h"
class SystemContainer
{
public:
SystemContainer();
QVector3D& gpsLocalOrigin(void);
QVector4D& target(void);
QVector< osg::ref_ptr<osg::Node> >& models(void);
QMap<int, QVector<osg::Vec3d> >& trailMap(void);
QMap<int, int>& trailIndexMap(void);
osg::ref_ptr<ImageWindowGeode>& depthImageNode(void);
osg::ref_ptr<osg::Geode>& localGridNode(void);
osg::ref_ptr<osg::Node>& modelNode(void);
osg::ref_ptr<osg::Group>& orientationNode(void);
osg::ref_ptr<osg::Geode>& pointCloudNode(void);
osg::ref_ptr<ImageWindowGeode>& rgbImageNode(void);
osg::ref_ptr<osg::Group>& setpointGroupNode(void);
osg::ref_ptr<osg::Node>& targetNode(void);
osg::ref_ptr<osg::Geode>& trailNode(void);
osg::ref_ptr<WaypointGroupNode>& waypointGroupNode(void);
private:
QVector3D mGPSLocalOrigin;
QVector4D mTarget;
QVector< osg::ref_ptr<osg::Node> > mModels;
// map component id to component-specific trail
QMap<int, QVector<osg::Vec3d> > mTrailMap;
QMap<int, int> mTrailIndexMap;
// osg structures
osg::ref_ptr<ImageWindowGeode> mDepthImageNode;
osg::ref_ptr<osg::Geode> mLocalGridNode;
osg::ref_ptr<osg::Node> mModelNode;
osg::ref_ptr<osg::Group> mOrientationNode;
osg::ref_ptr<osg::Geode> mPointCloudNode;
osg::ref_ptr<ImageWindowGeode> mRGBImageNode;
osg::ref_ptr<osg::Group> mSetpointGroupNode;
osg::ref_ptr<osg::Node> mTargetNode;
osg::ref_ptr<osg::Geode> mTrailNode;
osg::ref_ptr<WaypointGroupNode> mWaypointGroupNode;
};
#endif // SYSTEMCONTAINER_H
This diff is collapsed.
#ifndef SYSTEMGROUPNODE_H
#define SYSTEMGROUPNODE_H
#include <osg/PositionAttitudeTransform>
#include <osg/Switch>
class SystemGroupNode : public osg::Group
{
public:
SystemGroupNode();
osg::ref_ptr<osg::Switch>& allocentricMap(void);
osg::ref_ptr<osg::Switch>& rollingMap(void);
osg::ref_ptr<osg::Switch>& egocentricMap(void);
osg::ref_ptr<osg::PositionAttitudeTransform>& position(void);
osg::ref_ptr<osg::PositionAttitudeTransform>& attitude(void);
private:
osg::ref_ptr<osg::Node> createAxisGeode(void);
osg::ref_ptr<osg::Switch> mAllocentricMap;
osg::ref_ptr<osg::Switch> mRollingMap;
osg::ref_ptr<osg::Switch> mEgocentricMap;
osg::ref_ptr<osg::PositionAttitudeTransform> mPosition;
osg::ref_ptr<osg::PositionAttitudeTransform> mAttitude;
};
#endif // SYSTEMGROUPNODE_H
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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