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() = default;
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 
485  Position getClosestPositionInMap(const Position& position) const;
486 
487  private:
493  bool isValid(DataType value) const;
494 
500  void clearCols(unsigned int index, unsigned int nCols);
501 
507  void clearRows(unsigned int index, unsigned int nRows);
508 
516  bool atPositionLinearInterpolated(const std::string& layer, const Position& position, float& value) const;
517 
518 
530  bool atPositionBicubicConvolutionInterpolated(const std::string& layer, const Position& position,
531  float& value) const;
532 
544  bool atPositionBicubicInterpolated(const std::string& layer, const Position& position,
545  float& value) const;
546 
547 
552  void resize(const Index& bufferSize);
553 
555  std::string frameId_;
556 
559 
561  std::unordered_map<std::string, Matrix> data_;
562 
564  std::vector<std::string> layers_;
565 
569  std::vector<std::string> basicLayers_;
570 
573 
575  double resolution_;
576 
579 
582 
585 
586  public:
587  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
588 };
589 
590 } /* namespace */
const Length & getLength() const
Definition: GridMap.cpp:644
Eigen::Array2i Index
Definition: TypeDefs.hpp:22
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
Definition: GridMap.cpp:45
Time getTimestamp() const
Definition: GridMap.cpp:628
bool atPositionBicubicConvolutionInterpolated(const std::string &layer, const Position &position, float &value) const
Definition: GridMap.cpp:847
Size size_
Size of the buffer (rows and cols of the data structure).
Definition: GridMap.hpp:581
virtual ~GridMap()=default
void setPosition(const Position &position)
Definition: GridMap.cpp:447
float & atPosition(const std::string &layer, const Position &position)
Definition: GridMap.cpp:160
const Index & getStartIndex() const
Definition: GridMap.cpp:664
void clear(const std::string &layer)
Definition: GridMap.cpp:738
void setBasicLayers(const std::vector< std::string > &basicLayers)
Definition: GridMap.cpp:68
const Position & getPosition() const
Definition: GridMap.cpp:648
Eigen::Array2i Size
Definition: TypeDefs.hpp:23
const std::string & getFrameId() const
Definition: GridMap.cpp:640
double resolution_
Map resolution in xy plane [m/cell].
Definition: GridMap.hpp:575
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:569
std::unordered_map< std::string, Matrix > data_
Grid map data stored as layers of matrices.
Definition: GridMap.hpp:561
Position getClosestPositionInMap(const Position &position) const
Definition: GridMap.cpp:702
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:281
std::string frameId_
Frame id of the grid map.
Definition: GridMap.hpp:555
const Matrix & operator[](const std::string &layer) const
Definition: GridMap.cpp:127
grid_map::Matrix Matrix
Definition: GridMap.hpp:45
bool atPositionBicubicInterpolated(const std::string &layer, const Position &position, float &value) const
Definition: GridMap.cpp:863
bool move(const Position &position, std::vector< BufferRegion > &newRegions)
Definition: GridMap.cpp:451
void convertToDefaultStartIndex()
Definition: GridMap.cpp:672
InterpolationMethods
Definition: TypeDefs.hpp:39
bool addDataFrom(const GridMap &other, bool extendMap, bool overwriteData, bool copyAllLayers, std::vector< std::string > layers=std::vector< std::string >())
Definition: GridMap.cpp:523
GridMap getSubmap(const Position &position, const Length &length, bool &isSuccess) const
Definition: GridMap.cpp:291
bool isValid(const Index &index) const
Definition: GridMap.cpp:249
Eigen::Vector3d Position3
Definition: TypeDefs.hpp:20
bool exists(const std::string &layer) const
Definition: GridMap.cpp:107
bool extendToInclude(const GridMap &other)
Definition: GridMap.cpp:553
double getResolution() const
Definition: GridMap.cpp:652
const std::vector< std::string > & getLayers() const
Definition: GridMap.cpp:156
std::vector< std::string > layers_
Names of the data layers.
Definition: GridMap.hpp:564
bool isInside(const Position &position) const
Definition: GridMap.cpp:241
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
bool isDefaultStartIndex() const
Definition: GridMap.cpp:668
void resetTimestamp()
Definition: GridMap.cpp:632
void setStartIndex(const Index &startIndex)
Definition: GridMap.cpp:660
uint64_t Time
Definition: TypeDefs.hpp:25
Position position_
Map position in the grid map frame [m].
Definition: GridMap.hpp:578
float & at(const std::string &layer, const Index &index)
Definition: GridMap.cpp:217
bool hasSameLayers(const grid_map::GridMap &other) const
Definition: GridMap.cpp:80
Time timestamp_
Timestamp of the grid map (nanoseconds).
Definition: GridMap.hpp:558
bool hasBasicLayers() const
Definition: GridMap.cpp:76
Matrix::Scalar DataType
Definition: TypeDefs.hpp:17
Index startIndex_
Circular buffer start indeces.
Definition: GridMap.hpp:584
void add(const std::string &layer, const double value=NAN)
Definition: GridMap.cpp:89
bool atPositionLinearInterpolated(const std::string &layer, const Position &position, float &value) const
Definition: GridMap.cpp:770
void clearCols(unsigned int index, unsigned int nCols)
Definition: GridMap.cpp:764
void clearRows(unsigned int index, unsigned int nRows)
Definition: GridMap.cpp:758
Length length_
Side length of the map in x- and y-direction [m].
Definition: GridMap.hpp:572
void setFrameId(const std::string &frameId)
Definition: GridMap.cpp:636
GridMap & operator=(const GridMap &)=default
void setTimestamp(const Time timestamp)
Definition: GridMap.cpp:624
bool erase(const std::string &layer)
Definition: GridMap.cpp:135
bool getIndex(const Position &position, Index &index) const
Definition: GridMap.cpp:233
bool getPosition3(const std::string &layer, const Index &index, Position3 &position) const
Definition: GridMap.cpp:269
Eigen::Array2d Length
Definition: TypeDefs.hpp:24
void resize(const Index &bufferSize)
Definition: GridMap.cpp:839
const std::vector< std::string > & getBasicLayers() const
Definition: GridMap.cpp:72
const Size & getSize() const
Definition: GridMap.cpp:656


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Tue Jun 1 2021 02:13:27