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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A RGB-color definition
21 /****************************************************************************/
22 #pragma once
23 #include <iostream>
24 #include <random>
26 
27 
28 // ===========================================================================
29 // class definitions
30 // ===========================================================================
36 class RGBColor {
37 public:
40  RGBColor();
41 
47  RGBColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255);
48 
52  unsigned char red() const {
53  return myRed;
54  }
55 
59  unsigned char green() const {
60  return myGreen;
61  }
62 
66  unsigned char blue() const {
67  return myBlue;
68  }
69 
73  unsigned char alpha() const {
74  return myAlpha;
75  }
76 
83  void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
84 
88  inline void setAlpha(unsigned char alpha) {
89  myAlpha = alpha;
90  }
91 
92 
98  RGBColor changedBrightness(int change, int toChange = 3) const;
99 
101  RGBColor invertedColor() const;
102 
103  static std::mt19937* getColorRNG() {
104  return &myRNG;
105  }
106 
118  static RGBColor parseColor(std::string coldef);
119 
135  static RGBColor parseColorReporting(const std::string& coldef, const std::string& objecttype,
136  const char* objectid, bool report, bool& ok);
137 
148  static RGBColor interpolate(const RGBColor& minColor, const RGBColor& maxColor, double weight);
149 
156  static RGBColor fromHSV(double h, double s, double v);
157 
163  static RGBColor randomHue(double s = 1, double v = 1);
164 
170  friend std::ostream& operator<<(std::ostream& os, const RGBColor& col);
171 
172  // @brief Equality operator
173  bool operator==(const RGBColor& c) const;
174 
175  // @brief Inequality operator
176  bool operator!=(const RGBColor& c) const;
177 
180  static const RGBColor RED;
181  static const RGBColor GREEN;
182  static const RGBColor BLUE;
183  static const RGBColor YELLOW;
184  static const RGBColor CYAN;
185  static const RGBColor MAGENTA;
186  static const RGBColor ORANGE;
187  static const RGBColor WHITE;
188  static const RGBColor BLACK;
189  static const RGBColor GREY;
190  static const RGBColor INVISIBLE;
192 
194  static const RGBColor DEFAULT_COLOR;
195 
197  static const std::string DEFAULT_COLOR_STRING;
198 
199 private:
201  unsigned char myRed, myGreen, myBlue, myAlpha;
202 
204  static std::mt19937 myRNG;
205 };
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
Definition: RGBColor.cpp:284
unsigned char myRed
The color amounts.
Definition: RGBColor.h:201
void setAlpha(unsigned char alpha)
Sets a new alpha value.
Definition: RGBColor.h:88
static const RGBColor WHITE
Definition: RGBColor.h:187
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:52
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.
Definition: RGBColor.h:197
static const RGBColor BLUE
Definition: RGBColor.h:182
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:73
static const RGBColor GREY
Definition: RGBColor.h:189
static const RGBColor YELLOW
Definition: RGBColor.h:183
static const RGBColor INVISIBLE
Definition: RGBColor.h:190
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition: RGBColor.cpp:168
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:258
RGBColor()
Constructor.
Definition: RGBColor.cpp:62
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:59
static const RGBColor ORANGE
Definition: RGBColor.h:186
static const RGBColor CYAN
Definition: RGBColor.h:184
RGBColor invertedColor() const
obtain inverted of current RGBColor
Definition: RGBColor.cpp:134
static const RGBColor GREEN
Definition: RGBColor.h:181
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb....
Definition: RGBColor.cpp:300
unsigned char myBlue
Definition: RGBColor.h:201
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:66
friend std::ostream & operator<<(std::ostream &os, const RGBColor &col)
Writes the color to the given stream.
Definition: RGBColor.cpp:80
static std::mt19937 * getColorRNG()
Definition: RGBColor.h:103
static const RGBColor BLACK
Definition: RGBColor.h:188
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
bool operator!=(const RGBColor &c) const
Definition: RGBColor.cpp:128
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition: RGBColor.cpp:71
unsigned char myGreen
Definition: RGBColor.h:201
static const RGBColor MAGENTA
Definition: RGBColor.h:185
bool operator==(const RGBColor &c) const
Definition: RGBColor.cpp:122
unsigned char myAlpha
Definition: RGBColor.h:201
static std::mt19937 myRNG
A random number generator to generate random colors independent of other randomness.
Definition: RGBColor.h:204
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:194
static const RGBColor RED
named colors
Definition: RGBColor.h:180
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
Definition: RGBColor.cpp:329