draw_trajectories.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include "cartographer/io/image.h"
21 
22 namespace cartographer {
23 namespace io {
24 
25 void DrawTrajectory(const mapping::proto::Trajectory& trajectory,
26  const FloatColor& color,
27  const PoseToPixelFunction& pose_to_pixel,
28  cairo_surface_t* surface) {
29  if (trajectory.node_size() == 0) {
30  return;
31  }
32  constexpr double kTrajectoryWidth = 4.;
33  constexpr double kTrajectoryEndMarkers = 6.;
34  constexpr double kAlpha = 0.7;
35 
36  auto cr = ::cartographer::io::MakeUniqueCairoPtr(cairo_create(surface));
37 
38  cairo_set_source_rgba(cr.get(), color[0], color[1], color[2], kAlpha);
39  cairo_set_line_width(cr.get(), kTrajectoryWidth);
40 
41  for (const auto& node : trajectory.node()) {
42  const Eigen::Array2i pixel =
43  pose_to_pixel(transform::ToRigid3(node.pose()));
44  cairo_line_to(cr.get(), pixel.x(), pixel.y());
45  }
46  cairo_stroke(cr.get());
47 
48  // Draw beginning and end markers.
49  {
50  const Eigen::Array2i pixel =
51  pose_to_pixel(transform::ToRigid3(trajectory.node(0).pose()));
52  cairo_set_source_rgba(cr.get(), 0., 1., 0., kAlpha);
53  cairo_arc(cr.get(), pixel.x(), pixel.y(), kTrajectoryEndMarkers, 0,
54  2 * M_PI);
55  cairo_fill(cr.get());
56  }
57  {
58  const Eigen::Array2i pixel = pose_to_pixel(transform::ToRigid3(
59  trajectory.node(trajectory.node_size() - 1).pose()));
60  cairo_set_source_rgba(cr.get(), 1., 0., 0., kAlpha);
61  cairo_arc(cr.get(), pixel.x(), pixel.y(), kTrajectoryEndMarkers, 0,
62  2 * M_PI);
63  cairo_fill(cr.get());
64  }
65  cairo_surface_flush(surface);
66 }
67 
68 } // namespace io
69 } // namespace cartographer
transform::Rigid3d ToRigid3(const proto::Rigid3d &rigid)
Definition: transform.cc:71
std::array< float, 3 > FloatColor
Definition: color.h:29
std::function< Eigen::Array2i(const transform::Rigid3d &pose)> PoseToPixelFunction
UniqueCairoPtr MakeUniqueCairoPtr(cairo_t *surface)
Definition: image.cc:45
transform::Rigid3d pose
void DrawTrajectory(const mapping::proto::Trajectory &trajectory, const FloatColor &color, const PoseToPixelFunction &pose_to_pixel, cairo_surface_t *surface)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58