VPTissue Reference Manual
hsv.h
Go to the documentation of this file.
1 #ifndef SIMPT_CELL_COLOR_HSV_H_
2 #define SIMPT_CELL_COLOR_HSV_H_
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include <cassert>
23 #include <iostream>
24 #include <tuple>
25 
26 namespace SimPT_Sim {
27 namespace Color {
28 
29 using hsv_t = std::tuple<double, double, double>;
30 
31 // -----------------------------------------------------------
32 // see http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
33 // -----------------------------------------------------------
34 const hsv_t black { 0.0 / 360.0, 0.0, 0.0 };
35 const hsv_t white {180.0 / 360.0, 0.0, 1.0 };
36 const hsv_t red { 0.0 / 360.0, 1.0, 1.0 };
37 const hsv_t lime {120.0 / 360.0, 1.0, 1.0 };
38 const hsv_t blue {240.0 / 360.0, 1.0, 1.0 };
39 const hsv_t yellow { 60.0 / 360.0, 1.0, 1.0 };
40 const hsv_t cyan {180.0 / 360.0, 1.0, 1.0 };
41 const hsv_t magenta {300.0 / 360.0, 1.0, 1.0 };
42 const hsv_t gray { 0.0 / 360.0, 0.0, 0.5 };
43 const hsv_t teal {180.0 / 360.0, 1.0, 0.5 };
44 const hsv_t navy {240.0 / 360.0, 1.0, 0.5 };
45 
46 inline hsv_t interpolate(double x, hsv_t t_a, double x_a, hsv_t t_b, double x_b)
47 {
48  assert(x_b < x_a);
49  assert(x_a <= x && x <= x_b);
50 
51  const double s = (x - x_a) / (x_b - x_a);
52  return std::make_tuple(
53  (1.0 - s) * std::get<0>(t_a) + s * std::get<0>(t_b),
54  (1.0 - s) * std::get<1>(t_a) + s * std::get<1>(t_b),
55  (1.0 - s) * std::get<2>(t_a) + s * std::get<2>(t_b));
56 }
57 
58 inline std::ostream& operator<<(std::ostream& os , hsv_t t)
59 {
60  os << std::get<0>(t) << " - " << std::get<1>(t) << " - " << std::get<2>(t);
61  return os;
62 }
63 
64 } // namespace
65 } // namespace
66 
67 #endif // end_of_include_guard
Namespace for the core simulator.