assets_writer.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 
26 #include "cartographer/mapping/proto/trajectory.pb.h"
27 #include "cartographer/mapping_2d/proto/range_data_inserter_options.pb.h"
30 #include "nav_msgs/OccupancyGrid.h"
31 
32 namespace cartographer_ros {
33 
34 // Writes an occupancy grid.
36  const std::vector<::cartographer::mapping::TrajectoryNode>&
37  trajectory_nodes,
38  const string& map_frame,
39  const ::cartographer::mapping_2d::proto::SubmapsOptions& submaps_options,
40  const std::string& stem) {
41  ::nav_msgs::OccupancyGrid occupancy_grid;
42  BuildOccupancyGrid2D(trajectory_nodes, map_frame, submaps_options,
43  &occupancy_grid);
44  WriteOccupancyGridToPgmAndYaml(occupancy_grid, stem);
45 }
46 
47 // Writes X-ray images and PLY files from the 'trajectory_nodes'. The filenames
48 // will all start with 'stem'.
49 void Write3DAssets(const std::vector<::cartographer::mapping::TrajectoryNode>&
50  trajectory_nodes,
51  const double voxel_size, const std::string& stem) {
52  namespace carto = ::cartographer;
53  const auto file_writer_factory = [](const string& filename) {
54  return carto::common::make_unique<carto::io::StreamFileWriter>(filename);
55  };
56 
57  carto::io::NullPointsProcessor null_points_processor;
58  carto::io::XRayPointsProcessor xy_xray_points_processor(
59  voxel_size,
60  carto::transform::Rigid3f::Rotation(
61  Eigen::AngleAxisf(-M_PI / 2.f, Eigen::Vector3f::UnitY())),
62  {}, stem + "_xray_xy", file_writer_factory, &null_points_processor);
63  carto::io::XRayPointsProcessor yz_xray_points_processor(
64  voxel_size,
65  carto::transform::Rigid3f::Rotation(
66  Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitZ())),
67  {}, stem + "_xray_yz", file_writer_factory, &xy_xray_points_processor);
68  carto::io::XRayPointsProcessor xz_xray_points_processor(
69  voxel_size,
70  carto::transform::Rigid3f::Rotation(
71  Eigen::AngleAxisf(-M_PI / 2.f, Eigen::Vector3f::UnitZ())),
72  {}, stem + "_xray_xz", file_writer_factory, &yz_xray_points_processor);
73  carto::io::PlyWritingPointsProcessor ply_writing_points_processor(
74  file_writer_factory(stem + ".ply"), &xz_xray_points_processor);
75 
76  for (const auto& node : trajectory_nodes) {
77  const carto::sensor::RangeData range_data =
78  carto::sensor::TransformRangeData(
79  carto::sensor::Decompress(node.constant_data->range_data_3d),
80  node.pose.cast<float>());
81 
82  auto points_batch = carto::common::make_unique<carto::io::PointsBatch>();
83  points_batch->origin = range_data.origin;
84  points_batch->points = range_data.returns;
85  ply_writing_points_processor.Process(std::move(points_batch));
86  }
87  ply_writing_points_processor.Flush();
88 }
89 
90 } // namespace cartographer_ros
void Write3DAssets(const std::vector<::cartographer::mapping::TrajectoryNode > &trajectory_nodes, const double voxel_size, const std::string &stem)
filename
f
void Write2DAssets(const std::vector<::cartographer::mapping::TrajectoryNode > &trajectory_nodes, const string &map_frame, const ::cartographer::mapping_2d::proto::SubmapsOptions &submaps_options, const std::string &stem)
void BuildOccupancyGrid2D(const std::vector<::cartographer::mapping::TrajectoryNode > &trajectory_nodes, const string &map_frame, const ::cartographer::mapping_2d::proto::SubmapsOptions &submaps_options,::nav_msgs::OccupancyGrid *const occupancy_grid)
void WriteOccupancyGridToPgmAndYaml(const ::nav_msgs::OccupancyGrid &occupancy_grid, const std::string &stem)
Definition: map_writer.cc:82


cartographer_ros
Author(s):
autogenerated on Wed Jun 5 2019 22:35:56