ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
DemoDopplerICPSequence.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <IJsonConvertible.h>
9 #include <Logging.h>
10 #include <json/json.h>
11 
12 #include <Eigen/Geometry>
13 #include <fstream>
14 #include <iomanip>
15 #include <sstream>
16 #include <string>
17 #include <vector>
18 
20 
21 namespace cloudViewer {
22 namespace data {
23 
24 namespace {
25 
26 bool ReadJSONFromFile(const std::string& path, Json::Value& json) {
27  std::ifstream file(path);
28  if (!file.is_open()) {
29  utility::LogWarning("Failed to open: {}", path);
30  return false;
31  }
32 
33  Json::CharReaderBuilder builder;
34  builder["collectComments"] = false;
35  Json::String errs;
36  bool is_parse_successful = parseFromStream(builder, file, &json, &errs);
37  if (!is_parse_successful) {
38  utility::LogWarning("Read JSON failed: {}.", errs);
39  return false;
40  }
41  return true;
42 }
43 
44 std::vector<std::pair<double, Eigen::Matrix4d>> LoadTUMTrajectory(
45  const std::string& filename) {
46  std::vector<std::pair<double, Eigen::Matrix4d>> trajectory;
47 
48  std::ifstream file(filename);
49  if (!file.is_open()) {
50  utility::LogError("Failed to open: {}", filename);
51  }
52 
53  std::string line;
54  while (std::getline(file, line)) {
55  std::istringstream iss(line);
56  double timestamp, x, y, z, qx, qy, qz, qw;
57  if (!(iss >> timestamp >> x >> y >> z >> qx >> qy >> qz >> qw)) {
58  utility::LogError("Error parsing line: {}", line);
59  }
60 
61  Eigen::Affine3d transform = Eigen::Affine3d::Identity();
62  transform.translate(Eigen::Vector3d(x, y, z));
63  transform.rotate(Eigen::Quaterniond(qw, qx, qy, qz));
64 
65  trajectory.emplace_back(timestamp, transform.matrix());
66  }
67 
68  return trajectory;
69 }
70 
71 } // namespace
72 
75  "doppler-icp-data/carla-town05-curved-walls.zip",
76  "73a9828fb7790481168124c02398ee01"};
77 
79  : DownloadDataset("DemoDopplerICPSequence", data_descriptor, data_root) {
80  for (int i = 1; i <= 100; ++i) {
81  std::stringstream ss;
82  ss << std::setw(5) << std::setfill('0') << i;
83  paths_.push_back(GetExtractDir() + "/xyzd_sequence/" + ss.str() +
84  ".xyzd");
85  }
86 
87  calibration_path_ = GetExtractDir() + "/calibration.json";
88  trajectory_path_ = GetExtractDir() + "/ground_truth_poses.txt";
89 }
90 
91 std::string DemoDopplerICPSequence::GetPath(std::size_t index) const {
92  if (index > 99) {
94  "Invalid index. Expected index between 0 to 99 but got {}.",
95  index);
96  }
97  return paths_[index];
98 }
99 
100 bool DemoDopplerICPSequence::GetCalibration(Eigen::Matrix4d& calibration,
101  double& period) const {
102  Json::Value calibration_data;
103  Eigen::Matrix4d calibration_temp;
104  if (ReadJSONFromFile(calibration_path_, calibration_data) &&
106  calibration_temp,
107  calibration_data["transform_vehicle_to_sensor"])) {
108  calibration = calibration_temp.transpose();
109  period = calibration_data["period"].asDouble();
110  return true;
111  }
112  return false;
113 }
114 
115 std::vector<std::pair<double, Eigen::Matrix4d>>
117  return LoadTUMTrajectory(trajectory_path_);
118 }
119 
120 } // namespace data
121 } // namespace cloudViewer
std::string filename
const std::string GetExtractDir() const
Get absolute path to extract directory. i.e. ${data_root}/extract/${prefix}.
Definition: Dataset.h:94
DemoDopplerICPSequence(const std::string &data_root="")
std::string GetPath(std::size_t index) const
Path to the point cloud at index.
std::vector< std::pair< double, Eigen::Matrix4d > > GetTrajectory() const
Returns a list of (timestamp, pose) representing the ground truth trajectory of the sequence.
bool GetCalibration(Eigen::Matrix4d &calibration, double &period) const
Returns the vehicle to sensor calibration transformation and the time period (in secs) between sequen...
Dataset class with one or more downloaded file.
Definition: Dataset.h:152
static bool EigenMatrix4dFromJsonArray(Eigen::Matrix4d &mat, const Json::Value &value)
#define LogWarning(...)
Definition: Logging.h:72
#define LogError(...)
Definition: Logging.h:60
std::string CloudViewerDownloadsPrefix()
Definition: Dataset.cpp:49
static const DataDescriptor data_descriptor
static const std::string path
Definition: PointCloud.cpp:59
Generic file read and write utility for python interface.
Infomation about a file to be downloaded.
Definition: Dataset.h:111