Eclipse SUMO - Simulation of Urban MObility
RGBColor.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A RGB-color definition
18 /****************************************************************************/
19 #ifndef RGBColor_h
20 #define RGBColor_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 
27 #include <iostream>
28 #include <random>
30 
31 
32 // ===========================================================================
33 // class definitions
34 // ===========================================================================
40 class RGBColor {
41 public:
44  RGBColor();
45 
51  RGBColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255);
52 
54  RGBColor(const RGBColor& col);
55 
57  ~RGBColor();
58 
62  unsigned char red() const {
63  return myRed;
64  }
65 
69  unsigned char green() const {
70  return myGreen;
71  }
72 
76  unsigned char blue() const {
77  return myBlue;
78  }
79 
83  unsigned char alpha() const {
84  return myAlpha;
85  }
86 
93  void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
94 
98  inline void setAlpha(unsigned char alpha) {
99  myAlpha = alpha;
100  }
101 
102 
108  RGBColor changedBrightness(int change, int toChange = 3) const;
109 
111  RGBColor invertedColor() const;
112 
113  static std::mt19937* getColorRNG() {
114  return &myRNG;
115  }
116 
128  static RGBColor parseColor(std::string coldef);
129 
145  static RGBColor parseColorReporting(const std::string& coldef, const std::string& objecttype,
146  const char* objectid, bool report, bool& ok);
147 
158  static RGBColor interpolate(const RGBColor& minColor, const RGBColor& maxColor, double weight);
159 
166  static RGBColor fromHSV(double h, double s, double v);
167 
173  static RGBColor randomHue(double s = 1, double v = 1);
174 
180  friend std::ostream& operator<<(std::ostream& os, const RGBColor& col);
181 
182  // @brief Equality operator
183  bool operator==(const RGBColor& c) const;
184 
185  // @brief Inequality operator
186  bool operator!=(const RGBColor& c) const;
187 
190  static const RGBColor RED;
191  static const RGBColor GREEN;
192  static const RGBColor BLUE;
193  static const RGBColor YELLOW;
194  static const RGBColor CYAN;
195  static const RGBColor MAGENTA;
196  static const RGBColor ORANGE;
197  static const RGBColor WHITE;
198  static const RGBColor BLACK;
199  static const RGBColor GREY;
200  static const RGBColor INVISIBLE;
202 
204  static const RGBColor DEFAULT_COLOR;
205 
207  static const std::string DEFAULT_COLOR_STRING;
208 
209 private:
211  unsigned char myRed, myGreen, myBlue, myAlpha;
212 
214  static std::mt19937 myRNG;
215 };
216 
217 
218 #endif
219 
220 /****************************************************************************/
221 
static const RGBColor BLUE
Definition: RGBColor.h:192
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
Definition: RGBColor.cpp:328
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition: RGBColor.cpp:177
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:154
~RGBColor()
Destructor.
Definition: RGBColor.cpp:76
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb.htm.
Definition: RGBColor.cpp:299
static const RGBColor WHITE
Definition: RGBColor.h:197
static RGBColor parseColorReporting(const std::string &coldef, const std::string &objecttype, const char *objectid, bool report, bool &ok)
Parses a color information.
Definition: RGBColor.cpp:257
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:83
static const RGBColor ORANGE
Definition: RGBColor.h:196
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:76
friend std::ostream & operator<<(std::ostream &os, const RGBColor &col)
Writes the color to the given stream.
Definition: RGBColor.cpp:89
static const RGBColor BLACK
Definition: RGBColor.h:198
bool operator==(const RGBColor &c) const
Definition: RGBColor.cpp:131
RGBColor invertedColor() const
obtain inverted of current RGBColor
Definition: RGBColor.cpp:143
bool operator!=(const RGBColor &c) const
Definition: RGBColor.cpp:137
static const RGBColor GREEN
Definition: RGBColor.h:191
static const RGBColor GREY
Definition: RGBColor.h:199
unsigned char myAlpha
Definition: RGBColor.h:211
unsigned char myRed
The color amounts.
Definition: RGBColor.h:211
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:204
unsigned char myGreen
Definition: RGBColor.h:211
void setAlpha(unsigned char alpha)
Sets a new alpha value.
Definition: RGBColor.h:98
static const RGBColor MAGENTA
Definition: RGBColor.h:195
static std::mt19937 myRNG
A random number generator to generate random colors independent of other randomness.
Definition: RGBColor.h:214
static const RGBColor YELLOW
Definition: RGBColor.h:193
static const RGBColor RED
named colors
Definition: RGBColor.h:190
static const RGBColor CYAN
Definition: RGBColor.h:194
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:69
unsigned char myBlue
Definition: RGBColor.h:211
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:62
RGBColor()
Constructor.
Definition: RGBColor.cpp:64
static const RGBColor INVISIBLE
Definition: RGBColor.h:200
static std::mt19937 * getColorRNG()
Definition: RGBColor.h:113
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
Definition: RGBColor.cpp:283
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.
Definition: RGBColor.h:207