Eclipse SUMO - Simulation of Urban MObility
RGBColor Class Reference

#include <RGBColor.h>

Collaboration diagram for RGBColor:
[legend]

Public Member Functions

unsigned char alpha () const
 Returns the alpha-amount of the color. More...
 
unsigned char blue () const
 Returns the blue-amount of the color. More...
 
RGBColor changedBrightness (int change, int toChange=3) const
 Returns a new color with altered brightness. More...
 
unsigned char green () const
 Returns the green-amount of the color. More...
 
RGBColor invertedColor () const
 obtain inverted of current RGBColor More...
 
bool operator!= (const RGBColor &c) const
 
bool operator== (const RGBColor &c) const
 
unsigned char red () const
 Returns the red-amount of the color. More...
 
 RGBColor ()
 Constructor. More...
 
 RGBColor (unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
 Constructor. More...
 
void set (unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 assigns new values More...
 
void setAlpha (unsigned char alpha)
 Sets a new alpha value. More...
 

Static Public Member Functions

static RGBColor fromHSV (double h, double s, double v)
 Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb.htm. More...
 
static std::mt19937 * getColorRNG ()
 
static RGBColor interpolate (const RGBColor &minColor, const RGBColor &maxColor, double weight)
 Interpolates between two colors. More...
 
static RGBColor parseColor (std::string coldef)
 Parses a color information. More...
 
static RGBColor parseColorReporting (const std::string &coldef, const std::string &objecttype, const char *objectid, bool report, bool &ok)
 Parses a color information. More...
 
static RGBColor randomHue (double s=1, double v=1)
 Return color with random hue. More...
 

Static Public Attributes

static const RGBColor DEFAULT_COLOR = RGBColor::YELLOW
 The default color (for vehicle types and vehicles) More...
 
static const std::string DEFAULT_COLOR_STRING = toString(RGBColor::DEFAULT_COLOR)
 The string description of the default color. More...
 
static const RGBColor RED = RGBColor(255, 0, 0, 255)
 named colors More...
 
static const RGBColor GREEN = RGBColor(0, 255, 0, 255)
 
static const RGBColor BLUE = RGBColor(0, 0, 255, 255)
 
static const RGBColor YELLOW = RGBColor(255, 255, 0, 255)
 
static const RGBColor CYAN = RGBColor(0, 255, 255, 255)
 
static const RGBColor MAGENTA = RGBColor(255, 0, 255, 255)
 
static const RGBColor ORANGE = RGBColor(255, 128, 0, 255)
 
static const RGBColor WHITE = RGBColor(255, 255, 255, 255)
 
static const RGBColor BLACK = RGBColor(0, 0, 0, 255)
 
static const RGBColor GREY = RGBColor(128, 128, 128, 255)
 
static const RGBColor INVISIBLE = RGBColor(0, 0, 0, 0)
 

Private Attributes

unsigned char myAlpha
 
unsigned char myBlue
 
unsigned char myGreen
 
unsigned char myRed
 The color amounts. More...
 

Static Private Attributes

static std::mt19937 myRNG
 A random number generator to generate random colors independent of other randomness. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const RGBColor &col)
 Writes the color to the given stream. More...
 

Detailed Description

The definition of a color in the RGB-space with an alpha channel. The cube is meant to lie between (0, 0, 0) and (255, 255, 255)

Definition at line 36 of file RGBColor.h.

Constructor & Destructor Documentation

◆ RGBColor() [1/2]

RGBColor::RGBColor ( )

Constructor.

Definition at line 62 of file RGBColor.cpp.

Referenced by fromHSV(), interpolate(), invertedColor(), parseColor(), and parseColorReporting().

Here is the caller graph for this function:

◆ RGBColor() [2/2]

RGBColor::RGBColor ( unsigned char  red,
unsigned char  green,
unsigned char  blue,
unsigned char  alpha = 255 
)

Constructor.

Parameters
[in]redThe red component's value
[in]greenThe green component's value
[in]blueThe blue component's value

Definition at line 66 of file RGBColor.cpp.

Member Function Documentation

◆ alpha()

unsigned char RGBColor::alpha ( ) const
inline

Returns the alpha-amount of the color.

Returns
The alpha component's value

Definition at line 73 of file RGBColor.h.

References myAlpha.

Referenced by GNEEdge::drawEdgeGeometryPoints(), GNEEdge::drawEdgeName(), GUIEdge::drawGL(), GUIJunctionWrapper::drawGL(), GUILane::drawGL(), GNEJunction::drawGL(), GNELane::drawGL(), GLHelper::drawText(), GLHelper::drawTextBox(), MFXUtils::getFXColor(), GUISUMOAbstractView::makeSnapshot(), libsumo::Helper::makeTraCIColor(), GUISUMOAbstractView::onConfigure(), GUISUMOAbstractView::paintGL(), setAlpha(), and GLHelper::setColor().

Here is the caller graph for this function:

◆ blue()

unsigned char RGBColor::blue ( ) const
inline

Returns the blue-amount of the color.

Returns
The blue component's value

Definition at line 66 of file RGBColor.h.

References myBlue.

Referenced by changedBrightness(), GLHelper::drawText(), GUIParameterTracker::GUIParameterTrackerPanel::drawValue(), MFXUtils::getFXColor(), GUISUMOAbstractView::makeSnapshot(), libsumo::Helper::makeTraCIColor(), GUISUMOAbstractView::onConfigure(), GUISUMOAbstractView::paintGL(), and GLHelper::setColor().

Here is the caller graph for this function:

◆ changedBrightness()

◆ fromHSV()

RGBColor RGBColor::fromHSV ( double  h,
double  s,
double  v 
)
static

Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb.htm.

Parameters
[in]hHue (0-360)
[in]sSaturation (0-1)
[in]vValue (0-1)
Returns
The color as RGB

Definition at line 300 of file RGBColor.cpp.

References RGBColor().

Referenced by GUIViewTraffic::buildColorRainbow(), GNEViewNet::buildColorRainbow(), parseColor(), randomHue(), GNEVehicle::setColor(), GUILane::setFunctionalColor(), GUIContainer::setFunctionalColor(), GUIPerson::setFunctionalColor(), GUIBaseVehicle::setFunctionalColor(), and GNELane::setFunctionalColor().

Here is the caller graph for this function:

◆ getColorRNG()

static std::mt19937* RGBColor::getColorRNG ( )
inlinestatic

Definition at line 103 of file RGBColor.h.

References myRNG.

Referenced by GUILane::setFunctionalColor().

Here is the caller graph for this function:

◆ green()

unsigned char RGBColor::green ( ) const
inline

Returns the green-amount of the color.

Returns
The green component's value

Definition at line 59 of file RGBColor.h.

References myGreen.

Referenced by changedBrightness(), GLHelper::drawText(), GUIParameterTracker::GUIParameterTrackerPanel::drawValue(), MFXUtils::getFXColor(), GUISUMOAbstractView::makeSnapshot(), libsumo::Helper::makeTraCIColor(), GUISUMOAbstractView::onConfigure(), GUISUMOAbstractView::paintGL(), and GLHelper::setColor().

Here is the caller graph for this function:

◆ interpolate()

RGBColor RGBColor::interpolate ( const RGBColor minColor,
const RGBColor maxColor,
double  weight 
)
static

Interpolates between two colors.

The interpolated color is calculated as a weighted average of the RGB values of minColor and maxColor, giving weight to maxColor and 1-weight to minColor.

Parameters
[in]minColorThe color to interpolate from
[in]maxColorThe color to interpolate to
[in]weightThe weight of the first color
Returns
The interpolated color

Definition at line 284 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, myRed, and RGBColor().

Referenced by GUISUMOAbstractView::displayColorLegend(), and GUIPropertyScheme< T >::interpolate().

Here is the caller graph for this function:

◆ invertedColor()

RGBColor RGBColor::invertedColor ( ) const

obtain inverted of current RGBColor

Definition at line 134 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, myRed, and RGBColor().

Referenced by GNEPoly::drawGL(), and GNETAZ::drawGL().

Here is the caller graph for this function:

◆ operator!=()

bool RGBColor::operator!= ( const RGBColor c) const

Definition at line 128 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, and myRed.

◆ operator==()

bool RGBColor::operator== ( const RGBColor c) const

Definition at line 122 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, and myRed.

◆ parseColor()

RGBColor RGBColor::parseColor ( std::string  coldef)
static

Parses a color information.

It is assumed that the color is stored as "<RED>,<GREEN>,<BLUE>" and each color is represented as a double. Alternatively the color can be stored as "<RED>,<GREEN>,<BLUE>,<ALPHA>" and each color is represented as an unsigned byte.

Parameters
[in]coldefThe color definition to parse
Returns
The parsed color
Exceptions
EmptyDataIf the definition has less than three entries
NumberFormatExceptionIf one of the components is not numeric

Definition at line 168 of file RGBColor.cpp.

References BLACK, BLUE, CYAN, fromHSV(), StringTokenizer::getVector(), GREEN, GREY, StringUtils::hexToInt(), INVISIBLE, MAGENTA, myRNG, ORANGE, RandHelper::rand(), RED, RGBColor(), StringUtils::toDouble(), StringUtils::toInt(), WHITE, and YELLOW.

Referenced by PCTypeMap::add(), NLHandler::addDistrict(), GNEPolygonFrame::addPOI(), GNEPolygonFrame::addPOILane(), GNEPolygonFrame::addPolygon(), SUMOSAXAttributesImpl_Cached::getColor(), SUMOSAXAttributesImpl_Xerces::getColor(), PCLoaderArcView::load(), PCLoaderVisum::load(), PCLoaderDlrNavteq::loadPOIFile(), PCLoaderDlrNavteq::loadPolyFile(), PCLoaderXML::myStartElement(), GNEFrameAttributesModuls::AttributesEditorRow::onCmdOpenAttributeDialog(), GNEFrameAttributesModuls::AttributesCreatorRow::onCmdSelectColorButton(), GNETAZFrame::TAZParameters::onCmdSetColorAttribute(), GNEVehicleTypeDialog::VTypeAtributes::VTypeAttributeRow::openColorDialog(), parseColorReporting(), PCTypeMap::PCTypeMap(), and GUILane::setFunctionalColor().

Here is the caller graph for this function:

◆ parseColorReporting()

RGBColor RGBColor::parseColorReporting ( const std::string &  coldef,
const std::string &  objecttype,
const char *  objectid,
bool  report,
bool &  ok 
)
static

Parses a color information.

It is assumed that the color is stored as "<RED>,<GREEN>,<BLUE>" and each color is represented as a double. Alternatively the color can be stored as "<RED>,<GREEN>,<BLUE>,<ALPHA>" and each color is represented as an unsigned byte.

Parameters
[in]coldefThe color definition to parse
[in]objecttypeThe type of the currently parsed object
[in]objectidThe id of the currently parsed object
[in]reportWhether errors shall be reported
[in,out]okWhether parsing was successful
Returns
The parsed color
Exceptions
EmptyDataIf the definition has less than three entries
NumberFormatExceptionIf one of the components is not numeric

Definition at line 258 of file RGBColor.cpp.

References parseColor(), RGBColor(), UNUSED_PARAMETER, and WRITE_ERROR.

Referenced by GUISettingsHandler::myStartElement(), and GUISettingsHandler::parseTextSettings().

Here is the caller graph for this function:

◆ randomHue()

RGBColor RGBColor::randomHue ( double  s = 1,
double  v = 1 
)
static

Return color with random hue.

Parameters
[in]sSaturation (0-1)
[in]vValue (0-1)
Returns
The color as RGB

Definition at line 329 of file RGBColor.cpp.

References fromHSV(), myRNG, and RandHelper::rand().

Referenced by GLHelper::debugVertices().

Here is the caller graph for this function:

◆ red()

unsigned char RGBColor::red ( ) const
inline

Returns the red-amount of the color.

Returns
The red component's value

Definition at line 52 of file RGBColor.h.

References myRed.

Referenced by changedBrightness(), GLHelper::drawText(), GUIParameterTracker::GUIParameterTrackerPanel::drawValue(), MFXUtils::getFXColor(), GUISUMOAbstractView::makeSnapshot(), libsumo::Helper::makeTraCIColor(), GUISUMOAbstractView::onConfigure(), GUISUMOAbstractView::paintGL(), and GLHelper::setColor().

Here is the caller graph for this function:

◆ set()

void RGBColor::set ( unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)

assigns new values

Parameters
[in]rThe red component's value
[in]gThe green component's value
[in]bThe blue component's value
[in]aThe alpha component's value

Definition at line 71 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, and myRed.

◆ setAlpha()

void RGBColor::setAlpha ( unsigned char  alpha)
inline

Sets a new alpha value.

Parameters
[in]alphaThe new value to use

Definition at line 88 of file RGBColor.h.

References alpha(), and myAlpha.

Referenced by GNEViewNet::drawTemporalJunction(), and Shape::setShapeAlpha().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const RGBColor col 
)
friend

Writes the color to the given stream.

Parameters
[out]osThe stream to write to
[in]colThe color to write
Returns
The stream

Definition at line 79 of file RGBColor.cpp.

Field Documentation

◆ BLACK

◆ BLUE

◆ CYAN

◆ DEFAULT_COLOR

◆ DEFAULT_COLOR_STRING

const std::string RGBColor::DEFAULT_COLOR_STRING = toString(RGBColor::DEFAULT_COLOR)
static

The string description of the default color.

Definition at line 197 of file RGBColor.h.

◆ GREEN

◆ GREY

◆ INVISIBLE

const RGBColor RGBColor::INVISIBLE = RGBColor(0, 0, 0, 0)
static

Definition at line 190 of file RGBColor.h.

Referenced by GLHelper::drawTextAtEnd(), GLHelper::drawTextSettings(), and parseColor().

◆ MAGENTA

◆ myAlpha

unsigned char RGBColor::myAlpha
private

◆ myBlue

unsigned char RGBColor::myBlue
private

◆ myGreen

unsigned char RGBColor::myGreen
private

◆ myRed

unsigned char RGBColor::myRed
private

The color amounts.

Definition at line 201 of file RGBColor.h.

Referenced by changedBrightness(), interpolate(), invertedColor(), operator!=(), operator==(), red(), and set().

◆ myRNG

std::mt19937 RGBColor::myRNG
staticprivate

A random number generator to generate random colors independent of other randomness.

Definition at line 204 of file RGBColor.h.

Referenced by getColorRNG(), parseColor(), and randomHue().

◆ ORANGE

◆ RED

◆ WHITE

◆ YELLOW


The documentation for this class was generated from the following files: