PointCloudCrafter
Loading...
Searching...
No Matches
pointcloudcrafter_rosbag.hpp
1/*
2 * Copyright 2024 2024 Markus Pielmeier, Florian Sauerbeck,
3 * Dominik Kulmer, Maximilian Leitenstern
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19#include <message_filters/connection.h>
20#include <message_filters/sync_policies/approximate_time.h>
21#include <message_filters/synchronizer.h>
22#include <message_filters/time_synchronizer.h>
23#include <tf2_ros/buffer.h>
24
25#include <Eigen/Eigen>
26#include <memory>
27#include <rclcpp/rclcpp.hpp>
28#include <sensor_msgs/msg/detail/point_cloud2__struct.hpp>
29#include <sensor_msgs/msg/point_cloud2.hpp>
30#include <string>
31#include <tf2_msgs/msg/detail/tf_message__struct.hpp>
32#include <tf2_msgs/msg/tf_message.hpp>
33#include <unordered_map>
34#include <utility>
35#include <vector>
36
37#include "rosbag_reader.hpp"
38#include "cli/cli_config.hpp"
39
40// clang-format off
41typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::msg::PointCloud2, sensor_msgs::msg::PointCloud2, sensor_msgs::msg::PointCloud2, sensor_msgs::msg::PointCloud2> ApproxTimeSyncPolicy; // NOLINT
42// clang-format on
43namespace pointcloudcrafter
44{
48class Rosbag
49{
50public:
54 explicit Rosbag(const config::RosbagConfig & cfg);
58 void run() { reader_.process(); }
59
60protected:
74 const sensor_msgs::msg::PointCloud2::ConstSharedPtr & pc1,
75 const sensor_msgs::msg::PointCloud2::ConstSharedPtr & pc2,
76 const sensor_msgs::msg::PointCloud2::ConstSharedPtr & pc3,
77 const sensor_msgs::msg::PointCloud2::ConstSharedPtr & pc4);
84 void process_pointclouds(std::vector<sensor_msgs::msg::PointCloud2::ConstSharedPtr> & pc_msgs);
90 void transform_pc(
91 const sensor_msgs::msg::PointCloud2 & msg_in, sensor_msgs::msg::PointCloud2 & msg_out);
92
93private:
94 // CLI Configuration
96 // Custom rosbag reader
97 tools::RosbagReader reader_;
98 // TF2 buffer to store transform
99 tf2_ros::Buffer tf2_buffer_;
100 // ROS logger
101 rclcpp::Logger logger_;
102 // Subscribers for pointclouds
103 std::vector<std::unique_ptr<tools::MsgFilter<sensor_msgs::msg::PointCloud2>>> subscribers_;
104 // Synchronizer for pointclouds
105 std::unique_ptr<message_filters::Synchronizer<ApproxTimeSyncPolicy>> synchronizer_;
106 message_filters::Connection sync_connection_{};
107 // Map to store transforms given by file
108 std::unordered_map<std::string, Eigen::Affine3d> file_transforms_{};
109
110 // Storage
111 size_t num_sensors_{};
112 int64_t loaded_frames_{0};
113 int64_t stride_frames_{0};
114 int64_t skip_frames_{0};
115};
116} // namespace pointcloudcrafter
Rosbag(const config::RosbagConfig &cfg)
Constructor.
Definition pointcloudcrafter_rosbag.cpp:61
void transform_pc(const sensor_msgs::msg::PointCloud2 &msg_in, sensor_msgs::msg::PointCloud2 &msg_out)
Transform a pointcloud given the transform from either the file or the TF buffer.
Definition pointcloudcrafter_rosbag.cpp:307
void pointcloud_sync_callback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr &pc1, const sensor_msgs::msg::PointCloud2::ConstSharedPtr &pc2, const sensor_msgs::msg::PointCloud2::ConstSharedPtr &pc3, const sensor_msgs::msg::PointCloud2::ConstSharedPtr &pc4)
Callback for synchronized pointclouds.
Definition pointcloudcrafter_rosbag.cpp:156
void run()
Run the pointcloud crafter.
Definition pointcloudcrafter_rosbag.hpp:58
void process_pointclouds(std::vector< sensor_msgs::msg::PointCloud2::ConstSharedPtr > &pc_msgs)
Process the pointclouds once all pointclouds are synchronized.
Definition pointcloudcrafter_rosbag.cpp:186
void tf_callback(const tools::RosbagReaderMsg< tf2_msgs::msg::TFMessage > &msg)
Callback for TF messages.
Definition pointcloudcrafter_rosbag.cpp:140
Definition rosbag_reader.hpp:91
Rosbag input configuration.
Definition cli_config.hpp:236
Struct to hold a ROS message and its corresponding rosbag message.
Definition rosbag_reader.hpp:42