22 #ifndef OV_CORE_DATASET_READER_H
23 #define OV_CORE_DATASET_READER_H
25 #include <Eigen/Eigen>
62 static void load_gt_file(std::string path, std::map<
double, Eigen::Matrix<double, 17, 1>> >_states) {
76 std::exit(EXIT_FAILURE);
80 std::getline(file, line);
83 while (std::getline(file, line)) {
86 std::istringstream
s(line);
88 Eigen::Matrix<double, 17, 1> temp = Eigen::Matrix<double, 17, 1>::Zero();
90 while (getline(
s, field,
',')) {
95 std::exit(EXIT_FAILURE);
98 temp(i, 0) = std::atof(field.c_str());
102 gt_states.insert({1e-9 * temp(0, 0), temp});
114 static bool get_gt_state(
double timestep, Eigen::Matrix<double, 17, 1> &imustate,
115 std::map<
double, Eigen::Matrix<double, 17, 1>> >_states) {
118 if (gt_states.empty()) {
119 PRINT_ERROR(
RED "Groundtruth data loaded is empty, make sure you call load before asking for a state.\n" RESET);
124 double closest_time = INFINITY;
125 auto it0 = gt_states.begin();
126 while (it0 != gt_states.end()) {
127 if (std::abs(it0->first - timestep) < std::abs(closest_time - timestep)) {
128 closest_time = it0->first;
134 if (std::abs(closest_time - timestep) < 0.10) {
137 timestep = closest_time;
141 if (gt_states.find(timestep) == gt_states.end()) {
147 Eigen::Matrix<double, 17, 1> state = gt_states[timestep];
150 imustate(0, 0) = timestep;
151 imustate(1, 0) = state(5, 0);
152 imustate(2, 0) = state(6, 0);
153 imustate(3, 0) = state(7, 0);
154 imustate(4, 0) = state(4, 0);
155 imustate(5, 0) = state(1, 0);
156 imustate(6, 0) = state(2, 0);
157 imustate(7, 0) = state(3, 0);
158 imustate(8, 0) = state(8, 0);
159 imustate(9, 0) = state(9, 0);
160 imustate(10, 0) = state(10, 0);
161 imustate(11, 0) = state(11, 0);
162 imustate(12, 0) = state(12, 0);
163 imustate(13, 0) = state(13, 0);
164 imustate(14, 0) = state(14, 0);
165 imustate(15, 0) = state(15, 0);
166 imustate(16, 0) = state(16, 0);
185 std::exit(EXIT_FAILURE);
189 std::string base_filename = path.substr(path.find_last_of(
"/\\") + 1);
190 PRINT_DEBUG(
"loaded trajectory %s\n", base_filename.c_str());
193 std::string current_line;
194 while (std::getline(file, current_line)) {
197 if (!current_line.find(
"#"))
202 std::istringstream
s(current_line);
204 Eigen::Matrix<double, 8, 1> data;
207 while (std::getline(
s, field,
' ')) {
209 if (field.empty() || i >= data.rows())
212 data(i) = std::atof(field.c_str());
218 traj_data.push_back(data);
230 if (traj_data.empty()) {
233 std::exit(EXIT_FAILURE);