GridMap.hpp
Go to the documentation of this file.
1 /*
2  * GridMap.hpp
3  *
4  * Created on: Jul 14, 2014
5  * Author: Péter Fankhauser
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
9 #pragma once
10 
14 
15 // STL
16 #include <vector>
17 #include <unordered_map>
18 
19 // Eigen
20 #include <Eigen/Core>
21 #include <Eigen/Geometry>
22 
23 namespace grid_map {
24 
25 class SubmapGeometry;
26 
40 class GridMap
41 {
42  public:
43  // Type traits for use with template methods/classes using GridMap as a template parameter.
46 
51  GridMap(const std::vector<std::string>& layers);
52 
56  GridMap();
57 
61  GridMap(const GridMap&) = default;
62  GridMap& operator=(const GridMap&) = default;
63  GridMap(GridMap&&) = default;
64  GridMap& operator=(GridMap&&) = default;
65 
69  virtual ~GridMap();
70 
77  void setGeometry(const Length& length, const double resolution,
78  const Position& position = Position::Zero());
79 
84  void setGeometry(const SubmapGeometry& geometry);
85 
91  void add(const std::string& layer, const double value = NAN);
92 
98  void add(const std::string& layer, const Matrix& data);
99 
105  bool exists(const std::string& layer) const;
106 
113  const Matrix& get(const std::string& layer) const;
114 
122  Matrix& get(const std::string& layer);
123 
130  const Matrix& operator [](const std::string& layer) const;
131 
139  Matrix& operator [](const std::string& layer);
140 
146  bool erase(const std::string& layer);
147 
152  const std::vector<std::string>& getLayers() const;
153 
160  void setBasicLayers(const std::vector<std::string>& basicLayers);
161 
166  const std::vector<std::string>& getBasicLayers() const;
167 
172  bool hasBasicLayers() const;
173 
181  bool hasSameLayers(const grid_map::GridMap& other) const;
182 
190  float& atPosition(const std::string& layer, const Position& position);
191 
200  float atPosition(const std::string& layer, const Position& position,
201  InterpolationMethods interpolationMethod = InterpolationMethods::INTER_NEAREST) const;
202 
210  float& at(const std::string& layer, const Index& index);
211 
219  float at(const std::string& layer, const Index& index) const;
220 
227  bool getIndex(const Position& position, Index& index) const;
228 
236  bool getPosition(const Index& index, Position& position) const;
237 
243  bool isInside(const Position& position) const;
244 
251  bool isValid(const Index& index) const;
252 
259  bool isValid(const Index& index, const std::string& layer) const;
260 
267  bool isValid(const Index& index, const std::vector<std::string>& layers) const;
268 
277  bool getPosition3(const std::string& layer, const Index& index, Position3& position) const;
278 
286  bool getVector(const std::string& layerPrefix, const Index& index,
287  Eigen::Vector3d& vector) const;
288 
299  GridMap getSubmap(const Position& position, const Length& length, bool& isSuccess) const;
300 
312  GridMap getSubmap(const Position& position, const Length& length, Index& indexInSubmap,
313  bool& isSuccess) const;
314 
328  GridMap getTransformedMap(const Eigen::Isometry3d& transform, const std::string& heightLayerName,
329  const std::string& newFrameId,
330  const double sampleRatio = 0.0) const;
331 
340  void setPosition(const Position& position);
341 
352  bool move(const Position& position, std::vector<BufferRegion>& newRegions);
353 
361  bool move(const Position& position);
362 
372  bool addDataFrom(const GridMap& other, bool extendMap,
373  bool overwriteData, bool copyAllLayers,
374  std::vector<std::string> layers = std::vector<std::string>());
375 
381  bool extendToInclude(const GridMap& other);
382 
387  void clear(const std::string& layer);
388 
393  void clearBasic();
394 
400  void clearAll();
401 
406  void setTimestamp(const Time timestamp);
407 
412  Time getTimestamp() const;
413 
417  void resetTimestamp();
418 
423  void setFrameId(const std::string& frameId);
424 
429  const std::string& getFrameId() const;
430 
435  const Length& getLength() const;
436 
441  const Position& getPosition() const;
442 
447  double getResolution() const;
448 
453  const Size& getSize() const;
454 
460  void setStartIndex(const Index& startIndex);
461 
466  const Index& getStartIndex() const;
467 
472  bool isDefaultStartIndex() const;
473 
478 
479  private:
480 
486  void clearCols(unsigned int index, unsigned int nCols);
487 
493  void clearRows(unsigned int index, unsigned int nRows);
494 
502  bool atPositionLinearInterpolated(const std::string& layer, const Position& position, float& value) const;
503 
508  void resize(const Index& bufferSize);
509 
511  std::string frameId_;
512 
515 
517  std::unordered_map<std::string, Matrix> data_;
518 
520  std::vector<std::string> layers_;
521 
525  std::vector<std::string> basicLayers_;
526 
529 
531  double resolution_;
532 
535 
538 
541 
542  public:
543  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
544 };
545 
546 } /* namespace */
const Length & getLength() const
Definition: GridMap.cpp:655
Eigen::Array2i Index
Definition: TypeDefs.hpp:22
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
Definition: GridMap.cpp:51
Time getTimestamp() const
Definition: GridMap.cpp:635
Size size_
Size of the buffer (rows and cols of the data structure).
Definition: GridMap.hpp:537
void setPosition(const Position &position)
Definition: GridMap.cpp:448
float & atPosition(const std::string &layer, const Position &position)
Definition: GridMap.cpp:174
const Index & getStartIndex() const
Definition: GridMap.cpp:679
void clear(const std::string &layer)
Definition: GridMap.cpp:720
void setBasicLayers(const std::vector< std::string > &basicLayers)
Definition: GridMap.cpp:77
const Position & getPosition() const
Definition: GridMap.cpp:660
Eigen::Array2i Size
Definition: TypeDefs.hpp:23
const std::string & getFrameId() const
Definition: GridMap.cpp:650
double resolution_
Map resolution in xy plane [m/cell].
Definition: GridMap.hpp:531
GridMap getTransformedMap(const Eigen::Isometry3d &transform, const std::string &heightLayerName, const std::string &newFrameId, const double sampleRatio=0.0) const
Definition: GridMap.cpp:341
std::vector< std::string > basicLayers_
Definition: GridMap.hpp:525
std::unordered_map< std::string, Matrix > data_
Grid map data stored as layers of matrices.
Definition: GridMap.hpp:517
Eigen::MatrixXf Matrix
Definition: TypeDefs.hpp:16
grid_map::DataType DataType
Definition: GridMap.hpp:44
bool getVector(const std::string &layerPrefix, const Index &index, Eigen::Vector3d &vector) const
Definition: GridMap.cpp:273
std::string frameId_
Frame id of the grid map.
Definition: GridMap.hpp:511
const Matrix & operator[](const std::string &layer) const
Definition: GridMap.cpp:143
grid_map::Matrix Matrix
Definition: GridMap.hpp:45
bool move(const Position &position, std::vector< BufferRegion > &newRegions)
Definition: GridMap.cpp:453
void convertToDefaultStartIndex()
Definition: GridMap.cpp:689
InterpolationMethods
Definition: TypeDefs.hpp:27
bool addDataFrom(const GridMap &other, bool extendMap, bool overwriteData, bool copyAllLayers, std::vector< std::string > layers=std::vector< std::string >())
Definition: GridMap.cpp:527
GridMap getSubmap(const Position &position, const Length &length, bool &isSuccess) const
Definition: GridMap.cpp:287
bool isValid(const Index &index) const
Definition: GridMap.cpp:242
Eigen::Vector3d Position3
Definition: TypeDefs.hpp:20
bool exists(const std::string &layer) const
Definition: GridMap.cpp:120
bool extendToInclude(const GridMap &other)
Definition: GridMap.cpp:559
double getResolution() const
Definition: GridMap.cpp:665
const std::vector< std::string > & getLayers() const
Definition: GridMap.cpp:169
std::vector< std::string > layers_
Names of the data layers.
Definition: GridMap.hpp:520
bool isInside(const Position &position) const
Definition: GridMap.cpp:237
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
bool isDefaultStartIndex() const
Definition: GridMap.cpp:684
void resetTimestamp()
Definition: GridMap.cpp:640
void setStartIndex(const Index &startIndex)
Definition: GridMap.cpp:675
uint64_t Time
Definition: TypeDefs.hpp:25
virtual ~GridMap()
Definition: GridMap.cpp:47
Position position_
Map position in the grid map frame [m].
Definition: GridMap.hpp:534
float & at(const std::string &layer, const Index &index)
Definition: GridMap.cpp:209
bool hasSameLayers(const grid_map::GridMap &other) const
Definition: GridMap.cpp:92
Time timestamp_
Timestamp of the grid map (nanoseconds).
Definition: GridMap.hpp:514
bool hasBasicLayers() const
Definition: GridMap.cpp:87
Matrix::Scalar DataType
Definition: TypeDefs.hpp:17
Index startIndex_
Circular buffer start indeces.
Definition: GridMap.hpp:540
void add(const std::string &layer, const double value=NAN)
Definition: GridMap.cpp:100
bool atPositionLinearInterpolated(const std::string &layer, const Position &position, float &value) const
Definition: GridMap.cpp:763
void clearCols(unsigned int index, unsigned int nCols)
Definition: GridMap.cpp:753
void clearRows(unsigned int index, unsigned int nRows)
Definition: GridMap.cpp:743
Length length_
Side length of the map in x- and y-direction [m].
Definition: GridMap.hpp:528
void setFrameId(const std::string &frameId)
Definition: GridMap.cpp:645
GridMap & operator=(const GridMap &)=default
void setTimestamp(const Time timestamp)
Definition: GridMap.cpp:630
bool erase(const std::string &layer)
Definition: GridMap.cpp:153
bool getIndex(const Position &position, Index &index) const
Definition: GridMap.cpp:227
bool getPosition3(const std::string &layer, const Index &index, Position3 &position) const
Definition: GridMap.cpp:262
Eigen::Array2d Length
Definition: TypeDefs.hpp:24
void resize(const Index &bufferSize)
Definition: GridMap.cpp:819
const std::vector< std::string > & getBasicLayers() const
Definition: GridMap.cpp:82
const Size & getSize() const
Definition: GridMap.cpp:670


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Tue Jun 25 2019 20:02:08