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

3D View perspective now uses the OpenSceneGraph framework. Imagery feature is based on osgEarth.

parent c043b38a
#-------------------------------------------------
#
# -------------------------------------------------
# QGroundControl - Micro Air Vehicle Groundstation
#
# Please see our website at <http://qgroundcontrol.org>
#
# Author:
# Lorenz Meier <mavteam@student.ethz.ch>
#
# (c) 2009-2010 PIXHAWK Team
#
# This file is part of the mav groundstation 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
......@@ -20,10 +15,7 @@
# 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/>.
#
#-------------------------------------------------
# -------------------------------------------------
# Include QMapControl map library
# prefer version from external directory /
# from http://github.com/pixhawk/qmapcontrol/
......@@ -31,7 +23,6 @@
# Version from GIT repository is preferred
# include ( "../qmapcontrol/QMapControl/QMapControl.pri" ) #{
# Include bundled version if necessary
include(lib/QMapControl/QMapControl.pri)
# message("Including bundled QMapControl version as FALLBACK. This is fine on Linux and MacOS, but not the best choice in Windows")
......@@ -50,40 +41,43 @@ CONFIG += debug_and_release \
OBJECTS_DIR = $$BUILDDIR/obj
MOC_DIR = $$BUILDDIR/moc
UI_HEADERS_DIR = src/ui/generated
MAVLINK_CONF = ""
exists(user_config.pri) {
exists(user_config.pri) {
message("----- USING USER QGROUNDCONTROL CONFIG FROM user_config.pri -----")
include(user_config.pri)
}
INCLUDEPATH += $$BASEDIR/../mavlink/include/common
contains(MAVLINK_CONF, pixhawk) {
# Remove the default set - it is included anyway
INCLUDEPATH -= $$BASEDIR/../mavlink/include/common
# PIXHAWK SPECIAL MESSAGES
INCLUDEPATH += $$BASEDIR/../mavlink/include/pixhawk
DEFINES += QGC_USE_PIXHAWK_MESSAGES
contains(MAVLINK_CONF, pixhawk) {
# Remove the default set - it is included anyway
INCLUDEPATH -= $$BASEDIR/../mavlink/include/common
# PIXHAWK SPECIAL MESSAGES
INCLUDEPATH += $$BASEDIR/../mavlink/include/pixhawk
DEFINES += QGC_USE_PIXHAWK_MESSAGES
}
contains(MAVLINK_CONF, slugs) {
# Remove the default set - it is included anyway
INCLUDEPATH -= $$BASEDIR/../mavlink/include/common
# SLUGS SPECIAL MESSAGES
INCLUDEPATH += $$BASEDIR/../mavlink/include/slugs
DEFINES += QGC_USE_SLUGS_MESSAGES
contains(MAVLINK_CONF, slugs) {
# Remove the default set - it is included anyway
INCLUDEPATH -= $$BASEDIR/../mavlink/include/common
# SLUGS SPECIAL MESSAGES
INCLUDEPATH += $$BASEDIR/../mavlink/include/slugs
DEFINES += QGC_USE_SLUGS_MESSAGES
}
contains(MAVLINK_CONF, ualberta) {
# Remove the default set - it is included anyway
INCLUDEPATH -= $$BASEDIR/../mavlink/include/common
# UALBERTA SPECIAL MESSAGES
INCLUDEPATH += $$BASEDIR/../mavlink/include/ualberta
DEFINES += QGC_USE_UALBERTA_MESSAGES
contains(MAVLINK_CONF, ualberta) {
# Remove the default set - it is included anyway
INCLUDEPATH -= $$BASEDIR/../mavlink/include/common
# UALBERTA SPECIAL MESSAGES
INCLUDEPATH += $$BASEDIR/../mavlink/include/ualberta
DEFINES += QGC_USE_UALBERTA_MESSAGES
}
# Include OpenSceneGraph and osgEarth libraries
LIBS += -losg \
-losgViewer \
-losgEarth
QMAKE_CXXFLAGS += -Wl,-E
# }
# Include general settings for MAVGround
# necessary as last include to override any non-acceptable settings
......@@ -226,15 +220,15 @@ HEADERS += src/MG.h \
src/ui/RadioCalibration/CurveCalibrator.h \
src/ui/RadioCalibration/AbstractCalibrator.h \
src/ui/map3D/Q3DWidget.h \
src/ui/map3D/CheetahModel.h \
src/ui/map3D/CheetahGL.h \
src/ui/map3D/QMap3DWidget.h \
src/ui/map3D/PixhawkCheetahGeode.h \
src/ui/map3D/Texture.h \
src/ui/map3D/TextureCache.h \
src/ui/map3D/WebImage.h \
src/ui/map3D/WebImageCache.h \
src/ui/map3D/Imagery.h \
src/comm/QGCMAVLink.h
src/comm/QGCMAVLink.h \
src/ui/map3D/Pixhawk3DWidget.h \
src/ui/map3D/Q3DWidgetFactory.h
SOURCES += src/main.cc \
src/Core.cc \
src/uas/UASManager.cc \
......@@ -306,14 +300,14 @@ SOURCES += src/main.cc \
src/ui/RadioCalibration/RadioCalibrationData.cc \
src/ui/WaypointGlobalView.cc \
src/ui/map3D/Q3DWidget.cc \
src/ui/map3D/CheetahModel.cc \
src/ui/map3D/CheetahGL.cc \
src/ui/map3D/QMap3DWidget.cc \
src/ui/map3D/PixhawkCheetahGeode.cc \
src/ui/map3D/Texture.cc \
src/ui/map3D/TextureCache.cc \
src/ui/map3D/WebImageCache.cc \
src/ui/map3D/WebImage.cc \
src/ui/map3D/Imagery.cc
src/ui/map3D/Imagery.cc \
src/ui/map3D/Pixhawk3DWidget.cc \
src/ui/map3D/Q3DWidgetFactory.cc
RESOURCES = mavground.qrc
# Include RT-LAB Library
......
......@@ -45,7 +45,7 @@ This file is part of the QGROUNDCONTROL project
#include "MainWindow.h"
#include "JoystickWidget.h"
#include "GAudioOutput.h"
#include "QMap3DWidget.h"
#include "Q3DWidgetFactory.h"
// FIXME Move
#include "PxQuadMAV.h"
......@@ -132,7 +132,7 @@ void MainWindow::buildWidgets()
mapWidget = new MapWidget(this);
protocolWidget = new XMLCommProtocolWidget(this);
dataplotWidget = new QGCDataPlot2D(this);
map3DWidget = new QMap3DWidget(this);
_3DWidget = Q3DWidgetFactory::get("PIXHAWK");
// Dock widgets
controlDockWidget = new QDockWidget(tr("Control"), this);
......@@ -224,7 +224,7 @@ void MainWindow::arrangeCenterStack()
if (linechartWidget) centerStack->addWidget(linechartWidget);
if (protocolWidget) centerStack->addWidget(protocolWidget);
if (mapWidget) centerStack->addWidget(mapWidget);
if (map3DWidget) centerStack->addWidget(map3DWidget);
if (_3DWidget) centerStack->addWidget(_3DWidget);
if (hudWidget) centerStack->addWidget(hudWidget);
if (dataplotWidget) centerStack->addWidget(dataplotWidget);
......@@ -665,13 +665,13 @@ void MainWindow::loadPixhawkView()
// Engineer view, used in EMAV2009
// 3D map
if (map3DWidget)
if (_3DWidget)
{
QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
if (centerStack)
{
//map3DWidget->setActive(true);
centerStack->setCurrentWidget(map3DWidget);
centerStack->setCurrentWidget(_3DWidget);
}
}
......@@ -955,13 +955,13 @@ void MainWindow::load3DView()
clearView();
// 3D map
if (map3DWidget)
if (_3DWidget)
{
QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
if (centerStack)
{
//map3DWidget->setActive(true);
centerStack->setCurrentWidget(map3DWidget);
centerStack->setCurrentWidget(_3DWidget);
}
}
......
......@@ -63,7 +63,7 @@ This file is part of the QGROUNDCONTROL project
#include "HSIDisplay.h"
#include "QGCDataPlot2D.h"
#include "QGCRemoteControlView.h"
#include "QMap3DWidget.h"
#include "Q3DWidget.h"
#include "LogCompressor.h"
......@@ -163,7 +163,7 @@ protected:
QPointer<MapWidget> mapWidget;
QPointer<XMLCommProtocolWidget> protocolWidget;
QPointer<QGCDataPlot2D> dataplotWidget;
QPointer<QMap3DWidget> map3DWidget;
QPointer<Q3DWidget> _3DWidget;
// Dock widgets
QPointer<QDockWidget> controlDockWidget;
QPointer<QDockWidget> infoDockWidget;
......
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@student.ethz.ch>
*
*/
#ifndef PIXHAWK3DWIDGET_H
#define PIXHAWK3DWIDGET_H
#include <osgText/Text>
#include "Q3DWidget.h"
class UASInterface;
/**
* @brief A 3D View widget which displays vehicle-centric information.
**/
class Pixhawk3DWidget : public Q3DWidget
{
Q_OBJECT
public:
explicit Pixhawk3DWidget(QWidget* parent = 0);
~Pixhawk3DWidget();
void buildLayout(void);
static void display(void* clientData);
void displayHandler(void);
static void mouse(Qt::MouseButton button, MouseState state,
int32_t x, int32_t y, void* clientData);
void mouseHandler(Qt::MouseButton button, MouseState state,
int32_t x, int32_t y);
static void timer(void* clientData);
void timerHandler(void);
double getTime(void) const;
public slots:
void setActiveUAS(UASInterface* uas);
void markTarget(void);
private slots:
void showGrid(int state);
void showTrail(int state);
void recenterCamera(void);
void toggleLockCamera(int state);
protected:
UASInterface* uas;
private:
osg::ref_ptr<osg::Geode> createGrid(void);
osg::ref_ptr<osg::Geode> createTrail(void);
osg::ref_ptr<osg::Group> createTarget(void);
osg::ref_ptr<osg::Group> createWaypoints(void);
void setupHUD(void);
void updateHUD(float robotX, float robotY, float robotZ,
float robotRoll, float robotPitch, float robotYaw);
void updateTrail(float robotX, float robotY, float robotZ);
void updateTarget(float robotX, float robotY, float robotZ);
void updateWaypoints(void);
double lastRedrawTime;
bool displayGrid;
bool displayTrail;
bool displayTarget;
bool displayWaypoints;
typedef struct
{
float x;
float y;
float z;
} Pose3D;
bool lockCamera;
osg::ref_ptr<osg::Vec3Array> trailVertices;
QVarLengthArray<osg::Vec3, 10000> trail;
osg::Vec3 targetPosition;
osg::ref_ptr<osg::Geometry> hudBackgroundGeometry;
osg::ref_ptr<osgText::Text> statusText;
osg::ref_ptr<osg::Geode> gridNode;
osg::ref_ptr<osg::Geode> trailNode;
osg::ref_ptr<osg::Geometry> trailGeometry;
osg::ref_ptr<osg::DrawArrays> trailDrawArrays;
osg::ref_ptr<osg::Group> targetNode;
osg::ref_ptr<osg::Group> waypointsNode;
};
#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 Generates a geode which renders a Pixhawk Cheetah MAV.
*
* @author Lionel Heng <hengli@student.ethz.ch>
*
*/
#ifndef PIXHAWKCHEETAHGEODE_H_
#define PIXHAWKCHEETAHGEODE_H_
#include <osg/Geode>
/**
* @brief Creates a geode 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 The pointer to the geode.
**/
class PixhawkCheetahGeode
{
public:
PixhawkCheetahGeode();
static osg::ref_ptr<osg::Geode> instance(void);
private:
static osg::ref_ptr<osg::Geode> create(float red, float green, float blue);
static osg::ref_ptr<osg::Geode> _instance;
};
#endif
This diff is collapsed.
......@@ -29,47 +29,14 @@ This file is part of the QGROUNDCONTROL project
*
*/
#ifndef Q3DWIDGET_H_
#define Q3DWIDGET_H_
#ifndef Q3DWIDGET_H
#define Q3DWIDGET_H
#include <inttypes.h>
#include <string>
#include <QtOpenGL>
#include <QtGui>
//class GLUquadricObj;
enum CameraState
{
IDLE = 0,
ROTATING = 1,
MOVING = 2,
ZOOMING = 3
};
struct CameraPose
{
CameraState state;
float pan, tilt, distance;
float xOffset, yOffset, zOffset;
float xOffset2D, yOffset2D, rotation2D, zoom, warpX, warpY;
};
struct CameraParams
{
float zoomSensitivity;
float rotateSensitivity;
float moveSensitivity;
float minZoomRange;
float cameraFov;
float minClipRange;
float maxClipRange;
float zoomSensitivity2D;
float rotateSensitivity2D;
float moveSensitivity2D;
};
#include <osg/LineSegment>
#include <osg/PositionAttitudeTransform>
#include <osgViewer/Viewer>
enum MouseState
{
......@@ -79,148 +46,113 @@ enum MouseState
typedef void (*DisplayFunc)(void *);
typedef void (*KeyboardFunc)(char, void *);
typedef void (*MouseFunc)(Qt::MouseButton, MouseState, int32_t, int32_t, void *);
typedef void (*MotionFunc)(int32_t, int32_t, void *);
typedef void (*MouseFunc)(Qt::MouseButton, MouseState, int, int, void *);
typedef void (*MotionFunc)(int, int, void *);
/**
* @brief A base 3D widget which executes OpenGL commands.
**/
class Q3DWidget: public QGLWidget
class Q3DWidget : public QGLWidget, public osgViewer::Viewer
{
Q_OBJECT
public:
explicit Q3DWidget(QWidget* parent);
~Q3DWidget();
Q3DWidget(QWidget* parent = 0);
virtual ~Q3DWidget();
void initialize(int32_t windowX, int32_t windowY,
int32_t windowWidth, int32_t windowHeight, float fps);
void setCameraParams(float zoomSensitivity, float rotateSensitivity,
float moveSensitivity, float minZoomRange,
float cameraFov, float minClipRange,
void init(float fps);
void setCameraParams(float minZoomRange, float cameraFov,
float minClipRange,
float maxClipRange);
void setCameraLimit(bool onoff);
void set2DCameraParams(float zoomSensitivity,
float rotateSensitivity,
float moveSensitivity);
void set3D(bool onoff);
bool is3D(void) const;
void setInitialCameraPos(float pan, float tilt, float range,
float xOffset, float yOffset, float zOffset);
void setInitial2DCameraPos(float xOffset, float yOffset,
float rotation, float zoom);
void setCameraPose(const CameraPose& cameraPose);
CameraPose getCameraPose(void) const;
void forceRedraw(void);
void recenter(void);
void setDisplayMode3D(void);
void setDisplayFunc(DisplayFunc func, void* clientData);
void setKeyboardFunc(KeyboardFunc func, void* clientData);
void setMouseFunc(MouseFunc func, void* clientData);
void setMotionFunc(MotionFunc func, void* clientData);
void addTimerFunc(uint32_t msecs, void(*func)(void *),
void addTimerFunc(uint msecs, void(*func)(void *),
void* clientData);
void forceRedraw(void);
void set2DWarping(float warpX, float warpY);
void recenter(void);
void recenter2D(void);
void set2DRotation(bool onoff);
void setDisplayMode2D(void);
std::pair<float,float> getGlobalCursorPosition(int32_t mouseX,
int32_t mouseY);
std::pair<float,float> getPositionIn3DMode(int32_t mouseX,
int32_t mouseY);
std::pair<float,float> getPositionIn2DMode(int32_t mouseX,
int32_t mouseY);
int32_t getWindowWidth(void);
int32_t getWindowHeight(void);
int32_t getLastMouseX(void);
int32_t getLastMouseY(void);
int32_t getMouseX(void);
int32_t getMouseY(void);
private Q_SLOTS:
protected slots:
void redraw(void);
void userTimer(void);
protected:
void rotateCamera(float dx, float dy);
void zoomCamera(float dy);
void moveCamera(float dx, float dy);
void rotateCamera2D(float dx);
void zoomCamera2D(float dx);
void moveCamera2D(float dx, float dy);
void switchTo3DMode(void);
void setDisplayMode3D(void);
float r2d(float angle) const;
float d2r(float angle) const;
void wireSphere(double radius, int slices, int stacks) const;
void solidSphere(double radius, int slices, int stacks) const;
void wireCone(double base, double height, int slices, int stacks) const;
void solidCone(double base, double height, int slices, int stacks) const;
void drawBox(float size, GLenum type) const;
void wireCube(double size) const;
void solidCube(double size) const;
void doughnut(float r, float R, int nsides, int rings) const;
void wireTorus(double innerRadius, double outerRadius,
int nsides, int rings) const;
void solidTorus(double innerRadius, double outerRadius,
int nsides, int rings) const;
GLUquadricObj* quadObj;
// QGLWidget events
void initializeGL(void);
void paintGL(void);
void resizeGL(int32_t width, int32_t height);
// Qt events
void keyPressEvent(QKeyEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent *wheel);
void timerEvent(QTimerEvent* event);
void closeEvent(QCloseEvent* event);
osg::ref_ptr<osg::Geode> createRobot(void);
osg::ref_ptr<osg::Node> createHUD(void);
int getMouseX(void);
int getMouseY(void);
int getLastMouseX(void);
int getLastMouseY(void);
osgViewer::GraphicsWindow* getGraphicsWindow(void);
const osgViewer::GraphicsWindow* getGraphicsWindow(void) const;
virtual void resizeGL(int width, int height);
virtual void paintGL(void);
virtual void keyPressEvent(QKeyEvent* event);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
virtual void mouseMoveEvent(QMouseEvent* event);
virtual void wheelEvent(QWheelEvent* event);
float r2d(float angle);
float d2r(float angle);
osgGA::GUIEventAdapter::KeySymbol convertKey(int key) const;
osg::ref_ptr<osg::LineSegment> projectNormalizedXYIntoObjectCoordinates(
const osg::Matrix& projectionMatrix,
const osg::Matrix& viewMatrix,
float x,
float y) const;
bool getPlaneLineIntersection(const osg::Vec4d& plane,
const osg::LineSegment& line,
osg::Vec3d& isect);
osg::ref_ptr<osg::Group> root;
osg::ref_ptr<osg::Switch> allocentricMap;
osg::ref_ptr<osg::Switch> rollingMap;
osg::ref_ptr<osg::Switch> egocentricMap;
osg::ref_ptr<osg::PositionAttitudeTransform> robotPosition;
osg::ref_ptr<osg::PositionAttitudeTransform> robotAttitude;
osg::ref_ptr<osg::Geode> hudGeode;
osg::ref_ptr<osg::Projection> hudProjectionMatrix;
DisplayFunc userDisplayFunc;
KeyboardFunc userKeyboardFunc;
MouseFunc userMouseFunc;
MotionFunc userMotionFunc;
void (*userTimerFunc)(void *);
void* userDisplayFuncData;
void* userKeyboardFuncData;
void* userMouseFuncData;
void* userMotionFuncData;
void* userTimerFuncData;
int32_t windowWidth, windowHeight;
float requestedFps;
CameraPose cameraPose;
int32_t lastMouseX, lastMouseY;
osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> osgGW;
bool _is3D;
QTimer timer;
bool _forceRedraw;
bool allow2DRotation;
bool limitCamera;
struct CameraParams
{
float minZoomRange;
float cameraFov;
float minClipRange;
float maxClipRange;
};
CameraParams cameraParams;
QBasicTimer timer;
int lastMouseX;
int lastMouseY;
void (*timerFunc)(void *);
void* timerFuncData;
bool _forceRedraw;
};
#endif
#endif // Q3DWIDGET_H
#include "Q3DWidgetFactory.h"
#include "Pixhawk3DWidget.h"
QPointer<Q3DWidget>
Q3DWidgetFactory::get(const std::string& type)
{
if (type == "PIXHAWK")
{
return QPointer<Q3DWidget>(new Pixhawk3DWidget);
}
else
{
return QPointer<Q3DWidget>(new Q3DWidget);
}
}
#ifndef Q3DWIDGETFACTORY_H
#define Q3DWIDGETFACTORY_H
#include <QPointer>
#include "Q3DWidget.h"
class Q3DWidgetFactory
{
public:
static QPointer<Q3DWidget> get(const std::string& type);
};
#endif // Q3DWIDGETFACTORY_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