Skip to content
Snippets Groups Projects
Commit 88886143 authored by Joel Vongehr's avatar Joel Vongehr
Browse files

QImage hates me and I hate QImage

parent f25e4a59
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@
#include <QPaintEvent>
#include <QTimer>
#include <QVector>
#include <turtlesim_xl/img.h>
// This prevents a MOC error with versions of boost >= 1.48
#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
......@@ -59,8 +60,7 @@ public:
std::string spawnTurtle(const std::string& name, float x, float y, float angle);
std::string spawnTurtle(const std::string& name, float x, float y, float angle, size_t index);
void setShape(std::string shape);
void drawShape();
void drawImage(turtlesim_xl::img img);
protected:
void paintEvent(QPaintEvent* event);
......@@ -102,8 +102,6 @@ private:
float meter_;
float width_in_meters_;
float height_in_meters_;
std::string shape;
};
}
int64 x
int64 y
# uint64[] img
string imgPath
\ No newline at end of file
uint8[] img
# string imgPath
\ No newline at end of file
......@@ -28,6 +28,7 @@
*/
#include "turtlesim/turtle_frame.h"
#include <turtlesim_xl/img.h>
#include <QPointF>
......@@ -294,28 +295,50 @@ bool TurtleFrame::resetCallback(std_srvs::Empty::Request&, std_srvs::Empty::Resp
return true;
}
void TurtleFrame::drawShape() {
path_painter_.setPen(QColor(0xff,0xff,0xff));
int xTurtleStart = 12*meter_;
int yTurtleStart = FRAME_HEIGHT - 7*meter_;
if(shape == "triangle") {
int xTopRight = xTurtleStart;
int xTopLeft = xTopRight/2;
int xBottom = (xTopLeft + xTopRight) / 2;
void TurtleFrame::drawImage(turtlesim_xl::img imgData) {
QPointF point;
int yTop = yTurtleStart;
int yBottom = yTop + 5*meter_;
point.setX(130);
point.setY(140);
path_painter_.drawLine(xTopLeft, yTop, xTopRight, yTop);
path_painter_.drawLine(xTopLeft, yTop, xBottom, yBottom);
path_painter_.drawLine(xBottom, yBottom, xTopRight, yTop);
}else {
path_painter_.drawRect((12-5)*meter_,FRAME_HEIGHT-(7-5)*meter_,5*meter_,-5*meter_);
}
// const uint8_t *rawImg = imgData.img.data();
std::vector<uint8_t> rawImg;
for(uint8_t nr : imgData.img) {
rawImg.push_back(nr);
}
void TurtleFrame::setShape(std::string shape) {
this->shape = shape;
const char *c = reinterpret_cast<const char *>(rawImg.data());
QByteArray byAr = QByteArray(c);
// for(uint8_t nr : imgData.img) {
// // byAr.append(nr);
// // char byte = nr;
// // byAr.append(byte);
// // QByteArray tmp = QByteArray::fromRawData(&byte, sizeof(nr));
// // byAr += tmp;
// const char *c = reinterpret_cast<const char *>(&nr);
// byAr.append(c);
// if(i % 250 == 0 && nr != 0) {
// ROS_INFO("img data: %d; char: %d; QByte: %d", nr, c, byAr.at(i));
// }
// }
ROS_INFO("Img Count: %d; QByte Count: %d", imgData.img.size() , byAr.size());
QImage img;
img.loadFromData(byAr);
ROS_INFO("Draw msg img at: x = %d; y = %d", 130, 140);
path_painter_.drawImage(point, img);
// ROS_INFO("Draw loaded img at: x = %d; y = %d", 230, 240);
// point.setX(230);
// point.setY(240);
// img.load("/home/tsu/catkin_ws/src/turtleswarm/images/test.png");
// path_painter_.drawImage(point, img);
}
}
......@@ -36,7 +36,6 @@
class TurtleApp : public QApplication
{
turtlesim_xl::img shapeData;
ros::Subscriber shapeSub;
turtlesim::TurtleFrame* frame;
public:
......@@ -57,9 +56,6 @@ public:
int exec(std::string shape = "rectangle")
{
frame->setShape(shape);
ROS_INFO("Offset before calling draw: x = %d; y = %d", shapeData.x, shapeData.y);
frame->drawShape();
frame->show();
return QApplication::exec();
......@@ -67,10 +63,8 @@ public:
private:
void updateShape(turtlesim_xl::img data) {
shapeData = data;
ROS_INFO("NEW SHAPE DATA SAVED");
frame->setShape("triangle");
frame->drawShape();
frame->drawImage(data);
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment