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

MaliputViewer: Adds Traffic Lights. #401

Merged
merged 2 commits into from
May 12, 2021
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
38 changes: 34 additions & 4 deletions delphyne_gui/visualizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,37 @@ install(
ARCHIVE DESTINATION lib
)

# ----------------------------------------
# traffic light manager library.
add_library(traffic_light_manager
traffic_light_manager.cc
)
add_library(delphyne_gui::traffic_light_manager ALIAS traffic_light_manager)
set_target_properties(traffic_light_manager
PROPERTIES
OUTPUT_NAME delphyne_gui_traffic_light_manager
)

ament_target_dependencies(traffic_light_manager
"maliput"
)

target_link_libraries(traffic_light_manager
delphyne::public_headers
ignition-common3::ignition-common3
ignition-math6::ignition-math6
ignition-rendering3::ignition-rendering3
maliput::api
)

install(
TARGETS traffic_light_manager
EXPORT ${PROJECT_NAME}-targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

# global_attributes library.
add_library(global_attributes
global_attributes.cc
Expand Down Expand Up @@ -141,6 +172,7 @@ target_link_libraries(MaliputViewerPlugin
delphyne_gui::global_attributes
delphyne_gui::maliput_viewer_model
delphyne_gui::selector
delphyne_gui::traffic_light_manager
ignition-gui3::ignition-gui3
ignition-common3::ignition-common3
ignition-transport8::ignition-transport8
Expand Down Expand Up @@ -172,8 +204,6 @@ add_library(maliput_viewer_widget
${CMAKE_CURRENT_SOURCE_DIR}/rules_visualizer_widget.cc
orbit_view_control.cc
render_maliput_widget.cc
arrow_mesh.cc
traffic_light_manager.cc
${MaliputViewerWidget_MOC}
${LayerSelectionWidget_MOC}
${RenderMaliputWidget_MOC}
Expand All @@ -191,6 +221,7 @@ target_link_libraries(maliput_viewer_widget
delphyne_gui::global_attributes
delphyne_gui::maliput_viewer_model
delphyne_gui::selector
delphyne_gui::traffic_light_manager
ignition-common3::ignition-common3
ignition-gui0::ignition-gui0
ignition-msgs5::ignition-msgs5
Expand Down Expand Up @@ -355,8 +386,7 @@ add_library(TopicsStats
add_library(delphyne_gui::TopicsStats ALIAS TopicsStats)
set_target_properties(TopicsStats
PROPERTIES
# TODO(#379): Use TopicsStats instead after removing ign-gui0 from workspace.
OUTPUT_NAME TopicsStatsPlugin
OUTPUT_NAME TopicsStats
)

target_link_libraries(TopicsStats
Expand Down
11 changes: 10 additions & 1 deletion delphyne_gui/visualizer/maliput_viewer_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ void MaliputViewerPlugin::OnNewRoadNetwork(const QString& _mapFile, const QStrin
phaseTreeModel.AddPhaseToPhaseRing(phase, phaseRing.first);
}
}

// Create traffic light manager.
trafficLightManager->CreateTrafficLights(model->GetTrafficLights());
}

void MaliputViewerPlugin::UpdateLaneList() {
Expand Down Expand Up @@ -277,6 +280,8 @@ void MaliputViewerPlugin::OnPhaseSelection(const QModelIndex& _index) {
}
currentPhase.first = item->text().toStdString();
currentPhase.second = phaseRingItem->text().toStdString();
trafficLightManager->SetBulbStates(
model->GetBulbStates(currentPhase.second /* phaseRingId */, currentPhase.first /* phaseId */));
}
}

Expand Down Expand Up @@ -429,6 +434,9 @@ void MaliputViewerPlugin::Clear() {
// Reset phase table.
phaseTreeModel.Clear();
currentPhase = {"" /* phaseId */, "", /* phaseRingId*/};

// Resert traffic light manager.
trafficLightManager->Clear();
}

void MaliputViewerPlugin::CreateLaneLabelMaterial(ignition::rendering::MaterialPtr& _material) {
Expand Down Expand Up @@ -527,7 +535,7 @@ void MaliputViewerPlugin::Initialize() {
// Create a Selector.
selector = std::make_unique<Selector>(this->scene, 0.3 /* scaleX */, 0.5 /* scaleY */, 0.1 /* scaleZ */,
50 /* poolSize */, 15 /* numLanes */, 0.6 /* minTolerance */);

trafficLightManager = std::make_unique<TrafficLightManager>(this->scene);
// Install event filter to get mouse event from the main scene.
const ignition::gui::Plugin* scene3D = FilterPluginsByTitle(mainScene3dPluginTitle);
if (!scene3D) {
Expand Down Expand Up @@ -562,6 +570,7 @@ bool MaliputViewerPlugin::eventFilter(QObject* _obj, QEvent* _event) {
}
if (_event->type() == ignition::gui::events::Render::kType) {
arrow->Update();
trafficLightManager->Tick();
if (renderMeshesOption.executeMeshRendering) {
RenderRoadMeshes(model->Meshes());
renderMeshesOption.executeMeshRendering = false;
Expand Down
4 changes: 4 additions & 0 deletions delphyne_gui/visualizer/maliput_viewer_plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "arrow_mesh.hh"
#include "maliput_viewer_model.hh"
#include "selector.hh"
#include "traffic_light_manager.hh"

namespace delphyne {
namespace gui {
Expand Down Expand Up @@ -358,6 +359,9 @@ class MaliputViewerPlugin : public ignition::gui::Plugin {

/// \brief Selector used for selecting clicked lanes in the visualizer.
std::unique_ptr<Selector> selector;

/// \brief Manager of traffic lights visualization.
std::unique_ptr<TrafficLightManager> trafficLightManager;
};

} // namespace gui
Expand Down