transform.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 namespace cartographer {
20 namespace transform {
21 
22 Rigid2d ToRigid2(const proto::Rigid2d& transform) {
23  return Rigid2d({transform.translation().x(), transform.translation().y()},
24  transform.rotation());
25 }
26 
27 Eigen::Vector2d ToEigen(const proto::Vector2d& vector) {
28  return Eigen::Vector2d(vector.x(), vector.y());
29 }
30 
31 Eigen::Vector3f ToEigen(const proto::Vector3f& vector) {
32  return Eigen::Vector3f(vector.x(), vector.y(), vector.z());
33 }
34 
35 Eigen::Vector4f ToEigen(const proto::Vector4f& vector) {
36  return Eigen::Vector4f(vector.x(), vector.y(), vector.z(), vector.t());
37 }
38 
39 Eigen::Vector3d ToEigen(const proto::Vector3d& vector) {
40  return Eigen::Vector3d(vector.x(), vector.y(), vector.z());
41 }
42 
43 Eigen::Quaterniond ToEigen(const proto::Quaterniond& quaternion) {
44  return Eigen::Quaterniond(quaternion.w(), quaternion.x(), quaternion.y(),
45  quaternion.z());
46 }
47 
49  proto::Rigid2d proto;
50  proto.mutable_translation()->set_x(transform.translation().x());
51  proto.mutable_translation()->set_y(transform.translation().y());
52  proto.set_rotation(transform.rotation().angle());
53  return proto;
54 }
55 
57  proto::Rigid2f proto;
58  proto.mutable_translation()->set_x(transform.translation().x());
59  proto.mutable_translation()->set_y(transform.translation().y());
60  proto.set_rotation(transform.rotation().angle());
61  return proto;
62 }
63 
65  proto::Rigid3d proto;
66  *proto.mutable_translation() = ToProto(rigid.translation());
67  *proto.mutable_rotation() = ToProto(rigid.rotation());
68  return proto;
69 }
70 
72  return transform::Rigid3d(ToEigen(rigid.translation()),
73  ToEigen(rigid.rotation()));
74 }
75 
77  proto::Rigid3f proto;
78  *proto.mutable_translation() = ToProto(rigid.translation());
79  *proto.mutable_rotation() = ToProto(rigid.rotation());
80  return proto;
81 }
82 
83 proto::Vector2d ToProto(const Eigen::Vector2d& vector) {
84  proto::Vector2d proto;
85  proto.set_x(vector.x());
86  proto.set_y(vector.y());
87  return proto;
88 }
89 
90 proto::Vector3f ToProto(const Eigen::Vector3f& vector) {
91  proto::Vector3f proto;
92  proto.set_x(vector.x());
93  proto.set_y(vector.y());
94  proto.set_z(vector.z());
95  return proto;
96 }
97 
98 proto::Vector4f ToProto(const Eigen::Vector4f& vector) {
99  proto::Vector4f proto;
100  proto.set_x(vector.x());
101  proto.set_y(vector.y());
102  proto.set_z(vector.z());
103  proto.set_t(vector.w());
104  return proto;
105 }
106 
107 proto::Vector3d ToProto(const Eigen::Vector3d& vector) {
108  proto::Vector3d proto;
109  proto.set_x(vector.x());
110  proto.set_y(vector.y());
111  proto.set_z(vector.z());
112  return proto;
113 }
114 
115 proto::Quaternionf ToProto(const Eigen::Quaternionf& quaternion) {
116  proto::Quaternionf proto;
117  proto.set_w(quaternion.w());
118  proto.set_x(quaternion.x());
119  proto.set_y(quaternion.y());
120  proto.set_z(quaternion.z());
121  return proto;
122 }
123 
124 proto::Quaterniond ToProto(const Eigen::Quaterniond& quaternion) {
125  proto::Quaterniond proto;
126  proto.set_w(quaternion.w());
127  proto.set_x(quaternion.x());
128  proto.set_y(quaternion.y());
129  proto.set_z(quaternion.z());
130  return proto;
131 }
132 
133 } // namespace transform
134 } // namespace cartographer
Rigid3< double > Rigid3d
Rigid2d ToRigid2(const proto::Rigid2d &transform)
Definition: transform.cc:22
transform::Rigid3d ToRigid3(const proto::Rigid3d &rigid)
Definition: transform.cc:71
const Quaternion & rotation() const
Rigid2< double > Rigid2d
proto::Rigid2d ToProto(const transform::Rigid2d &transform)
Definition: transform.cc:48
const Vector & translation() const
const Vector & translation() const
Eigen::Transform< T, 2, Eigen::Affine > ToEigen(const Rigid2< T > &rigid2)


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