VPTissue Reference Manual
Hsv2Rgb.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
21 #include "Hsv2Rgb.h"
22 
23 #include <array>
24 #include <cmath>
25 
26 namespace SimPT_Sim {
27 namespace Color {
28 
29 using namespace std;
30 
31 std::array<double, 3> Hsv2Rgb(double h, double s, double v)
32 {
33  array<double, 3> ret_val {{v, v, v}}; // achromatic (grey)
34  h /= 60.0; // sector 0 to 5
35  const int i = floor(h);
36  const double f = h - i; // factorial part of h
37  const double p = v * (1.0 - s);
38  const double q = v * (1.0 - s * f);
39  const double t = v * (1.0 - s * (1.0 - f));
40 
41  switch( i ) {
42  case 0: ret_val = {{v, t, p}}; break;
43  case 1: ret_val = {{q, v, p}}; break;
44  case 2: ret_val = {{p, v, t}}; break;
45  case 3: ret_val = {{p, q, v}}; break;
46  case 4: ret_val = {{t, p, v}}; break;
47  default: ret_val = {{v, p, q}}; break;
48  }
49 
50  return ret_val;
51 }
52 
53 } // namespace
54 } // namespace
STL namespace.
Namespace for the core simulator.
Rgb color def to Hsv color def: r,g,b values are from 0 to 1 and h = [0,360], s = [0...