Open3D (C++ API)  0.12.0
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 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 class align;
44 } // namespace rs2
45 
46 namespace open3d {
47 namespace t {
48 namespace io {
49 
68 class RSBagReader : public RGBDVideoReader {
69 public:
70  static const size_t DEFAULT_BUFFER_SIZE = 32;
71 
76  explicit RSBagReader(size_t buffer_size = DEFAULT_BUFFER_SIZE);
77 
78  RSBagReader(const RSBagReader &) = delete;
79  RSBagReader &operator=(const RSBagReader &) = delete;
80  virtual ~RSBagReader();
81 
83  virtual bool IsOpened() const override { return is_opened_; }
84 
86  virtual bool IsEOF() const override;
87 
91  virtual bool Open(const std::string &filename) override;
92 
94  virtual void Close() override;
95 
97  virtual const RGBDVideoMetadata &GetMetadata() const override {
98  return metadata_;
99  }
100 
102  virtual RGBDVideoMetadata &GetMetadata() override { return metadata_; }
103 
107  virtual bool SeekTimestamp(uint64_t timestamp) override;
108 
110  virtual uint64_t GetTimestamp() const override;
111 
113  virtual t::geometry::RGBDImage NextFrame() override;
114 
116  virtual std::string GetFilename() const override { return filename_; };
117 
118  using RGBDVideoReader::SaveFrames;
119  using RGBDVideoReader::ToString;
120 
121 private:
122  std::string filename_;
123  RGBDVideoMetadata metadata_;
124 
125  std::atomic<bool> is_eof_{false}; // Write by frame_reader_thread.
126  std::atomic<bool> is_opened_{false}; // Read by frame_reader_thread.
136  std::vector<t::geometry::RGBDImage> frame_buffer_;
137  std::vector<uint64_t>
138  frame_position_us_;
139  static const size_t BUFFER_REFILL_FACTOR =
140  4;
141  std::atomic<uint64_t> head_fid_{
142  0};
143  std::atomic<uint64_t> tail_fid_{0};
144  std::atomic<uint64_t> seek_to_{UINT64_MAX};
145  std::condition_variable need_frames_;
151  void fill_frame_buffer();
152  std::thread frame_reader_thread_;
153 
154  std::unique_ptr<rs2::pipeline> pipe_;
155  std::unique_ptr<rs2::align> align_to_color_;
156 
157  Json::Value GetMetadataJson();
158  std::string GetTagInMetadata(const std::string &tag_name);
159 };
160 } // namespace io
161 } // namespace t
162 } // namespace open3d
virtual const RGBDVideoMetadata & GetMetadata() const override
Get (read-only) metadata of the playback.
Definition: RSBagReader.h:97
virtual bool IsOpened() const override
Check If the RSBag file is opened.
Definition: RSBagReader.h:83
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:116
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:102
Definition: RSBagReader.h:68