scenario_simulator_v2 C++ API
lanelet_pose.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 
15 #ifndef TRAFFIC_SIMULATOR__DATA_TYPE__LANELET_POSE_HPP_
16 #define TRAFFIC_SIMULATOR__DATA_TYPE__LANELET_POSE_HPP_
17 
18 #include <lanelet2_core/geometry/Lanelet.h>
19 
20 #include <geometry_msgs/msg/pose.hpp>
21 #include <optional>
26 #include <traffic_simulator_msgs/msg/lanelet_pose.hpp>
27 
28 namespace traffic_simulator
29 {
31 
32 inline namespace lanelet_pose
33 {
35 {
36 public:
37  explicit CanonicalizedLaneletPose(const LaneletPose & non_canonicalized_lanelet_pose);
38  explicit CanonicalizedLaneletPose(
39  const LaneletPose & non_canonicalized_lanelet_pose, const lanelet::Ids & route_lanelets);
43  explicit operator LaneletPose() const noexcept { return lanelet_pose_; }
44  explicit operator geometry_msgs::msg::Pose() const noexcept { return map_pose_; }
45 
46  auto getLaneletPose() const -> const LaneletPose & { return lanelet_pose_; }
47  auto getAltitude() const -> double { return map_pose_.position.z; }
48  auto getLaneletId() const noexcept -> lanelet::Id { return lanelet_pose_.lanelet_id; }
49  auto alignOrientationToLanelet() -> void;
50  auto hasAlternativeLaneletPose() const -> bool { return lanelet_poses_.size() > 1; }
52  LaneletPose from,
53  const RoutingConfiguration & routing_configuration = RoutingConfiguration()) const
54  -> std::optional<LaneletPose>;
55 
56  static auto setConsiderPoseByRoadSlope(bool consider_pose_by_road_slope) -> void
57  {
58  consider_pose_by_road_slope_ = consider_pose_by_road_slope;
59  }
60  static auto getConsiderPoseByRoadSlope() -> bool { return consider_pose_by_road_slope_; }
61 
67 #define DEFINE_COMPARISON_OPERATOR(OPERATOR) \
68  bool operator OPERATOR(const CanonicalizedLaneletPose & rhs) const \
69  { \
70  if ( \
71  static_cast<LaneletPose>(*this).lanelet_id == static_cast<LaneletPose>(rhs).lanelet_id && \
72  static_cast<LaneletPose>(*this).s OPERATOR static_cast<LaneletPose>(rhs).s) { \
73  return true; \
74  } \
75  return false; \
76  }
77 
82 #undef DEFINE_COMPARISON_OPERATOR
83 
84  friend std::ostream & operator<<(std::ostream & os, const CanonicalizedLaneletPose & obj)
85  {
86  os << "CanonicalizedLaneletPose(\n";
87  os << obj.lanelet_pose_ << "\n";
88  if (obj.lanelet_poses_.size() == 1) {
89  os << " alternative from lanelet_poses_: " << obj.lanelet_poses_.front() << "\n";
90  } else if (obj.lanelet_poses_.size() > 1) {
91  os << " lanelet_poses_: [\n";
92  for (const auto & pose : obj.lanelet_poses_) {
93  os << " - " << pose << "\n";
94  }
95  os << " ]\n";
96  }
97  os << " map_pose_: " << obj.map_pose_ << "\n";
98  os << " consider_pose_by_road_slope_: "
99  << (CanonicalizedLaneletPose::consider_pose_by_road_slope_ ? "true" : "false") << "\n";
100  os << ")";
101  return os;
102  }
103 
104 private:
105  auto adjustOrientationAndOzPosition() -> void;
107  std::vector<LaneletPose> lanelet_poses_;
109  inline static bool consider_pose_by_road_slope_{false};
110 };
111 } // namespace lanelet_pose
112 
114 auto isSameLaneletId(const CanonicalizedLaneletPose &, const lanelet::Id lanelet_id) -> bool;
115 } // namespace traffic_simulator
116 
117 #endif // TRAFFIC_SIMULATOR__DATA_TYPE__LANELET_POSE_HPP_
Definition: lanelet_pose.hpp:35
LaneletPose lanelet_pose_
Definition: lanelet_pose.hpp:106
static bool consider_pose_by_road_slope_
Definition: lanelet_pose.hpp:109
auto hasAlternativeLaneletPose() const -> bool
Definition: lanelet_pose.hpp:50
static auto setConsiderPoseByRoadSlope(bool consider_pose_by_road_slope) -> void
Definition: lanelet_pose.hpp:56
auto getAlternativeLaneletPoseBaseOnShortestRouteFrom(LaneletPose from, const RoutingConfiguration &routing_configuration=RoutingConfiguration()) const -> std::optional< LaneletPose >
Definition: lanelet_pose.cpp:70
auto getLaneletId() const noexcept -> lanelet::Id
Definition: lanelet_pose.hpp:48
auto alignOrientationToLanelet() -> void
Definition: lanelet_pose.cpp:91
std::vector< LaneletPose > lanelet_poses_
Definition: lanelet_pose.hpp:107
geometry_msgs::msg::Pose map_pose_
Definition: lanelet_pose.hpp:108
auto getAltitude() const -> double
Definition: lanelet_pose.hpp:47
CanonicalizedLaneletPose & operator=(const CanonicalizedLaneletPose &obj)
Definition: lanelet_pose.cpp:61
DEFINE_COMPARISON_OPERATOR(<=) DEFINE_COMPARISON_OPERATOR(<) DEFINE_COMPARISON_OPERATOR(>
CanonicalizedLaneletPose(const LaneletPose &non_canonicalized_lanelet_pose)
Definition: lanelet_pose.cpp:29
auto getLaneletPose() const -> const LaneletPose &
Definition: lanelet_pose.hpp:46
static auto getConsiderPoseByRoadSlope() -> bool
Definition: lanelet_pose.hpp:60
Definition: lanelet_wrapper.hpp:43
geometry_msgs::msg::Pose Pose
Definition: lanelet_wrapper.hpp:70
Definition: api.hpp:33
traffic_simulator_msgs::msg::LaneletPose LaneletPose
Definition: lanelet_pose.hpp:30
auto isSameLaneletId(const CanonicalizedEntityStatus &first_status, const CanonicalizedEntityStatus &second_status) -> bool
Definition: entity_status.cpp:198
std::ostream & operator<<(std::ostream &os, const geometry_msgs::msg::Point &point)
Definition: ostream_helpers.cpp:21
Definition: routing_configuration.hpp:24