From 271017ad5c4caf14502b980fbbd5ad4b1834bb9e Mon Sep 17 00:00:00 2001 From: youliang Date: Fri, 31 Dec 2021 16:38:25 +0800 Subject: [PATCH 1/2] save and load roi polygons Signed-off-by: youliang --- rmf_traffic_editor/gui/editor.cpp | 1 + rmf_traffic_editor/gui/level.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/rmf_traffic_editor/gui/editor.cpp b/rmf_traffic_editor/gui/editor.cpp index 7307da3a..6e82702c 100644 --- a/rmf_traffic_editor/gui/editor.cpp +++ b/rmf_traffic_editor/gui/editor.cpp @@ -1014,6 +1014,7 @@ const QString Editor::tool_id_to_string(const int id) case TOOL_ADD_MODEL: return "add m&odel"; case TOOL_ADD_FLOOR: return "add &floor"; case TOOL_ADD_HOLE: return "add hole"; + case TOOL_ADD_ROI: return "add roi"; case TOOL_EDIT_POLYGON: return "&edit polygon"; case TOOL_ADD_HUMAN_LANE: return "add human lane"; case TOOL_ADD_FEATURE: return "add &feature"; diff --git a/rmf_traffic_editor/gui/level.cpp b/rmf_traffic_editor/gui/level.cpp index 0ae76866..787e0670 100644 --- a/rmf_traffic_editor/gui/level.cpp +++ b/rmf_traffic_editor/gui/level.cpp @@ -160,6 +160,17 @@ bool Level::from_yaml( } } + if (_data["rois"] && _data["rois"].IsSequence()) + { + const YAML::Node& yf = _data["rois"]; + for (YAML::const_iterator it = yf.begin(); it != yf.end(); ++it) + { + Polygon p; + p.from_yaml(*it, Polygon::ROI); + polygons.push_back(p); + } + } + if (_data["elevation"]) elevation = _data["elevation"].as(); @@ -277,6 +288,9 @@ YAML::Node Level::to_yaml() const case Polygon::HOLE: y["holes"].push_back(polygon.to_yaml()); break; + case Polygon::ROI: + y["rois"].push_back(polygon.to_yaml()); + break; default: printf("tried to save an unknown polygon type: %d\n", static_cast(polygon.type)); @@ -1035,6 +1049,7 @@ void Level::draw_polygons(QGraphicsScene* scene) const { const QBrush floor_brush(QColor::fromRgbF(0.9, 0.9, 0.9, 0.8)); const QBrush hole_brush(QColor::fromRgbF(0.3, 0.3, 0.3, 0.5)); + const QBrush roi_brush(QColor::fromRgbF(0.5, 0.5, 0.3, 0.3)); // first draw the floor polygons for (const auto& polygon : polygons) @@ -1050,6 +1065,13 @@ void Level::draw_polygons(QGraphicsScene* scene) const draw_polygon(scene, hole_brush, polygon); } + // now draw the holes + for (const auto& polygon : polygons) + { + if (polygon.type == Polygon::ROI) + draw_polygon(scene, roi_brush, polygon); + } + #if 0 // ahhhhh only for debugging... // plot the nearest projection point to a polygon, if it's set From 41c114cccef9415f0454b4eb155a00f9f077a1c0 Mon Sep 17 00:00:00 2001 From: youliang Date: Fri, 31 Dec 2021 16:43:28 +0800 Subject: [PATCH 2/2] typo Signed-off-by: youliang --- rmf_traffic_editor/gui/level.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmf_traffic_editor/gui/level.cpp b/rmf_traffic_editor/gui/level.cpp index 787e0670..5853189b 100644 --- a/rmf_traffic_editor/gui/level.cpp +++ b/rmf_traffic_editor/gui/level.cpp @@ -1065,7 +1065,7 @@ void Level::draw_polygons(QGraphicsScene* scene) const draw_polygon(scene, hole_brush, polygon); } - // now draw the holes + // now draw the region of interests for (const auto& polygon : polygons) { if (polygon.type == Polygon::ROI)