scenario_simulator_v2 C++ API
catmull_rom_spline.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 #ifndef GEOMETRY__SPLINE__CATMULL_ROM_SPLINE_HPP_
15 #define GEOMETRY__SPLINE__CATMULL_ROM_SPLINE_HPP_
16 
17 #include <exception>
21 #include <geometry_msgs/msg/point.hpp>
22 #include <memory>
23 #include <optional>
24 #include <string>
25 #include <traffic_simulator_msgs/msg/polyline_trajectory.hpp>
26 #include <utility>
27 #include <vector>
28 
29 namespace math
30 {
31 namespace geometry
32 {
34 {
35 public:
36  CatmullRomSpline() = default;
37  explicit CatmullRomSpline(const std::vector<geometry_msgs::msg::Point> & control_points);
38  explicit CatmullRomSpline(
39  const geometry_msgs::msg::Point & start_point,
40  const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> & trajectory);
41  auto getLength() const -> double override { return total_length_; }
42  auto getMaximum2DCurvature() const -> double;
43  auto getPoint(const double s) const -> geometry_msgs::msg::Point;
44  auto getPoint(const double s, const double offset) const -> geometry_msgs::msg::Point;
45  auto getTangentVector(const double s) const -> geometry_msgs::msg::Vector3;
46  auto getNormalVector(const double s) const -> geometry_msgs::msg::Vector3;
47  auto getPose(const double s, const bool fill_pitch = true) const -> geometry_msgs::msg::Pose;
48  auto getTrajectory(
49  const double start_s, const double end_s, const double resolution,
50  const double offset = 0.0) const -> std::vector<geometry_msgs::msg::Point>;
51  auto getTrajectoryPoses(const double start_s, const double end_s, const double resolution) const
52  -> std::vector<geometry_msgs::msg::Pose>;
53  auto getSValue(const geometry_msgs::msg::Pose & pose, double threshold_distance = 3.0) const
54  -> std::optional<double>;
55  auto getSquaredDistanceIn2D(const geometry_msgs::msg::Point & point, const double s) const
56  -> double override;
57  auto getSquaredDistanceVector(const geometry_msgs::msg::Point & point, const double s) const
58  -> geometry_msgs::msg::Vector3;
60  const std::vector<geometry_msgs::msg::Point> & polygon, const bool search_backward = false,
61  const std::optional<std::pair<double, double>> & s_range = std::nullopt) const
62  -> std::set<double>;
64  const geometry_msgs::msg::Point & point0, const geometry_msgs::msg::Point & point1,
65  const bool search_backward = false) const -> std::optional<double>;
67  const std::vector<geometry_msgs::msg::Point> & polygon, const bool search_backward = false,
68  const std::optional<std::pair<double, double>> & s_range = std::nullopt) const
69  -> std::optional<double> override;
70  auto getPolygon(const double width, const size_t num_points = 30, const double z_offset = 0)
71  -> std::vector<geometry_msgs::msg::Point>;
72  const std::vector<geometry_msgs::msg::Point> control_points;
73  virtual ~CatmullRomSpline() = default;
74 
75 private:
76  auto getRightBounds(const double width, const size_t num_points = 30, const double z_offset = 0)
77  const -> std::vector<geometry_msgs::msg::Point>;
78  auto getLeftBounds(const double width, const size_t num_points = 30, const double z_offset = 0)
79  const -> std::vector<geometry_msgs::msg::Point>;
80  auto getSInSplineCurve(const size_t curve_index, const double s) const -> double;
81  auto getCurveIndexAndS(const double s) const -> std::pair<size_t, double>;
82  auto checkConnection() const -> bool;
83  auto equals(const geometry_msgs::msg::Point & p0, const geometry_msgs::msg::Point & p1) const
84  -> bool;
85  std::vector<LineSegment> line_segments_;
86  std::vector<HermiteCurve> curves_;
87  std::vector<double> length_list_;
89  mutable std::vector<double> maximum_2d_curvatures_;
90  double total_length_;
91 };
92 } // namespace geometry
93 } // namespace math
94 
95 #endif // GEOMETRY__SPLINE__CATMULL_ROM_SPLINE_HPP_
Definition: catmull_rom_spline_interface.hpp:30
Definition: catmull_rom_spline.hpp:34
auto getCollisionPointIn2D(const geometry_msgs::msg::Point &point0, const geometry_msgs::msg::Point &point1, const bool search_backward=false) const -> std::optional< double >
Definition: catmull_rom_spline.cpp:464
auto getSquaredDistanceIn2D(const geometry_msgs::msg::Point &point, const double s) const -> double override
Definition: catmull_rom_spline.cpp:532
auto getPoint(const double s) const -> geometry_msgs::msg::Point
Definition: catmull_rom_spline.cpp:606
auto getSValue(const geometry_msgs::msg::Pose &pose, double threshold_distance=3.0) const -> std::optional< double >
Definition: catmull_rom_spline.cpp:489
auto getTrajectoryPoses(const double start_s, const double end_s, const double resolution) const -> std::vector< geometry_msgs::msg::Pose >
Definition: catmull_rom_spline.cpp:131
const std::vector< geometry_msgs::msg::Point > control_points
Definition: catmull_rom_spline.hpp:72
auto getPolygon(const double width, const size_t num_points=30, const double z_offset=0) -> std::vector< geometry_msgs::msg::Point >
Definition: catmull_rom_spline.cpp:29
auto getSquaredDistanceVector(const geometry_msgs::msg::Point &point, const double s) const -> geometry_msgs::msg::Vector3
Definition: catmull_rom_spline.cpp:568
auto getCollisionPointsIn2D(const std::vector< geometry_msgs::msg::Point > &polygon, const bool search_backward=false, const std::optional< std::pair< double, double >> &s_range=std::nullopt) const -> std::set< double >
Definition: catmull_rom_spline.cpp:349
auto getLength() const -> double override
Definition: catmull_rom_spline.hpp:41
auto getTrajectory(const double start_s, const double end_s, const double resolution, const double offset=0.0) const -> std::vector< geometry_msgs::msg::Point >
Definition: catmull_rom_spline.cpp:100
auto getPose(const double s, const bool fill_pitch=true) const -> geometry_msgs::msg::Pose
Definition: catmull_rom_spline.cpp:749
auto getMaximum2DCurvature() const -> double
Definition: catmull_rom_spline.cpp:653
auto getTangentVector(const double s) const -> geometry_msgs::msg::Vector3
Definition: catmull_rom_spline.cpp:704
auto getNormalVector(const double s) const -> geometry_msgs::msg::Vector3
Definition: catmull_rom_spline.cpp:675
Definition: hermite_curve.hpp:32
Definition: line_segment.hpp:30
Definition: bounding_box.hpp:32
Definition: lanelet_wrapper.hpp:40
geometry_msgs::msg::Pose Pose
Definition: lanelet_wrapper.hpp:66
geometry_msgs::msg::Point Point
Definition: lanelet_wrapper.hpp:65
geometry_msgs::msg::Vector3 Vector3
Definition: lanelet_wrapper.hpp:69