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