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 /****************************************************************************/
16 // A RGB-color definition
17 /****************************************************************************/
18 #ifndef RGBColor_h
19 #define RGBColor_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 
26 #include <iostream>
27 #include <random>
29 
30 
31 // ===========================================================================
32 // class definitions
33 // ===========================================================================
39 class RGBColor {
40 public:
43  RGBColor();
44 
50  RGBColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255);
51 
53  RGBColor(const RGBColor& col);
54 
56  ~RGBColor();
57 
61  unsigned char red() const {
62  return myRed;
63  }
64 
68  unsigned char green() const {
69  return myGreen;
70  }
71 
75  unsigned char blue() const {
76  return myBlue;
77  }
78 
82  unsigned char alpha() const {
83  return myAlpha;
84  }
85 
92  void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
93 
97  inline void setAlpha(unsigned char alpha) {
98  myAlpha = alpha;
99  }
100 
101 
107  RGBColor changedBrightness(int change, int toChange = 3) const;
108 
110  RGBColor invertedColor() const;
111 
112  static std::mt19937* getColorRNG() {
113  return &myRNG;
114  }
115 
127  static RGBColor parseColor(std::string coldef);
128 
144  static RGBColor parseColorReporting(const std::string& coldef, const std::string& objecttype,
145  const char* objectid, bool report, bool& ok);
146 
157  static RGBColor interpolate(const RGBColor& minColor, const RGBColor& maxColor, double weight);
158 
165  static RGBColor fromHSV(double h, double s, double v);
166 
172  static RGBColor randomHue(double s = 1, double v = 1);
173 
179  friend std::ostream& operator<<(std::ostream& os, const RGBColor& col);
180 
181  // @brief Equality operator
182  bool operator==(const RGBColor& c) const;
183 
184  // @brief Inequality operator
185  bool operator!=(const RGBColor& c) const;
186 
189  static const RGBColor RED;
190  static const RGBColor GREEN;
191  static const RGBColor BLUE;
192  static const RGBColor YELLOW;
193  static const RGBColor CYAN;
194  static const RGBColor MAGENTA;
195  static const RGBColor ORANGE;
196  static const RGBColor WHITE;
197  static const RGBColor BLACK;
198  static const RGBColor GREY;
199  static const RGBColor INVISIBLE;
201 
203  static const RGBColor DEFAULT_COLOR;
204 
206  static const std::string DEFAULT_COLOR_STRING;
207 
208 private:
210  unsigned char myRed, myGreen, myBlue, myAlpha;
211 
213  static std::mt19937 myRNG;
214 };
215 
216 
217 #endif
218 
219 /****************************************************************************/
220 
RGBColor::alpha
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:82
RGBColor::GREY
static const RGBColor GREY
Definition: RGBColor.h:198
RGBColor::myAlpha
unsigned char myAlpha
Definition: RGBColor.h:210
RGBColor::DEFAULT_COLOR
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:203
RGBColor::setAlpha
void setAlpha(unsigned char alpha)
Sets a new alpha value.
Definition: RGBColor.h:97
RGBColor::INVISIBLE
static const RGBColor INVISIBLE
Definition: RGBColor.h:199
RGBColor::myGreen
unsigned char myGreen
Definition: RGBColor.h:210
RGBColor::BLACK
static const RGBColor BLACK
Definition: RGBColor.h:197
RGBColor::operator==
bool operator==(const RGBColor &c) const
Definition: RGBColor.cpp:130
RGBColor::YELLOW
static const RGBColor YELLOW
Definition: RGBColor.h:192
RGBColor::CYAN
static const RGBColor CYAN
Definition: RGBColor.h:193
RGBColor::myRed
unsigned char myRed
The color amounts.
Definition: RGBColor.h:210
RGBColor::red
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:61
RGBColor::RGBColor
RGBColor()
Constructor.
Definition: RGBColor.cpp:63
RGBColor::interpolate
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
Definition: RGBColor.cpp:282
RGBColor
Definition: RGBColor.h:39
RGBColor::MAGENTA
static const RGBColor MAGENTA
Definition: RGBColor.h:194
RGBColor::DEFAULT_COLOR_STRING
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.
Definition: RGBColor.h:206
RGBColor::ORANGE
static const RGBColor ORANGE
Definition: RGBColor.h:195
RGBColor::myRNG
static std::mt19937 myRNG
A random number generator to generate random colors independent of other randomness.
Definition: RGBColor.h:213
RGBColor::parseColor
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition: RGBColor.cpp:176
RGBColor::getColorRNG
static std::mt19937 * getColorRNG()
Definition: RGBColor.h:112
RGBColor::BLUE
static const RGBColor BLUE
Definition: RGBColor.h:191
UtilExceptions.h
RGBColor::RED
static const RGBColor RED
named colors
Definition: RGBColor.h:189
RGBColor::randomHue
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
Definition: RGBColor.cpp:327
RGBColor::fromHSV
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:298
RGBColor::parseColorReporting
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:256
RGBColor::green
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:68
RGBColor::blue
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:75
RGBColor::operator<<
friend std::ostream & operator<<(std::ostream &os, const RGBColor &col)
Writes the color to the given stream.
Definition: RGBColor.cpp:88
RGBColor::invertedColor
RGBColor invertedColor() const
obtain inverted of current RGBColor
Definition: RGBColor.cpp:142
RGBColor::GREEN
static const RGBColor GREEN
Definition: RGBColor.h:190
RGBColor::operator!=
bool operator!=(const RGBColor &c) const
Definition: RGBColor.cpp:136
RGBColor::changedBrightness
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:153
RGBColor::~RGBColor
~RGBColor()
Destructor.
Definition: RGBColor.cpp:75
RGBColor::set
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition: RGBColor.cpp:79
RGBColor::WHITE
static const RGBColor WHITE
Definition: RGBColor.h:196
RGBColor::myBlue
unsigned char myBlue
Definition: RGBColor.h:210