Time-of-Flight Library(ToF)  3.2.2
csf_reader.hpp
1 #ifndef _CHRONOPTICS_TOF_CSF_READER_HPP_
2 #define _CHRONOPTICS_TOF_CSF_READER_HPP_
3 
4 #include <chronoptics/tof/csf_reader.h>
5 
6 #include <chronoptics/tof/data.hpp>
7 #include <chronoptics/tof/stream.hpp>
8 #include <chronoptics/tof/calibration.hpp>
9 #include <chronoptics/tof/camera_config.hpp>
10 
11 namespace chronoptics {
12 namespace tof {
13 
14 /** This class reads csf files
15 */
16 class CsfReader : public detail::Base<tof_csf_reader, tof_csf_reader_delete> {
17  public:
18  /** Construct from pointer */
19  CsfReader(tof_csf_reader_t ptr = nullptr) {
20  this->ptr_ = ptr;
21  }
22 
23  /** Open a csf file for reading
24  * @param file_location File location of the csf file
25  */
26  CsfReader(StringView file_location) {
27  this->ptr_ = tof_csf_reader_new(file_location, TOF_ERROR_HANDLER{});
28  }
29 
30  /** Read the next data frame from disk
31  * @return A data frame
32  */
34  Data new_data(static_cast<tof_data_t>(nullptr));
35  auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
36  *ptr = tof_csf_reader_read_frame(this->ptr_, TOF_ERROR_HANDLER{});
37  return new_data;
38  }
39 
40  /** Read the next data frame from disk into the supplied pointer
41  * @param pointer The pointer to the data to write into
42  * @param capacity The amount of data the pointer can hold
43  * @param callback Callback that will be called when pointer is no longer in
44  * use
45  * @return A data frame
46  */
47  Data read_frame_into_pointer(uint8_t* pointer, size_t capacity, user_pointer_destructed_fn &callback) {
48  Data new_data(static_cast<tof_data_t>(nullptr));
49  auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
50  *ptr = tof_csf_reader_read_frame_into_pointer(this->ptr_, pointer, capacity, user_pointer_destructed_cb_handler, &callback, TOF_ERROR_HANDLER{});
51  return new_data;
52  }
53 
54  /** Read the next data frame from disk into the supplied pointer
55  * @param pointer The pointer to the data to write into
56  * @param capacity The amount of data the pointer can hold
57  * @param callback Callback that will be called when pointer is no longer in
58  * use
59  * @param callback_user_data User data that will be passed back when the function pointer is called
60  * @return A data frame
61  */
62  Data read_frame_into_pointer(uint8_t* pointer, size_t capacity, tof_user_pointer_destructed_t callback, void* callback_user_data) {
63  Data new_data(static_cast<tof_data_t>(nullptr));
64  auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
65  *ptr = tof_csf_reader_read_frame_into_pointer(this->ptr_, pointer, capacity, callback, callback_user_data, TOF_ERROR_HANDLER{});
66  return new_data;
67  }
68 
69  /** Get the total number of frames in the csf file
70  * @return Total number of frames in the csf file
71  */
72  size_t number_of_frames() const {
73  return tof_csf_reader_number_of_frames(this->ptr_, TOF_ERROR_HANDLER{});
74  }
75 
76  /** Returns an empty Data class containing the header information for the
77  * specified frame
78  * @param index Which frame to get the header from
79  * @return Empty Data instance containing header information
80  */
81  Data get_header(size_t index) const {
82  Data new_data(static_cast<tof_data_t>(nullptr));
83  auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
84  *ptr = tof_csf_reader_get_header(this->ptr_, index, TOF_ERROR_HANDLER{});
85  return new_data;
86  }
87 
88  /** Get the stream information of the next frame
89  * @return Information on the next frame
90  */
91  Stream next_stream() const {
92  Stream new_stream(static_cast<tof_stream_t>(nullptr));
93  auto ptr = reinterpret_cast<tof_stream_t*>(&new_stream);
94  *ptr = tof_csf_reader_next_stream(this->ptr_, TOF_ERROR_HANDLER{});
95  return new_stream;
96  }
97 
98  /** Get the size of the next frame
99  * @return Size of the next frame
100  */
101  size_t next_frame_size() const {
102  return tof_csf_reader_next_frame_size(this->ptr_, TOF_ERROR_HANDLER{});
103  }
104 
105  /** Get the current frame position
106  * @return Frame index
107  */
108  size_t frame_index() const {
109  return tof_csf_reader_frame_index(this->ptr_, TOF_ERROR_HANDLER{});
110  }
111 
112  /** Go to specified frame
113  * @param index The index of the frame to jump to
114  */
115  void go_to_frame(size_t index) {
116  return tof_csf_reader_go_to_frame(this->ptr_, index, TOF_ERROR_HANDLER{});
117  }
118 
119  /** Get the streams that are in the csf file
120  * @return Streams in the csf file
121  */
122  std::vector<Stream> streams() const {
123  size_t size = tof_csf_reader_streams(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
124  std::vector<Stream> vec;
125  vec.reserve(size);
126  for (size_t i = 0; i < size; i++)
127  vec.emplace_back(static_cast<tof_stream_t>(nullptr));
128  auto data = reinterpret_cast<tof_stream_t*>(vec.data());
129  size = tof_csf_reader_streams(this->ptr_, data, vec.size(), TOF_ERROR_HANDLER{});
130  return vec;
131  }
132 
133  /** Get the number of frames contained in the file of the given stream
134  * @param stream The stream
135  * @return Number of frames for given stream
136  */
137  size_t stream_count(Stream &stream) const {
138  return tof_csf_reader_stream_count(this->ptr_, *reinterpret_cast<tof_stream_t*>(&stream), TOF_ERROR_HANDLER{});
139  }
140 
141  /** Go to the specified stream, the next read frame call will start from here
142  * @param stream The stream
143  * @param index The frame index
144  */
145  void go_to_stream(Stream &stream, size_t index) {
146  return tof_csf_reader_go_to_stream(this->ptr_, *reinterpret_cast<tof_stream_t*>(&stream), index, TOF_ERROR_HANDLER{});
147  }
148 
149  /** Get calibration from the csf file
150  * @return Calibration
151  */
153  Calibration new_calibration(static_cast<tof_calibration_t>(nullptr));
154  auto ptr = reinterpret_cast<tof_calibration_t*>(&new_calibration);
155  *ptr = tof_csf_reader_get_calibration(this->ptr_, TOF_ERROR_HANDLER{});
156  return new_calibration;
157  }
158 
159  /** Get camera config from the csf file
160  * @return Camera config
161  */
163  CameraConfig new_camera_config(static_cast<tof_camera_config_t>(nullptr));
164  auto ptr = reinterpret_cast<tof_camera_config_t*>(&new_camera_config);
165  *ptr = tof_csf_reader_get_camera_config(this->ptr_, TOF_ERROR_HANDLER{});
166  return new_camera_config;
167  }
168 
169 };
170 
171 } // tof
172 } // chronoptics
173 
174 #endif
This class contains all the calibration information.
Definition: calibration.hpp:13
This class allows you to view/edit the camera settings.
This class reads csf files.
Definition: csf_reader.hpp:16
size_t frame_index() const
Get the current frame position.
Definition: csf_reader.hpp:108
CsfReader(StringView file_location)
Open a csf file for reading.
Definition: csf_reader.hpp:26
CsfReader(tof_csf_reader_t ptr=nullptr)
Construct from pointer.
Definition: csf_reader.hpp:19
size_t stream_count(Stream &stream) const
Get the number of frames contained in the file of the given stream.
Definition: csf_reader.hpp:137
std::vector< Stream > streams() const
Get the streams that are in the csf file.
Definition: csf_reader.hpp:122
size_t next_frame_size() const
Get the size of the next frame.
Definition: csf_reader.hpp:101
void go_to_stream(Stream &stream, size_t index)
Go to the specified stream, the next read frame call will start from here.
Definition: csf_reader.hpp:145
Data read_frame_into_pointer(uint8_t *pointer, size_t capacity, user_pointer_destructed_fn &callback)
Read the next data frame from disk into the supplied pointer.
Definition: csf_reader.hpp:47
size_t number_of_frames() const
Get the total number of frames in the csf file.
Definition: csf_reader.hpp:72
CameraConfig get_camera_config() const
Get camera config from the csf file.
Definition: csf_reader.hpp:162
Data get_header(size_t index) const
Returns an empty Data class containing the header information for the specified frame.
Definition: csf_reader.hpp:81
Data read_frame()
Read the next data frame from disk.
Definition: csf_reader.hpp:33
Stream next_stream() const
Get the stream information of the next frame.
Definition: csf_reader.hpp:91
Calibration get_calibration() const
Get calibration from the csf file.
Definition: csf_reader.hpp:152
Data read_frame_into_pointer(uint8_t *pointer, size_t capacity, tof_user_pointer_destructed_t callback, void *callback_user_data)
Read the next data frame from disk into the supplied pointer.
Definition: csf_reader.hpp:62
void go_to_frame(size_t index)
Go to specified frame.
Definition: csf_reader.hpp:115
This is the class that contains depth or image data.
Definition: data.hpp:31
This class describes the different data streams coming from the camera.
Definition: stream.hpp:40