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