Apollo 10.0
自动驾驶开放平台
base_map_node_index.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 "cyber/common/log.h"
20
21namespace apollo {
22namespace localization {
23namespace msf {
24
26
27bool MapNodeIndex::operator<(const MapNodeIndex& index) const {
28 // Compare elements by priority.
29 return std::forward_as_tuple(resolution_id_, zone_id_, m_, n_) <
30 std::forward_as_tuple(index.resolution_id_, index.zone_id_, index.m_,
31 index.n_);
32}
33
34bool MapNodeIndex::operator==(const MapNodeIndex& index) const {
35 return resolution_id_ == index.resolution_id_ && zone_id_ == index.zone_id_ &&
36 m_ == index.m_ && n_ == index.n_;
37}
38
39bool MapNodeIndex::operator!=(const MapNodeIndex& index) const {
40 return !(*this == index);
41}
42
43std::string MapNodeIndex::ToString() const {
44 std::ostringstream ss;
45 ss << "Map node (Resolution ID: " << resolution_id_
46 << " Zone ID: " << zone_id_ << " Easting: " << n_ << " Northing: " << m_
47 << ")";
48 return ss.str();
49}
50
52 const Eigen::Vector3d& coordinate,
53 unsigned int resolution_id,
54 int zone_id) {
55 Eigen::Vector2d coord2d(coordinate[0], coordinate[1]);
56 return GetMapNodeIndex(option, coord2d, resolution_id, zone_id);
57}
58
60 const Eigen::Vector2d& coordinate,
61 unsigned int resolution_id,
62 int zone_id) {
63 DCHECK_LT(resolution_id, option.map_resolutions_.size());
64 MapNodeIndex index;
65 index.resolution_id_ = resolution_id;
66 index.zone_id_ = zone_id;
67 int n = static_cast<int>((coordinate[0] - option.map_range_.GetMinX()) /
68 (static_cast<float>(option.map_node_size_x_) *
69 option.map_resolutions_[resolution_id]));
70 int m = static_cast<int>((coordinate[1] - option.map_range_.GetMinY()) /
71 (static_cast<float>(option.map_node_size_y_) *
72 option.map_resolutions_[resolution_id]));
73 if (n >= 0 && m >= 0 &&
74 n < static_cast<int>(GetMapIndexRangeEast(option, resolution_id)) &&
75 m < static_cast<int>(GetMapIndexRangeNorth(option, resolution_id))) {
76 index.m_ = m;
77 index.n_ = n;
78 } else {
79 DCHECK(false); // should never reach here
80 }
81 return index;
82}
83
85 unsigned int resolution_id) {
86 return static_cast<unsigned int>(
87 (option.map_range_.GetMaxX() - option.map_range_.GetMinX()) /
88 (static_cast<float>(option.map_node_size_x_) *
89 option.map_resolutions_[resolution_id]));
90}
91
93 unsigned int resolution_id) {
94 return static_cast<unsigned int>(
95 (option.map_range_.GetMaxY() - option.map_range_.GetMinY()) /
96 (static_cast<float>(option.map_node_size_y_) *
97 option.map_resolutions_[resolution_id]));
98}
99
100std::ostream& operator<<(std::ostream& cerr, const MapNodeIndex& index) {
101 cerr << index.ToString();
102 return cerr;
103}
104
105} // namespace msf
106} // namespace localization
107} // namespace apollo
The options of the reflectance map.
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_y_
The map node size in pixels.
unsigned int map_node_size_x_
The map node size in pixels.
bool operator!=(const MapNodeIndex &index) const
Overload the unequal operator.
unsigned int m_
The map node ID at the northing direction.
unsigned int n_
The map node ID at the easting direction.
bool operator<(const MapNodeIndex &index) const
Overload the less than operator.
static unsigned int GetMapIndexRangeNorth(const BaseMapConfig &option, unsigned int resolution_id)
Get the index range (maximum possible index + 1) in the north direction.
bool operator==(const MapNodeIndex &index) const
Overload the equal operator.
static unsigned int GetMapIndexRangeEast(const BaseMapConfig &option, unsigned int resolution_id)
Get the index range (maximum possible index + 1) in the east direction.
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.
unsigned int resolution_id_
The ID of the resolution.
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
std::ostream & operator<<(std::ostream &cerr, const MapNodeIndex &index)
class register implement
Definition arena_queue.h:37