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>
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 
100  RGBColor changedBrightness(int change, int toChange = 3) const;
101 
103  RGBColor invertedColor() const;
104 
116  static RGBColor parseColor(std::string coldef);
117 
133  static RGBColor parseColorReporting(const std::string& coldef, const std::string& objecttype,
134  const char* objectid, bool report, bool& ok);
135 
146  static RGBColor interpolate(const RGBColor& minColor, const RGBColor& maxColor, double weight);
147 
155  static RGBColor fromHSV(double h, double s, double v);
156 
162  friend std::ostream& operator<<(std::ostream& os, const RGBColor& col);
163 
164  // @brief Equality operator
165  bool operator==(const RGBColor& c) const;
166 
167  // @brief Inequality operator
168  bool operator!=(const RGBColor& c) const;
169 
172  static const RGBColor RED;
173  static const RGBColor GREEN;
174  static const RGBColor BLUE;
175  static const RGBColor YELLOW;
176  static const RGBColor CYAN;
177  static const RGBColor MAGENTA;
178  static const RGBColor ORANGE;
179  static const RGBColor WHITE;
180  static const RGBColor BLACK;
181  static const RGBColor GREY;
183 
185  static const RGBColor DEFAULT_COLOR;
186 
188  static const std::string DEFAULT_COLOR_STRING;
189 
190 private:
192  unsigned char myRed, myGreen, myBlue, myAlpha;
193 };
194 
195 
196 #endif
197 
198 /****************************************************************************/
199 
static const RGBColor BLUE
Definition: RGBColor.h:174
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition: RGBColor.cpp:173
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:150
~RGBColor()
Destructor.
Definition: RGBColor.cpp:72
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb.
Definition: RGBColor.cpp:295
static const RGBColor WHITE
Definition: RGBColor.h:179
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:253
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:83
static const RGBColor ORANGE
Definition: RGBColor.h:178
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:85
static const RGBColor BLACK
Definition: RGBColor.h:180
bool operator==(const RGBColor &c) const
Definition: RGBColor.cpp:127
RGBColor invertedColor() const
obtain inverted of current RGBColor
Definition: RGBColor.cpp:139
bool operator!=(const RGBColor &c) const
Definition: RGBColor.cpp:133
static const RGBColor GREEN
Definition: RGBColor.h:173
static const RGBColor GREY
Definition: RGBColor.h:181
unsigned char myAlpha
Definition: RGBColor.h:192
unsigned char myRed
The color amounts.
Definition: RGBColor.h:192
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:185
unsigned char myGreen
Definition: RGBColor.h:192
static const RGBColor MAGENTA
Definition: RGBColor.h:177
static const RGBColor YELLOW
Definition: RGBColor.h:175
static const RGBColor RED
named colors
Definition: RGBColor.h:172
static const RGBColor CYAN
Definition: RGBColor.h:176
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:69
unsigned char myBlue
Definition: RGBColor.h:192
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:62
RGBColor()
Constructor.
Definition: RGBColor.cpp:60
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
Definition: RGBColor.cpp:279
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.
Definition: RGBColor.h:188