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";
157 os << static_cast<int>(col.
myRed) <<
","
158 <<
static_cast<int>(col.
myGreen) <<
","
159 <<
static_cast<int>(col.
myBlue);
161 os <<
"," <<
static_cast<int>(col.
myAlpha);
182 const unsigned char r = (
unsigned char)(255 - (
int)
myRed);
183 const unsigned char g = (
unsigned char)(255 - (
int)
myGreen);
184 const unsigned char b = (
unsigned char)(255 - (
int)
myBlue);
198 const unsigned char red = (
unsigned char)(
MIN2(
MAX2(
myRed + change, 0), 255));
203 if (changed == toChange * change) {
205 }
else if (changed == 0) {
209 if (maxedColors == 3) {
212 const int toChangeNext = 3 - maxedColors;
213 return result.
changedBrightness((
int)((toChange * change - changed) / toChangeNext), toChangeNext);
228 const unsigned char red = (
unsigned char)floor(
MIN2(
MAX2(
myRed * factor, 0.0), 255.0) + 0.5);
229 const unsigned char blue = (
unsigned char)floor(
MIN2(
MAX2(
myBlue * factor, 0.0), 255.0) + 0.5);
230 const unsigned char green = (
unsigned char)floor(
MIN2(
MAX2(
myGreen * factor, 0.0), 255.0) + 0.5);
238 if (coldef ==
"red") {
241 if (coldef ==
"green") {
244 if (coldef ==
"blue") {
247 if (coldef ==
"yellow") {
250 if (coldef ==
"cyan") {
253 if (coldef ==
"magenta") {
256 if (coldef ==
"orange") {
259 if (coldef ==
"white") {
262 if (coldef ==
"black") {
265 if (coldef ==
"grey" || coldef ==
"gray") {
268 if (coldef ==
"invisible") {
271 if (coldef ==
"random") {
281 unsigned char a = 255;
282 if (coldef[0] ==
'#') {
284 if (coldef.length() == 7) {
285 r =
static_cast<unsigned char>((coldesc & 0xFF0000) >> 16);
286 g =
static_cast<unsigned char>((coldesc & 0x00FF00) >> 8);
288 }
else if (coldef.length() == 9) {
289 r =
static_cast<unsigned char>((coldesc & 0xFF000000) >> 24);
290 g =
static_cast<unsigned char>((coldesc & 0x00FF0000) >> 16);
291 b =
static_cast<unsigned char>((coldesc & 0x0000FF00) >> 8);
298 if (st.size() == 3 || st.size() == 4) {
303 if (st.size() == 4) {
306 if (r <= 1 && g <= 1 && b <= 1 && (st.size() == 3 || a <= 1)) {
313 if (st.size() == 4) {
327 const std::string& coldef,
const std::string& objecttype,
328 const char* objectid,
bool report,
bool& ok) {
336 std::ostringstream oss;
337 oss <<
"Attribute 'color' in definition of ";
338 if (objectid ==
nullptr) {
342 if (objectid !=
nullptr) {
343 oss <<
" '" << objectid <<
"'";
345 oss <<
" is not a valid color.";
359 const unsigned char r = (
unsigned char)((
int)minColor.
myRed + (((int)maxColor.
myRed - (
int)minColor.
myRed) * weight));
360 const unsigned char g = (
unsigned char)((
int)minColor.
myGreen + (((int)maxColor.
myGreen - (
int)minColor.
myGreen) * weight));
361 const unsigned char b = (
unsigned char)((
int)minColor.
myBlue + (((int)maxColor.
myBlue - (
int)minColor.
myBlue) * weight));
362 const unsigned char a = (
unsigned char)((
int)minColor.
myAlpha + (((int)maxColor.
myAlpha - (
int)minColor.
myAlpha) * weight));
370 const int i = int(floor(h));
375 const unsigned char m =
static_cast<unsigned char>(v * (1 - s) * 255. + 0.5);
376 const unsigned char n =
static_cast<unsigned char>(v * (1 - s * f) * 255. + 0.5);
377 const unsigned char vv =
static_cast<unsigned char>(v * 255. + 0.5);
393 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 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 std::string to_lower_case(std::string str)
Transfers the content to lower case.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...