@@ -44,9 +44,8 @@ void poseArrayMsgFromPath(const std::vector<Point_2>& waypoints,
4444 pose_array->poses .clear ();
4545 pose_array->poses .resize (waypoints.size ());
4646 for (size_t i = 0 ; i < waypoints.size (); i++) {
47- pose_array->poses [i].position .x = CGAL::to_double (waypoints[i].x ());
48- pose_array->poses [i].position .y = CGAL::to_double (waypoints[i].y ());
49- pose_array->poses [i].position .z = altitude;
47+ msgPointFromWaypoint (waypoints[i], altitude,
48+ &pose_array->poses [i].position );
5049 }
5150}
5251
@@ -79,6 +78,15 @@ void msgMultiDofJointTrajectoryFromPath(
7978 }
8079}
8180
81+ void msgPointFromWaypoint (const Point_2& waypoint, double altitude,
82+ geometry_msgs::Point* point) {
83+ ROS_ASSERT (point);
84+
85+ point->x = CGAL::to_double (waypoint.x ());
86+ point->y = CGAL::to_double (waypoint.y ());
87+ point->z = altitude;
88+ }
89+
8290void createMarkers (const std::vector<Point_2>& vertices, double altitude,
8391 const std::string& frame_id, const std::string& ns,
8492 const Color& points_color, const Color& lines_color,
@@ -111,9 +119,7 @@ void createMarkers(const std::vector<Point_2>& vertices, double altitude,
111119
112120 for (size_t i = 0 ; i < vertices.size (); i++) {
113121 geometry_msgs::Point p;
114- p.x = CGAL::to_double (vertices[i].x ());
115- p.y = CGAL::to_double (vertices[i].y ());
116- p.z = altitude;
122+ msgPointFromWaypoint (vertices[i], altitude, &p);
117123
118124 points->points .push_back (p);
119125 line_strip->points .push_back (p);
@@ -158,15 +164,14 @@ void createStartAndEndPointMarkers(const Point_2& start, const Point_2& end,
158164 const std::string& ns,
159165 visualization_msgs::Marker* start_point,
160166 visualization_msgs::Marker* end_point) {
167+ ROS_ASSERT (start_point);
168+ ROS_ASSERT (end_point);
169+
161170 geometry_msgs::Pose start_pose;
162- start_pose.position .x = CGAL::to_double (start.x ());
163- start_pose.position .y = CGAL::to_double (start.y ());
164- start_pose.position .z = altitude;
171+ msgPointFromWaypoint (start, altitude, &start_pose.position );
165172
166173 geometry_msgs::Pose end_pose;
167- end_pose.position .x = CGAL::to_double (end.x ());
168- end_pose.position .y = CGAL::to_double (end.y ());
169- end_pose.position .z = altitude;
174+ msgPointFromWaypoint (end, altitude, &end_pose.position );
170175
171176 return createStartAndEndPointMarkers (start_pose, end_pose, frame_id, ns,
172177 start_point, end_point);
@@ -212,15 +217,14 @@ void createStartAndEndTextMarkers(const Point_2& start, const Point_2& end,
212217 const std::string& ns,
213218 visualization_msgs::Marker* start_text,
214219 visualization_msgs::Marker* end_text) {
220+ ROS_ASSERT (start_text);
221+ ROS_ASSERT (end_text);
222+
215223 geometry_msgs::Pose start_pose;
216- start_pose.position .x = CGAL::to_double (start.x ());
217- start_pose.position .y = CGAL::to_double (start.y ());
218- start_pose.position .z = altitude;
224+ msgPointFromWaypoint (start, altitude, &start_pose.position );
219225
220226 geometry_msgs::Pose end_pose;
221- end_pose.position .x = CGAL::to_double (end.x ());
222- end_pose.position .y = CGAL::to_double (end.y ());
223- end_pose.position .z = altitude;
227+ msgPointFromWaypoint (end, altitude, &end_pose.position );
224228
225229 return createStartAndEndTextMarkers (start_pose, end_pose, frame_id, ns,
226230 start_text, end_text);
@@ -347,9 +351,7 @@ void createTriangles(const std::vector<std::vector<Point_2>>& triangles,
347351 ROS_ASSERT (t.size () == 3 );
348352 for (const auto & v : t) {
349353 geometry_msgs::Point p;
350- p.x = CGAL::to_double (v.x ());
351- p.y = CGAL::to_double (v.y ());
352- p.z = altitude;
354+ msgPointFromWaypoint (v, altitude, &p);
353355
354356 markers->points .push_back (p);
355357 }
0 commit comments