RGBColor Class Reference

#include <RGBColor.h>

Inheritance diagram for RGBColor:

PointOfInterest GUIPointOfInterest

Detailed Description

The definition of a color in the RGB-space. The cube is meant to lie between (0, 0, 0) and (1, 1, 1)

Definition at line 44 of file RGBColor.h.


Public Member Functions

SUMOReal blue () const throw ()
 Returns the blue-amount of the color.
SUMOReal green () const throw ()
 Returns the green-amount of the color.
bool operator!= (const RGBColor &c) const
bool operator== (const RGBColor &c) const
SUMOReal red () const throw ()
 Returns the red-amount of the color.
 RGBColor (const RGBColor &col) throw ()
 Copy constructor.
 RGBColor (SUMOReal red, SUMOReal green, SUMOReal blue) throw ()
 Constructor.
 RGBColor () throw ()
 Constructor.
void set (SUMOReal r, SUMOReal g, SUMOReal b) throw ()
 assigns new values
 ~RGBColor () throw ()
 Destructor.

Static Public Member Functions

static RGBColor fromHSV (SUMOReal h, SUMOReal s, SUMOReal v) throw ()
 Converts the given hsv-triplet to rgb.
static RGBColor getDefaultColor () throw ()
 Returns the default color by parsing DEFAULT_COLOR_STRING.
static RGBColor interpolate (const RGBColor &minColor, const RGBColor &maxColor, SUMOReal weight) throw ()
 Interpolates between two colors.
static RGBColor parseColor (const std::string &coldef) throw (EmptyData, NumberFormatException)
 Parses a color information.
static RGBColor parseColorReporting (const std::string &coldef, const char *objecttype, const char *objectid, bool report, bool &ok) throw ()
 Parses a color information.

Static Public Attributes

static const RGBColor DEFAULT_COLOR = RGBColor::parseColor(RGBColor::DEFAULT_COLOR_STRING)
 The default color (for vehicle types and vehicles).
static const std::string DEFAULT_COLOR_STRING = "1,1,0"
 The string description of the default color.

Private Attributes

SUMOReal myBlue
SUMOReal myGreen
SUMOReal myRed
 The color amounts.

Friends

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

Constructor & Destructor Documentation

RGBColor::RGBColor (  )  throw ()

Constructor.

Definition at line 53 of file RGBColor.cpp.

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

00054         : myRed(-1), myGreen(-1), myBlue(-1) {}

RGBColor::RGBColor ( SUMOReal  red,
SUMOReal  green,
SUMOReal  blue 
) throw ()

Constructor.

Parameters:
[in] red The red component's value
[in] green The green component's value
[in] blue The blue component's value

Definition at line 57 of file RGBColor.cpp.

00058         : myRed(red), myGreen(green), myBlue(blue) {}

RGBColor::RGBColor ( const RGBColor col  )  throw ()

Copy constructor.

Definition at line 61 of file RGBColor.cpp.

00062         : myRed(col.myRed), myGreen(col.myGreen), myBlue(col.myBlue) {}

RGBColor::~RGBColor (  )  throw ()

Destructor.

Definition at line 65 of file RGBColor.cpp.

00065 {}


Member Function Documentation

SUMOReal RGBColor::blue (  )  const throw () [inline]

RGBColor RGBColor::fromHSV ( SUMOReal  h,
SUMOReal  s,
SUMOReal  v 
) throw () [static]

Converts the given hsv-triplet to rgb.

Parameters:
[in] h Hue (0-360)
[in] s Saturation (0-1)
[in] v Value (0-1)
Returns:
The color as RGB
Author:
Alvy Ray Smith (http://www.alvyray.com/default.htm)

Definition at line 159 of file RGBColor.cpp.

References RGBColor().

Referenced by GUIVehicle::Colorer::setFunctionalColor().

00159                                                             {
00160     // H is given on [0, 6] or UNDEFINED. S and V are given on [0, 1].
00161     // RGB are each returned on [0, 1].
00162     //float h = HSV.H, s = HSV.S, v = HSV.V,
00163     float m, n, f;
00164     h /= 60.;
00165     int i;
00166     //if (h == UNDEFINED) RETURN_RGB(v, v, v);
00167     i = floor(h);
00168     f = h - i;
00169     if (!(i&1)) f = 1 - f;   // if i is even
00170     m = v * (1 - s);
00171     n = v * (1 - s * f);
00172     switch (i) {
00173     case 6:
00174     case 0:
00175         return RGBColor(v, n, m);
00176     case 1:
00177         return RGBColor(n, v, m);
00178     case 2:
00179         return RGBColor(m, v, n);
00180     case 3:
00181         return RGBColor(m, n, v);
00182     case 4:
00183         return RGBColor(n, m, v);
00184     case 5:
00185         return RGBColor(v, m, n);
00186     }
00187     return RGBColor(1, 1, 1);
00188 }

RGBColor RGBColor::getDefaultColor (  )  throw () [static]

Returns the default color by parsing DEFAULT_COLOR_STRING.

Returns:
The default color

Definition at line 142 of file RGBColor.cpp.

References DEFAULT_COLOR_STRING, and parseColor().

Referenced by MSRouteHandler::openRoute().

00142                                   {
00143     return parseColor(RGBColor::DEFAULT_COLOR_STRING);
00144 }

SUMOReal RGBColor::green (  )  const throw () [inline]

RGBColor RGBColor::interpolate ( const RGBColor minColor,
const RGBColor maxColor,
SUMOReal  weight 
) throw () [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] minColor The color to interpolate from
[in] maxColor The color to interpolate to
[in] weight The weight of the first color
Returns:
The interpolated color

Definition at line 148 of file RGBColor.cpp.

References RGBColor(), and SUMOReal.

Referenced by GUIColorScheme::getColor(), and TEST().

00148                                                                                                  {
00149     if (weight < 0) weight = 0;
00150     if (weight > 1) weight = 1;
00151     SUMOReal r = minColor.myRed + (maxColor.myRed - minColor.myRed) * weight;
00152     SUMOReal g = minColor.myGreen + (maxColor.myGreen - minColor.myGreen) * weight;
00153     SUMOReal b = minColor.myBlue + (maxColor.myBlue - minColor.myBlue) * weight;
00154     return RGBColor(r, g, b);
00155 }

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

Definition at line 95 of file RGBColor.cpp.

References myBlue, myGreen, and myRed.

00095                                             {
00096     return fabs(myRed-c.myRed)>0.1 || fabs(myGreen-c.myGreen)>0.1 || fabs(myBlue-c.myBlue)>0.1;
00097     //return myRed!=c.myRed||myGreen!=c.myGreen||myBlue!=c.myBlue;
00098 }

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

Definition at line 88 of file RGBColor.cpp.

References myBlue, myGreen, and myRed.

00088                                             {
00089     return fabs(myRed-c.myRed)<0.1 && fabs(myGreen-c.myGreen)<0.1 && fabs(myBlue-c.myBlue)<0.1;
00090     //return myRed==c.myRed&&myGreen==c.myGreen&&myBlue==c.myBlue;
00091 }

RGBColor RGBColor::parseColor ( const std::string &  coldef  )  throw (EmptyData, NumberFormatException) [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.

Parameters:
[in] coldef The color definition to parse
Returns:
The parsed color
Exceptions:
EmptyData If the definition has less than three entries
NumberFormatException If one of the components is not numeric

Definition at line 102 of file RGBColor.cpp.

References TplConvert< E >::_2SUMOReal(), StringTokenizer::next(), RGBColor(), StringTokenizer::size(), and SUMOReal.

Referenced by getDefaultColor(), PCLoaderVisum::load(), PCLoaderArcView::load(), PCLoaderOSM::loadIfSet(), PCLoaderDlrNavteq::loadPOIFile(), PCLoaderDlrNavteq::loadPolyFile(), PCLoaderXML::myStartElement(), parseColorReporting(), SUMOVehicleParserHelper::parseCommonAttributes(), and TEST().

00102                                                                                     {
00103     StringTokenizer st(coldef, ",");
00104     if (st.size()<3) {
00105         throw EmptyData();
00106     }
00107     SUMOReal r = TplConvert<char>::_2SUMOReal(st.next().c_str());
00108     SUMOReal g = TplConvert<char>::_2SUMOReal(st.next().c_str());
00109     SUMOReal b = TplConvert<char>::_2SUMOReal(st.next().c_str());
00110     return RGBColor(r, g, b);
00111 }

RGBColor RGBColor::parseColorReporting ( const std::string &  coldef,
const char *  objecttype,
const char *  objectid,
bool  report,
bool ok 
) throw () [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.

Parameters:
[in] coldef The color definition to parse
[in] objecttype The type of the currently parsed object
[in] objectid The id of the currently parsed object
[in] report Whether errors shall be reported
[in,out] ok Whether parsing was successful
Returns:
The parsed color
Exceptions:
EmptyData If the definition has less than three entries
NumberFormatException If one of the components is not numeric

Definition at line 115 of file RGBColor.cpp.

References MsgHandler::getErrorInstance(), MsgHandler::inform(), parseColor(), and RGBColor().

Referenced by NLHandler::addPOI(), NLHandler::addPoly(), SUMOVehicleParserHelper::beginVTypeParsing(), GUISettingsHandler::myStartElement(), MSRouteHandler::openRoute(), and RORDLoader_SUMOBase::startRoute().

00115                                                                                                                                   {
00116     try {
00117         return parseColor(coldef);
00118     } catch (NumberFormatException &) {
00119     } catch (EmptyData &) {
00120     }
00121     ok = false;
00122     std::ostringstream oss;
00123     oss << "Attribute 'color' in definition of ";
00124     if (objectid==0) {
00125         oss << "a ";
00126     }
00127     if (objecttype!=0) {
00128         oss << objecttype;
00129     } else {
00130         oss << "<unknown type>";
00131     }
00132     if (objectid!=0) {
00133         oss << " '" << objectid << "'";
00134     }
00135     oss << " is not a valid color.";
00136     MsgHandler::getErrorInstance()->inform(oss.str());
00137     return RGBColor();
00138 }

SUMOReal RGBColor::red (  )  const throw () [inline]

void RGBColor::set ( SUMOReal  r,
SUMOReal  g,
SUMOReal  b 
) throw ()

assigns new values

Parameters:
[in] r The red component's value
[in] g The green component's value
[in] b The blue component's value

Definition at line 69 of file RGBColor.cpp.

References myBlue, myGreen, and myRed.

00069                                                         {
00070     myRed = r;
00071     myGreen = g;
00072     myBlue = b;
00073 }


Friends And Related Function Documentation

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

Writes the color to the given stream.

Parameters:
[out] os The stream to write to
[in] col The color to write
Returns:
The stream

Definition at line 78 of file RGBColor.cpp.

00078                                                 {
00079     os
00080     << col.myRed << ","
00081     << col.myGreen << ","
00082     << col.myBlue;
00083     return os;
00084 }


Field Documentation

const RGBColor RGBColor::DEFAULT_COLOR = RGBColor::parseColor(RGBColor::DEFAULT_COLOR_STRING) [static]

The default color (for vehicle types and vehicles).

Definition at line 175 of file RGBColor.h.

Referenced by traci::TraCIServer::commandDistanceRequest(), and SUMOVehicleParserHelper::parseCommonAttributes().

const std::string RGBColor::DEFAULT_COLOR_STRING = "1,1,0" [static]

The string description of the default color.

Definition at line 171 of file RGBColor.h.

Referenced by getDefaultColor().

SUMOReal RGBColor::myBlue [private]

Definition at line 180 of file RGBColor.h.

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

SUMOReal RGBColor::myGreen [private]

Definition at line 180 of file RGBColor.h.

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

SUMOReal RGBColor::myRed [private]

The color amounts.

Definition at line 180 of file RGBColor.h.

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


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

Generated on Wed May 5 00:06:59 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6