Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/save and load roi polygons #411

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rmf_traffic_editor/gui/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
22 changes: 22 additions & 0 deletions rmf_traffic_editor/gui/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>();

Expand Down Expand Up @@ -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<int>(polygon.type));
Expand Down Expand Up @@ -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)
Expand All @@ -1050,6 +1065,13 @@ void Level::draw_polygons(QGraphicsScene* scene) const
draw_polygon(scene, hole_brush, polygon);
}

// now draw the region of interests
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
Expand Down