Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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.
 
unsigned char blue () const
 Returns the blue-amount of the color.
 
RGBColor changedAlpha (int change) const
 Returns a new color with altered opacity.
 
RGBColor changedBrightness (int change, int toChange=3) const
 Returns a new color with altered brightness.
 
unsigned char green () const
 Returns the green-amount of the color.
 
RGBColor invertedColor () const
 obtain inverted of current RGBColor
 
bool isRandom () const
 check if color is random
 
bool isValid () const
 check if RGBColor is valid
 
RGBColor multiply (double factor) const
 Returns a new color with altered brightness.
 
bool operator!= (const RGBColor &c) const
 
bool operator== (const RGBColor &c) const
 
unsigned char red () const
 Returns the red-amount of the color.
 
 RGBColor (bool valid=true)
 Constructor.
 
 RGBColor (unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255, bool random=false)
 Constructor.
 
void set (unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 assigns new values
 
void setAlpha (unsigned char alpha)
 Sets a new alpha value.
 
void setValid (const bool value)
 set valid
 

Static Public Member Functions

static RGBColor fromHSV (double h, double s, double v, bool random=false)
 Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb.htm.
 
static SumoRNGgetColorRNG ()
 get color RNG
 
static RGBColor interpolate (const RGBColor &minColor, const RGBColor &maxColor, double weight)
 Interpolates between two colors.
 
static bool isColor (std::string coldef)
 check if the given string can be parsed to color
 
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.
 
static RGBColor randomHue (double s=1, double v=1, bool random=false)
 Return color with random hue.
 

Static Public Attributes

static const RGBColor DEFAULT_COLOR = RGBColor::YELLOW
 The default color (for vehicle types and vehicles)
 
static const std::string DEFAULT_COLOR_STRING = toString(RGBColor::DEFAULT_COLOR)
 The string description of the default color.
 
static const RGBColor RED = RGBColor(255, 0, 0, 255)
 named colors
 
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 = 0
 
unsigned char myBlue = 0
 
unsigned char myGreen = 0
 
bool myRandom = false
 flag to check if color is random
 
unsigned char myRed = 0
 The color amounts.
 
bool myValid = true
 flag to check if color is valid
 

Static Private Attributes

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

Friends

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

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 42 of file RGBColor.h.

Constructor & Destructor Documentation

◆ RGBColor() [1/2]

RGBColor::RGBColor ( bool  valid = true)

Constructor.

Definition at line 65 of file RGBColor.cpp.

◆ RGBColor() [2/2]

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

Constructor.

Parameters
[in]redThe red component's value
[in]greenThe green component's value
[in]blueThe blue component's value
[in]ifthe given color is random

Definition at line 69 of file RGBColor.cpp.

Member Function Documentation

◆ alpha()

unsigned char RGBColor::alpha ( ) const

◆ blue()

unsigned char RGBColor::blue ( ) const

Returns the blue-amount of the color.

Returns
The blue component's value

Definition at line 90 of file RGBColor.cpp.

References myBlue.

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

Here is the caller graph for this function:

◆ changedAlpha()

RGBColor RGBColor::changedAlpha ( int  change) const

Returns a new color with altered opacity.

Definition at line 233 of file RGBColor.cpp.

References alpha(), MAX2(), MIN2(), myAlpha, myBlue, myGreen, and myRed.

Referenced by GUIParameterTracker::GUIParameterTrackerPanel::drawValue().

Here is the caller graph for this function:

◆ changedBrightness()

RGBColor RGBColor::changedBrightness ( int  change,
int  toChange = 3 
) const

Returns a new color with altered brightness.

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

Definition at line 210 of file RGBColor.cpp.

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

Referenced by changedBrightness(), GUIBasePersonHelper::drawAction_drawAsPoly(), GUIVehicle::drawAction_drawCarriageClass(), GUIBaseVehicleHelper::drawAction_drawVehicleAsPoly(), GUIGeometry::drawChildLine(), GNEConnection::drawConnection(), GNEConnection::drawConnectionArrows(), GNECrossing::drawCrossing(), GNELaneAreaDetector::drawE2(), GNEEdge::drawEdgeGeometryPoints(), GNEEdge::drawEdgeShape(), GNEEdge::drawEndGeometryPoint(), GNEStop::drawGeometryPoints(), GUIBusStop::drawGL(), GUILane::drawGL(), GNEBusStop::drawGL(), GNEChargingStation::drawGL(), GNEContainerStop::drawGL(), GNEInductionLoopDetector::drawGL(), GNEInstantInductionLoopDetector::drawGL(), GNEParkingArea::drawGL(), GNEPoly::drawGL(), GNERouteProbe::drawGL(), GNETAZ::drawGL(), GNEVaporizer::drawGL(), GNEStopPlan::drawGL(), GUIPerson::drawGLAdditional(), GNEJunction::drawJunctionAsShape(), GNEAdditionalListed::drawListedAdditional(), GUIGeometry::drawParentLine(), GNERerouterSymbol::drawRerouterSymbol(), GUIBaseVehicle::drawRoute(), GNEAdditional::drawSemiCircleGeometryPoint(), GNELane::drawShapeEdited(), GNELane::drawStartEndGeometryPoints(), GNEEdge::drawStartGeometryPoint(), GNEWalkingArea::drawTesselatedWalkingArea(), GUIParameterTracker::GUIParameterTrackerPanel::drawValue(), GNEVariableSpeedSignSymbol::drawVSSSymbol(), and GUIDottedGeometry::DottedGeometryColor::getColor().

Here is the caller graph for this function:

◆ fromHSV()

RGBColor RGBColor::fromHSV ( double  h,
double  s,
double  v,
bool  random = false 
)
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)
[in]randomif the value is random
Returns
The color as RGB

Definition at line 413 of file RGBColor.cpp.

References MAX2(), and MIN2().

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

Here is the caller graph for this function:

◆ getColorRNG()

SumoRNG * RGBColor::getColorRNG ( )
static

get color RNG

Definition at line 204 of file RGBColor.cpp.

References myRNG.

Referenced by GUILane::setFunctionalColor().

Here is the caller graph for this function:

◆ green()

unsigned char RGBColor::green ( ) const

Returns the green-amount of the color.

Returns
The green component's value

Definition at line 84 of file RGBColor.cpp.

References myGreen.

Referenced by changedBrightness(), GLHelper::drawText(), MFXUtils::getFXColor(), GUISUMOAbstractView::makeSnapshot(), libsumo::Helper::makeTraCIColor(), multiply(), 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 397 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, and myRed.

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

References myAlpha, myBlue, myGreen, and myRed.

Referenced by GUIGeometry::drawGeometryPoints().

Here is the caller graph for this function:

◆ isColor()

bool RGBColor::isColor ( std::string  coldef)
static

check if the given string can be parsed to color

Definition at line 339 of file RGBColor.cpp.

References StringTokenizer::getVector(), StringUtils::isDouble(), StringUtils::isHex(), and StringUtils::to_lower_case().

Referenced by GNEAttributeCarrier::canParse().

Here is the caller graph for this function:

◆ isRandom()

bool RGBColor::isRandom ( ) const

check if color is random

Definition at line 130 of file RGBColor.cpp.

References myRandom.

Referenced by GNEVehicle::getAttribute(), and SUMOVehicleParameter::write().

Here is the caller graph for this function:

◆ isValid()

bool RGBColor::isValid ( ) const

check if RGBColor is valid

Definition at line 124 of file RGBColor.cpp.

References myValid.

Referenced by NBPTLine::write(), and NBPTStop::write().

Here is the caller graph for this function:

◆ multiply()

RGBColor RGBColor::multiply ( double  factor) const

Returns a new color with altered brightness.

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

Definition at line 240 of file RGBColor.cpp.

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

Referenced by GUIBaseVehicle::drawRoute().

Here is the caller graph for this function:

◆ operator!=()

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

Definition at line 187 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, myRed, and myValid.

◆ operator==()

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

Definition at line 181 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, myRed, and myValid.

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

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

Referenced by PCTypeMap::add(), NLHandler::addDistrict(), GUIBusStop::finishedLoading(), SUMOSAXAttributes::fromString(), PCLoaderArcView::load(), PCLoaderVisum::load(), PCLoaderDlrNavteq::loadPOIFile(), PCLoaderDlrNavteq::loadPolyFile(), PCLoaderXML::myStartElement(), NIImporter_OpenStreetMap::RelationHandler::myStartElement(), GNEAttributeCarrier::parse(), 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 371 of file RGBColor.cpp.

References parseColor(), UNUSED_PARAMETER, and WRITE_ERROR.

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

Here is the caller graph for this function:

◆ randomHue()

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

Return color with random hue.

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

Definition at line 446 of file RGBColor.cpp.

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

◆ red()

unsigned char RGBColor::red ( ) const

Returns the red-amount of the color.

Returns
The red component's value

Definition at line 78 of file RGBColor.cpp.

References myRed.

Referenced by GUIDialog_ViewSettings::build3DFrame(), changedBrightness(), GLHelper::drawText(), MFXUtils::getFXColor(), GUISUMOAbstractView::makeSnapshot(), libsumo::Helper::makeTraCIColor(), multiply(), 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 102 of file RGBColor.cpp.

References myAlpha, myBlue, myGreen, myRed, and myValid.

Referenced by GUIDialog_ViewSettings::onCmdColorChange().

Here is the caller graph for this function:

◆ setAlpha()

void RGBColor::setAlpha ( unsigned char  alpha)

Sets a new alpha value.

Parameters
[in]alphaThe new value to use

Definition at line 112 of file RGBColor.cpp.

References alpha(), and myAlpha.

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

Here is the caller graph for this function:

◆ setValid()

void RGBColor::setValid ( const bool  value)

set valid

Definition at line 118 of file RGBColor.cpp.

References myValid.

Friends And Related Symbol 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 135 of file RGBColor.cpp.

Field Documentation

◆ BLACK

const RGBColor RGBColor::BLACK = RGBColor(0, 0, 0, 255)
static

Definition at line 206 of file RGBColor.h.

Referenced by GUIParameterTracker::addTrackedMultiplot(), GNETLSEditorFrame::TLSAttributes::clearTLSAttributes(), GNEInternalLane::colorForLinksState(), GUISUMOAbstractView::displayColorLegend(), GUISUMOAbstractView::displayLegend(), GNEDistributionFrame::DistributionRow::DistributionRow(), GUIBaseVehicleHelper::drawAction_drawVehicleAsPoly(), GNECalibrator::drawCalibratorSymbol(), GNELaneAreaDetector::drawE2(), GNELaneAreaDetector::drawE2PartialLane(), GNEGenericData::drawFilteredAttribute(), GNEDemandElementFlow::drawFlowLabel(), GUICalibrator::drawGL(), GUIOverheadWire::drawGL(), GUITriggeredRerouter::GUITriggeredRerouterEdge::drawGL(), GNECalibratorFlow::drawGL(), GNEInductionLoopDetector::drawGL(), GNEInstantInductionLoopDetector::drawGL(), GNEVariableSpeedSignStep::drawGL(), GNEEdgeData::drawLanePartialGL(), GNEEdgeRelData::drawLanePartialGL(), GNELane::drawOverlappedRoutes(), GNERerouterSymbol::drawRerouterSymbol(), GUIBaseVehicle::drawRoute(), GNEViewNet::drawTemporalJunction(), GUIParameterTracker::GUIParameterTrackerPanel::drawValue(), GUITLLogicPhasesTrackerWindow::drawValues(), GNEVariableSpeedSignSymbol::drawVSSSymbol(), GUIDottedGeometry::DottedGeometryColor::getColor(), GLHelper::getDottedcontourColors(), GUIParameterTracker::GUIParameterTracker(), GUIVisualizationSettings::initNeteditDefaults(), GUIVisualizationSettings::initSumoGuiDefaults(), GNETLSEditorFrame::TLSAttributes::initTLSAttributes(), GNETLSEditorFrame::TLSAttributes::isValidOffset(), GNETLSEditorFrame::TLSAttributes::isValidParameters(), NIImporter_Vissim::NIImporter_Vissim(), GNEAttributeCarrierDialog::AttributeTextField::onCmdOpenColorDialog(), GNEAttributesEditorRow::onCmdOpenColorDialog(), GUIParam_PopupMenuInterface::onCmdOpenTracker(), GNEDistributionFrame::DistributionRow::onCmdSetProbability(), GUIParameterTableWindow::onLeftBtnPress(), GNEVehicleTypeDialog::VTypeAttributes::VTypeAttributeRow::openColorDialog(), parseColor(), GNETLSEditorFrame::TLSAttributes::setOffset(), and GNETLSEditorFrame::TLSAttributes::setParameters().

◆ 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 215 of file RGBColor.h.

◆ GREEN

◆ GREY

◆ INVISIBLE

◆ MAGENTA

◆ myAlpha

unsigned char RGBColor::myAlpha = 0
private

◆ myBlue

unsigned char RGBColor::myBlue = 0
private

◆ myGreen

unsigned char RGBColor::myGreen = 0
private

◆ myRandom

bool RGBColor::myRandom = false
private

flag to check if color is random

Definition at line 225 of file RGBColor.h.

Referenced by isRandom().

◆ myRed

unsigned char RGBColor::myRed = 0
private

The color amounts.

Definition at line 219 of file RGBColor.h.

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

◆ myRNG

SumoRNG RGBColor::myRNG
staticprivate

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

Definition at line 228 of file RGBColor.h.

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

◆ myValid

bool RGBColor::myValid = true
private

flag to check if color is valid

Definition at line 222 of file RGBColor.h.

Referenced by isValid(), operator!=(), operator==(), set(), and setValid().

◆ ORANGE

◆ RED

const RGBColor RGBColor::RED = RGBColor(255, 0, 0, 255)
static

named colors

Definition at line 198 of file RGBColor.h.

Referenced by AGActivityTripWriter::AGActivityTripWriter(), GNELaneAreaDetector::drawE2PartialJunction(), GUISUMOAbstractView::drawFPS(), GNEDemandElementPlan::drawFromArrow(), GUIOverheadWire::drawGL(), GNEClosingLaneReroute::drawGL(), GNEClosingReroute::drawGL(), GNEDestProbReroute::drawGL(), GNEParkingAreaReroute::drawGL(), GNERerouterInterval::drawGL(), GNERouteProbReroute::drawGL(), GNEDemandElement::drawJunctionLine(), GNEVehicle::drawLanePartialGL(), GNEDemandElementPlan::drawPlanJunctionPartial(), GNERoute::drawRoutePartialJunction(), GNERoute::drawRoutePartialLane(), GLHelper::drawSpaceOccupancies(), GNEConsecutiveSelector::drawTemporalConsecutiveLanePath(), GNEViewNet::drawTemporalDrawingShape(), GNEDemandElementPlan::drawToArrow(), GUIParameterTracker::GUIParameterTrackerPanel::drawValue(), GNEVariableSpeedSignSymbol::drawVSSSymbol(), MSActuatedTrafficLightLogic::gapControl(), GNEDemandElement::getColorByScheme(), GUIParameterTracker::GUIParameterTracker(), GUIVisualizationSettings::initNeteditDefaults(), GUIVisualizationSettings::initSumoGuiDefaults(), GNETLSEditorFrame::TLSAttributes::isValidOffset(), GNETLSEditorFrame::TLSAttributes::isValidParameters(), NIImporter_Vissim::NIImporter_Vissim(), GUIApplicationWindow::onCmdGaming(), GNEDistributionFrame::DistributionRow::onCmdSetProbability(), parseColor(), AdditionalHandler::parsePOIAttributes(), AdditionalHandler::parsePolyAttributes(), AdditionalHandler::parseTAZAttributes(), RODFDetectorCon::saveAsPOIs(), GNEEdgeData::setColor(), GUIBaseVehicle::setFunctionalColor(), GNEPOI::writeAdditional(), and NBSign::writeAsPOI().

◆ WHITE

◆ YELLOW


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