Open3D (C++ API)  0.13.0+ec16c02
RSBagReader.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <atomic>
30 #include <condition_variable>
31 #include <string>
32 #include <thread>
33 #include <unordered_map>
34 #include <vector>
35 
39 
40 // Forward declarations for librealsense classes
41 namespace rs2 {
42 class pipeline;
43 } // namespace rs2
44 
45 namespace open3d {
46 namespace t {
47 namespace io {
48 
67 class RSBagReader : public RGBDVideoReader {
68 public:
69  static const size_t DEFAULT_BUFFER_SIZE = 32;
70 
75  explicit RSBagReader(size_t buffer_size = DEFAULT_BUFFER_SIZE);
76 
77  RSBagReader(const RSBagReader &) = delete;
78  RSBagReader &operator=(const RSBagReader &) = delete;
79  virtual ~RSBagReader();
80 
82  virtual bool IsOpened() const override { return is_opened_; }
83 
85  virtual bool IsEOF() const override;
86 
90  virtual bool Open(const std::string &filename) override;
91 
93  virtual void Close() override;
94 
96  virtual const RGBDVideoMetadata &GetMetadata() const override {
97  return metadata_;
98  }
99 
101  virtual RGBDVideoMetadata &GetMetadata() override { return metadata_; }
102 
106  virtual bool SeekTimestamp(uint64_t timestamp) override;
107 
109  virtual uint64_t GetTimestamp() const override;
110 
112  virtual t::geometry::RGBDImage NextFrame() override;
113 
115  virtual std::string GetFilename() const override { return filename_; };
116 
117  using RGBDVideoReader::SaveFrames;
118  using RGBDVideoReader::ToString;
119 
120 private:
121  std::string filename_;
122  RGBDVideoMetadata metadata_;
123 
124  std::atomic<bool> is_eof_{false}; // Write by frame_reader_thread.
125  std::atomic<bool> is_opened_{false}; // Read by frame_reader_thread.
135  std::vector<t::geometry::RGBDImage> frame_buffer_;
136  std::vector<uint64_t>
137  frame_position_us_;
138  static const size_t BUFFER_REFILL_FACTOR =
139  4;
140  std::atomic<uint64_t> head_fid_{
141  0};
142  std::atomic<uint64_t> tail_fid_{0};
143  std::atomic<uint64_t> seek_to_{UINT64_MAX};
144  std::condition_variable need_frames_;
150  void fill_frame_buffer();
151  std::thread frame_reader_thread_;
152 
153  std::unique_ptr<rs2::pipeline> pipe_;
154 
155  Json::Value GetMetadataJson();
156  std::string GetTagInMetadata(const std::string &tag_name);
157 };
158 } // namespace io
159 } // namespace t
160 } // namespace open3d
virtual const RGBDVideoMetadata & GetMetadata() const override
Get (read-only) metadata of the playback.
Definition: RSBagReader.h:96
virtual bool IsOpened() const override
Check If the RSBag file is opened.
Definition: RSBagReader.h:82
Definition: RealSenseSensor.h:36
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample uint64_t
Definition: K4aPlugin.cpp:352
RGBD video metadata.
Definition: RGBDVideoMetadata.h:45
Definition: RGBDVideoReader.h:37
virtual std::string GetFilename() const override
Return filename being read.
Definition: RSBagReader.h:115
Definition: PinholeCameraIntrinsic.cpp:35
RGBDImage A pair of color and depth images.
Definition: RGBDImage.h:40
virtual RGBDVideoMetadata & GetMetadata() override
Get reference to the metadata of the RGBD video playback.
Definition: RSBagReader.h:101
Definition: RSBagReader.h:67