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-2023 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 <iostream>
25#include <random>
28
29
30// ===========================================================================
31// class definitions
32// ===========================================================================
38class RGBColor {
39public:
42 RGBColor(bool valid = true);
43
49 RGBColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255);
50
54 unsigned char red() const;
55
59 unsigned char green() const;
60
64 unsigned char blue() const;
65
69 unsigned char alpha() const;
70
77 void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
78
82 void setAlpha(unsigned char alpha);
83
85 void setValid(const bool value);
86
88 bool isValid() const;
89
95 RGBColor changedBrightness(int change, int toChange = 3) const;
96
98 RGBColor changedAlpha(int change) const;
99
104 RGBColor multiply(double factor) const;
105
107 RGBColor invertedColor() const;
108
110 static SumoRNG* getColorRNG();
111
123 static RGBColor parseColor(std::string coldef);
124
140 static RGBColor parseColorReporting(const std::string& coldef, const std::string& objecttype,
141 const char* objectid, bool report, bool& ok);
142
153 static RGBColor interpolate(const RGBColor& minColor, const RGBColor& maxColor, double weight);
154
161 static RGBColor fromHSV(double h, double s, double v);
162
168 static RGBColor randomHue(double s = 1, double v = 1);
169
175 friend std::ostream& operator<<(std::ostream& os, const RGBColor& col);
176
177 // @brief Equality operator
178 bool operator==(const RGBColor& c) const;
179
180 // @brief Inequality operator
181 bool operator!=(const RGBColor& c) const;
182
185 static const RGBColor RED;
186 static const RGBColor GREEN;
187 static const RGBColor BLUE;
188 static const RGBColor YELLOW;
189 static const RGBColor CYAN;
190 static const RGBColor MAGENTA;
191 static const RGBColor ORANGE;
192 static const RGBColor WHITE;
193 static const RGBColor BLACK;
194 static const RGBColor GREY;
195 static const RGBColor INVISIBLE;
197
200
202 static const std::string DEFAULT_COLOR_STRING;
203
204private:
206 unsigned char myRed, myGreen, myBlue, myAlpha;
207
210
213};
bool myValid
flag to check if color is valid
Definition RGBColor.h:209
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
Definition RGBColor.cpp:355
unsigned char myRed
The color amounts.
Definition RGBColor.h:206
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:192
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:202
static const RGBColor BLUE
Definition RGBColor.h:187
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
static const RGBColor GREY
Definition RGBColor.h:194
static const RGBColor YELLOW
Definition RGBColor.h:188
static SumoRNG myRNG
A random number generator to generate random colors independent of other randomness.
Definition RGBColor.h:212
static const RGBColor INVISIBLE
Definition RGBColor.h:195
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:329
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:191
static const RGBColor CYAN
Definition RGBColor.h:189
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:186
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:371
unsigned char myBlue
Definition RGBColor.h:206
unsigned char blue() const
Returns the blue-amount of the color.
Definition RGBColor.cpp:86
static const RGBColor BLACK
Definition RGBColor.h:193
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:206
static const RGBColor MAGENTA
Definition RGBColor.h:190
bool operator==(const RGBColor &c) const
Definition RGBColor.cpp:171
unsigned char myAlpha
Definition RGBColor.h:206
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition RGBColor.h:199
static const RGBColor RED
named colors
Definition RGBColor.h:185
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
Definition RGBColor.cpp:403