66 : myRed(0), myGreen(0), myBlue(0), myAlpha(0), myValid(valid) {}
69 RGBColor::RGBColor(
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha)
70 : myRed(red), myGreen(green), myBlue(blue), myAlpha(alpha), myValid(true) {}
98 RGBColor::set(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a) {
131 return os <<
"green";
137 return os <<
"yellow";
143 return os <<
"magenta";
146 return os <<
"orange";
149 return os <<
"white";
152 return os <<
"black";
158 return os <<
"invisible";
160 os << static_cast<int>(col.
myRed) <<
","
161 <<
static_cast<int>(col.
myGreen) <<
","
162 <<
static_cast<int>(col.
myBlue);
164 os <<
"," <<
static_cast<int>(col.
myAlpha);
185 const unsigned char r = (
unsigned char)(255 - (
int)
myRed);
186 const unsigned char g = (
unsigned char)(255 - (
int)
myGreen);
187 const unsigned char b = (
unsigned char)(255 - (
int)
myBlue);
201 const unsigned char red = (
unsigned char)(
MIN2(
MAX2(
myRed + change, 0), 255));
206 if (changed == toChange * change) {
208 }
else if (changed == 0) {
212 if (maxedColors == 3) {
215 const int toChangeNext = 3 - maxedColors;
216 return result.
changedBrightness((
int)((toChange * change - changed) / toChangeNext), toChangeNext);
231 const unsigned char red = (
unsigned char)floor(
MIN2(
MAX2(
myRed * factor, 0.0), 255.0) + 0.5);
232 const unsigned char blue = (
unsigned char)floor(
MIN2(
MAX2(
myBlue * factor, 0.0), 255.0) + 0.5);
233 const unsigned char green = (
unsigned char)floor(
MIN2(
MAX2(
myGreen * factor, 0.0), 255.0) + 0.5);
241 if (coldef ==
"red") {
244 if (coldef ==
"green") {
247 if (coldef ==
"blue") {
250 if (coldef ==
"yellow") {
253 if (coldef ==
"cyan") {
256 if (coldef ==
"magenta") {
259 if (coldef ==
"orange") {
262 if (coldef ==
"white") {
265 if (coldef ==
"black") {
268 if (coldef ==
"grey" || coldef ==
"gray") {
271 if (coldef ==
"invisible") {
274 if (coldef ==
"random") {
284 unsigned char a = 255;
285 if (coldef[0] ==
'#') {
287 if (coldef.length() == 7) {
288 r =
static_cast<unsigned char>((coldesc & 0xFF0000) >> 16);
289 g =
static_cast<unsigned char>((coldesc & 0x00FF00) >> 8);
291 }
else if (coldef.length() == 9) {
292 r =
static_cast<unsigned char>((coldesc & 0xFF000000) >> 24);
293 g =
static_cast<unsigned char>((coldesc & 0x00FF0000) >> 16);
294 b =
static_cast<unsigned char>((coldesc & 0x0000FF00) >> 8);
301 if (st.size() == 3 || st.size() == 4) {
306 if (st.size() == 4) {
309 if (r <= 1 && g <= 1 && b <= 1 && (st.size() == 3 || a <= 1)) {
316 if (st.size() == 4) {
330 const std::string& coldef,
const std::string& objecttype,
331 const char* objectid,
bool report,
bool& ok) {
339 std::ostringstream oss;
340 oss <<
"Attribute 'color' in definition of ";
341 if (objectid ==
nullptr) {
345 if (objectid !=
nullptr) {
346 oss <<
" '" << objectid <<
"'";
348 oss <<
" is not a valid color.";
362 const unsigned char r = (
unsigned char)((
int)minColor.
myRed + (((int)maxColor.
myRed - (
int)minColor.
myRed) * weight));
363 const unsigned char g = (
unsigned char)((
int)minColor.
myGreen + (((int)maxColor.
myGreen - (
int)minColor.
myGreen) * weight));
364 const unsigned char b = (
unsigned char)((
int)minColor.
myBlue + (((int)maxColor.
myBlue - (
int)minColor.
myBlue) * weight));
365 const unsigned char a = (
unsigned char)((
int)minColor.
myAlpha + (((int)maxColor.
myAlpha - (
int)minColor.
myAlpha) * weight));
376 const int i = int(floor(h));
381 const unsigned char m =
static_cast<unsigned char>(v * (1 - s) * 255. + 0.5);
382 const unsigned char n =
static_cast<unsigned char>(v * (1 - s * f) * 255. + 0.5);
383 const unsigned char vv =
static_cast<unsigned char>(v * 255. + 0.5);
399 return RGBColor(255, 255, 255, 255);
std::ostream & operator<<(std::ostream &os, const RGBColor &col)
#define UNUSED_PARAMETER(x)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
bool myValid
flag to check if color is valid
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
unsigned char myRed
The color amounts.
void setValid(const bool value)
set valid
void setAlpha(unsigned char alpha)
Sets a new alpha value.
static const RGBColor WHITE
unsigned char red() const
Returns the red-amount of the color.
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.
static const RGBColor BLUE
unsigned char alpha() const
Returns the alpha-amount of the color.
static const RGBColor GREY
static const RGBColor YELLOW
static SumoRNG myRNG
A random number generator to generate random colors independent of other randomness.
static const RGBColor INVISIBLE
RGBColor(bool valid=true)
Constructor.
static SumoRNG * getColorRNG()
get color RNG
RGBColor multiply(double factor) const
Returns a new color with altered brightness.
static RGBColor parseColor(std::string coldef)
Parses a color information.
static RGBColor parseColorReporting(const std::string &coldef, const std::string &objecttype, const char *objectid, bool report, bool &ok)
Parses a color information.
unsigned char green() const
Returns the green-amount of the color.
static const RGBColor ORANGE
static const RGBColor CYAN
RGBColor invertedColor() const
obtain inverted of current RGBColor
bool isValid() const
check if RGBColor is valid
static const RGBColor GREEN
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb....
unsigned char blue() const
Returns the blue-amount of the color.
static const RGBColor BLACK
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
bool operator!=(const RGBColor &c) const
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
RGBColor changedAlpha(int change) const
Returns a new color with altered opacity.
static const RGBColor MAGENTA
bool operator==(const RGBColor &c) const
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
static const RGBColor RED
named colors
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
std::vector< std::string > getVector()
return vector of strings
static std::string to_lower_case(const std::string &str)
Transfers the content to lower case.
static int hexToInt(const std::string &sData)
converts a string with a hex value into the integer value described by it by calling the char-type co...
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...