Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
Color.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
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 // FIXME: Including QVariant here should be replaced by a specific tulip-core header similar to TulipMetaTypes.h
26 #include <QtCore/QVariant>
27 
28 ///
29 namespace tlp {
30 
31 class TLP_SCOPE Color : public tlp::Vector<unsigned char,4> {
32 public:
33  ///
34  inline Color(const tlp::Vector<unsigned char,4>&);
35  ///
36  inline Color(const unsigned char red=0 ,const unsigned char green=0 ,const unsigned char blue=0,const unsigned char alpha=255);
37  ///
38  inline void set(const unsigned char red=0,const unsigned char green=0 ,const unsigned char blue=0, const unsigned char alpha=255);
39  ///
40  inline float getRGL()const;
41  ///
42  inline float getGGL()const;
43  ///
44  inline float getBGL()const;
45  ///
46  inline float getAGL()const;
47  ///
48  inline float* getGL()const;
49  ///
50  inline unsigned char getR()const;
51  ///
52  inline unsigned char getG()const;
53  ///
54  inline unsigned char getB()const;
55  ///
56  inline unsigned char getA()const;
57  ///
58  inline void setR(const unsigned char red);
59  ///
60  inline void setG(const unsigned char green);
61  ///
62  inline void setB(const unsigned char blue);
63  ///
64  inline void setA(const unsigned char alpha);
65  ///
66  long getTrueColor();
67  ///
68  int getH() const;
69  ///
70  int getS() const;
71  ///
72  int getV() const;
73  ///
74  void setH(int );
75  ///
76  void setS(int );
77  ///
78  void setV(int );
79 };
80 
81 TLP_SCOPE std::ostream& operator<<(std::ostream &os,const tlp::Color &);
82 TLP_SCOPE std::istream& operator>>(std::istream &is, tlp::Color &);
83 
84 }
85 
86 Q_DECLARE_METATYPE(tlp::Color)
87 
88 tlp::Color::Color(const tlp::Vector<unsigned char,4> &v) : tlp::Vector<unsigned char,4>(v) {}
89 
90 tlp::Color::Color(const unsigned char red ,const unsigned char green ,const unsigned char blue,const unsigned char alpha) {
91  array[0]=red;
92  array[1]=green;
93  array[2]=blue;
94  array[3]=alpha;
95 }
96 void tlp::Color::set(unsigned char red,unsigned char green,unsigned char blue, unsigned char alpha) {
97  array[0]=red;
98  array[1]=green;
99  array[2]=blue;
100  array[3]=alpha;
101 }
102 
103 unsigned char tlp::Color::getR()const {
104  return array[0];
105 }
106 unsigned char tlp::Color::getG()const {
107  return array[1];
108 }
109 unsigned char tlp::Color::getB()const {
110  return array[2];
111 }
112 unsigned char tlp::Color::getA()const {
113  return array[3];
114 }
115 
116 float tlp::Color::getRGL()const {
117  return (float)array[0]/255.0;
118 }
119 float tlp::Color::getGGL()const {
120  return (float)array[1]/255.0;
121 }
122 float tlp::Color::getBGL()const {
123  return (float)array[2]/255.0;
124 }
125 float tlp::Color::getAGL()const {
126  return (float)array[3]/255.0;
127 }
128 float* tlp::Color::getGL()const {
129  float *result=new float[4];
130  result[0]=getRGL();
131  result[1]=getGGL();
132  result[2]=getBGL();
133  result[3]=getAGL();
134  return result;
135 }
136 
137 void tlp::Color::setR(unsigned char red) {
138  array[0]=red;
139 }
140 void tlp::Color::setG(unsigned char green) {
141  array[1]=green;
142 }
143 void tlp::Color::setB(unsigned char blue) {
144  array[2]=blue;
145 }
146 void tlp::Color::setA(unsigned char alpha) {
147  array[3]=alpha;
148 }
149 
150 TLP_BEGIN_HASH_NAMESPACE {
151  template <>
152  struct hash<tlp::Color> {
153  inline std::size_t operator()(const tlp::Color &c) const {
154  return hash_vector(c);
155  }
156  };
157 } TLP_END_HASH_NAMESPACE
158 
159 #endif
160 
161 ///@endcond