Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
turtlesim_xl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
w2v
turtlesim_xl
Commits
88886143
Commit
88886143
authored
Sep 2, 2021
by
Joel Vongehr
Browse files
Options
Downloads
Patches
Plain Diff
QImage hates me and I hate QImage
parent
f25e4a59
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/turtlesim/turtle_frame.h
+2
-4
2 additions, 4 deletions
include/turtlesim/turtle_frame.h
msg/img.msg
+2
-2
2 additions, 2 deletions
msg/img.msg
src/turtle_frame.cpp
+43
-20
43 additions, 20 deletions
src/turtle_frame.cpp
src/turtlesim_xl.cpp
+1
-7
1 addition, 7 deletions
src/turtlesim_xl.cpp
with
48 additions
and
33 deletions
include/turtlesim/turtle_frame.h
+
2
−
4
View file @
88886143
...
@@ -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
;
};
};
}
}
This diff is collapsed.
Click to expand it.
msg/img.msg
+
2
−
2
View file @
88886143
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
This diff is collapsed.
Click to expand it.
src/turtle_frame.cpp
+
43
−
20
View file @
88886143
...
@@ -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
;
po
int
.
setX
(
130
)
;
int
yBottom
=
yTop
+
5
*
meter_
;
po
int
.
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);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/turtlesim_xl.cpp
+
1
−
7
View file @
88886143
...
@@ -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
();
}
}
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment