63 : myRed(0), myGreen(0), myBlue(0), myAlpha(0) {}
66 RGBColor::RGBColor(
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha)
67 : myRed(red), myGreen(green), myBlue(blue), myAlpha(alpha) {}
71 RGBColor::set(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a) {
91 return os <<
"yellow";
97 return os <<
"magenta";
100 return os <<
"orange";
103 return os <<
"white";
106 return os <<
"black";
111 os << static_cast<int>(col.
myRed) <<
","
112 <<
static_cast<int>(col.
myGreen) <<
","
113 <<
static_cast<int>(col.
myBlue);
115 os <<
"," <<
static_cast<int>(col.
myAlpha);
136 const unsigned char r = (
unsigned char)(255 - (
int)
myRed);
137 const unsigned char g = (
unsigned char)(255 - (
int)
myGreen);
138 const unsigned char b = (
unsigned char)(255 - (
int)
myBlue);
146 const unsigned char red = (
unsigned char)(
MIN2(
MAX2(
myRed + change, 0), 255));
151 if (changed == toChange * change) {
153 }
else if (changed == 0) {
157 if (maxedColors == 3) {
160 const int toChangeNext = 3 - maxedColors;
161 return result.
changedBrightness((
int)((toChange * change - changed) / toChangeNext), toChangeNext);
169 std::transform(coldef.begin(), coldef.end(), coldef.begin(), tolower);
170 if (coldef ==
"red") {
173 if (coldef ==
"green") {
176 if (coldef ==
"blue") {
179 if (coldef ==
"yellow") {
182 if (coldef ==
"cyan") {
185 if (coldef ==
"magenta") {
188 if (coldef ==
"orange") {
191 if (coldef ==
"white") {
194 if (coldef ==
"black") {
197 if (coldef ==
"grey" || coldef ==
"gray") {
200 if (coldef ==
"invisible") {
203 if (coldef ==
"random") {
213 unsigned char a = 255;
214 if (coldef[0] ==
'#') {
216 if (coldef.length() == 7) {
217 r =
static_cast<unsigned char>((coldesc & 0xFF0000) >> 16);
218 g =
static_cast<unsigned char>((coldesc & 0x00FF00) >> 8);
220 }
else if (coldef.length() == 9) {
221 r =
static_cast<unsigned char>((coldesc & 0xFF000000) >> 24);
222 g =
static_cast<unsigned char>((coldesc & 0x00FF0000) >> 16);
223 b =
static_cast<unsigned char>((coldesc & 0x0000FF00) >> 8);
230 if (st.size() == 3 || st.size() == 4) {
235 if (st.size() == 4) {
238 if (r <= 1 && g <= 1 && b <= 1 && (st.size() == 3 || a <= 1)) {
245 if (st.size() == 4) {
259 const std::string& coldef,
const std::string& objecttype,
260 const char* objectid,
bool report,
bool& ok) {
268 std::ostringstream oss;
269 oss <<
"Attribute 'color' in definition of ";
270 if (objectid ==
nullptr) {
274 if (objectid !=
nullptr) {
275 oss <<
" '" << objectid <<
"'";
277 oss <<
" is not a valid color.";
291 const unsigned char r = (
unsigned char)((
int)minColor.
myRed + (((int)maxColor.
myRed - (
int)minColor.
myRed) * weight));
292 const unsigned char g = (
unsigned char)((
int)minColor.
myGreen + (((int)maxColor.
myGreen - (
int)minColor.
myGreen) * weight));
293 const unsigned char b = (
unsigned char)((
int)minColor.
myBlue + (((int)maxColor.
myBlue - (
int)minColor.
myBlue) * weight));
294 const unsigned char a = (
unsigned char)((
int)minColor.
myAlpha + (((int)maxColor.
myAlpha - (
int)minColor.
myAlpha) * weight));
302 const int i = int(floor(h));
307 const unsigned char m =
static_cast<unsigned char>(v * (1 - s) * 255. + 0.5);
308 const unsigned char n =
static_cast<unsigned char>(v * (1 - s * f) * 255. + 0.5);
309 const unsigned char vv =
static_cast<unsigned char>(v * 255. + 0.5);
325 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)
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
unsigned char myRed
The color amounts.
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
static const RGBColor GREY
static const RGBColor YELLOW
static const RGBColor INVISIBLE
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
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
static const RGBColor MAGENTA
bool operator==(const RGBColor &c) const
static std::mt19937 myRNG
A random number generator to generate random colors independent of other randomness.
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(std::mt19937 *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 int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...