relations_text_file.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include <fstream>
20 
24 #include "glog/logging.h"
25 
26 namespace cartographer {
27 namespace ground_truth {
28 
29 namespace {
30 
31 common::Time UnixToCommonTime(double unix_time) {
32  constexpr int64 kUtsTicksPerSecond = 10000000;
34  kUtsTicksPerSecond) +
35  common::FromSeconds(unix_time);
36 }
37 
38 } // namespace
39 
40 proto::GroundTruth ReadRelationsTextFile(
41  const std::string& relations_filename) {
42  proto::GroundTruth ground_truth;
43  std::ifstream relations_stream(relations_filename.c_str());
44  double unix_time_1, unix_time_2, x, y, z, roll, pitch, yaw;
45  while (relations_stream >> unix_time_1 >> unix_time_2 >> x >> y >> z >>
46  roll >> pitch >> yaw) {
47  const common::Time common_time_1 = UnixToCommonTime(unix_time_1);
48  const common::Time common_time_2 = UnixToCommonTime(unix_time_2);
49  const transform::Rigid3d expected =
51  transform::RollPitchYaw(roll, pitch, yaw));
52  auto* const new_relation = ground_truth.add_relation();
53  new_relation->set_timestamp1(common::ToUniversal(common_time_1));
54  new_relation->set_timestamp2(common::ToUniversal(common_time_2));
55  *new_relation->mutable_expected() = transform::ToProto(expected);
56  }
57  CHECK(relations_stream.eof());
58  return ground_truth;
59 }
60 
61 } // namespace ground_truth
62 } // namespace cartographer
Rigid3< double > Rigid3d
proto::GroundTruth ReadRelationsTextFile(const std::string &relations_filename)
constexpr int64 kUtsEpochOffsetFromUnixEpochInSeconds
Definition: time.h:29
int64_t int64
Definition: port.h:33
UniversalTimeScaleClock::time_point Time
Definition: time.h:44
Time FromUniversal(const int64 ticks)
Definition: time.cc:34
proto::Rigid2d ToProto(const transform::Rigid2d &transform)
Definition: transform.cc:48
Duration FromSeconds(const double seconds)
Definition: time.cc:24
int64 ToUniversal(const Time time)
Definition: time.cc:36
Eigen::Quaterniond RollPitchYaw(const double roll, const double pitch, const double yaw)
Eigen::Matrix< double, 3, 1 > Vector


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58