relations_text_file.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "cartographer/ground_truth/relations_text_file.h"
00018 
00019 #include <fstream>
00020 
00021 #include "cartographer/common/time.h"
00022 #include "cartographer/transform/rigid_transform.h"
00023 #include "cartographer/transform/transform.h"
00024 #include "glog/logging.h"
00025 
00026 namespace cartographer {
00027 namespace ground_truth {
00028 
00029 namespace {
00030 
00031 common::Time UnixToCommonTime(double unix_time) {
00032   constexpr int64 kUtsTicksPerSecond = 10000000;
00033   return common::FromUniversal(common::kUtsEpochOffsetFromUnixEpochInSeconds *
00034                                kUtsTicksPerSecond) +
00035          common::FromSeconds(unix_time);
00036 }
00037 
00038 }  // namespace
00039 
00040 proto::GroundTruth ReadRelationsTextFile(
00041     const std::string& relations_filename) {
00042   proto::GroundTruth ground_truth;
00043   std::ifstream relations_stream(relations_filename.c_str());
00044   double unix_time_1, unix_time_2, x, y, z, roll, pitch, yaw;
00045   while (relations_stream >> unix_time_1 >> unix_time_2 >> x >> y >> z >>
00046          roll >> pitch >> yaw) {
00047     const common::Time common_time_1 = UnixToCommonTime(unix_time_1);
00048     const common::Time common_time_2 = UnixToCommonTime(unix_time_2);
00049     const transform::Rigid3d expected =
00050         transform::Rigid3d(transform::Rigid3d::Vector(x, y, z),
00051                            transform::RollPitchYaw(roll, pitch, yaw));
00052     auto* const new_relation = ground_truth.add_relation();
00053     new_relation->set_timestamp1(common::ToUniversal(common_time_1));
00054     new_relation->set_timestamp2(common::ToUniversal(common_time_2));
00055     *new_relation->mutable_expected() = transform::ToProto(expected);
00056   }
00057   CHECK(relations_stream.eof());
00058   return ground_truth;
00059 }
00060 
00061 }  // namespace ground_truth
00062 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35