Tulip  5.2.0
Large graphs analysis and drawing
Color.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef _COLOR_H
22 #define _COLOR_H
23 #include <tulip/Vector.h>
24 
25 ///
26 namespace tlp {
27 
28 class TLP_SCOPE Color : public tlp::Vector<unsigned char, 4> {
29 public:
30  ///
31  inline Color(const tlp::Vector<unsigned char, 4> &);
32  ///
33  inline Color(const unsigned char red = 0, const unsigned char green = 0,
34  const unsigned char blue = 0, const unsigned char alpha = 255);
35  ///
36  inline void set(const unsigned char red = 0, const unsigned char green = 0,
37  const unsigned char blue = 0, const unsigned char alpha = 255);
38  ///
39  inline float getRGL() const;
40  ///
41  inline float getGGL() const;
42  ///
43  inline float getBGL() const;
44  ///
45  inline float getAGL() const;
46  ///
47  inline float *getGL() const;
48  ///
49  inline unsigned char getR() const;
50  ///
51  inline unsigned char getG() const;
52  ///
53  inline unsigned char getB() const;
54  ///
55  inline unsigned char getA() const;
56  ///
57  inline void setR(const unsigned char red);
58  ///
59  inline void setG(const unsigned char green);
60  ///
61  inline void setB(const unsigned char blue);
62  ///
63  inline void setA(const unsigned char alpha);
64  ///
65  long getTrueColor();
66  ///
67  int getH() const;
68  ///
69  int getS() const;
70  ///
71  int getV() const;
72  ///
73  void setH(int);
74  ///
75  void setS(int);
76  ///
77  void setV(int);
78 
79  static const Color Amaranth;
80  static const Color Amber;
81  static const Color Apricot;
82  static const Color Aquamarine;
83  static const Color Azure;
84  static const Color BabyBlue;
85  static const Color Beige;
86  static const Color Black;
87  static const Color Blue;
88  static const Color BlueGreen;
89  static const Color BlueViolet;
90  static const Color Blush;
91  static const Color Bronze;
92  static const Color Brown;
93  static const Color Burgundy;
94  static const Color Byzantium;
95  static const Color Carmine;
96  static const Color Cerise;
97  static const Color Cerulean;
98  static const Color Champagne;
99  static const Color ChartreuseGreen;
100  static const Color Chocolate;
101  static const Color Coffee;
102  static const Color Copper;
103  static const Color Coral;
104  static const Color Crimson;
105  static const Color Cyan;
106  static const Color DesertSand;
107  static const Color ElectricBlue;
108  static const Color Erin;
109  static const Color Gold;
110  static const Color Gray;
111  static const Color Green;
112  static const Color Harlequin;
113  static const Color Indigo;
114  static const Color Ivory;
115  static const Color Jade;
116  static const Color JungleGreen;
117  static const Color Lavender;
118  static const Color Lemon;
119  static const Color Lilac;
120  static const Color Lime;
121  static const Color Magenta;
122  static const Color MagentaRose;
123  static const Color Maroon;
124  static const Color Mauve;
125  static const Color NavyBlue;
126  static const Color Olive;
127  static const Color Orange;
128  static const Color OrangeRed;
129  static const Color Orchid;
130  static const Color Peach;
131  static const Color Pear;
132  static const Color Periwinkle;
133  static const Color PersianBlue;
134  static const Color Pink;
135  static const Color Plum;
136  static const Color PrussianBlue;
137  static const Color Puce;
138  static const Color Purple;
139  static const Color Raspberry;
140  static const Color Red;
141  static const Color RedViolet;
142  static const Color Rose;
143  static const Color Salmon;
144  static const Color Sapphire;
145  static const Color Scarlet;
146  static const Color Silver;
147  static const Color SlateGray;
148  static const Color SpringBud;
149  static const Color SpringGreen;
150  static const Color Tan;
151  static const Color Taupe;
152  static const Color Teal;
153  static const Color Turquoise;
154  static const Color Violet;
155  static const Color Viridian;
156  static const Color White;
157  static const Color Yellow;
158 };
159 
160 TLP_SCOPE std::ostream &operator<<(std::ostream &os, const tlp::Color &);
161 TLP_SCOPE std::istream &operator>>(std::istream &is, tlp::Color &);
162 }
163 
164 tlp::Color::Color(const tlp::Vector<unsigned char, 4> &v) : tlp::Vector<unsigned char, 4>(v) {}
165 
166 tlp::Color::Color(const unsigned char red, const unsigned char green, const unsigned char blue,
167  const unsigned char alpha) {
168  set(red, green, blue, alpha);
169 }
170 
171 void tlp::Color::set(unsigned char red, unsigned char green, unsigned char blue,
172  unsigned char alpha) {
173  (*this)[0] = red;
174  (*this)[1] = green;
175  (*this)[2] = blue;
176  (*this)[3] = alpha;
177 }
178 
179 unsigned char tlp::Color::getR() const {
180  return (*this)[0];
181 }
182 unsigned char tlp::Color::getG() const {
183  return (*this)[1];
184 }
185 unsigned char tlp::Color::getB() const {
186  return (*this)[2];
187 }
188 unsigned char tlp::Color::getA() const {
189  return (*this)[3];
190 }
191 
192 float tlp::Color::getRGL() const {
193  return float((*this)[0] / 255.0);
194 }
195 float tlp::Color::getGGL() const {
196  return float((*this)[1] / 255.0);
197 }
198 float tlp::Color::getBGL() const {
199  return float((*this)[2] / 255.0);
200 }
201 float tlp::Color::getAGL() const {
202  return float((*this)[3] / 255.0);
203 }
204 float *tlp::Color::getGL() const {
205  float *result = new float[4];
206  result[0] = getRGL();
207  result[1] = getGGL();
208  result[2] = getBGL();
209  result[3] = getAGL();
210  return result;
211 }
212 
213 void tlp::Color::setR(unsigned char red) {
214  (*this)[0] = red;
215 }
216 void tlp::Color::setG(unsigned char green) {
217  (*this)[1] = green;
218 }
219 void tlp::Color::setB(unsigned char blue) {
220  (*this)[2] = blue;
221 }
222 void tlp::Color::setA(unsigned char alpha) {
223  (*this)[3] = alpha;
224 }
225 
226 TLP_BEGIN_HASH_NAMESPACE {
227  template <>
228  struct hash<tlp::Color> {
229  inline std::size_t operator()(const tlp::Color &c) const {
230  return hash_vector(c);
231  }
232  };
233 }
234 TLP_END_HASH_NAMESPACE
235 
236 #endif
237 
238 ///@endcond
std::istream & operator>>(std::istream &is, Array< T, N > &array)
operator >> stream operator to easily read an array
std::ostream & operator<<(std::ostream &os, const Array< T, N > &array)
operator << stream operator to easily print an array, or save it to a file.