Commit 1b650fe3 authored by roangel's avatar roangel
Browse files

Does not compile. Want to construct marker object from message unlabeled...

Does not compile. Want to construct marker object from message unlabeled marker, and CF Object from message CF
parent 6712db3e
......@@ -10,8 +10,6 @@
#ifdef CATKIN_MAKE
#include "rosNodeThread.h"
#include "d_fall_pps/UnlabeledMarker.h"
#include "d_fall_pps/UnlabeledMarkersArray.h"
#endif
#include "ui_mainguiwindow.h"
......@@ -100,7 +98,7 @@ private slots:
void on_checkBox_vicon_highlight_markers_toggled(bool checked);
#ifdef CATKIN_MAKE
void setPosMarkers(const ptrToMessage& p_msg);
void updateNewViconData(const ptrToMessage& p_msg);
#endif
private:
......@@ -109,8 +107,7 @@ private:
void _init();
std::vector<Marker*> markers_vector;
crazyFly* crazyFly_1;
std::vector<crazyFly*> crazyflies_vector;
#ifdef CATKIN_MAKE
rosNodeThread* _rosNodeThread;
......
......@@ -5,6 +5,15 @@
#include <QGraphicsEllipseItem>
#ifdef CATKIN_MAKE
#include "d_fall_pps/UnlabeledMarker.h"
#endif
#ifdef CATKIN_MAKE
using namespace d_fall_pps;
#endif
#define MARKER_DIAMETER 20 * FROM_MILIMETERS_TO_UNITS
#define HIGHLIGHT_DIAMETER 20
......@@ -14,7 +23,7 @@
class Marker : public QGraphicsEllipseItem
{
public:
explicit Marker(QPointF p, QGraphicsItem *parent = 0);
explicit Marker(const UnlabeledMarker::ConstPtr& marker_msg, QGraphicsItem *parent = 0);
~Marker();
void setHighlighted(void);
......@@ -23,13 +32,17 @@ public:
bool getHighlighted(void);
void setPosMarker(QPointF new_p);
void updateMarker(const UnlabeledMarker::ConstPtr& marker_msg);
private:
// info to fill by message
qreal m_x;
qreal m_y;
qreal m_z;
// properties of marker itself
qreal _diameter;
qreal _x; // coordinates of top-left corner of marker
qreal _y;
qreal _center_x; // coordinates of center of marker
qreal _center_y;
......
......@@ -11,6 +11,10 @@
#include <QMetaType>
#include <QDir>
#ifdef CATKIN_MAKE
#include "d_fall_pps/UnlabeledMarker.h"
#endif
#include <string>
#define N_MAX_CRAZYFLIES 20 // protection number
......@@ -69,8 +73,6 @@ void MainGUIWindow::_init()
scene->setSceneRect(-100 * FROM_METERS_TO_UNITS, -100 * FROM_METERS_TO_UNITS, 200 * FROM_METERS_TO_UNITS, 200 * FROM_METERS_TO_UNITS);
ui->graphicsView->setScene(scene);
crazyFly_1 = new crazyFly(QPointF(50,50));
scene->addItem(crazyFly_1);
QObject::connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)), scene, SLOT(removeCrazyFlyZone(int)));
QObject::connect(scene, SIGNAL(numCrazyFlyZonesChanged(int)), this, SLOT(set_tabs(int)));
......@@ -84,14 +86,16 @@ void MainGUIWindow::_init()
#ifdef CATKIN_MAKE
_rosNodeThread->init();
qRegisterMetaType<ptrToMessage>("ptrToMessage");
QObject::connect(_rosNodeThread, SIGNAL(newViconData(const ptrToMessage&)), this, SLOT(setPosMarkers(const ptrToMessage&)));
QObject::connect(_rosNodeThread, SIGNAL(newViconData(const ptrToMessage&)), this, SLOT(updateNewViconData(const ptrToMessage&)));
#endif
}
#ifdef CATKIN_MAKE
void MainGUIWindow::setPosMarkers(const ptrToMessage& p_msg) //connected to newViconData, from node
void MainGUIWindow::updateNewViconData(const ptrToMessage& p_msg) //connected to newViconData, from node
{
// update Markers
if(p_msg->markers.size() < markers_vector.size()) // some markers have dissapeared, received stuff is smaller than what we have
{
for(int i = p_msg->markers.size(); i < markers_vector.size(); i++)
......@@ -110,10 +114,10 @@ void MainGUIWindow::setPosMarkers(const ptrToMessage& p_msg) //connected to newV
{
ROS_INFO_STREAM("element index: " << i << " added");
QPointF p(p_msg->markers[i].x * FROM_MILIMETERS_TO_UNITS, p_msg->markers[i].y * FROM_MILIMETERS_TO_UNITS);
Marker* tmp_p_marker = new Marker(scene->mapFromWorldToScene(p));
Marker* tmp_p_marker = new Marker(&(p_msg->markers[i]));
markers_vector.push_back(tmp_p_marker); // what happens with the new indexes? check if this is correct
if(ui->checkBox_vicon_markers->checkState() == Qt::Checked) //only if markers checkbox info is checked..
if(ui->checkBox_vicon_markers->checkState() == Qt::Checked) //only if markers checkbox info is checked..
{
scene->addItem(markers_vector[i]);
if(ui->checkBox_vicon_highlight_markers->checkState() == Qt::Checked)
......@@ -125,9 +129,16 @@ void MainGUIWindow::setPosMarkers(const ptrToMessage& p_msg) //connected to newV
else
{
ROS_INFO_STREAM("element index: " << i << " moved, already existed");
markers_vector[i]->setPosMarker(scene->mapFromWorldToScene(QPointF(p_msg->markers[i].x * FROM_MILIMETERS_TO_UNITS, p_msg->markers[i].y * FROM_MILIMETERS_TO_UNITS)));
markers_vector[i]->updateMarker(&(p_msg->markers[i]));
}
}
// update Crazyflies
// TODO: create a vector of pointers to CFs with all the info inside. Update this vector with new coming data
// To access this vector by name, we should maybe create a second array of strings (names), that are located at the
// same position as the information of CFs is
}
#endif
......
......@@ -4,35 +4,36 @@
#include <QBrush>
Marker::Marker(QPointF p, QGraphicsItem * parent)
Marker::Marker(const UnlabeledMarker::ConstPtr& marker_msg, QGraphicsItem * parent)
: QGraphicsEllipseItem(-MARKER_DIAMETER/2, - MARKER_DIAMETER/2, MARKER_DIAMETER, MARKER_DIAMETER, parent)
{
updateMarker(marker_msg);
_highlighted = false;
_highlight_diameter = HIGHLIGHT_DIAMETER;
// save original x and y
_center_x = p.x();
_center_y = p.y();
QPointF p(m_x, m_y);
_diameter = MARKER_DIAMETER; // x and y are top left coordinates
this->setPos(_center_x, _center_y); //where it is now, it is the center
this->setPos(m_x, m_y); //where it is now, it is the center
_x_highlight = _center_x - _highlight_diameter/2; // update top-left corner coordinates of highlighing circle
_y_highlight = _center_y - _highlight_diameter/2;
_x_highlight = m_x - _highlight_diameter/2; // update top-left corner coordinates of highlighing circle
_y_highlight = m_y - _highlight_diameter/2;
this->setPen(Qt::NoPen);
this->setBrush(QColor(255, 0, 0));
this->setZValue(10); // max z value, should always be seen
}
void Marker::setPosMarker(QPointF new_p)
void Marker::updateMarker(const UnlabeledMarker::ConstPtr& marker_msg)
{
prepareGeometryChange();
this->setPos(_center_x, _center_y);
_center_x = new_p.x(); // update center coordinates
_center_y = new_p.y();
m_x = marker_msg->x;
m_y = marker_msg->y;
m_z = marker_msg->z;
this->setPos(m_x * FROM_MILIMETERS_TO_UNITS, -m_y * FROM_MILIMETERS_TO_UNITS); // - y because of coordinates
}
void Marker::setHighlighted(void)
{
if(!_highlighted)
......
Supports Markdown
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