scenario_simulator_v2 C++ API
visualization_component.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
19 #ifndef TRAFFIC_SIMULATOR__VISUALIZATION__VISUALIZATION_COMPONENT_HPP_
20 #define TRAFFIC_SIMULATOR__VISUALIZATION__VISUALIZATION_COMPONENT_HPP_
21 
22 #if __cplusplus
23 extern "C" {
24 #endif
25 
26 // The below macros are taken from https://gcc.gnu.org/wiki/Visibility and from
27 // demos/composition/include/composition/visibility_control.h at https://github.com/ros2/demos
28 #if defined _WIN32 || defined __CYGWIN__
29 #ifdef __GNUC__
30 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_EXPORT __attribute__((dllexport))
31 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_IMPORT __attribute__((dllimport))
32 #else
33 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_EXPORT __declspec(dllexport)
34 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_IMPORT __declspec(dllimport)
35 #endif
36 #ifdef TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_BUILDING_DLL
37 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_PUBLIC \
38  TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_EXPORT
39 #else
40 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_PUBLIC \
41  TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_IMPORT
42 #endif
43 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_PUBLIC_TYPE \
44  TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_PUBLIC
45 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_LOCAL
46 #else
47 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_EXPORT __attribute__((visibility("default")))
48 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_IMPORT
49 #if __GNUC__ >= 4
50 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_PUBLIC __attribute__((visibility("default")))
51 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_LOCAL __attribute__((visibility("hidden")))
52 #else
53 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_PUBLIC
54 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_LOCAL
55 #endif
56 #define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_PUBLIC_TYPE
57 #endif
58 
59 #if __cplusplus
60 } // extern "C"
61 #endif
62 
63 #include <rclcpp/rclcpp.hpp>
64 #include <string>
66 #include <traffic_simulator_msgs/msg/entity_status_with_trajectory_array.hpp>
67 #include <unordered_map>
68 #include <visualization_msgs/msg/marker_array.hpp>
69 
70 namespace traffic_simulator
71 {
75 class VisualizationComponent : public rclcpp::Node
76 {
77 public:
79  explicit VisualizationComponent(const rclcpp::NodeOptions &);
80 
81 private:
86  void entityStatusCallback(
87  const traffic_simulator_msgs::msg::EntityStatusWithTrajectoryArray::ConstSharedPtr msg);
93  const visualization_msgs::msg::MarkerArray generateDeleteMarker(std::string ns);
98  const visualization_msgs::msg::MarkerArray generateDeleteMarker() const;
106  int goal_pose_max_size = 0;
107  const visualization_msgs::msg::MarkerArray generateMarker(
109  const std::vector<geometry_msgs::msg::Pose> & goal_pose,
110  const traffic_simulator_msgs::msg::WaypointsArray & waypoints,
111  const traffic_simulator_msgs::msg::Obstacle & obstacle, bool obstacle_find);
115  rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr marker_pub_;
119  rclcpp::Subscription<traffic_simulator_msgs::msg::EntityStatusWithTrajectoryArray>::SharedPtr
120  entity_status_sub_;
124  std::unordered_map<std::string, visualization_msgs::msg::MarkerArray> markers_;
125 };
126 } // namespace traffic_simulator
127 
128 #endif // TRAFFIC_SIMULATOR__VISUALIZATION__VISUALIZATION_COMPONENT_HPP_
ROS 2 component for visualizing simulation result.
Definition: visualization_component.hpp:76
TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_PUBLIC VisualizationComponent(const rclcpp::NodeOptions &)
Definition: visualization_component.cpp:58
Definition: api.hpp:49
std::string string
Definition: junit5.hpp:26
traffic_simulator_msgs::EntityStatus EntityStatus
Definition: helper_functions.hpp:32
#define TRAFFIC_SIMULATOR_VISUALIZATION_COMPONENT_PUBLIC
Definition: visualization_component.hpp:53