Skip to content

Commit d5d3cf9

Browse files
saippuaOlli
andauthored
Debug drawing extension to allow drawing primitives on HUD layer (#7168)
* Extended debug draw functions to allow drawing primitives on HUD layer * Added documentation for new drawing features * Added debug draw changes to changelog --------- Co-authored-by: Olli <[email protected]>
1 parent b6b4b4f commit d5d3cf9

File tree

10 files changed

+717
-316
lines changed

10 files changed

+717
-316
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* make PythonAPI Windows: Fixed incompatibility issue with Anaconda due `py` command.
1111
* Added function to get actor' sockets names
1212
* Fixed bug in python agents when vehicle list was empty causing a check on all vehicles (BasicAgent.py) and detected pedestrians as vehicles if no pedestrains are present (BehaviourAgent.py)
13+
* Extended debug drawing functions to allow drawing primitives on HUD layer
1314
* Added possibility to change gravity variable in imui sensor for the accelerometer
1415
* Fixed ROS2 native extension build error when ROS2 is installed in the system.
1516
* ROS2Native: Force fast-dds dependencies download to avoid build crash when boost_asio and tinyxml2 are not installed in Linux.

Docs/python_api.md

Lines changed: 273 additions & 241 deletions
Large diffs are not rendered by default.

LibCarla/source/carla/client/DebugHelper.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ namespace client {
3535
DrawShape(_episode, point, color, life_time, persistent_lines);
3636
}
3737

38+
void DebugHelper::DrawHUDPoint(
39+
const geom::Location &location,
40+
float size,
41+
sensor::data::Color color,
42+
float life_time,
43+
bool persistent_lines) {
44+
Shape::HUDPoint point{location, size};
45+
DrawShape(_episode, point, color, life_time, persistent_lines);
46+
}
47+
3848
void DebugHelper::DrawLine(
3949
const geom::Location &begin,
4050
const geom::Location &end,
@@ -46,6 +56,17 @@ namespace client {
4656
DrawShape(_episode, line, color, life_time, persistent_lines);
4757
}
4858

59+
void DebugHelper::DrawHUDLine(
60+
const geom::Location &begin,
61+
const geom::Location &end,
62+
float thickness,
63+
Color color,
64+
float life_time,
65+
bool persistent_lines) {
66+
Shape::HUDLine line{begin, end, thickness};
67+
DrawShape(_episode, line, color, life_time, persistent_lines);
68+
}
69+
4970
void DebugHelper::DrawArrow(
5071
const geom::Location &begin,
5172
const geom::Location &end,
@@ -59,6 +80,19 @@ namespace client {
5980
DrawShape(_episode, arrow, color, life_time, persistent_lines);
6081
}
6182

83+
void DebugHelper::DrawHUDArrow(
84+
const geom::Location &begin,
85+
const geom::Location &end,
86+
float thickness,
87+
float arrow_size,
88+
sensor::data::Color color,
89+
float life_time,
90+
bool persistent_lines) {
91+
Shape::HUDLine line{begin, end, thickness};
92+
Shape::HUDArrow arrow{line, arrow_size};
93+
DrawShape(_episode, arrow, color, life_time, persistent_lines);
94+
}
95+
6296
void DebugHelper::DrawBox(
6397
const geom::BoundingBox &box,
6498
const geom::Rotation &rotation,
@@ -70,6 +104,17 @@ namespace client {
70104
DrawShape(_episode, the_box, color, life_time, persistent_lines);
71105
}
72106

107+
void DebugHelper::DrawHUDBox(
108+
const geom::BoundingBox &box,
109+
const geom::Rotation &rotation,
110+
float thickness,
111+
sensor::data::Color color,
112+
float life_time,
113+
bool persistent_lines) {
114+
Shape::HUDBox the_box{box, rotation, thickness};
115+
DrawShape(_episode, the_box, color, life_time, persistent_lines);
116+
}
117+
73118
void DebugHelper::DrawString(
74119
const geom::Location &location,
75120
const std::string &text,

LibCarla/source/carla/client/DebugHelper.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ namespace client {
3030
float life_time = -1.0f,
3131
bool persistent_lines = true);
3232

33+
void DrawHUDPoint(
34+
const geom::Location &location,
35+
float size = 0.1f,
36+
Color color = Color{255u, 0u, 0u},
37+
float life_time = -1.0f,
38+
bool persistent_lines = true);
39+
3340
void DrawLine(
3441
const geom::Location &begin,
3542
const geom::Location &end,
@@ -38,6 +45,14 @@ namespace client {
3845
float life_time = -1.0f,
3946
bool persistent_lines = true);
4047

48+
void DrawHUDLine(
49+
const geom::Location &begin,
50+
const geom::Location &end,
51+
float thickness = 1.0f,
52+
Color color = Color{225u, 0u, 0u},
53+
float life_time = -1.0f,
54+
bool presistent_lines = true);
55+
4156
void DrawArrow(
4257
const geom::Location &begin,
4358
const geom::Location &end,
@@ -47,6 +62,15 @@ namespace client {
4762
float life_time = -1.0f,
4863
bool persistent_lines = true);
4964

65+
void DrawHUDArrow(
66+
const geom::Location &begin,
67+
const geom::Location &end,
68+
float thickness = 0.1f,
69+
float arrow_size = 0.1f,
70+
Color color = Color{255u, 0u, 0u},
71+
float life_time = -1.0f,
72+
bool persistent_lines = true);
73+
5074
void DrawBox(
5175
const geom::BoundingBox &box,
5276
const geom::Rotation &rotation,
@@ -55,6 +79,14 @@ namespace client {
5579
float life_time = -1.0f,
5680
bool persistent_lines = true);
5781

82+
void DrawHUDBox(
83+
const geom::BoundingBox &box,
84+
const geom::Rotation &rotation,
85+
float thickness = 0.1f,
86+
Color color = Color{255u, 0u, 0u},
87+
float life_time = -1.0f,
88+
bool persistent_lines = true);
89+
5890
void DrawString(
5991
const geom::Location &location,
6092
const std::string &text,

LibCarla/source/carla/rpc/DebugShape.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,60 @@ namespace rpc {
3535
MSGPACK_DEFINE_ARRAY(location, size);
3636
};
3737

38+
struct HUDPoint {
39+
geom::Location location;
40+
float size;
41+
MSGPACK_DEFINE_ARRAY(location, size);
42+
};
43+
3844
struct Line {
3945
geom::Location begin;
4046
geom::Location end;
4147
float thickness;
4248
MSGPACK_DEFINE_ARRAY(begin, end, thickness);
4349
};
4450

51+
struct HUDLine {
52+
geom::Location begin;
53+
geom::Location end;
54+
float thickness;
55+
MSGPACK_DEFINE_ARRAY(begin, end, thickness);
56+
};
57+
4558
struct Arrow {
4659
Line line;
4760
float arrow_size;
4861
MSGPACK_DEFINE_ARRAY(line, arrow_size);
4962
};
5063

64+
struct HUDArrow {
65+
HUDLine line;
66+
float arrow_size;
67+
MSGPACK_DEFINE_ARRAY(line, arrow_size);
68+
};
69+
5170
struct Box {
5271
geom::BoundingBox box;
5372
geom::Rotation rotation;
5473
float thickness;
5574
MSGPACK_DEFINE_ARRAY(box, rotation, thickness);
5675
};
5776

77+
struct HUDBox {
78+
geom::BoundingBox box;
79+
geom::Rotation rotation;
80+
float thickness;
81+
MSGPACK_DEFINE_ARRAY(box, rotation, thickness);
82+
};
83+
5884
struct String {
5985
geom::Location location;
6086
std::string text;
6187
bool draw_shadow;
6288
MSGPACK_DEFINE_ARRAY(location, text, draw_shadow);
6389
};
6490

65-
boost::variant2::variant<Point, Line, Arrow, Box, String> primitive;
91+
boost::variant2::variant<Point, Line, Arrow, Box, String, HUDPoint, HUDLine, HUDArrow, HUDBox> primitive;
6692

6793
Color color = {255u, 0u, 0u};
6894

PythonAPI/carla/source/libcarla/World.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,26 @@ void export_world() {
374374
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
375375
arg("life_time")=-1.0f,
376376
arg("persistent_lines")=true))
377+
.def("draw_hud_point", &cc::DebugHelper::DrawHUDPoint,
378+
(arg("location"),
379+
arg("size")=0.1f,
380+
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
381+
arg("life_time")=-1.0f,
382+
arg("persistent_lines")=true))
377383
.def("draw_line", &cc::DebugHelper::DrawLine,
378384
(arg("begin"),
379385
arg("end"),
380386
arg("thickness")=0.1f,
381387
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
382388
arg("life_time")=-1.0f,
383389
arg("persistent_lines")=true))
390+
.def("draw_hud_line", &cc::DebugHelper::DrawHUDLine,
391+
(arg("begin"),
392+
arg("end"),
393+
arg("thickness")=0.1f,
394+
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
395+
arg("life_time")=-1.0f,
396+
arg("persistent_lines")=true))
384397
.def("draw_arrow", &cc::DebugHelper::DrawArrow,
385398
(arg("begin"),
386399
arg("end"),
@@ -389,13 +402,28 @@ void export_world() {
389402
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
390403
arg("life_time")=-1.0f,
391404
arg("persistent_lines")=true))
405+
.def("draw_hud_arrow", &cc::DebugHelper::DrawHUDArrow,
406+
(arg("begin"),
407+
arg("end"),
408+
arg("thickness")=0.1f,
409+
arg("arrow_size")=0.1f,
410+
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
411+
arg("life_time")=-1.0f,
412+
arg("persistent_lines")=true))
392413
.def("draw_box", &cc::DebugHelper::DrawBox,
393414
(arg("box"),
394415
arg("rotation"),
395416
arg("thickness")=0.1f,
396417
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
397418
arg("life_time")=-1.0f,
398419
arg("persistent_lines")=true))
420+
.def("draw_hud_box", &cc::DebugHelper::DrawHUDBox,
421+
(arg("box"),
422+
arg("rotation"),
423+
arg("thickness")=0.1f,
424+
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
425+
arg("life_time")=-1.0f,
426+
arg("persistent_lines")=true))
399427
.def("draw_string", &cc::DebugHelper::DrawString,
400428
(arg("location"),
401429
arg("text"),
@@ -404,4 +432,6 @@ void export_world() {
404432
arg("life_time")=-1.0f,
405433
arg("persistent_lines")=true))
406434
;
435+
// scope HUD = class_<cc::DebugHelper>(
436+
407437
}

0 commit comments

Comments
 (0)