SUMO - Simulation of Urban MObility
RGBColor.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A RGB-color definition
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef RGBColor_h
23 #define RGBColor_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <iostream>
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
47 class RGBColor {
48 public:
51  RGBColor();
52 
53 
59  RGBColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255);
60 
61 
64  RGBColor(const RGBColor& col);
65 
66 
68  ~RGBColor();
69 
70 
71 
75  unsigned char red() const {
76  return myRed;
77  }
78 
79 
83  unsigned char green() const {
84  return myGreen;
85  }
86 
87 
91  unsigned char blue() const {
92  return myBlue;
93  }
94 
95 
99  unsigned char alpha() const {
100  return myAlpha;
101  }
102 
103 
110  void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
111 
112 
118  friend std::ostream& operator<<(std::ostream& os, const RGBColor& col);
119 
120 
121  bool operator==(const RGBColor& c) const;
122  bool operator!=(const RGBColor& c) const;
123 
124 
130  RGBColor changedBrightness(int change, int toChange = 3) const;
131 
132 
144  static RGBColor parseColor(std::string coldef);
145 
146 
162  static RGBColor parseColorReporting(const std::string& coldef, const std::string& objecttype,
163  const char* objectid, bool report, bool& ok);
164 
165 
176  static RGBColor interpolate(const RGBColor& minColor, const RGBColor& maxColor, SUMOReal weight);
177 
178 
186  static RGBColor fromHSV(SUMOReal h, SUMOReal s, SUMOReal v);
187 
188 
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;
200  static const RGBColor DEFAULT_COLOR;
201 
202 
204  static const std::string DEFAULT_COLOR_STRING;
205 
206 
207 private:
209  unsigned char myRed, myGreen, myBlue, myAlpha;
210 
211 };
212 
213 
214 #endif
215 
216 /****************************************************************************/
217 
static const RGBColor BLUE
Definition: RGBColor.h:191
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition: RGBColor.cpp:172
~RGBColor()
Destructor.
Definition: RGBColor.cpp:83
static RGBColor fromHSV(SUMOReal h, SUMOReal s, SUMOReal v)
Converts the given hsv-triplet to rgb.
Definition: RGBColor.cpp:294
static const RGBColor WHITE
Definition: RGBColor.h:196
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:252
bool operator==(const RGBColor &c) const
Definition: RGBColor.cpp:138
static const RGBColor ORANGE
Definition: RGBColor.h:195
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, SUMOReal weight)
Interpolates between two colors.
Definition: RGBColor.cpp:278
friend std::ostream & operator<<(std::ostream &os, const RGBColor &col)
Writes the color to the given stream.
Definition: RGBColor.cpp:96
static const RGBColor BLACK
Definition: RGBColor.h:197
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
bool operator!=(const RGBColor &c) const
Definition: RGBColor.cpp:144
static const RGBColor GREEN
Definition: RGBColor.h:190
static const RGBColor GREY
Definition: RGBColor.h:198
unsigned char myAlpha
Definition: RGBColor.h:209
unsigned char myRed
The color amounts.
Definition: RGBColor.h:209
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:200
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:99
unsigned char myGreen
Definition: RGBColor.h:209
static const RGBColor MAGENTA
Definition: RGBColor.h:194
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:150
static const RGBColor YELLOW
Definition: RGBColor.h:192
static const RGBColor RED
Definition: RGBColor.h:189
static const RGBColor CYAN
Definition: RGBColor.h:193
unsigned char myBlue
Definition: RGBColor.h:209
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
#define SUMOReal
Definition: config.h:213
RGBColor()
Constructor.
Definition: RGBColor.cpp:71
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.
Definition: RGBColor.h:204