Skip to content

Commit

Permalink
MaliputViewer: Adds Traffic Lights. (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
francocipollone committed May 12, 2021
1 parent e889e5d commit fb7e818
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
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 @@ -528,7 +536,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 @@ -563,6 +571,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

0 comments on commit fb7e818

Please sign in to comment.