Belle II Software development
Colors.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <tracking/trackFindingCDC/display/Colors.h>
9
10#include <sstream>
11
12using namespace Belle2;
13using namespace TrackFindingCDC;
14
15std::vector<std::string> Colors::getList()
16{
17 return {
18 "red",
19 "blue",
20 "green",
21 "orangered",
22 "cyan",
23 "olive",
24 "maroon",
25 "turquoise",
26 "lime",
27 "teal",
28 "darkgreen",
29 "indigo",
30 "darkolivegreen",
31 "orange",
32 "darkmagenta",
33 "seagreen",
34 "magenta",
35 "midnightblue",
36 "darkgoldenrod"
37 };
38}
39
40double Colors::hueToRgb(const double p, const double q, double t)
41{
42 while (t < 0) t += 1;
43 while (t > 1) t -= 1;
44 if (t < 1. / 6.) {
45 return p + (q - p) * 6 * t;
46 }
47 if (t < 1. / 2.) {
48 return q;
49 }
50 if (t < 2. / 3.) {
51 return p + (q - p) * (2. / 3. - t) * 6;
52 }
53 return p;
54}
55
56std::array<double, 3> Colors::hlsToRgb(const double h, const double l, const double s)
57{
58 if (s == 0) {
59 return {l, l, l};
60 } else {
61 double q = l < 0.5 ? l * (1 + s) : l + s - l * s;
62 double p = 2 * l - q;
63 return {
64 hueToRgb(p, q, h + 1. / 3.), //r
65 hueToRgb(p, q, h), //g
66 hueToRgb(p, q, h - 1. / 3.) //b
67 };
68 }
69}
70
71std::string Colors::getWheelColor(int degree)
72{
73 double hue(degree % 360 / 360.);
74 double saturation = 0.75;
75 double lightness = 0.5;
76
77 std::array<double, 3> rgb = Colors::hlsToRgb(hue, lightness, saturation);
78 std::ostringstream oss;
79 oss << "rgb(" << rgb[0] * 100 << "%, " << rgb[1] * 100 << "%, " << rgb[2] * 100 << "%)";
80 return oss.str();
81}
static std::string getWheelColor(int degree)
Get a color from the wheel of colors.
Definition: Colors.cc:71
static double hueToRgb(double p, double q, double t)
Transforms a Color given in the HLS System to RGB.
Definition: Colors.cc:40
static std::array< double, 3 > hlsToRgb(double h, double l, double s)
Transforms a Color given in the HLS System to RGB.
Definition: Colors.cc:56
static std::vector< std::string > getList()
Get a list of useful colors.
Definition: Colors.cc:15
Abstract base class for different kinds of events.