supereight
reader_base.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2014 University of Edinburgh, Imperial College London, University of Manchester
3  * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
4  * SPDX-FileCopyrightText: 2020-2022 Smart Robotics Lab, Imperial College London, Technical University of Munich
5  * SPDX-FileCopyrightText: 2020-2022 Nils Funk
6  * SPDX-FileCopyrightText: 2020-2022 Sotiris Papatheodorou
7  * SPDX-License-Identifier: MIT
8  */
9 
10 #ifndef __READER_BASE_HPP
11 #define __READER_BASE_HPP
12 
13 #include <Eigen/Dense>
14 #include <chrono>
15 #include <cstdint>
16 #include <fstream>
17 #include <string>
18 
19 #include "se/common/str_utils.hpp"
20 #include "se/image/image.hpp"
21 
22 
23 
24 namespace se {
25 
26 enum class ReaderType {
28  OPENNI,
30  RAW,
32  TUM,
37  UNKNOWN
38 };
39 
40 ReaderType string_to_reader_type(const std::string& s);
41 
42 std::string reader_type_to_string(ReaderType t);
43 
44 
45 
46 struct ReaderConfig {
50 
54  std::string sequence_path;
55 
58  std::string ground_truth_file;
59 
65  float inverse_scale = 0.0f;
66 
73  float fps = 0.0f;
74 
85  bool drop_frames = false;
86 
91  int verbose = 0;
92 
96  void readYaml(const std::string& filename);
97 };
98 
99 std::ostream& operator<<(std::ostream& os, const ReaderConfig& c);
100 
101 
102 
105 enum class ReaderStatus : int {
107  ok = 0,
111  skip,
113  eof,
117  error,
118 };
119 
120 std::ostream& operator<<(std::ostream& os, const ReaderStatus& s);
121 
122 
123 
139 class Reader {
140  public:
148  Reader(const ReaderConfig& c);
149 
150  virtual ~Reader(){};
151 
159  ReaderStatus nextData(Image<float>& depth_image);
160 
169  ReaderStatus nextData(Image<float>& depth_image, Image<uint32_t>& rgba_image);
170 
181  nextData(Image<float>& depth_image, Image<uint32_t>& rgba_image, Eigen::Matrix4f& T_WB);
182 
193  ReaderStatus getPose(Eigen::Matrix4f& T_WB, const size_t frame);
194 
202  virtual void restart() = 0;
203 
208  virtual std::string name() const = 0;
209 
216  bool good() const;
217 
225  size_t frame() const;
226 
232  size_t numFrames() const;
233 
238  Eigen::Vector2i depthImageRes() const;
239 
244  Eigen::Vector2i RGBAImageRes() const;
245 
250  bool isLiveReader() const;
251 
258  static ReaderStatus mergeStatus(ReaderStatus status_1, ReaderStatus status_2);
259 
260  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
261 
262  protected:
263  std::string sequence_path_;
264  std::string ground_truth_file_;
265  std::ifstream ground_truth_fs_;
266  Eigen::Vector2i depth_image_res_;
267  Eigen::Vector2i rgba_image_res_;
268  float fps_;
269  double spf_;
271  int verbose_;
278  size_t frame_;
279  size_t num_frames_;
280 
281 
296  ReaderStatus readPose(Eigen::Matrix4f& T_WB, const size_t frame, const char delimiter = ' ');
297 
298 
310  ReaderStatus nextPose(Eigen::Matrix4f& T_WB);
311 
312  private:
313  size_t ground_truth_frame_;
314  char ground_truth_delimiter_;
315  std::chrono::steady_clock::time_point prev_frame_timestamp_;
316 
323  void nextFrame();
324 
330  virtual ReaderStatus nextDepth(Image<float>& depth_image) = 0;
331 
337  virtual ReaderStatus nextRGBA(Image<uint32_t>& rgba_image) = 0;
338 };
339 
340 } // namespace se
341 
346 static std::ostream& operator<<(std::ostream& out, se::Reader* reader)
347 {
348  out << se::str_utils::header_to_pretty_str("READER") << "\n";
349  out << se::str_utils::str_to_pretty_str(reader->name(), "Reader type") << "\n";
351  ((reader->numFrames() == 0) ? "Unknown" : std::to_string(reader->numFrames())),
352  "Number frames")
353  << "\n";
354  out << "\n";
355  return out;
356 }
357 
358 
359 #endif
Use the se::OpenNIReader.
Definition: reader_base.hpp:46
virtual ~Reader()
Definition: reader_base.hpp:150
size_t num_frames_
Definition: reader_base.hpp:279
Base abstract class for dataset readers.
Definition: reader_base.hpp:139
Data read successfully.
std::string sequence_path
The path to the dataset.
Definition: reader_base.hpp:54
std::ifstream ground_truth_fs_
Definition: reader_base.hpp:265
std::ostream & operator<<(std::ostream &os, const FieldDataConfig< se::Field::Occupancy > &c)
Use the se::RAWReader.
ReaderStatus
The result of trying to read a depth/RGB image or a pose.
Definition: reader_base.hpp:105
double spf_
Definition: reader_base.hpp:269
Temporary data read error.
bool drop_frames_
Definition: reader_base.hpp:270
Eigen::Vector2i depth_image_res_
Definition: reader_base.hpp:266
Fatal data read error.
std::string sequence_path_
Definition: reader_base.hpp:263
virtual std::string name() const =0
The name of the reader.
Use the se::InteriorNetReader.
std::string reader_type_to_string(ReaderType t)
Use the se::TUMReader.
bool is_live_reader_
Definition: reader_base.hpp:272
Use the se::NewerCollegeReader.
std::string header_to_pretty_str(const std::string &header_name, const int width=default_width)
Convert header name to a standardised string output.
End of dataset reached.
ReaderStatus status_
Definition: reader_base.hpp:273
float fps_
Definition: reader_base.hpp:268
std::string str_to_pretty_str(const std::string &string, const std::string &string_name="", const int width=default_width)
Convert a string name and value to a standardised string output.
int verbose_
Definition: reader_base.hpp:271
size_t numFrames() const
The total number of frames in the current dataset.
ReaderType
Definition: reader_base.hpp:26
std::string ground_truth_file
The path to the ground truth file.
Definition: reader_base.hpp:58
std::string ground_truth_file_
Definition: reader_base.hpp:264
Eigen::Vector2i rgba_image_res_
Definition: reader_base.hpp:267
Helper wrapper to allocate and de-allocate octants in the octree.
Definition: colour_utils.hpp:17
ReaderType string_to_reader_type(const std::string &s)
size_t frame_
The frame_ is initialized to SIZE_MAX, so that when first incremented it becomes 0.
Definition: reader_base.hpp:278