Skip to content

Commit

Permalink
Debug drawing extension to allow drawing primitives on HUD layer (#7168)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
saippua and Olli authored Mar 27, 2024
1 parent b6b4b4f commit d5d3cf9
Show file tree
Hide file tree
Showing 10 changed files with 717 additions and 316 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* make PythonAPI Windows: Fixed incompatibility issue with Anaconda due `py` command.
* Added function to get actor' sockets names
* 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)
* Extended debug drawing functions to allow drawing primitives on HUD layer
* Added possibility to change gravity variable in imui sensor for the accelerometer
* Fixed ROS2 native extension build error when ROS2 is installed in the system.
* ROS2Native: Force fast-dds dependencies download to avoid build crash when boost_asio and tinyxml2 are not installed in Linux.
Expand Down
514 changes: 273 additions & 241 deletions Docs/python_api.md

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions LibCarla/source/carla/client/DebugHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ namespace client {
DrawShape(_episode, point, color, life_time, persistent_lines);
}

void DebugHelper::DrawHUDPoint(
const geom::Location &location,
float size,
sensor::data::Color color,
float life_time,
bool persistent_lines) {
Shape::HUDPoint point{location, size};
DrawShape(_episode, point, color, life_time, persistent_lines);
}

void DebugHelper::DrawLine(
const geom::Location &begin,
const geom::Location &end,
Expand All @@ -46,6 +56,17 @@ namespace client {
DrawShape(_episode, line, color, life_time, persistent_lines);
}

void DebugHelper::DrawHUDLine(
const geom::Location &begin,
const geom::Location &end,
float thickness,
Color color,
float life_time,
bool persistent_lines) {
Shape::HUDLine line{begin, end, thickness};
DrawShape(_episode, line, color, life_time, persistent_lines);
}

void DebugHelper::DrawArrow(
const geom::Location &begin,
const geom::Location &end,
Expand All @@ -59,6 +80,19 @@ namespace client {
DrawShape(_episode, arrow, color, life_time, persistent_lines);
}

void DebugHelper::DrawHUDArrow(
const geom::Location &begin,
const geom::Location &end,
float thickness,
float arrow_size,
sensor::data::Color color,
float life_time,
bool persistent_lines) {
Shape::HUDLine line{begin, end, thickness};
Shape::HUDArrow arrow{line, arrow_size};
DrawShape(_episode, arrow, color, life_time, persistent_lines);
}

void DebugHelper::DrawBox(
const geom::BoundingBox &box,
const geom::Rotation &rotation,
Expand All @@ -70,6 +104,17 @@ namespace client {
DrawShape(_episode, the_box, color, life_time, persistent_lines);
}

void DebugHelper::DrawHUDBox(
const geom::BoundingBox &box,
const geom::Rotation &rotation,
float thickness,
sensor::data::Color color,
float life_time,
bool persistent_lines) {
Shape::HUDBox the_box{box, rotation, thickness};
DrawShape(_episode, the_box, color, life_time, persistent_lines);
}

void DebugHelper::DrawString(
const geom::Location &location,
const std::string &text,
Expand Down
32 changes: 32 additions & 0 deletions LibCarla/source/carla/client/DebugHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ namespace client {
float life_time = -1.0f,
bool persistent_lines = true);

void DrawHUDPoint(
const geom::Location &location,
float size = 0.1f,
Color color = Color{255u, 0u, 0u},
float life_time = -1.0f,
bool persistent_lines = true);

void DrawLine(
const geom::Location &begin,
const geom::Location &end,
Expand All @@ -38,6 +45,14 @@ namespace client {
float life_time = -1.0f,
bool persistent_lines = true);

void DrawHUDLine(
const geom::Location &begin,
const geom::Location &end,
float thickness = 1.0f,
Color color = Color{225u, 0u, 0u},
float life_time = -1.0f,
bool presistent_lines = true);

void DrawArrow(
const geom::Location &begin,
const geom::Location &end,
Expand All @@ -47,6 +62,15 @@ namespace client {
float life_time = -1.0f,
bool persistent_lines = true);

void DrawHUDArrow(
const geom::Location &begin,
const geom::Location &end,
float thickness = 0.1f,
float arrow_size = 0.1f,
Color color = Color{255u, 0u, 0u},
float life_time = -1.0f,
bool persistent_lines = true);

void DrawBox(
const geom::BoundingBox &box,
const geom::Rotation &rotation,
Expand All @@ -55,6 +79,14 @@ namespace client {
float life_time = -1.0f,
bool persistent_lines = true);

void DrawHUDBox(
const geom::BoundingBox &box,
const geom::Rotation &rotation,
float thickness = 0.1f,
Color color = Color{255u, 0u, 0u},
float life_time = -1.0f,
bool persistent_lines = true);

void DrawString(
const geom::Location &location,
const std::string &text,
Expand Down
28 changes: 27 additions & 1 deletion LibCarla/source/carla/rpc/DebugShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,60 @@ namespace rpc {
MSGPACK_DEFINE_ARRAY(location, size);
};

struct HUDPoint {
geom::Location location;
float size;
MSGPACK_DEFINE_ARRAY(location, size);
};

struct Line {
geom::Location begin;
geom::Location end;
float thickness;
MSGPACK_DEFINE_ARRAY(begin, end, thickness);
};

struct HUDLine {
geom::Location begin;
geom::Location end;
float thickness;
MSGPACK_DEFINE_ARRAY(begin, end, thickness);
};

struct Arrow {
Line line;
float arrow_size;
MSGPACK_DEFINE_ARRAY(line, arrow_size);
};

struct HUDArrow {
HUDLine line;
float arrow_size;
MSGPACK_DEFINE_ARRAY(line, arrow_size);
};

struct Box {
geom::BoundingBox box;
geom::Rotation rotation;
float thickness;
MSGPACK_DEFINE_ARRAY(box, rotation, thickness);
};

struct HUDBox {
geom::BoundingBox box;
geom::Rotation rotation;
float thickness;
MSGPACK_DEFINE_ARRAY(box, rotation, thickness);
};

struct String {
geom::Location location;
std::string text;
bool draw_shadow;
MSGPACK_DEFINE_ARRAY(location, text, draw_shadow);
};

boost::variant2::variant<Point, Line, Arrow, Box, String> primitive;
boost::variant2::variant<Point, Line, Arrow, Box, String, HUDPoint, HUDLine, HUDArrow, HUDBox> primitive;

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

Expand Down
30 changes: 30 additions & 0 deletions PythonAPI/carla/source/libcarla/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,26 @@ void export_world() {
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
arg("life_time")=-1.0f,
arg("persistent_lines")=true))
.def("draw_hud_point", &cc::DebugHelper::DrawHUDPoint,
(arg("location"),
arg("size")=0.1f,
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
arg("life_time")=-1.0f,
arg("persistent_lines")=true))
.def("draw_line", &cc::DebugHelper::DrawLine,
(arg("begin"),
arg("end"),
arg("thickness")=0.1f,
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
arg("life_time")=-1.0f,
arg("persistent_lines")=true))
.def("draw_hud_line", &cc::DebugHelper::DrawHUDLine,
(arg("begin"),
arg("end"),
arg("thickness")=0.1f,
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
arg("life_time")=-1.0f,
arg("persistent_lines")=true))
.def("draw_arrow", &cc::DebugHelper::DrawArrow,
(arg("begin"),
arg("end"),
Expand All @@ -389,13 +402,28 @@ void export_world() {
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
arg("life_time")=-1.0f,
arg("persistent_lines")=true))
.def("draw_hud_arrow", &cc::DebugHelper::DrawHUDArrow,
(arg("begin"),
arg("end"),
arg("thickness")=0.1f,
arg("arrow_size")=0.1f,
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
arg("life_time")=-1.0f,
arg("persistent_lines")=true))
.def("draw_box", &cc::DebugHelper::DrawBox,
(arg("box"),
arg("rotation"),
arg("thickness")=0.1f,
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
arg("life_time")=-1.0f,
arg("persistent_lines")=true))
.def("draw_hud_box", &cc::DebugHelper::DrawHUDBox,
(arg("box"),
arg("rotation"),
arg("thickness")=0.1f,
arg("color")=cc::DebugHelper::Color(255u, 0u, 0u),
arg("life_time")=-1.0f,
arg("persistent_lines")=true))
.def("draw_string", &cc::DebugHelper::DrawString,
(arg("location"),
arg("text"),
Expand All @@ -404,4 +432,6 @@ void export_world() {
arg("life_time")=-1.0f,
arg("persistent_lines")=true))
;
// scope HUD = class_<cc::DebugHelper>(

}
Loading

0 comments on commit d5d3cf9

Please sign in to comment.