00001 /* 00002 * Copyright 2016 The Cartographer Authors 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef CARTOGRAPHER_MAPPING_2D_PROBABILITY_GRID_H_ 00018 #define CARTOGRAPHER_MAPPING_2D_PROBABILITY_GRID_H_ 00019 00020 #include <vector> 00021 00022 #include "cartographer/common/port.h" 00023 #include "cartographer/mapping/2d/grid_2d.h" 00024 #include "cartographer/mapping/2d/map_limits.h" 00025 #include "cartographer/mapping/2d/xy_index.h" 00026 00027 namespace cartographer { 00028 namespace mapping { 00029 00030 // Represents a 2D grid of probabilities. 00031 class ProbabilityGrid : public Grid2D { 00032 public: 00033 explicit ProbabilityGrid(const MapLimits& limits, 00034 ValueConversionTables* conversion_tables); 00035 explicit ProbabilityGrid(const proto::Grid2D& proto, 00036 ValueConversionTables* conversion_tables); 00037 00038 // Sets the probability of the cell at 'cell_index' to the given 00039 // 'probability'. Only allowed if the cell was unknown before. 00040 void SetProbability(const Eigen::Array2i& cell_index, 00041 const float probability); 00042 00043 // Applies the 'odds' specified when calling ComputeLookupTableToApplyOdds() 00044 // to the probability of the cell at 'cell_index' if the cell has not already 00045 // been updated. Multiple updates of the same cell will be ignored until 00046 // FinishUpdate() is called. Returns true if the cell was updated. 00047 // 00048 // If this is the first call to ApplyOdds() for the specified cell, its value 00049 // will be set to probability corresponding to 'odds'. 00050 bool ApplyLookupTable(const Eigen::Array2i& cell_index, 00051 const std::vector<uint16>& table); 00052 00053 GridType GetGridType() const override; 00054 00055 // Returns the probability of the cell with 'cell_index'. 00056 float GetProbability(const Eigen::Array2i& cell_index) const; 00057 00058 proto::Grid2D ToProto() const override; 00059 std::unique_ptr<Grid2D> ComputeCroppedGrid() const override; 00060 bool DrawToSubmapTexture( 00061 proto::SubmapQuery::Response::SubmapTexture* const texture, 00062 transform::Rigid3d local_pose) const override; 00063 00064 private: 00065 ValueConversionTables* conversion_tables_; 00066 }; 00067 00068 } // namespace mapping 00069 } // namespace cartographer 00070 00071 #endif // CARTOGRAPHER_MAPPING_2D_PROBABILITY_GRID_H_