SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RGBColor Class Reference

#include <RGBColor.h>

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 (const char change)
 Returns a new color with altered brightness. More...
 
unsigned char green () const
 Returns the green-amount of the color. 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...
 
 RGBColor (const RGBColor &col)
 Copy constructor. More...
 
void set (unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 assigns new values More...
 
 ~RGBColor ()
 Destructor. More...
 

Static Public Member Functions

static RGBColor fromHSV (SUMOReal h, SUMOReal s, SUMOReal v)
 Converts the given hsv-triplet to rgb. More...
 
static RGBColor interpolate (const RGBColor &minColor, const RGBColor &maxColor, SUMOReal 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 Public Attributes

static const RGBColor BLACK = RGBColor(0, 0, 0, 255)
 
static const RGBColor BLUE = RGBColor(0, 0, 255, 255)
 
static const RGBColor CYAN = RGBColor(0, 255, 255, 255)
 
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 GREEN = RGBColor(0, 255, 0, 255)
 
static const RGBColor GREY = RGBColor(128, 128, 128, 255)
 
static const RGBColor MAGENTA = RGBColor(255, 0, 255, 255)
 
static const RGBColor RED = RGBColor(255, 0, 0, 255)
 
static const RGBColor WHITE = RGBColor(255, 255, 255, 255)
 
static const RGBColor YELLOW = RGBColor(255, 255, 0, 255)
 

Private Attributes

unsigned char myAlpha
 
unsigned char myBlue
 
unsigned char myGreen
 
unsigned char myRed
 The color amounts. 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 47 of file RGBColor.h.

Constructor & Destructor Documentation

RGBColor::RGBColor ( )

Constructor.

Definition at line 69 of file RGBColor.cpp.

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

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 73 of file RGBColor.cpp.

RGBColor::RGBColor ( const RGBColor col)

Copy constructor.

Definition at line 77 of file RGBColor.cpp.

RGBColor::~RGBColor ( )

Destructor.

Definition at line 81 of file RGBColor.cpp.

Member Function Documentation

RGBColor RGBColor::changedBrightness ( const char  change)

Returns a new color with altered brightness.

Parameters
[in]changeThe absolute change applied to all channels (within bounds)
Returns
The new color

Definition at line 145 of file RGBColor.cpp.

References blue(), green(), MAX2(), MIN2(), myAlpha, myBlue, myGreen, myRed, red(), and RGBColor().

Referenced by GUIPerson::drawAction_drawAsPoly(), GUIVehicle::drawAction_drawRailCarriages(), and GUIVehicle::drawAction_drawVehicleAsPoly().

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

Converts the given hsv-triplet to rgb.

Parameters
[in]hHue (0-360)
[in]sSaturation (0-1)
[in]vValue (0-1)
Returns
The color as RGB
Author
Alvy Ray Smith (http://www.alvyray.com/default.htm)

Definition at line 273 of file RGBColor.cpp.

References RGBColor(), and SUMOReal.

Referenced by GUIVehicle::setFunctionalColor().

RGBColor RGBColor::interpolate ( const RGBColor minColor,
const RGBColor maxColor,
SUMOReal  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 257 of file RGBColor.cpp.

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

Referenced by GUIColorScheme::getColor().

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

Definition at line 139 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, and myRed.

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

Definition at line 133 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, and myRed.

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 SUMOReal. 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 154 of file RGBColor.cpp.

References TplConvert::_2int(), TplConvert::_2SUMOReal(), TplConvert::_hex2int(), BLACK, BLUE, CYAN, StringTokenizer::getVector(), GREEN, GREY, MAGENTA, RED, RGBColor(), WHITE, and YELLOW.

Referenced by PCTypeMap::add(), NLHandler::addDistrict(), SUMOSAXAttributesImpl_Xerces::getColor(), PCLoaderVisum::load(), PCLoaderArcView::load(), PCLoaderDlrNavteq::loadPOIFile(), PCLoaderDlrNavteq::loadPolyFile(), PCLoaderXML::myStartElement(), parseColorReporting(), and PCTypeMap::PCTypeMap().

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 SUMOReal. 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 231 of file RGBColor.cpp.

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

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

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 85 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, and myRed.

Referenced by TraCIServerAPI_Vehicle::processSet(), and TraCIServer::readTypeCheckingColor().

Friends And Related Function Documentation

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 94 of file RGBColor.cpp.

Field Documentation

const RGBColor RGBColor::BLUE = RGBColor(0, 0, 255, 255)
static
const RGBColor RGBColor::CYAN = RGBColor(0, 255, 255, 255)
static
const RGBColor RGBColor::DEFAULT_COLOR = RGBColor::YELLOW
static

The default color (for vehicle types and vehicles)

Definition at line 198 of file RGBColor.h.

Referenced by MSRoute::getColor(), SUMOVehicleParserHelper::parseCommonAttributes(), MSBaseVehicle::replaceRouteEdges(), and GUIVehicle::setFunctionalColor().

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

The string description of the default color.

Definition at line 202 of file RGBColor.h.

const RGBColor RGBColor::GREY = RGBColor(128, 128, 128, 255)
static
const RGBColor RGBColor::MAGENTA = RGBColor(255, 0, 255, 255)
static

Definition at line 193 of file RGBColor.h.

Referenced by NIImporter_Vissim::NIImporter_Vissim(), and parseColor().

unsigned char RGBColor::myAlpha
private

Definition at line 207 of file RGBColor.h.

Referenced by alpha(), changedBrightness(), interpolate(), operator!=(), operator<<(), operator==(), and set().

unsigned char RGBColor::myBlue
private

Definition at line 207 of file RGBColor.h.

Referenced by blue(), changedBrightness(), interpolate(), operator!=(), operator<<(), operator==(), and set().

unsigned char RGBColor::myGreen
private

Definition at line 207 of file RGBColor.h.

Referenced by changedBrightness(), green(), interpolate(), operator!=(), operator<<(), operator==(), and set().

unsigned char RGBColor::myRed
private

The color amounts.

Definition at line 207 of file RGBColor.h.

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

const RGBColor RGBColor::WHITE = RGBColor(255, 255, 255, 255)
static

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