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

refactor(perception_rviz_plugin): only delete markers with unused MarkersIDs during updates. #4783

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
m_marker_common.addMessage(markers_ptr);
}

void deleteMarker(rviz_default_plugins::displays::MarkerID marker_id)

Check warning on line 149 in common/autoware_auto_perception_rviz_plugin/include/object_detection/object_polygon_display_base.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_auto_perception_rviz_plugin/include/object_detection/object_polygon_display_base.hpp#L149

Added line #L149 was not covered by tests
{
m_marker_common.deleteMarker(marker_id);
}

Check warning on line 152 in common/autoware_auto_perception_rviz_plugin/include/object_detection/object_polygon_display_base.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_auto_perception_rviz_plugin/include/object_detection/object_polygon_display_base.hpp#L151-L152

Added lines #L151 - L152 were not covered by tests

protected:
/// \brief Convert given shape msg into a Marker
/// \tparam ClassificationContainerT List type with ObjectClassificationMsg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <condition_variable>
#include <list>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -112,6 +113,7 @@ class AUTOWARE_AUTO_PERCEPTION_RVIZ_PLUGIN_PUBLIC PredictedObjectsDisplay
std::mutex mutex;
std::condition_variable condition;
std::vector<visualization_msgs::msg::Marker::SharedPtr> markers;
std::set<rviz_default_plugins::displays::MarkerID> existing_marker_ids;
};

} // namespace object_detection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <object_detection/predicted_objects_display.hpp>

#include <memory>
#include <set>

namespace autoware
{
Expand Down Expand Up @@ -130,7 +131,7 @@
auto acceleration_text_marker_ptr = acceleration_text_marker.value();
acceleration_text_marker_ptr->header = msg->header;
acceleration_text_marker_ptr->id = uuid_to_marker_id(object.object_id);
add_marker(acceleration_text_marker_ptr);
markers.push_back(acceleration_text_marker_ptr);

Check warning on line 134 in common/autoware_auto_perception_rviz_plugin/src/object_detection/predicted_objects_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_auto_perception_rviz_plugin/src/object_detection/predicted_objects_display.cpp#L134

Added line #L134 was not covered by tests
}

// Get marker for twist
Expand Down Expand Up @@ -195,11 +196,19 @@
std::unique_lock<std::mutex> lock(mutex);

if (!markers.empty()) {
clear_markers();

std::set new_marker_ids = std::set<rviz_default_plugins::displays::MarkerID>();
for (const auto & marker : markers) {
rviz_default_plugins::displays::MarkerID marker_id =
rviz_default_plugins::displays::MarkerID(marker->ns, marker->id);
add_marker(marker);
new_marker_ids.insert(marker_id);
}
for (auto itr = existing_marker_ids.begin(); itr != existing_marker_ids.end(); itr++) {
if (new_marker_ids.find(*itr) == new_marker_ids.end()) {
deleteMarker(*itr);

Check warning on line 208 in common/autoware_auto_perception_rviz_plugin/src/object_detection/predicted_objects_display.cpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_auto_perception_rviz_plugin/src/object_detection/predicted_objects_display.cpp#L206-L208

Added lines #L206 - L208 were not covered by tests
}
}
existing_marker_ids = new_marker_ids;

Check warning on line 211 in common/autoware_auto_perception_rviz_plugin/src/object_detection/predicted_objects_display.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

PredictedObjectsDisplay::update has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

markers.clear();
}
Expand Down
Loading