Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef CARTOGRAPHER_MAPPING_TSD_VALUE_CONVERTER_H_
00018 #define CARTOGRAPHER_MAPPING_TSD_VALUE_CONVERTER_H_
00019
00020 #include <cmath>
00021 #include <vector>
00022
00023 #include "cartographer/common/math.h"
00024 #include "cartographer/common/port.h"
00025 #include "cartographer/mapping/value_conversion_tables.h"
00026 #include "glog/logging.h"
00027
00028 namespace cartographer {
00029 namespace mapping {
00030
00031
00032
00033 class TSDValueConverter {
00034 public:
00035 TSDValueConverter(float max_tsd, float max_weight,
00036 ValueConversionTables* conversion_tables);
00037
00038
00039 inline uint16 TSDToValue(const float tsd) const {
00040 const int value =
00041 common::RoundToInt((ClampTSD(tsd) - min_tsd_) * tsd_resolution_) + 1;
00042 DCHECK_GE(value, 1);
00043 DCHECK_LE(value, 32767);
00044 return value;
00045 }
00046
00047
00048 inline uint16 WeightToValue(const float weight) const {
00049 const int value = common::RoundToInt((ClampWeight(weight) - min_weight_) *
00050 weight_resolution_) +
00051 1;
00052 DCHECK_GE(value, 1);
00053 DCHECK_LE(value, 32767);
00054 return value;
00055 }
00056
00057
00058
00059 inline float ValueToTSD(const uint16 value) const {
00060 return (*value_to_tsd_)[value];
00061 }
00062
00063
00064
00065 inline float ValueToWeight(const uint16 value) const {
00066 return (*value_to_weight_)[value];
00067 }
00068
00069 static uint16 getUnknownTSDValue() { return unknown_tsd_value_; }
00070 static uint16 getUnknownWeightValue() { return unknown_weight_value_; }
00071 static uint16 getUpdateMarker() { return update_marker_; }
00072 float getMaxTSD() const { return max_tsd_; }
00073 float getMinTSD() const { return min_tsd_; }
00074 float getMaxWeight() const { return max_weight_; }
00075 float getMinWeight() const { return min_weight_; }
00076
00077 private:
00078
00079 inline float ClampTSD(const float tsd) const {
00080 return common::Clamp(tsd, min_tsd_, max_tsd_);
00081 }
00082
00083 inline float ClampWeight(const float weight) const {
00084 return common::Clamp(weight, min_weight_, max_weight_);
00085 }
00086
00087 float max_tsd_;
00088 float min_tsd_;
00089 float max_weight_;
00090 float tsd_resolution_;
00091 float weight_resolution_;
00092 static constexpr float min_weight_ = 0.f;
00093 static constexpr uint16 unknown_tsd_value_ = 0;
00094 static constexpr uint16 unknown_weight_value_ = 0;
00095 static constexpr uint16 update_marker_ = 1u << 15;
00096
00097 const std::vector<float>* value_to_tsd_;
00098 const std::vector<float>* value_to_weight_;
00099 };
00100
00101 }
00102 }
00103
00104 #endif // CARTOGRAPHER_MAPPING_TSD_VALUE_CONVERTER_H_