Apollo
11.0
自动驾驶开放平台
frame_transform.cc
浏览该文件的文档.
1
/******************************************************************************
2
* Copyright 2018 The Apollo Authors. All Rights Reserved.
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
17
#include "
modules/localization/msf/common/util/frame_transform.h
"
18
19
#include <string>
20
21
#include "absl/strings/str_cat.h"
22
23
namespace
apollo
{
24
namespace
localization {
25
namespace
msf {
26
27
bool
FrameTransform::LatlonToUtmXY
(
double
lon_rad,
double
lat_rad,
28
UTMCoor
*utm_xy) {
29
projPJ pj_latlon;
30
projPJ pj_utm;
31
int
zone = 0;
32
zone =
static_cast<
int
>
((lon_rad *
RAD_TO_DEG
+ 180) / 6) + 1;
33
std::string latlon_src =
34
"+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs"
;
35
std::string utm_dst =
36
absl::StrCat(
"+proj=utm +zone="
, zone,
" +ellps=GRS80 +units=m +no_defs"
);
37
if
(!(pj_latlon = pj_init_plus(latlon_src.c_str()))) {
38
return
false
;
39
}
40
if
(!(pj_utm = pj_init_plus(utm_dst.c_str()))) {
41
return
false
;
42
}
43
double
longitude = lon_rad;
44
double
latitude = lat_rad;
45
pj_transform(pj_latlon, pj_utm, 1, 1, &longitude, &latitude,
nullptr
);
46
utm_xy->
x
= longitude;
47
utm_xy->
y
= latitude;
48
pj_free(pj_latlon);
49
pj_free(pj_utm);
50
return
true
;
51
}
52
bool
FrameTransform::UtmXYToLatlon
(
double
x,
double
y,
int
zone,
bool
southhemi,
53
WGS84Corr
*latlon) {
54
projPJ pj_latlon;
55
projPJ pj_utm;
56
std::string latlon_src =
57
"+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs"
;
58
std::string utm_dst =
59
absl::StrCat(
"+proj=utm +zone="
, zone,
" +ellps=GRS80 +units=m +no_defs"
);
60
if
(!(pj_latlon = pj_init_plus(latlon_src.c_str()))) {
61
return
false
;
62
}
63
if
(!(pj_utm = pj_init_plus(utm_dst.c_str()))) {
64
return
false
;
65
}
66
pj_transform(pj_utm, pj_latlon, 1, 1, &x, &y,
nullptr
);
67
latlon->
log
= x;
68
latlon->
lat
= y;
69
pj_free(pj_latlon);
70
pj_free(pj_utm);
71
return
true
;
72
}
73
74
bool
FrameTransform::XYZToBlh
(
const
Vector3d
&xyz,
Vector3d
*blh) {
75
projPJ pj_xyz;
76
projPJ pj_blh;
77
std::string xyz_src =
"+proj=geocent +datum=WGS84"
;
78
std::string blh_dst =
"+proj=latlong +datum=WGS84"
;
79
if
(!(pj_xyz = pj_init_plus(xyz_src.c_str()))) {
80
return
false
;
81
}
82
if
(!(pj_blh = pj_init_plus(blh_dst.c_str()))) {
83
return
false
;
84
}
85
double
x = xyz[0];
86
double
y = xyz[1];
87
double
z = xyz[2];
88
pj_transform(pj_xyz, pj_blh, 1, 1, &x, &y, &z);
89
(*blh)[0] = x;
90
(*blh)[1] = y;
91
(*blh)[2] = z;
92
pj_free(pj_xyz);
93
pj_free(pj_blh);
94
return
true
;
95
}
96
bool
FrameTransform::BlhToXYZ
(
const
Vector3d
&blh,
Vector3d
*xyz) {
97
projPJ pj_xyz;
98
projPJ pj_blh;
99
std::string blh_src =
"+proj=latlong +datum=WGS84"
;
100
std::string xyz_dst =
"+proj=geocent +datum=WGS84"
;
101
102
if
(!(pj_blh = pj_init_plus(blh_src.c_str()))) {
103
return
false
;
104
}
105
if
(!(pj_xyz = pj_init_plus(xyz_dst.c_str()))) {
106
return
false
;
107
}
108
double
longitude = blh[0];
109
double
latitude = blh[1];
110
double
height = blh[2];
111
pj_transform(pj_blh, pj_xyz, 1, 1, &longitude, &latitude, &height);
112
(*xyz)[0] = longitude;
113
(*xyz)[1] = latitude;
114
(*xyz)[2] = height;
115
pj_free(pj_xyz);
116
pj_free(pj_blh);
117
return
true
;
118
}
119
120
}
// namespace msf
121
}
// namespace localization
122
}
// namespace apollo
apollo::localization::msf::FrameTransform::LatlonToUtmXY
static bool LatlonToUtmXY(double lon, double lat, UTMCoor *utm_xy)
Definition
frame_transform.cc:27
apollo::localization::msf::FrameTransform::UtmXYToLatlon
static bool UtmXYToLatlon(double x, double y, int zone, bool southhemi, WGS84Corr *latlon)
Definition
frame_transform.cc:52
apollo::localization::msf::FrameTransform::XYZToBlh
static bool XYZToBlh(const Vector3d &xyz, Vector3d *blh)
Definition
frame_transform.cc:74
apollo::localization::msf::FrameTransform::BlhToXYZ
static bool BlhToXYZ(const Vector3d &blh, Vector3d *xyz)
Definition
frame_transform.cc:96
frame_transform.h
RAD_TO_DEG
#define RAD_TO_DEG
Definition
lslidar_parser.h:66
apollo::localization::msf::Vector3d
Eigen::Vector3d Vector3d
Definition
frame_transform.h:27
apollo
class register implement
Definition
arena_queue.h:37
apollo::localization::msf::UTMCoor
the UTM coordinate struct including x and y.
Definition
frame_transform.h:30
apollo::localization::msf::UTMCoor::x
double x
Definition
frame_transform.h:32
apollo::localization::msf::UTMCoor::y
double y
Definition
frame_transform.h:33
apollo::localization::msf::WGS84Corr
the WGS84 coordinate struct
Definition
frame_transform.h:38
apollo::localization::msf::WGS84Corr::log
double log
Definition
frame_transform.h:40
apollo::localization::msf::WGS84Corr::lat
double lat
Definition
frame_transform.h:41
modules
localization
msf
common
util
frame_transform.cc