ros_reader.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 #include <core/serialization.h>
6 #include "rosbag/view.h"
7 #include "ros_file_format.h"
8 
9 namespace librealsense
10 {
11  using namespace device_serializer;
12 
14  {
15  public:
16  ros_reader(const std::string& file, const std::shared_ptr<context>& ctx);
17  device_snapshot query_device_description(const nanoseconds& time) override;
18  std::shared_ptr<serialized_data> read_next_data() override;
19  void seek_to_time(const nanoseconds& seek_time) override;
20  std::vector<std::shared_ptr<serialized_data>> fetch_last_frames(const nanoseconds& seek_time) override;
21  nanoseconds query_duration() const override;
22  void reset() override;
23  virtual void enable_stream(const std::vector<device_serializer::stream_identifier>& stream_ids) override;
24  virtual void disable_stream(const std::vector<device_serializer::stream_identifier>& stream_ids) override;
25  const std::string& get_file_name() const override;
26 
27  private:
28 
29  template <typename ROS_TYPE>
30  static typename ROS_TYPE::ConstPtr instantiate_msg(const rosbag::MessageInstance& msg)
31  {
32  typename ROS_TYPE::ConstPtr msg_instnance_ptr = msg.instantiate<ROS_TYPE>();
33  if (msg_instnance_ptr == nullptr)
34  {
35  throw io_exception(to_string()
36  << "Invalid file format, expected "
38  << " message but got: " << msg.getDataType()
39  << "(Topic: " << msg.getTopic() << ")");
40  }
41  return msg_instnance_ptr;
42  }
43 
44  std::shared_ptr<serialized_frame> create_frame(const rosbag::MessageInstance& msg);
45  static nanoseconds get_file_duration(const rosbag::Bag& file, uint32_t version);
46  static void get_legacy_frame_metadata(const rosbag::Bag& bag,
48  const rosbag::MessageInstance &msg,
49  frame_additional_data& additional_data);
50 
51  template <typename T>
52  static bool safe_convert(const std::string& key, T& val)
53  {
54  bool ret{ false };
55  try
56  {
57  ret = convert(key, val);
58  }
59  catch (const std::exception& e)
60  {
61  LOG_ERROR(e.what());
62  }
63  return ret;
64  }
65 
66  static std::map<std::string, std::string> get_frame_metadata(const rosbag::Bag& bag,
67  const std::string& topic,
68  const device_serializer::stream_identifier& stream_id,
69  const rosbag::MessageInstance &msg,
70  frame_additional_data& additional_data);
71  frame_holder create_image_from_message(const rosbag::MessageInstance &image_data) const;
72  frame_holder create_motion_sample(const rosbag::MessageInstance &motion_data) const;
73  static inline float3 to_float3(const geometry_msgs::Vector3& v);
74  static inline float4 to_float4(const geometry_msgs::Quaternion& q);
75  frame_holder create_pose_sample(const rosbag::MessageInstance &msg) const;
76  static uint32_t read_file_version(const rosbag::Bag& file);
77  bool try_read_legacy_stream_extrinsic(const stream_identifier& stream_id, uint32_t& group_id, rs2_extrinsics& extrinsic) const;
78  bool try_read_stream_extrinsic(const stream_identifier& stream_id, uint32_t& group_id, rs2_extrinsics& extrinsic) const;
79  static void update_sensor_options(const rosbag::Bag& file, uint32_t sensor_index, const nanoseconds& time, uint32_t file_version, snapshot_collection& sensor_extensions, uint32_t version);
80  void update_proccesing_blocks(const rosbag::Bag& file, uint32_t sensor_index, const nanoseconds& time, uint32_t file_version, snapshot_collection& sensor_extensions, uint32_t version, std::string pid, std::string sensor_name);
81  void update_l500_depth_sensor(const rosbag::Bag& file, uint32_t sensor_index, const nanoseconds& time, uint32_t file_version, snapshot_collection& sensor_extensions, uint32_t version, std::string pid, std::string sensor_name);
82  void add_sensor_extension(snapshot_collection & sensor_extensions, std::string sensor_name);
83 
84  bool is_depth_sensor(std::string sensor_name);
85  bool is_color_sensor(std::string sensor_name);
86  bool is_motion_module_sensor(std::string sensor_name);
87  bool is_fisheye_module_sensor(std::string sensor_name);
88  bool is_ds5_PID(int pid);
89  bool is_sr300_PID(int pid);
90  bool is_l500_PID(int pid);
91  std::shared_ptr<recommended_proccesing_blocks_snapshot> read_proccesing_blocks_for_version_under_4(std::string pid, std::string sensor_name, std::shared_ptr<options_interface> options);
92  std::shared_ptr<recommended_proccesing_blocks_snapshot> read_proccesing_blocks(const rosbag::Bag& file, device_serializer::sensor_identifier sensor_id, const nanoseconds& timestamp,
93  std::shared_ptr<options_interface> options, uint32_t file_version, std::string pid, std::string sensor_name);
94  device_snapshot read_device_description(const nanoseconds& time, bool reset = false);
95  std::shared_ptr<info_container> read_legacy_info_snapshot(uint32_t sensor_index) const;
96  std::shared_ptr<info_container> read_info_snapshot(const std::string& topic) const;
97  std::set<uint32_t> read_sensor_indices(uint32_t device_index) const;
98  static std::shared_ptr<pose_stream_profile> create_pose_profile(uint32_t stream_index, uint32_t fps);
99  static std::shared_ptr<motion_stream_profile> create_motion_stream(rs2_stream stream_type, uint32_t stream_index, uint32_t fps, rs2_format format, rs2_motion_device_intrinsic intrinsics);
100  static std::shared_ptr<video_stream_profile> create_video_stream_profile(const platform::stream_profile& sp,
101  const sensor_msgs::CameraInfo& ci,
102  const stream_descriptor& sd);
103 
104  stream_profiles read_legacy_stream_info(uint32_t sensor_index) const;
105  stream_profiles read_stream_info(uint32_t device_index, uint32_t sensor_index) const;
106  static std::string read_option_description(const rosbag::Bag& file, const std::string& topic);
107  /*Until Version 2 (including)*/
108  static std::pair<rs2_option, std::shared_ptr<librealsense::option>> create_property(const rosbag::MessageInstance& property_message_instance);
109  /*Starting version 3*/
110  static std::pair<rs2_option, std::shared_ptr<librealsense::option>> create_option(const rosbag::Bag& file, const rosbag::MessageInstance& value_message_instance);
111  static std::shared_ptr<librealsense::processing_block_interface> create_processing_block(const rosbag::MessageInstance& value_message_instance, bool& depth_to_disparity, std::shared_ptr<options_interface> options);
112 
114  {
119  };
120 
122  {
125  float baseline;
126  };
127 
128  l500_depth_data create_l500_intrinsic_depth(const rosbag::MessageInstance& value_message_instance);
129  ivcam2::intrinsic_depth ros_l500_depth_data_to_intrinsic_depth(ros_reader::l500_depth_data data);
130 
131  static notification create_notification(const rosbag::Bag& file, const rosbag::MessageInstance& message_instance);
132  static std::shared_ptr<options_container> read_sensor_options(const rosbag::Bag& file, device_serializer::sensor_identifier sensor_id, const nanoseconds& timestamp, uint32_t file_version);
133  static std::vector<std::string> get_topics(std::unique_ptr<rosbag::View>& view);
134 
135  std::shared_ptr<metadata_parser_map> m_metadata_parser_map;
139  std::shared_ptr<frame_source> m_frame_source;
141  std::unique_ptr<rosbag::View> m_samples_view;
143  std::vector<std::string> m_enabled_streams_topics;
144  std::shared_ptr<context> m_context;
146  };
147 }
constexpr uint32_t file_version()
static bool safe_convert(const std::string &key, T &val)
Definition: ros_reader.h:52
GLboolean reset
nanoseconds m_total_duration
Definition: ros_reader.h:137
void convert(rs2_format source, std::string &target)
GLsizei const GLchar *const * string
Specialize to provide the datatype for a message.
std::unique_ptr< rosbag::View > m_samples_view
Definition: ros_reader.h:141
An iterator that points to a MessageInstance from a bag.
Definition: view.h:60
e
Definition: rmse.py:177
device_snapshot m_initial_device_description
Definition: ros_reader.h:136
std::shared_ptr< frame_source > m_frame_source
Definition: ros_reader.h:139
GLuint GLfloat * val
GLuint64 key
Definition: glext.h:8966
std::vector< std::string > m_enabled_streams_topics
Definition: ros_reader.h:143
std::shared_ptr< metadata_parser_map > m_metadata_parser_map
Definition: ros_reader.h:135
unsigned int uint32_t
Definition: stdint.h:80
A class pointing into a bag file.
GLint GLint GLsizei GLint GLenum format
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
#define LOG_ERROR(...)
Definition: src/types.h:242
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
Definition: streaming.h:165
dictionary intrinsics
Definition: t265_stereo.py:142
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
static ROS_TYPE::ConstPtr instantiate_msg(const rosbag::MessageInstance &msg)
Definition: ros_reader.h:30
std::chrono::duration< uint64_t, std::nano > nanoseconds
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
std::string get_file_name(const std::string &path)
Definition: os.cpp:224
GLdouble GLdouble GLdouble q
int stream_id
Definition: sync.h:17
std::string const & getTopic() const
std::string const & getDataType() const
std::shared_ptr< context > m_context
Definition: ros_reader.h:144
Motion device intrinsics: scale, bias, and variances.
Definition: rs_types.h:103
rosbag::View::iterator m_samples_itrator
Definition: ros_reader.h:142
static const int MAX_NUM_OF_DEPTH_RESOLUTIONS
Definition: l500-private.h:13
std::shared_ptr< T > instantiate() const
Templated call to instantiate a message.
GLdouble v
Definition: parser.hpp:150
std::string to_string(T value)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40