 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
64 : myRed(0), myGreen(0), myBlue(0), myAlpha(0) {}
67 RGBColor::RGBColor(
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha)
68 : myRed(red), myGreen(green), myBlue(blue), myAlpha(alpha) {}
72 : myRed(col.myRed), myGreen(col.myGreen), myBlue(col.myBlue), myAlpha(col.myAlpha) {}
79 RGBColor::set(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a) {
99 return os <<
"yellow";
105 return os <<
"magenta";
108 return os <<
"orange";
111 return os <<
"white";
114 return os <<
"black";
119 os << static_cast<int>(col.
myRed) <<
","
120 <<
static_cast<int>(col.
myGreen) <<
","
121 <<
static_cast<int>(col.
myBlue);
123 os <<
"," <<
static_cast<int>(col.
myAlpha);
144 const unsigned char r = (
unsigned char)(255 - (
int)
myRed);
145 const unsigned char g = (
unsigned char)(255 - (
int)
myGreen);
146 const unsigned char b = (
unsigned char)(255 - (
int)
myBlue);
154 const unsigned char red = (
unsigned char)(
MIN2(
MAX2(
myRed + change, 0), 255));
159 if (changed == toChange * change) {
161 }
else if (changed == 0) {
165 if (maxedColors == 3) {
168 const int toChangeNext = 3 - maxedColors;
169 return result.
changedBrightness((
int)((toChange * change - changed) / toChangeNext), toChangeNext);
177 std::transform(coldef.begin(), coldef.end(), coldef.begin(), tolower);
178 if (coldef ==
"red") {
181 if (coldef ==
"green") {
184 if (coldef ==
"blue") {
187 if (coldef ==
"yellow") {
190 if (coldef ==
"cyan") {
193 if (coldef ==
"magenta") {
196 if (coldef ==
"orange") {
199 if (coldef ==
"white") {
202 if (coldef ==
"black") {
205 if (coldef ==
"grey" || coldef ==
"gray") {
211 unsigned char a = 255;
212 if (coldef[0] ==
'#') {
214 if (coldef.length() == 7) {
215 r =
static_cast<unsigned char>((coldesc & 0xFF0000) >> 16);
216 g =
static_cast<unsigned char>((coldesc & 0x00FF00) >> 8);
218 }
else if (coldef.length() == 9) {
219 r =
static_cast<unsigned char>((coldesc & 0xFF000000) >> 24);
220 g =
static_cast<unsigned char>((coldesc & 0x00FF0000) >> 16);
221 b =
static_cast<unsigned char>((coldesc & 0x0000FF00) >> 8);
228 if (st.size() == 3 || st.size() == 4) {
233 if (st.size() == 4) {
236 if (r <= 1 && g <= 1 && b <= 1 && (st.size() == 3 || a <= 1)) {
243 if (st.size() == 4) {
257 const std::string& coldef,
const std::string& objecttype,
258 const char* objectid,
bool report,
bool& ok) {
266 std::ostringstream oss;
267 oss <<
"Attribute 'color' in definition of ";
268 if (objectid ==
nullptr) {
272 if (objectid !=
nullptr) {
273 oss <<
" '" << objectid <<
"'";
275 oss <<
" is not a valid color.";
289 const unsigned char r = (
unsigned char)((
int)minColor.
myRed + (((int)maxColor.
myRed - (
int)minColor.
myRed) * weight));
290 const unsigned char g = (
unsigned char)((
int)minColor.
myGreen + (((int)maxColor.
myGreen - (
int)minColor.
myGreen) * weight));
291 const unsigned char b = (
unsigned char)((
int)minColor.
myBlue + (((int)maxColor.
myBlue - (
int)minColor.
myBlue) * weight));
292 const unsigned char a = (
unsigned char)((
int)minColor.
myAlpha + (((int)maxColor.
myAlpha - (
int)minColor.
myAlpha) * weight));
300 const int i = int(floor(h));
305 const unsigned char m =
static_cast<unsigned char>(v * (1 - s) * 255. + 0.5);
306 const unsigned char n =
static_cast<unsigned char>(v * (1 - s * f) * 255. + 0.5);
307 const unsigned char vv =
static_cast<unsigned char>(v * 255. + 0.5);
323 return RGBColor(255, 255, 255, 255);
static const RGBColor GREY
#define UNUSED_PARAMETER(x)
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
static const RGBColor INVISIBLE
std::ostream & operator<<(std::ostream &os, const RGBColor &col)
static const RGBColor BLACK
bool operator==(const RGBColor &c) const
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static const RGBColor YELLOW
static const RGBColor CYAN
unsigned char myRed
The color amounts.
unsigned char red() const
Returns the red-amount of the color.
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
static const RGBColor MAGENTA
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.
static const RGBColor ORANGE
static std::mt19937 myRNG
A random number generator to generate random colors independent of other randomness.
static RGBColor parseColor(std::string coldef)
Parses a color information.
static const RGBColor BLUE
static const RGBColor RED
named colors
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb....
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 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...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
unsigned char blue() const
Returns the blue-amount of the color.
std::vector< std::string > getVector()
return vector of strings
RGBColor invertedColor() const
obtain inverted of current RGBColor
static const RGBColor GREEN
bool operator!=(const RGBColor &c) const
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
static const RGBColor WHITE