Apollo 11.0
自动驾驶开放平台
base_map_node_index.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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
18
19#include <iostream>
20#include <sstream>
21#include <string>
22
23namespace apollo {
24namespace localization {
25namespace msf {
26namespace pyramid_map {
27
30 zone_id_ = 50;
31 m_ = 0;
32 n_ = 0;
33}
34
35bool MapNodeIndex::operator<(const MapNodeIndex& index) const {
36 // Compare elements by priority.
37 return std::forward_as_tuple(resolution_id_, zone_id_, m_, n_) <
38 std::forward_as_tuple(index.resolution_id_, index.zone_id_, index.m_,
39 index.n_);
40}
41
42bool MapNodeIndex::operator==(const MapNodeIndex& index) const {
43 return resolution_id_ == index.resolution_id_ && zone_id_ == index.zone_id_ &&
44 m_ == index.m_ && n_ == index.n_;
45}
46
47bool MapNodeIndex::operator!=(const MapNodeIndex& index) const {
48 return !(*this == index);
49}
50
51std::string MapNodeIndex::ToString() const {
52 std::ostringstream ss;
53 ss << "Map node (Resolution ID: " << resolution_id_
54 << " Zone ID: " << zone_id_ << " Easting: " << n_ << " Northing: " << m_
55 << ")";
56 return ss.str();
57}
58
60 const Eigen::Vector3d& coordinate,
61 unsigned int resolution_id,
62 int zone_id) {
63 Vector2d coord2d(coordinate[0], coordinate[1]);
64 return GetMapNodeIndex(option, coord2d, resolution_id, zone_id);
65}
66
68 const Eigen::Vector2d& coordinate,
69 unsigned int resolution_id,
70 int zone_id) {
71 // assert(resolution_id < option.map_resolutions_.size());
72 MapNodeIndex index;
73 index.resolution_id_ = resolution_id;
74 index.zone_id_ = zone_id;
75 unsigned int n =
76 static_cast<int>((coordinate[0] - option.map_range_.GetMinX()) /
77 (static_cast<float>(option.map_node_size_x_) *
78 option.map_resolutions_[resolution_id]));
79 unsigned int m =
80 static_cast<int>((coordinate[1] - option.map_range_.GetMinY()) /
81 (static_cast<float>(option.map_node_size_y_) *
82 option.map_resolutions_[resolution_id]));
83 if (n < GetMapIndexRangeEast(option, resolution_id) &&
84 m < GetMapIndexRangeNorth(option, resolution_id)) {
85 index.m_ = m;
86 index.n_ = n;
87 } else {
88 std::cerr << "MapNodeIndex::get_map_node_index illegal n: " << n
89 << ",m: " << m << std::endl;
90 // assert(0 == 1); // should never reach here
91 }
92 return index;
93}
94
96 unsigned int resolution_id) {
97 return static_cast<unsigned int>(
98 (option.map_range_.GetMaxX() - option.map_range_.GetMinX()) /
99 (static_cast<float>(option.map_node_size_x_) *
100 option.map_resolutions_[resolution_id]));
101}
102
104 unsigned int resolution_id) {
105 return static_cast<unsigned int>(
106 (option.map_range_.GetMaxY() - option.map_range_.GetMinY()) /
107 (static_cast<float>(option.map_node_size_y_) *
108 option.map_resolutions_[resolution_id]));
109}
110
111std::ostream& operator<<(std::ostream& cerr, const MapNodeIndex& index) {
112 cerr << index.ToString();
113 return cerr;
114}
115
116} // namespace pyramid_map
117} // namespace msf
118} // namespace localization
119} // namespace apollo
T GetMaxY() const
Get the max y of the rectangle.
Definition rect2d.h:88
T GetMaxX() const
Get the max x of the rectangle.
Definition rect2d.h:83
T GetMinX() const
Get the min x of the rectangle.
Definition rect2d.h:73
T GetMinY() const
Get the min y of the rectangle.
Definition rect2d.h:78
unsigned int map_node_size_y_
The map node size in pixels.
std::vector< float > map_resolutions_
The pixel resolutions in the map in meters.
Rect2D< double > map_range_
The minimum and maximum UTM range in the map.
unsigned int map_node_size_x_
The map node size in pixels.
unsigned int m_
The map node ID at the northing direction.
bool operator<(const MapNodeIndex &index) const
Overload the less than operator.
static unsigned int GetMapIndexRangeEast(const BaseMapConfig &option, unsigned int resolution_id)
Get the index range (maximum possible index + 1) in the east direction.
bool operator!=(const MapNodeIndex &index) const
Overload the unequal operator.
unsigned int resolution_id_
The ID of the resolution.
unsigned int n_
The map node ID at the easting direction.
bool operator==(const MapNodeIndex &index) const
Overload the equal operator.
static MapNodeIndex GetMapNodeIndex(const BaseMapConfig &option, const Eigen::Vector3d &coordinate, unsigned int resolution_id, int zone_id)
Construct a map node index, given a global coordinate, eigen version.
static unsigned int GetMapIndexRangeNorth(const BaseMapConfig &option, unsigned int resolution_id)
Get the index range (maximum possible index + 1) in the north direction.
std::ostream & operator<<(std::ostream &cerr, const MapNodeIndex &index)
class register implement
Definition arena_queue.h:37