Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cartographer/io/color.h"
00018
00019 #include <cmath>
00020
00021 #include "cartographer/common/port.h"
00022 #include "glog/logging.h"
00023
00024 namespace cartographer {
00025 namespace io {
00026
00027 namespace {
00028
00029 constexpr float kInitialHue = 0.69f;
00030 constexpr float kSaturation = 0.85f;
00031 constexpr float kValue = 0.77f;
00032
00033 FloatColor HsvToRgb(const float h, const float s, const float v) {
00034 const float h_6 = (h == 1.f) ? 0.f : 6 * h;
00035 const int h_i = std::floor(h_6);
00036 const float f = h_6 - h_i;
00037
00038 const float p = v * (1.f - s);
00039 const float q = v * (1.f - f * s);
00040 const float t = v * (1.f - (1.f - f) * s);
00041
00042 if (h_i == 0) {
00043 return {{v, t, p}};
00044 } else if (h_i == 1) {
00045 return {{q, v, p}};
00046 } else if (h_i == 2) {
00047 return {{p, v, t}};
00048 } else if (h_i == 3) {
00049 return {{p, q, v}};
00050 } else if (h_i == 4) {
00051 return {{t, p, v}};
00052 } else if (h_i == 5) {
00053 return {{v, p, q}};
00054 } else {
00055 return {{0.f, 0.f, 0.f}};
00056 }
00057 }
00058
00059 }
00060
00061 FloatColor GetColor(int id) {
00062 CHECK_GE(id, 0);
00063
00064
00065 constexpr float kGoldenRatioConjugate = 0.6180339887498949f;
00066 const float hue = std::fmod(kInitialHue + kGoldenRatioConjugate * id, 1.f);
00067 return HsvToRgb(hue, kSaturation, kValue);
00068 }
00069
00070 }
00071 }