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-2018 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 #include <config.h>
27 
28 #include <iostream>
29 #include <random>
31 
32 
33 // ===========================================================================
34 // class definitions
35 // ===========================================================================
41 class RGBColor {
42 public:
45  RGBColor();
46 
52  RGBColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255);
53 
55  RGBColor(const RGBColor& col);
56 
58  ~RGBColor();
59 
63  unsigned char red() const {
64  return myRed;
65  }
66 
70  unsigned char green() const {
71  return myGreen;
72  }
73 
77  unsigned char blue() const {
78  return myBlue;
79  }
80 
84  unsigned char alpha() const {
85  return myAlpha;
86  }
87 
94  void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
95 
101  RGBColor changedBrightness(int change, int toChange = 3) const;
102 
104  RGBColor invertedColor() const;
105 
106  static std::mt19937* getColorRNG() {
107  return &myRNG;
108  }
109 
121  static RGBColor parseColor(std::string coldef);
122 
138  static RGBColor parseColorReporting(const std::string& coldef, const std::string& objecttype,
139  const char* objectid, bool report, bool& ok);
140 
151  static RGBColor interpolate(const RGBColor& minColor, const RGBColor& maxColor, double weight);
152 
160  static RGBColor fromHSV(double h, double s, double v);
161 
167  static RGBColor randomHue(double s = 1, double v = 1);
168 
174  friend std::ostream& operator<<(std::ostream& os, const RGBColor& col);
175 
176  // @brief Equality operator
177  bool operator==(const RGBColor& c) const;
178 
179  // @brief Inequality operator
180  bool operator!=(const RGBColor& c) const;
181 
184  static const RGBColor RED;
185  static const RGBColor GREEN;
186  static const RGBColor BLUE;
187  static const RGBColor YELLOW;
188  static const RGBColor CYAN;
189  static const RGBColor MAGENTA;
190  static const RGBColor ORANGE;
191  static const RGBColor WHITE;
192  static const RGBColor BLACK;
193  static const RGBColor GREY;
194  static const RGBColor INVISIBLE;
196 
198  static const RGBColor DEFAULT_COLOR;
199 
201  static const std::string DEFAULT_COLOR_STRING;
202 
203 private:
205  unsigned char myRed, myGreen, myBlue, myAlpha;
206 
208  static std::mt19937 myRNG;
209 };
210 
211 
212 #endif
213 
214 /****************************************************************************/
215 
static const RGBColor BLUE
Definition: RGBColor.h:186
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
Definition: RGBColor.cpp:334
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.
Definition: RGBColor.cpp:299
static const RGBColor WHITE
Definition: RGBColor.h:191
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:84
static const RGBColor ORANGE
Definition: RGBColor.h:190
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:77
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:192
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:185
static const RGBColor GREY
Definition: RGBColor.h:193
unsigned char myAlpha
Definition: RGBColor.h:205
unsigned char myRed
The color amounts.
Definition: RGBColor.h:205
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:198
unsigned char myGreen
Definition: RGBColor.h:205
static const RGBColor MAGENTA
Definition: RGBColor.h:189
static std::mt19937 myRNG
A random number generator to generate random colors independent of other randomness.
Definition: RGBColor.h:208
static const RGBColor YELLOW
Definition: RGBColor.h:187
static const RGBColor RED
named colors
Definition: RGBColor.h:184
static const RGBColor CYAN
Definition: RGBColor.h:188
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:70
unsigned char myBlue
Definition: RGBColor.h:205
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:63
RGBColor()
Constructor.
Definition: RGBColor.cpp:64
static const RGBColor INVISIBLE
Definition: RGBColor.h:194
static std::mt19937 * getColorRNG()
Definition: RGBColor.h:106
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:201