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_2d/proto/map_limits.pb.h"
33 #include "glog/logging.h"
34 
35 namespace cartographer {
36 namespace mapping_2d {
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 ('x', 'y') which may be
67  // outside the map, i.e., negative or too large indices that will return
68  // false for Contains().
69  Eigen::Array2i GetXYIndexOfCellContainingPoint(const double x,
70  const double y) const {
71  // Index values are row major and the top left has Eigen::Array2i::Zero()
72  // and contains (centered_max_x, centered_max_y). We need to flip and
73  // rotate.
74  return Eigen::Array2i(
75  common::RoundToInt((max_.y() - y) / resolution_ - 0.5),
76  common::RoundToInt((max_.x() - x) / resolution_ - 0.5));
77  }
78 
79  // Returns true of the ProbabilityGrid contains 'xy_index'.
80  bool Contains(const Eigen::Array2i& xy_index) const {
81  return (Eigen::Array2i(0, 0) <= xy_index).all() &&
82  (xy_index <
84  .all();
85  }
86 
87  private:
88  double resolution_;
89  Eigen::Vector2d max_;
91 };
92 
93 inline proto::MapLimits ToProto(const MapLimits& map_limits) {
94  proto::MapLimits result;
95  result.set_resolution(map_limits.resolution());
96  *result.mutable_max() = transform::ToProto(map_limits.max());
97  *result.mutable_cell_limits() = ToProto(map_limits.cell_limits());
98  return result;
99 }
100 
101 } // namespace mapping_2d
102 } // namespace cartographer
103 
104 #endif // CARTOGRAPHER_MAPPING_2D_MAP_LIMITS_H_
const Eigen::Vector2d & max() const
Definition: map_limits.h:61
int RoundToInt(const float x)
Definition: port.h:42
MapLimits(const proto::MapLimits &map_limits)
Definition: map_limits.h:50
Eigen::Array2i GetXYIndexOfCellContainingPoint(const double x, const double y) const
Definition: map_limits.h:69
proto::Rigid2d ToProto(const transform::Rigid2d &transform)
Definition: transform.cc:44
const CellLimits & cell_limits() const
Definition: map_limits.h:64
bool Contains(const Eigen::Array2i &xy_index) const
Definition: map_limits.h:80
proto::MapLimits ToProto(const MapLimits &map_limits)
Definition: map_limits.h:93
Eigen::Transform< T, 2, Eigen::Affine > ToEigen(const Rigid2< T > &rigid2)
MapLimits(const double resolution, const Eigen::Vector2d &max, const CellLimits &cell_limits)
Definition: map_limits.h:42


cartographer
Author(s):
autogenerated on Mon Jun 10 2019 12:51:39