grid_2d.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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_GRID_2D_H_
18 #define CARTOGRAPHER_MAPPING_2D_GRID_2D_H_
19 
20 #include <vector>
21 
24 #include "cartographer/mapping/proto/2d/grid_2d.pb.h"
25 #include "cartographer/mapping/proto/2d/submaps_options_2d.pb.h"
26 #include "cartographer/mapping/proto/submap_visualization.pb.h"
27 
28 namespace cartographer {
29 namespace mapping {
30 
31 proto::GridOptions2D CreateGridOptions2D(
32  common::LuaParameterDictionary* const parameter_dictionary);
33 
34 class Grid2D : public GridInterface {
35  public:
36  explicit Grid2D(const MapLimits& limits, float min_correspondence_cost,
37  float max_correspondence_cost);
38  explicit Grid2D(const proto::Grid2D& proto);
39 
40  // Returns the limits of this Grid2D.
41  const MapLimits& limits() const { return limits_; }
42 
43  // Finishes the update sequence.
44  void FinishUpdate();
45  // Returns the correspondence cost of the cell with 'cell_index'.
46  float GetCorrespondenceCost(const Eigen::Array2i& cell_index) const;
47 
48  // Returns the minimum possible correspondence cost.
50 
51  // Returns the maximum possible correspondence cost.
53 
54  // Returns true if the probability at the specified index is known.
55  bool IsKnown(const Eigen::Array2i& cell_index) const;
56 
57  // Fills in 'offset' and 'limits' to define a subregion of that contains all
58  // known cells.
59  void ComputeCroppedLimits(Eigen::Array2i* const offset,
60  CellLimits* const limits) const;
61 
62  // Grows the map as necessary to include 'point'. This changes the meaning of
63  // these coordinates going forward. This method must be called immediately
64  // after 'FinishUpdate', before any calls to 'ApplyLookupTable'.
65  virtual void GrowLimits(const Eigen::Vector2f& point);
66 
67  virtual std::unique_ptr<Grid2D> ComputeCroppedGrid() const = 0;
68 
69  virtual proto::Grid2D ToProto() const;
70 
71  virtual bool DrawToSubmapTexture(
72  proto::SubmapQuery::Response::SubmapTexture* const texture,
73  transform::Rigid3d local_pose) const = 0;
74 
75  protected:
76  const std::vector<uint16>& correspondence_cost_cells() const {
78  }
79  const std::vector<int>& update_indices() const { return update_indices_; }
80  const Eigen::AlignedBox2i& known_cells_box() const {
81  return known_cells_box_;
82  }
83 
84  std::vector<uint16>* mutable_correspondence_cost_cells() {
86  }
87  std::vector<int>* mutable_update_indices() { return &update_indices_; }
88  Eigen::AlignedBox2i* mutable_known_cells_box() { return &known_cells_box_; }
89 
90  // Converts a 'cell_index' into an index into 'cells_'.
91  int ToFlatIndex(const Eigen::Array2i& cell_index) const;
92 
93  private:
95  std::vector<uint16> correspondence_cost_cells_;
98  std::vector<int> update_indices_;
99 
100  // Bounding box of known cells to efficiently compute cropping limits.
101  Eigen::AlignedBox2i known_cells_box_;
102 };
103 
104 } // namespace mapping
105 } // namespace cartographer
106 
107 #endif // CARTOGRAPHER_MAPPING_2D_GRID_2D_H_
float GetMinCorrespondenceCost() const
Definition: grid_2d.h:49
virtual void GrowLimits(const Eigen::Vector2f &point)
Definition: grid_2d.cc:116
Grid2D(const MapLimits &limits, float min_correspondence_cost, float max_correspondence_cost)
Definition: grid_2d.cc:36
float GetMaxCorrespondenceCost() const
Definition: grid_2d.h:52
virtual bool DrawToSubmapTexture(proto::SubmapQuery::Response::SubmapTexture *const texture, transform::Rigid3d local_pose) const =0
Eigen::AlignedBox2i * mutable_known_cells_box()
Definition: grid_2d.h:88
virtual std::unique_ptr< Grid2D > ComputeCroppedGrid() const =0
virtual proto::Grid2D ToProto() const
Definition: grid_2d.cc:147
Eigen::AlignedBox2i known_cells_box_
Definition: grid_2d.h:101
const Eigen::AlignedBox2i & known_cells_box() const
Definition: grid_2d.h:80
std::vector< uint16 > * mutable_correspondence_cost_cells()
Definition: grid_2d.h:84
const std::vector< uint16 > & correspondence_cost_cells() const
Definition: grid_2d.h:76
void ComputeCroppedLimits(Eigen::Array2i *const offset, CellLimits *const limits) const
Definition: grid_2d.cc:101
float GetCorrespondenceCost(const Eigen::Array2i &cell_index) const
Definition: grid_2d.cc:86
bool IsKnown(const Eigen::Array2i &cell_index) const
Definition: grid_2d.cc:93
const std::vector< int > & update_indices() const
Definition: grid_2d.h:79
const MapLimits & limits() const
Definition: grid_2d.h:41
int ToFlatIndex(const Eigen::Array2i &cell_index) const
Definition: grid_2d.cc:168
std::vector< uint16 > correspondence_cost_cells_
Definition: grid_2d.h:95
std::vector< int > * mutable_update_indices()
Definition: grid_2d.h:87
std::vector< int > update_indices_
Definition: grid_2d.h:98
proto::GridOptions2D CreateGridOptions2D(common::LuaParameterDictionary *const parameter_dictionary)
Definition: grid_2d.cc:23


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