|
| 1 | +// Copyright 2024 TIER IV, Inc. |
| 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 AUTOWARE__MOTION_VELOCITY_PLANNER_COMMON__TRAJECTORY_PREPROCESSING_HPP_ |
| 16 | +#define AUTOWARE__MOTION_VELOCITY_PLANNER_COMMON__TRAJECTORY_PREPROCESSING_HPP_ |
| 17 | + |
| 18 | +#include <autoware_planning_msgs/msg/trajectory_point.hpp> |
| 19 | + |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +namespace autoware::motion_velocity_planner |
| 23 | +{ |
| 24 | +/// @brief downsample a trajectory, reducing its number of points by the given factor |
| 25 | +/// @param[in] trajectory input trajectory |
| 26 | +/// @param[in] start_idx starting index of the input trajectory |
| 27 | +/// @param[in] end_idx ending index of the input trajectory |
| 28 | +/// @param[in] factor factor used for downsampling |
| 29 | +/// @return downsampled trajectory |
| 30 | +std::vector<autoware_planning_msgs::msg::TrajectoryPoint> downsample_trajectory( |
| 31 | + const std::vector<autoware_planning_msgs::msg::TrajectoryPoint> & trajectory, |
| 32 | + const size_t start_idx, const size_t end_idx, const int factor) |
| 33 | +{ |
| 34 | + if (factor < 1) { |
| 35 | + return trajectory; |
| 36 | + } |
| 37 | + std::vector<autoware_planning_msgs::msg::TrajectoryPoint> downsampled_traj; |
| 38 | + downsampled_traj.reserve((end_idx - start_idx) / factor + 1); |
| 39 | + for (size_t i = start_idx; i <= end_idx; i += factor) { |
| 40 | + downsampled_traj.push_back(trajectory[i]); |
| 41 | + } |
| 42 | + return downsampled_traj; |
| 43 | +} |
| 44 | +} // namespace autoware::motion_velocity_planner |
| 45 | + |
| 46 | +#endif // AUTOWARE__MOTION_VELOCITY_PLANNER_COMMON__TRAJECTORY_PREPROCESSING_HPP_ |
0 commit comments