map_limits.h
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 
17 #ifndef CARTOGRAPHER_MAPPING_2D_MAP_LIMITS_H_
18 #define CARTOGRAPHER_MAPPING_2D_MAP_LIMITS_H_
19 
20 #include <utility>
21 #include <vector>
22 
23 #include "Eigen/Core"
24 #include "Eigen/Geometry"
27 #include "cartographer/mapping/proto/2d/map_limits.pb.h"
33 #include "glog/logging.h"
34 
35 namespace cartographer {
36 namespace mapping {
37 
38 // Defines the limits of a grid map. This class must remain inlined for
39 // performance reasons.
40 class MapLimits {
41  public:
42  MapLimits(const double resolution, const Eigen::Vector2d& max,
43  const CellLimits& cell_limits)
44  : resolution_(resolution), max_(max), cell_limits_(cell_limits) {
45  CHECK_GT(resolution_, 0.);
46  CHECK_GT(cell_limits.num_x_cells, 0.);
47  CHECK_GT(cell_limits.num_y_cells, 0.);
48  }
49 
50  explicit MapLimits(const proto::MapLimits& map_limits)
51  : resolution_(map_limits.resolution()),
52  max_(transform::ToEigen(map_limits.max())),
53  cell_limits_(map_limits.cell_limits()) {}
54 
55  // Returns the cell size in meters. All cells are square and the resolution is
56  // the length of one side.
57  double resolution() const { return resolution_; }
58 
59  // Returns the corner of the limits, i.e., all pixels have positions with
60  // smaller coordinates.
61  const Eigen::Vector2d& max() const { return max_; }
62 
63  // Returns the limits of the grid in number of cells.
64  const CellLimits& cell_limits() const { return cell_limits_; }
65 
66  // Returns the index of the cell containing the 'point' which may be outside
67  // the map, i.e., negative or too large indices that will return false for
68  // Contains().
69  Eigen::Array2i GetCellIndex(const Eigen::Vector2f& point) const {
70  // Index values are row major and the top left has Eigen::Array2i::Zero()
71  // and contains (centered_max_x, centered_max_y). We need to flip and
72  // rotate.
73  return Eigen::Array2i(
74  common::RoundToInt((max_.y() - point.y()) / resolution_ - 0.5),
75  common::RoundToInt((max_.x() - point.x()) / resolution_ - 0.5));
76  }
77 
78  // Returns true if the ProbabilityGrid contains 'cell_index'.
79  bool Contains(const Eigen::Array2i& cell_index) const {
80  return (Eigen::Array2i(0, 0) <= cell_index).all() &&
81  (cell_index <
83  .all();
84  }
85 
86  private:
87  double resolution_;
88  Eigen::Vector2d max_;
90 };
91 
92 inline proto::MapLimits ToProto(const MapLimits& map_limits) {
93  proto::MapLimits result;
94  result.set_resolution(map_limits.resolution());
95  *result.mutable_max() = transform::ToProto(map_limits.max());
96  *result.mutable_cell_limits() = ToProto(map_limits.cell_limits());
97  return result;
98 }
99 
100 } // namespace mapping
101 } // namespace cartographer
102 
103 #endif // CARTOGRAPHER_MAPPING_2D_MAP_LIMITS_H_
const Eigen::Vector2d & max() const
Definition: map_limits.h:61
MapLimits(const double resolution, const Eigen::Vector2d &max, const CellLimits &cell_limits)
Definition: map_limits.h:42
int RoundToInt(const float x)
Definition: port.h:41
proto::Rigid2d ToProto(const transform::Rigid2d &transform)
Definition: transform.cc:48
bool Contains(const Eigen::Array2i &cell_index) const
Definition: map_limits.h:79
Eigen::Array2i GetCellIndex(const Eigen::Vector2f &point) const
Definition: map_limits.h:69
proto::MapLimits ToProto(const MapLimits &map_limits)
Definition: map_limits.h:92
Eigen::Transform< T, 2, Eigen::Affine > ToEigen(const Rigid2< T > &rigid2)
const CellLimits & cell_limits() const
Definition: map_limits.h:64
MapLimits(const proto::MapLimits &map_limits)
Definition: map_limits.h:50


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