Commit eeda94f3 authored by Lorenz Meier's avatar Lorenz Meier

Fixed HUD / Video widget to be useful

parent efd916af
...@@ -2026,15 +2026,13 @@ QImage UAS::getImage() ...@@ -2026,15 +2026,13 @@ QImage UAS::getImage()
// RAW greyscale // RAW greyscale
if (imageType == MAVLINK_DATA_STREAM_IMG_RAW8U) if (imageType == MAVLINK_DATA_STREAM_IMG_RAW8U)
{ {
// TODO FIXME int imgColors = 255;
int imgColors = 255;//imageSize/(imageWidth*imageHeight);
//const int headerSize = 15;
// Construct PGM header // Construct PGM header
QString header("P5\n%1 %2\n%3\n"); QString header("P5\n%1 %2\n%3\n");
header = header.arg(imageWidth).arg(imageHeight).arg(imgColors); header = header.arg(imageWidth).arg(imageHeight).arg(imgColors);
QByteArray tmpImage(header.toStdString().c_str(), header.toStdString().size()); QByteArray tmpImage(header.toStdString().c_str(), header.toStdString().size() - 1);
tmpImage.append(imageRecBuffer); tmpImage.append(imageRecBuffer);
//qDebug() << "IMAGE SIZE:" << tmpImage.size() << "HEADER SIZE: (15):" << header.size() << "HEADER: " << header; //qDebug() << "IMAGE SIZE:" << tmpImage.size() << "HEADER SIZE: (15):" << header.size() << "HEADER: " << header;
...@@ -2047,7 +2045,7 @@ QImage UAS::getImage() ...@@ -2047,7 +2045,7 @@ QImage UAS::getImage()
if (!image.loadFromData(tmpImage, "PGM")) if (!image.loadFromData(tmpImage, "PGM"))
{ {
qDebug()<< "could not create extracted image"; qDebug()<< __FILE__ << __LINE__ << "could not create extracted image";
return QImage(); return QImage();
} }
...@@ -2060,7 +2058,7 @@ QImage UAS::getImage() ...@@ -2060,7 +2058,7 @@ QImage UAS::getImage()
{ {
if (!image.loadFromData(imageRecBuffer)) if (!image.loadFromData(imageRecBuffer))
{ {
qDebug() << "Loading data from image buffer failed!"; qDebug() << __FILE__ << __LINE__ << "Loading data from image buffer failed!";
} }
} }
// Restart statemachine // Restart statemachine
......
...@@ -34,6 +34,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -34,6 +34,7 @@ This file is part of the QGROUNDCONTROL project
#include <QMenu> #include <QMenu>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFileDialog> #include <QFileDialog>
#include <QPaintEvent>
#include <QDebug> #include <QDebug>
#include <cmath> #include <cmath>
...@@ -43,14 +44,8 @@ This file is part of the QGROUNDCONTROL project ...@@ -43,14 +44,8 @@ This file is part of the QGROUNDCONTROL project
#include "UASManager.h" #include "UASManager.h"
#include "UAS.h" #include "UAS.h"
#include "HUD.h" #include "HUD.h"
#include "MG.h"
#include "QGC.h" #include "QGC.h"
// Fix for some platforms, e.g. windows
#ifndef GL_MULTISAMPLE
#define GL_MULTISAMPLE 0x809D
#endif
/** /**
* @warning The HUD widget will not start painting its content automatically * @warning The HUD widget will not start painting its content automatically
* to update the view, start the auto-update by calling HUD::start(). * to update the view, start the auto-update by calling HUD::start().
...@@ -60,7 +55,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -60,7 +55,7 @@ This file is part of the QGROUNDCONTROL project
* @param parent * @param parent
*/ */
HUD::HUD(int width, int height, QWidget* parent) HUD::HUD(int width, int height, QWidget* parent)
: QWidget(parent), : QLabel(parent),
uas(NULL), uas(NULL),
yawInt(0.0f), yawInt(0.0f),
mode(tr("UNKNOWN MODE")), mode(tr("UNKNOWN MODE")),
...@@ -119,22 +114,14 @@ HUD::HUD(int width, int height, QWidget* parent) ...@@ -119,22 +114,14 @@ HUD::HUD(int width, int height, QWidget* parent)
load(0.0f), load(0.0f),
offlineDirectory(""), offlineDirectory(""),
nextOfflineImage(""), nextOfflineImage(""),
HUDInstrumentsEnabled(true), HUDInstrumentsEnabled(false),
videoEnabled(true), videoEnabled(true),
xImageFactor(1.0), xImageFactor(1.0),
yImageFactor(1.0), yImageFactor(1.0),
imageRequested(false), imageRequested(false),
imageLoggingEnabled(false) imageLoggingEnabled(false),
image(NULL)
{ {
// Set auto fill to false
setAutoFillBackground(false);
// Set minimum size
setMinimumSize(80, 60);
// Set preferred size
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
scalingFactor = this->width()/vwidth;
// Fill with black background // Fill with black background
QImage fill = QImage(width, height, QImage::Format_Indexed8); QImage fill = QImage(width, height, QImage::Format_Indexed8);
fill.setNumColors(3); fill.setNumColors(3);
...@@ -142,27 +129,23 @@ HUD::HUD(int width, int height, QWidget* parent) ...@@ -142,27 +129,23 @@ HUD::HUD(int width, int height, QWidget* parent)
fill.setColor(1, qRgb(0, 0, 0)); fill.setColor(1, qRgb(0, 0, 0));
fill.setColor(2, qRgb(0, 0, 0)); fill.setColor(2, qRgb(0, 0, 0));
fill.fill(0); fill.fill(0);
glImage = fill;
//QString imagePath = "/Users/user/Desktop/frame0000.png"; // Set auto fill to false
//qDebug() << __FILE__ << __LINE__ << "template image:" << imagePath; setAutoFillBackground(false);
//fill = QImage(imagePath);
glImage = fill; // Set minimum size
setMinimumSize(80, 60);
// Set preferred size
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
scalingFactor = this->width()/vwidth;
// Refresh timer // Refresh timer
refreshTimer->setInterval(updateInterval); refreshTimer->setInterval(updateInterval);
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(paintHUD())); connect(refreshTimer, SIGNAL(timeout()), this, SLOT(repaint()));
// Resize to correct size and fill with image // Resize to correct size and fill with image
QWidget::resize(this->width(), this->height()); QWidget::resize(this->width(), this->height());
//glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits());
// Set size once
//setFixedSize(fill.size());
//setMinimumSize(fill.size());
//setMaximumSize(fill.size());
// Lock down the size
//setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
fontDatabase = QFontDatabase(); fontDatabase = QFontDatabase();
const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app
...@@ -502,10 +485,8 @@ void HUD::paintRollPitchStrips() ...@@ -502,10 +485,8 @@ void HUD::paintRollPitchStrips()
void HUD::paintEvent(QPaintEvent *event) void HUD::paintEvent(QPaintEvent *event)
{ {
// Event is not needed
// the event is ignored as this widget paintHUD();
// is refreshed automatically
Q_UNUSED(event);
} }
void HUD::paintHUD() void HUD::paintHUD()
...@@ -586,6 +567,13 @@ void HUD::paintHUD() ...@@ -586,6 +567,13 @@ void HUD::paintHUD()
} }
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
QPixmap pmap = QPixmap::fromImage(glImage).scaledToWidth(width());
painter.drawPixmap(0, (height() - pmap.height()) / 2, pmap);
// END OF OPENGL PAINTING // END OF OPENGL PAINTING
if (HUDInstrumentsEnabled) { if (HUDInstrumentsEnabled) {
...@@ -594,10 +582,7 @@ void HUD::paintHUD() ...@@ -594,10 +582,7 @@ void HUD::paintHUD()
// QT PAINTING // QT PAINTING
//makeCurrent(); //makeCurrent();
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
painter.translate((this->vwidth/2.0+xCenterOffset)*scalingFactor, (this->vheight/2.0+yCenterOffset)*scalingFactor); painter.translate((this->vwidth/2.0+xCenterOffset)*scalingFactor, (this->vheight/2.0+yCenterOffset)*scalingFactor);
// COORDINATE FRAME IS NOW (0,0) at CENTER OF WIDGET // COORDINATE FRAME IS NOW (0,0) at CENTER OF WIDGET
...@@ -759,13 +744,12 @@ void HUD::paintHUD() ...@@ -759,13 +744,12 @@ void HUD::paintHUD()
painter.rotate(-(att.x()/M_PI)* -180.0f); painter.rotate(-(att.x()/M_PI)* -180.0f);
} }
painter.end();
} else {
QPainter painter;
painter.begin(this);
painter.end();
} }
painter.end();
} }
} }
...@@ -1200,7 +1184,8 @@ void HUD::setImageSize(int width, int height, int depth, int channels) ...@@ -1200,7 +1184,8 @@ void HUD::setImageSize(int width, int height, int depth, int channels)
rawBuffer1 = (unsigned char*)malloc(rawExpectedBytes); rawBuffer1 = (unsigned char*)malloc(rawExpectedBytes);
rawBuffer2 = (unsigned char*)malloc(rawExpectedBytes); rawBuffer2 = (unsigned char*)malloc(rawExpectedBytes);
rawImage = rawBuffer1; rawImage = rawBuffer1;
// TODO check if old image should be deleted if (image)
delete image;
// Set image format // Set image format
// 8 BIT GREYSCALE IMAGE // 8 BIT GREYSCALE IMAGE
...@@ -1367,20 +1352,16 @@ void HUD::setPixels(int imgid, const unsigned char* imageData, int length, int s ...@@ -1367,20 +1352,16 @@ void HUD::setPixels(int imgid, const unsigned char* imageData, int length, int s
void HUD::copyImage() void HUD::copyImage()
{ {
if (isVisible() && HUDInstrumentsEnabled) UAS* u = dynamic_cast<UAS*>(this->uas);
if (u)
{ {
//qDebug() << "HUD::copyImage()"; this->glImage = u->getImage();
UAS* u = dynamic_cast<UAS*>(this->uas);
if (u)
{
this->glImage = u->getImage();
// Save to directory if logging is enabled // Save to directory if logging is enabled
if (imageLoggingEnabled) if (imageLoggingEnabled)
{ {
u->getImage().save(QString("%1/%2.png").arg(imageLogDirectory).arg(imageLogCounter)); u->getImage().save(QString("%1/%2.png").arg(imageLogDirectory).arg(imageLogCounter));
imageLogCounter++; imageLogCounter++;
}
} }
} }
} }
......
...@@ -34,6 +34,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -34,6 +34,7 @@ This file is part of the QGROUNDCONTROL project
#include <QImage> #include <QImage>
#include <QWidget> #include <QWidget>
#include <QLabel>
#include <QPainter> #include <QPainter>
#include <QFontDatabase> #include <QFontDatabase>
#include <QTimer> #include <QTimer>
...@@ -47,7 +48,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -47,7 +48,7 @@ This file is part of the QGROUNDCONTROL project
* It can superimpose the HUD over the current live image stream (any arriving image stream will be auto- * It can superimpose the HUD over the current live image stream (any arriving image stream will be auto-
* matically used as background), or it draws the classic blue-brown background known from instruments. * matically used as background), or it draws the classic blue-brown background known from instruments.
*/ */
class HUD : public QWidget class HUD : public QLabel
{ {
Q_OBJECT Q_OBJECT
public: public:
...@@ -139,7 +140,7 @@ protected: ...@@ -139,7 +140,7 @@ protected:
void contextMenuEvent (QContextMenuEvent* event); void contextMenuEvent (QContextMenuEvent* event);
void createActions(); void createActions();
static const int updateInterval = 40; static const int updateInterval = 100;
QImage* image; ///< Double buffer image QImage* image; ///< Double buffer image
QImage glImage; ///< The background / camera image QImage glImage; ///< The background / camera image
......
...@@ -17,8 +17,9 @@ MAVLinkDecoder::MAVLinkDecoder(MAVLinkProtocol* protocol, QObject *parent) : ...@@ -17,8 +17,9 @@ MAVLinkDecoder::MAVLinkDecoder(MAVLinkProtocol* protocol, QObject *parent) :
} }
// Fill filter // Fill filter
messageFilter.insert(MAVLINK_MSG_ID_HEARTBEAT, false); // Allow system status
messageFilter.insert(MAVLINK_MSG_ID_SYS_STATUS, false); // messageFilter.insert(MAVLINK_MSG_ID_HEARTBEAT, false);
// messageFilter.insert(MAVLINK_MSG_ID_SYS_STATUS, false);
messageFilter.insert(MAVLINK_MSG_ID_STATUSTEXT, false); messageFilter.insert(MAVLINK_MSG_ID_STATUSTEXT, false);
messageFilter.insert(MAVLINK_MSG_ID_COMMAND_LONG, false); messageFilter.insert(MAVLINK_MSG_ID_COMMAND_LONG, false);
messageFilter.insert(MAVLINK_MSG_ID_COMMAND_ACK, false); messageFilter.insert(MAVLINK_MSG_ID_COMMAND_ACK, false);
...@@ -200,7 +201,7 @@ void MAVLinkDecoder::emitFieldValue(mavlink_message_t* msg, int fieldid, quint64 ...@@ -200,7 +201,7 @@ void MAVLinkDecoder::emitFieldValue(mavlink_message_t* msg, int fieldid, quint64
// Add field tree widget item // Add field tree widget item
uint8_t msgid = msg->msgid; uint8_t msgid = msg->msgid;
//if (messageFilter.contains(msgid)) return; if (messageFilter.contains(msgid)) return;
QString fieldName(messageInfo[msgid].fields[fieldid].name); QString fieldName(messageInfo[msgid].fields[fieldid].name);
QString fieldType; QString fieldType;
uint8_t* m = ((uint8_t*)(receivedMessages+msgid))+8; uint8_t* m = ((uint8_t*)(receivedMessages+msgid))+8;
......
...@@ -466,11 +466,7 @@ void MainWindow::buildCommonWidgets() ...@@ -466,11 +466,7 @@ void MainWindow::buildCommonWidgets()
{ {
pilotView = new SubMainWindow(this); pilotView = new SubMainWindow(this);
pilotView->setObjectName("VIEW_FLIGHT"); pilotView->setObjectName("VIEW_FLIGHT");
//pilotView->setCentralWidget(new HUD(320,240,this));
pilotView->setCentralWidget(new QGCMapTool(this)); pilotView->setCentralWidget(new QGCMapTool(this));
//hudWidget = new HUD(320, 240, this);
//addCentralWidget(hudWidget, tr("Head Up Display"));
//mapWidget = new QGCMapTool(this);
addCentralWidget(pilotView, "Pilot"); addCentralWidget(pilotView, "Pilot");
} }
if (!configView) if (!configView)
...@@ -591,18 +587,9 @@ void MainWindow::buildCommonWidgets() ...@@ -591,18 +587,9 @@ void MainWindow::buildCommonWidgets()
connect(tempAction,SIGNAL(triggered(bool)),this, SLOT(showTool(bool))); connect(tempAction,SIGNAL(triggered(bool)),this, SLOT(showTool(bool)));
} }
// createDockWidget(simView,new HUD(320,240,this),tr("Head Up Display"),"HEAD_UP_DISPLAY_DOCKWIDGET",VIEW_SIMULATION,Qt::RightDockWidgetArea,this->width()/1.5); createDockWidget(engineeringView,new HUD(320,240,this),tr("Video Downlink"),"HEAD_UP_DISPLAY_DOCKWIDGET",VIEW_ENGINEER,Qt::RightDockWidgetArea,this->width()/1.5);
createDockWidget(simView,new PrimaryFlightDisplay(320,240,this),tr("Primary Flight Display"),"PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET",VIEW_SIMULATION,Qt::RightDockWidgetArea,this->width()/1.5); createDockWidget(simView,new PrimaryFlightDisplay(320,240,this),tr("Primary Flight Display"),"PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET",VIEW_SIMULATION,Qt::RightDockWidgetArea,this->width()/1.5);
//createDockWidget(pilotView,new UASListWidget(this),tr("Unmanned Systems"),"UNMANNED_SYSTEM_LIST_DOCKWIDGET",VIEW_FLIGHT,Qt::RightDockWidgetArea);
// createDockWidget(pilotView,new HUD(320,240,this),tr("Head Up Display"),"HEAD_UP_DISPLAY_DOCKWIDGET",VIEW_FLIGHT,Qt::LeftDockWidgetArea,this->width()/1.8);
//createDockWidget(pilotView,new UASQuickView(this),tr("Quick View"),"UAS_INFO_QUICKVIEW_DOCKWIDGET",VIEW_FLIGHT,Qt::LeftDockWidgetArea);
//UASQuickView *quickview = new UASQuickView(this);
//quickview->addSource(mavlinkDecoder);
//createDockWidget(pilotView,quickview,tr("Quick View"),"UAS_INFO_QUICKVIEW_DOCKWIDGET",VIEW_FLIGHT,Qt::LeftDockWidgetArea);
createDockWidget(pilotView,new PrimaryFlightDisplay(320,240,this),tr("Primary Flight Display"),"PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET",VIEW_FLIGHT,Qt::LeftDockWidgetArea,this->width()/1.8); createDockWidget(pilotView,new PrimaryFlightDisplay(320,240,this),tr("Primary Flight Display"),"PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET",VIEW_FLIGHT,Qt::LeftDockWidgetArea,this->width()/1.8);
QGCTabbedInfoView *infoview = new QGCTabbedInfoView(this); QGCTabbedInfoView *infoview = new QGCTabbedInfoView(this);
......
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