@@ -101,6 +101,12 @@ auto CatmullRomSpline::getTrajectory(
101
101
const double start_s, const double end_s, const double resolution, const double offset) const
102
102
-> std::vector<geometry_msgs::msg::Point>
103
103
{
104
+ if (std::fabs (resolution) <= std::numeric_limits<double >::epsilon ()) {
105
+ THROW_SIMULATION_ERROR (
106
+ " Resolution should not be zero." ,
107
+ " This message is not originally intended to be displayed, if you see it, please contact " ,
108
+ " the developer of traffic_simulator." );
109
+ }
104
110
if (start_s > end_s) {
105
111
std::vector<geometry_msgs::msg::Point> ret;
106
112
double s = start_s;
@@ -122,8 +128,70 @@ auto CatmullRomSpline::getTrajectory(
122
128
}
123
129
}
124
130
125
- CatmullRomSpline::CatmullRomSpline (const std::vector<geometry_msgs::msg::Point> & control_points)
126
- : control_points(control_points), line_segments_(getLineSegments(control_points)), total_length_(0 )
131
+ auto CatmullRomSpline::getTrajectoryPoses (
132
+ const double start_s, const double end_s, const double resolution) const
133
+ -> std::vector<geometry_msgs::msg::Pose>
134
+ {
135
+ if (std::fabs (resolution) <= std::numeric_limits<double >::epsilon ()) {
136
+ THROW_SIMULATION_ERROR (
137
+ " Resolution should not be zero." ,
138
+ " This message is not originally intended to be displayed, if you see it, please contact " ,
139
+ " the developer of traffic_simulator." );
140
+ }
141
+ if (start_s > end_s) {
142
+ std::vector<geometry_msgs::msg::Pose> ret;
143
+ double s = start_s;
144
+ while (s > end_s) {
145
+ ret.emplace_back (getPose (s));
146
+ s = s - std::fabs (resolution);
147
+ }
148
+ ret.emplace_back (getPose (end_s));
149
+ return ret;
150
+ } else {
151
+ std::vector<geometry_msgs::msg::Pose> ret;
152
+ double s = start_s;
153
+ while (s < end_s) {
154
+ ret.emplace_back (getPose (s));
155
+ s = s + std::fabs (resolution);
156
+ }
157
+ ret.emplace_back (getPose (end_s));
158
+ return ret;
159
+ }
160
+ }
161
+
162
+ CatmullRomSpline::CatmullRomSpline (
163
+ const geometry_msgs::msg::Point & start_point,
164
+ const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> & trajectory)
165
+ : CatmullRomSpline([start_point, trajectory] {
166
+ if (!trajectory) {
167
+ THROW_SIMULATION_ERROR (
168
+ " Trajectory is empty." ,
169
+ " This message is not originally intended to be displayed, if you see it, please contact "
170
+ " the developer of traffic_simulator." );
171
+ }
172
+ std::vector<geometry_msgs::msg::Point> control_points;
173
+ control_points.reserve (trajectory->shape .vertices .size () + 2UL );
174
+ control_points.emplace_back (start_point);
175
+ for (const auto & vertex : trajectory->shape .vertices ) {
176
+ control_points.emplace_back (vertex.position .position );
177
+ }
178
+ if (trajectory->closed ) {
179
+ control_points.emplace_back (control_points[0 ]);
180
+ }
181
+ return control_points;
182
+ }())
183
+ {
184
+ }
185
+
186
+ CatmullRomSpline::CatmullRomSpline (
187
+ const std::vector<geometry_msgs::msg::Point> & raw_control_points)
188
+ : control_points([raw_control_points]() {
189
+ std::vector<geometry_msgs::msg::Point> ret = raw_control_points;
190
+ ret.erase (std::unique (ret.begin (), ret.end ()), ret.end ());
191
+ return ret;
192
+ }()),
193
+ line_segments_ (getLineSegments(control_points)),
194
+ total_length_ (0 )
127
195
{
128
196
switch (control_points.size ()) {
129
197
case 0 :
@@ -232,7 +300,6 @@ CatmullRomSpline::CatmullRomSpline(const std::vector<geometry_msgs::msg::Point>
232
300
}
233
301
for (const auto & curve : curves_) {
234
302
length_list_.emplace_back (curve.getLength ());
235
- maximum_2d_curvatures_.emplace_back (curve.getMaximum2DCurvature ());
236
303
}
237
304
total_length_ = 0 ;
238
305
for (const auto & length : length_list_) {
@@ -585,8 +652,17 @@ auto CatmullRomSpline::getPoint(const double s, const double offset) const
585
652
586
653
auto CatmullRomSpline::getMaximum2DCurvature () const -> double
587
654
{
655
+ if (curves_.empty ()) {
656
+ THROW_SEMANTIC_ERROR (
657
+ " Curves are empty. We cannot determine the maximum 2D curvature of the spline." ,
658
+ " This message is not originally intended to be displayed, if you see it, please contact "
659
+ " the developer of traffic_simulator." );
660
+ }
661
+ // / @note Maximum 2D curvature is empty means that it is not calculated yet.
588
662
if (maximum_2d_curvatures_.empty ()) {
589
- THROW_SIMULATION_ERROR (" maximum 2D curvature vector size is 0." ); // LCOV_EXCL_LINE
663
+ for (const auto & curve : curves_) {
664
+ maximum_2d_curvatures_.emplace_back (curve.getMaximum2DCurvature ());
665
+ }
590
666
}
591
667
const auto [min, max] =
592
668
std::minmax_element (maximum_2d_curvatures_.begin (), maximum_2d_curvatures_.end ());
0 commit comments