Go to the documentation of this file.00001
00005 #pragma once
00006
00007 #include <vector>
00008 #include <unordered_map>
00009
00010
00011 #include <Eigen/Core>
00012 #include <grid_map_core/BufferRegion.hpp>
00013 #include <grid_map_core/TypeDefs.hpp>
00014 #include "common.hpp"
00015 #include "submap_geometry.hpp"
00016
00017 namespace cost_map {
00018
00019 class SubmapGeometry;
00020
00034 class CostMap
00035 {
00036 public:
00037
00038 typedef cost_map::Matrix::Scalar DataType;
00039 typedef cost_map::Matrix Matrix;
00045 CostMap(const std::vector<std::string>& layers);
00046
00050 CostMap();
00051
00055 virtual ~CostMap();
00056
00063 void setGeometry(const Length& length, const double resolution,
00064 const Position& position = Position::Zero());
00065
00070 void setGeometry(const SubmapGeometry& geometry);
00071
00076 void setPosition(const Position& position) { position_ = position; }
00077
00083 void add(const std::string& layer, const DataType value = NO_INFORMATION);
00084
00090 void add(const std::string& layer, const Matrix& data);
00091
00097 bool exists(const std::string& layer) const;
00098
00105 const Matrix& get(const std::string& layer) const;
00106
00114 Matrix& get(const std::string& layer);
00115
00122 const Matrix& operator [](const std::string& layer) const;
00123
00131 Matrix& operator [](const std::string& layer);
00132
00138 bool erase(const std::string& layer);
00139
00144 const std::vector<std::string>& getLayers() const;
00145
00152 void setBasicLayers(const std::vector<std::string>& basicLayers);
00153
00158 const std::vector<std::string>& getBasicLayers() const;
00159
00167 bool hasSameLayers(const CostMap& other) const;
00168
00176 DataType& atPosition(const std::string& layer, const Position& position);
00177
00186 DataType atPosition(const std::string& layer,
00187 const Position& position,
00188 grid_map::InterpolationMethods interpolation_method=grid_map::InterpolationMethods::INTER_NEAREST
00189 ) const;
00190
00198 DataType& at(const std::string& layer, const Index& index);
00199
00207 DataType at(const std::string& layer, const Index& index) const;
00208
00215 bool getIndex(const Position& position, Index& index) const;
00216
00224 bool getPosition(const Index& index, Position& position) const;
00225
00231 bool isInside(const Position& position) const;
00232
00243 bool isValid(const Index& index) const;
00244
00255 bool isValid(const Index& index, const std::string& layer) const;
00256
00267 bool isValid(const Index& index, const std::vector<std::string>& layers) const;
00268
00277 bool getPosition3(const std::string& layer, const Index& index,
00278 Position3& position) const;
00279
00287 bool getVector(const std::string& layerPrefix, const Index& index,
00288 Eigen::Vector3d& vector) const;
00289
00298 CostMap getSubmap(const Position& position, const Length& length,
00299 bool& isSuccess) const;
00300
00310 CostMap getSubmap(const Position& position, const Length& length,
00311 Index& indexInSubmap, bool& isSuccess) const;
00312
00321 bool move(const Position& position, std::vector<BufferRegion>& newRegions);
00322
00330 bool move(const Position& position);
00331
00341 bool addDataFrom(const CostMap& other, bool extendMap,
00342 bool overwriteData, bool copyAllLayers,
00343 std::vector<std::string> layers = std::vector<std::string>());
00344
00350 bool extendToInclude(const CostMap& other);
00351
00356 void clear(const std::string& layer);
00357
00362 void clearBasic();
00363
00369 void clearAll();
00370
00375 void setTimestamp(const Time timestamp);
00376
00381 Time getTimestamp() const;
00382
00386 void resetTimestamp();
00387
00392 void setFrameId(const std::string& frameId);
00393
00398 const std::string& getFrameId() const;
00399
00404 const Length& getLength() const;
00405
00410 const Position& getPosition() const;
00411
00416 double getResolution() const;
00417
00422 const Size& getSize() const;
00423
00429 void setStartIndex(const Index& startIndex);
00430
00435 const Index& getStartIndex() const;
00436
00437 private:
00438
00444 void clearCols(unsigned int index, unsigned int nCols);
00445
00451 void clearRows(unsigned int index, unsigned int nRows);
00452
00460 bool atPositionLinearInterpolated(const std::string& layer, const Position& position, float& value) const;
00461
00466 void resize(const Eigen::Array2i& bufferSize);
00467
00469 std::string frameId_;
00470
00472 Time timestamp_;
00473
00475 std::unordered_map<std::string, Matrix> data_;
00476
00478 std::vector<std::string> layers_;
00479
00483 std::vector<std::string> basicLayers_;
00484
00486 Length length_;
00487
00489 double resolution_;
00490
00492 Position position_;
00493
00495 Size size_;
00496
00498 Index startIndex_;
00499 };
00500
00501 }