Skip to content

Commit

Permalink
[py]add selected points in client for collection data
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-tz committed Oct 21, 2024
1 parent 5ab4ce5 commit 06fdea2
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 28 deletions.
105 changes: 99 additions & 6 deletions Client/src/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ int robotAmount;
int robotID[PARAM::ROBOTNUM];
int robotTeam;
auto originRobot = GlobalData::instance()->processRobot[0];
auto _G = GlobalData::instance();
}
namespace LeftEvent {
QPoint start;
Expand Down Expand Up @@ -191,6 +192,15 @@ Field::Field(QQuickItem *parent)
ZRecRecorder::instance()->init();
}

void Field::setType(int t){
this->_type = t;
// check if type in selected_points(type:map<int, vector<pair<int, int>>>)
std::scoped_lock lock(_G->selected_points_mutex);
if(_G->selected_points.find(t) == _G->selected_points.end()) {
_G->selected_points[t] = std::vector<std::pair<int, int>>();
}
}

void Field::paint(QPainter* painter) {
// painter->drawPixmap(area, *pixmap, QRect(zoomStart, ::size * zoomRatio));
painter->drawPixmap(area, *pixmap);
Expand Down Expand Up @@ -313,7 +323,6 @@ void Field::leftReleaseEvent(QMouseEvent *e) {
leftAltModifierReleaseEvent(e);
break;
}

}
void Field::leftCtrlModifierMoveEvent(QMouseEvent *e) {
auto x1 = ::rx(e->x());
Expand Down Expand Up @@ -387,7 +396,7 @@ void Field::leftAltModifierReleaseEvent(QMouseEvent *e) {
selectRobots = robotAmount > 0 ? true : false;
GlobalSettings::instance()->resetSelectCarArea();
}
void Field::rightMoveEvent(QMouseEvent *e) {
void Field::rightNoModifierMoveEvent(QMouseEvent *e) {
QLineF line(start, end);
if(pressedRobot) {
displayData = -line.angle();
Expand All @@ -400,15 +409,84 @@ void Field::rightMoveEvent(QMouseEvent *e) {
displayData = ballRatio * line.length() / 1000.0;
}
}
void Field::rightPressEvent(QMouseEvent *e) {

void Field::rightNoModifierPressEvent(QMouseEvent *e) {
}
void Field::rightReleaseEvent(QMouseEvent *e) {
void Field::rightNoModifierReleaseEvent(QMouseEvent *e) {
QLineF line(start, end);
if(!pressedRobot) {
Simulator::instance()->setBall(start.x() / 1000.0, start.y() / 1000.0, ballRatio * line.dx() / 1000.0, ballRatio * line.dy() / 1000.0);
}
}

void Field::rightMoveEvent(QMouseEvent *e){
switch(mouse_modifiers) {
case Qt::NoModifier:
rightNoModifierMoveEvent(e);
break;
case Qt::ControlModifier:
rightCtrlModifierMoveEvent(e);
break;
case Qt::AltModifier:
rightAltModifierMoveEvent(e);
break;
default:
break;
}
}
void Field::rightPressEvent(QMouseEvent *e){
switch(mouse_modifiers) {
case Qt::NoModifier:
rightNoModifierPressEvent(e);
break;
case Qt::ControlModifier:
rightCtrlModifierPressEvent(e);
break;
case Qt::AltModifier:
rightAltModifierPressEvent(e);
break;
default:
break;
}
}
void Field::rightReleaseEvent(QMouseEvent *e){
switch(mouse_modifiers) {
case Qt::NoModifier:
rightNoModifierReleaseEvent(e);
break;
case Qt::ControlModifier:
rightCtrlModifierReleaseEvent(e);
break;
case Qt::AltModifier:
rightAltModifierReleaseEvent(e);
break;
default:
break;
}
}
void Field::rightCtrlModifierMoveEvent(QMouseEvent *e){
}
void Field::rightCtrlModifierPressEvent(QMouseEvent *e){
}
void Field::rightCtrlModifierReleaseEvent(QMouseEvent *e){
std::scoped_lock lock(_G->selected_points_mutex);
if(_G->selected_points.find(_type) == _G->selected_points.end()) {
_G->selected_points[_type] = std::vector<std::pair<int, int>>();
}
auto pos = rp(e->pos());
_G->selected_points[_type].push_back(std::pair<int, int>(pos.x(), pos.y()));
}
void Field::rightAltModifierMoveEvent(QMouseEvent *e){
}
void Field::rightAltModifierPressEvent(QMouseEvent *e){
}
void Field::rightAltModifierReleaseEvent(QMouseEvent *e){
std::scoped_lock lock(_G->selected_points_mutex);
if(_G->selected_points.find(_type) == _G->selected_points.end()) {
_G->selected_points[_type] = std::vector<std::pair<int, int>>();
}
_G->selected_points[_type].clear();
}

void Field::middleMoveEvent(QMouseEvent *e) {
switch(mouse_modifiers) {
case Qt::NoModifier:
Expand Down Expand Up @@ -552,6 +630,7 @@ void Field::repaint() {//change here!!!!!!!
paintInit();
drawMaintainVision(0);
if (selectRobots) paintSelectedCar();
paintSelectedPoints();
drawDebugMessages(PARAM::BLUE); //BLUE
break;
case 3:
Expand All @@ -561,6 +640,7 @@ void Field::repaint() {//change here!!!!!!!
paintInit();
drawMaintainVision(0);
if (selectRobots) paintSelectedCar();
paintSelectedPoints();
drawDebugMessages(PARAM::YELLOW); //YELLOW
break;
default:
Expand All @@ -580,7 +660,7 @@ void Field::draw() {
repaint();
}
void Field::drawBallLine() {
if(pressed == Qt::RightButton) {
if(pressed == Qt::RightButton && mouse_modifiers == Qt::NoModifier) {
pixmapPainter.setBrush(QBrush(FONT_COLOR[0]));
pixmapPainter.setPen(QPen(FONT_COLOR[0], ::w(20), Qt::DashLine));
pixmapPainter.drawLine(p(start), p(end));
Expand Down Expand Up @@ -686,6 +766,19 @@ void Field::paintSelectedCar() {
pixmapPainter.drawChord(QRectF(::x(robot.pos.x() - radius), ::y(robot.pos.y() - radius), ::w(2 * radius), ::h(2 * radius)), ::a(90.0 - chordAngel + 180 / M_PI * robot.angle), ::r(180.0 + 2 * chordAngel));
}
}
void Field::paintSelectedPoints(){
pixmapPainter.setBrush(QBrush(COLOR_GREEN));
pixmapPainter.setPen(QPen(COLOR_GREEN, ::w(50)));
float size = 20;
std::scoped_lock lock(_G->selected_points_mutex);
if(_G->selected_points.find(_type) == _G->selected_points.end()) {
_G->selected_points[_type] = std::vector<std::pair<int, int>>();
}
auto points = _G->selected_points[_type];
for (auto& p : points) {
pixmapPainter.drawEllipse(QRectF(::x(p.first-size/2), ::y(p.second+size/2), ::w(size), ::h(-size)));
}
}
void Field::paintCarShadow(const QColor& color,qreal x, qreal y, qreal radian) {
static qreal radius = carDiameter / 2.0;
static qreal chordAngel = qRadiansToDegrees(qAcos(1.0 * carFaceWidth / carDiameter));
Expand Down
14 changes: 13 additions & 1 deletion Client/src/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QPainter>
#include <QPainterPath>
#include <QRectF>
#include <QVector>
#include <QMutex>
#include "messageformat.h"
#include "staticparams.h"
Expand All @@ -17,7 +18,7 @@ class Field : public QQuickPaintedItem{
void paint(QPainter* painter) override;
Field(QQuickItem *parent = 0);
inline int type() { return this->_type; }
inline void setType(int t) { this->_type = t; }
void setType(int t);
inline bool ifDraw() { return this->_draw; }
inline void setDraw(bool t) { this->_draw = t; }
void mouseMoveEvent(QMouseEvent *event) override;
Expand Down Expand Up @@ -47,6 +48,7 @@ private slots:
void paintCar(const QColor& color,quint8 num,qreal x,qreal y,qreal radian
,bool ifDrawNum = true,const QColor& textColor = Qt::white,bool needCircle = false);
void paintSelectedCar();
void paintSelectedPoints();
void paintCarShadow(const QColor& color,qreal x, qreal y, qreal radian);
void paintBall(const QColor& color,qreal x,qreal y);
void paintShadow(const QColor& color,qreal x,qreal y);
Expand All @@ -66,6 +68,15 @@ private slots:
void rightMoveEvent(QMouseEvent *);
void rightPressEvent(QMouseEvent *);
void rightReleaseEvent(QMouseEvent *);
void rightCtrlModifierMoveEvent(QMouseEvent *);
void rightCtrlModifierPressEvent(QMouseEvent *);
void rightCtrlModifierReleaseEvent(QMouseEvent *);
void rightAltModifierMoveEvent(QMouseEvent *);
void rightAltModifierPressEvent(QMouseEvent *);
void rightAltModifierReleaseEvent(QMouseEvent *);
void rightNoModifierMoveEvent(QMouseEvent *);
void rightNoModifierPressEvent(QMouseEvent *);
void rightNoModifierReleaseEvent(QMouseEvent *);
void middleMoveEvent(QMouseEvent *);
void middlePressEvent(QMouseEvent *);
void middleReleaseEvent(QMouseEvent *);
Expand All @@ -86,6 +97,7 @@ private slots:
int _type;
bool _draw;

// QVector<QPointF> selected_points;
private:
int pressed;
bool pressedRobot;
Expand Down
10 changes: 6 additions & 4 deletions Client/src/globaldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "messageformat.h"
#include "ballrecords.h"
#include "zss_cmd.pb.h"
#include <QMutex>
#include <mutex>
struct RobotInformation {
bool infrared;
bool flat;
Expand Down Expand Up @@ -41,7 +41,7 @@ class CGlobalData {
int cameraID[PARAM::CAMERA];//show the mapping of cameras id
double robotPossible[2][PARAM::ROBOTMAXID];
RobotInformation robotInformation[PARAM::TEAMS][PARAM::ROBOTMAXID];
QMutex robotInfoMutex;
std::mutex robotInfoMutex;
DataQueue<RobotCommands> robotCommand[PARAM::TEAMS];
int commandMissingFrame[PARAM::TEAMS];//team command VALID --> commandMissingFrame<20
CameraFix cameraFixMatrix[PARAM::CAMERA];
Expand All @@ -54,12 +54,14 @@ class CGlobalData {
int lastTouch;//Be attention it's id!!!
QByteArray debugBlueMessages;
QByteArray debugYellowMessages;
QMutex debugMutex;// debugMessages;
std::mutex debugMutex;// debugMessages;
bool ctrlC;
QMutex ctrlCMutex;
std::mutex ctrlCMutex;

void CameraInit();

std::mutex selected_points_mutex;
std::map<int, std::vector<std::pair<int, int>>> selected_points;
private:
CGeoPoint saoConvert(CGeoPoint);
void saoConvertEdge();
Expand Down
10 changes: 10 additions & 0 deletions Client/src/vision/visionmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ void CVisionModule::udpSend() {
robot->set_raw_rotate_vel(result.robot[team][i].rawRotateVel);
}
}
auto selected_points = GlobalData::instance()->selected_points;
for (auto& it : selected_points) {
auto selected_points_proto = detectionFrame.add_selected_points();
selected_points_proto->set_id(it.first);
for (auto& xy: it.second) {
selected_points_proto->add_x(xy.first);
selected_points_proto->add_y(xy.second);
}
}
int size = detectionFrame.ByteSizeLong();
QByteArray buffer(size, 0);
detectionFrame.SerializeToArray(buffer.data(), buffer.size());
Expand All @@ -327,6 +336,7 @@ void CVisionModule::udpSend() {
}
detectionFrame.clear_robots_blue();
detectionFrame.clear_robots_yellow();
detectionFrame.clear_selected_points();
}

/**
Expand Down
Loading

0 comments on commit 06fdea2

Please sign in to comment.