Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
RGBColor.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 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 <config.h>
24#include <iosfwd>
26
27
28// ===========================================================================
29// class declarations
30// ===========================================================================
31class SumoRNG;
32
33
34// ===========================================================================
35// class definitions
36// ===========================================================================
42class RGBColor {
43public:
46 RGBColor(bool valid = true);
47
53 RGBColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255);
54
58 unsigned char red() const;
59
63 unsigned char green() const;
64
68 unsigned char blue() const;
69
73 unsigned char alpha() const;
74
81 void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
82
86 void setAlpha(unsigned char alpha);
87
89 void setValid(const bool value);
90
92 bool isValid() const;
93
99 RGBColor changedBrightness(int change, int toChange = 3) const;
100
102 RGBColor changedAlpha(int change) const;
103
108 RGBColor multiply(double factor) const;
109
111 RGBColor invertedColor() const;
112
114 static SumoRNG* getColorRNG();
115
127 static RGBColor parseColor(std::string coldef);
128
130 static bool isColor(std::string coldef);
131
147 static RGBColor parseColorReporting(const std::string& coldef, const std::string& objecttype,
148 const char* objectid, bool report, bool& ok);
149
160 static RGBColor interpolate(const RGBColor& minColor, const RGBColor& maxColor, double weight);
161
168 static RGBColor fromHSV(double h, double s, double v);
169
175 static RGBColor randomHue(double s = 1, double v = 1);
176
182 friend std::ostream& operator<<(std::ostream& os, const RGBColor& col);
183
184 // @brief Equality operator
185 bool operator==(const RGBColor& c) const;
186
187 // @brief Inequality operator
188 bool operator!=(const RGBColor& c) const;
189
192 static const RGBColor RED;
193 static const RGBColor GREEN;
194 static const RGBColor BLUE;
195 static const RGBColor YELLOW;
196 static const RGBColor CYAN;
197 static const RGBColor MAGENTA;
198 static const RGBColor ORANGE;
199 static const RGBColor WHITE;
200 static const RGBColor BLACK;
201 static const RGBColor GREY;
202 static const RGBColor INVISIBLE;
204
207
209 static const std::string DEFAULT_COLOR_STRING;
210
211private:
213 unsigned char myRed, myGreen, myBlue, myAlpha;
214
217
220};
const std::string invalid_return< std::string >::value
bool myValid
flag to check if color is valid
Definition RGBColor.h:216
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
Definition RGBColor.cpp:387
unsigned char myRed
The color amounts.
Definition RGBColor.h:213
void setValid(const bool value)
set valid
Definition RGBColor.cpp:114
void setAlpha(unsigned char alpha)
Sets a new alpha value.
Definition RGBColor.cpp:108
static const RGBColor WHITE
Definition RGBColor.h:199
unsigned char red() const
Returns the red-amount of the color.
Definition RGBColor.cpp:74
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.
Definition RGBColor.h:209
static const RGBColor BLUE
Definition RGBColor.h:194
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
static const RGBColor GREY
Definition RGBColor.h:201
static const RGBColor YELLOW
Definition RGBColor.h:195
static SumoRNG myRNG
A random number generator to generate random colors independent of other randomness.
Definition RGBColor.h:219
static const RGBColor INVISIBLE
Definition RGBColor.h:202
RGBColor(bool valid=true)
Constructor.
Definition RGBColor.cpp:65
static SumoRNG * getColorRNG()
get color RNG
Definition RGBColor.cpp:194
RGBColor multiply(double factor) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:230
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition RGBColor.cpp:239
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:361
friend std::ostream & operator<<(std::ostream &os, const RGBColor &col)
Writes the color to the given stream.
Definition RGBColor.cpp:126
unsigned char green() const
Returns the green-amount of the color.
Definition RGBColor.cpp:80
static const RGBColor ORANGE
Definition RGBColor.h:198
static const RGBColor CYAN
Definition RGBColor.h:196
static bool isColor(std::string coldef)
check if the given string can be parsed to color
Definition RGBColor.cpp:329
RGBColor invertedColor() const
obtain inverted of current RGBColor
Definition RGBColor.cpp:183
bool isValid() const
check if RGBColor is valid
Definition RGBColor.cpp:120
static const RGBColor GREEN
Definition RGBColor.h:193
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:403
unsigned char myBlue
Definition RGBColor.h:213
unsigned char blue() const
Returns the blue-amount of the color.
Definition RGBColor.cpp:86
static const RGBColor BLACK
Definition RGBColor.h:200
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
bool operator!=(const RGBColor &c) const
Definition RGBColor.cpp:177
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition RGBColor.cpp:98
RGBColor changedAlpha(int change) const
Returns a new color with altered opacity.
Definition RGBColor.cpp:223
unsigned char myGreen
Definition RGBColor.h:213
static const RGBColor MAGENTA
Definition RGBColor.h:197
bool operator==(const RGBColor &c) const
Definition RGBColor.cpp:171
unsigned char myAlpha
Definition RGBColor.h:213
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles).
Definition RGBColor.h:206
static const RGBColor RED
named colors
Definition RGBColor.h:192
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
Definition RGBColor.cpp:435