DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Attributes | Private Attributes
DGtal::Color Class Reference

#include <Color.h>

Collaboration diagram for DGtal::Color:
Collaboration graph
[legend]

Public Member Functions

 ~Color ()
 Color (const unsigned int aRgb, unsigned char aAlpha=255)
 Color (unsigned char aRedValue, unsigned char aGreenValue, unsigned char aBlueValue, unsigned char aAlphaValue=255)
 Color (unsigned char aGrayValue, unsigned char aAlphaValue=255)
 Color (const bool aValidColor=true)
ColorsetRGBi (const unsigned char aRedValue, const unsigned char aGreenValue, const unsigned char aBlueValue, const unsigned char aAlphaValue)
void red (const unsigned char aRedValue)
void green (const unsigned char aGreenValue)
void blue (const unsigned char aBlueValue)
void alpha (const unsigned char aAlphaValue)
unsigned char red () const
unsigned char green () const
unsigned char blue () const
unsigned char alpha () const
bool valid () const
void selfDisplay (std::ostream &out) const
bool isValid () const
ColorsetRGBf (float red, float green, float blue, float alpha=1.0)
bool operator== (const Color &aColor) const
bool operator!= (const Color &aColor) const
bool operator< (const Color &aColor) const
void flushPostscript (std::ostream &) const
std::string svg () const
std::string svgAlpha (const char *aPrefix) const
std::string postscript () const
std::string tikz () const

Static Public Attributes

static const Color None
static const Color Black
static const Color Gray
static const Color White
static const Color Red
static const Color Green
static const Color Lime
static const Color Blue
static const Color Cyan
static const Color Magenta
static const Color Yellow
static const Color Silver
static const Color Purple
static const Color Navy
static const Color Aqua

Private Attributes

int myRed
int myGreen
int myBlue
int myAlpha

Detailed Description

Structure representing an RGB triple.

Description of class 'Color'

Examples:
geometry/surfaces/greedy-plane-segmentation-ex2.cpp, geometry/surfaces/greedy-plane-segmentation.cpp, io/boards/dgtalBoard2D-3-custom-classes.cpp, io/boards/dgtalBoard2D-3-custom-points.cpp, io/boards/dgtalBoard2D-4-colormaps.cpp, io/boards/dgtalBoard3DTo2D-3-objects.cpp, io/boards/dgtalBoard3DTo2D-5-custom.cpp, io/boards/dgtalBoard3DTo2D-6.cpp, io/digitalSetFromPointList.cpp, io/meshFromOFF.cpp, io/viewers/viewer3D-3-objects.cpp, io/viewers/viewer3D-5-custom.cpp, io/viewers/viewer3D-6-clipping.cpp, logoDGtal.cpp, topology/3dBorderExtraction.cpp, topology/3dKSSurfaceExtraction.cpp, topology/ctopo-1.cpp, topology/ctopo-2-3d.cpp, topology/ctopo-2.cpp, topology/frontierAndBoundary.cpp, topology/homotopicThinning3D.cpp, topology/khalimskySpaceScanner.cpp, topology/volScanBoundary.cpp, and topology/volTrackBoundary.cpp.

Definition at line 61 of file Color.h.


Constructor & Destructor Documentation

DGtal::Color::~Color ( )

Destructor.

Definition at line 175 of file Color.cpp.

{
}
DGtal::Color::Color ( const unsigned int  aRgb,
unsigned char  aAlpha = 255 
)

Constructor.

Parameters:
aRgb,:an unsigned int representing the color.
aAlpha,:color transparency (default value =255);

Definition at line 44 of file Color.cpp.

References myBlue, myGreen, and myRed.

:myAlpha( aAlphaValue )
{
myRed = ( rgb & 0xFF0000u ) >> 16;
myGreen = ( rgb & 0xFF00u ) >> 8;
myBlue = rgb & 0xFF;
}
DGtal::Color::Color ( unsigned char  aRedValue,
unsigned char  aGreenValue,
unsigned char  aBlueValue,
unsigned char  aAlphaValue = 255 
)
inline

Constructor from R, G, B and Alpha parameter.

Parameters:
aRedValue,aGreenValue,aBlueValue,aAlphaValue,:the three color components.
alpha,:color transparency.

Definition at line 92 of file Color.h.

: myRed(aRedValue),myGreen(aGreenValue),myBlue(aBlueValue),myAlpha(aAlphaValue) { }
DGtal::Color::Color ( unsigned char  aGrayValue,
unsigned char  aAlphaValue = 255 
)
inline

Constructor from gray scale value.

Parameters:
aGrayValue,:the color gray value.
alpha,:color transparency (default value =255);.

Definition at line 104 of file Color.h.

: myRed(aGrayValue),myGreen(aGrayValue), myBlue(aGrayValue), myAlpha(aAlphaValue) { }
DGtal::Color::Color ( const bool  aValidColor = true)
inline

Constructor.

Parameters:
aRedValue,aGreenValue,aBlueValue,:the three color components (set to -1)
alpha,:color transparency (default value =255);.

Definition at line 115 of file Color.h.

References myBlue, myGreen, and myRed.

: myRed(-1),myGreen(-1),myBlue(-1), myAlpha(255)
{
if ( aValidColor ) {
myRed = myGreen = myBlue = 0;
}
}

Member Function Documentation

void DGtal::Color::alpha ( const unsigned char  aAlphaValue)
inline
unsigned char DGtal::Color::alpha ( ) const
inline

Definition at line 123 of file Color.ih.

{
return myAlpha;
}
void DGtal::Color::blue ( const unsigned char  aBlueValue)
inline
unsigned char DGtal::Color::blue ( ) const
inline

Definition at line 116 of file Color.ih.

{
return myBlue;
}
void DGtal::Color::flushPostscript ( std::ostream &  stream) const

Definition at line 113 of file Color.cpp.

{
stream << ((double)myRed/255.0) << " "
<< ((double)myGreen/255.0) << " "
<< ((double)myBlue/255.0) << " srgb\n";
}
void DGtal::Color::green ( const unsigned char  aGreenValue)
inline
unsigned char DGtal::Color::green ( ) const
inline

Definition at line 109 of file Color.ih.

{
return myGreen;
}
bool DGtal::Color::isValid ( ) const

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Definition at line 216 of file Color.cpp.

{
return true;
}
bool DGtal::Color::operator!= ( const Color aColor) const

Definition at line 85 of file Color.cpp.

References myAlpha, myBlue, myGreen, and myRed.

{
return myRed != aColor.myRed
|| myGreen != aColor.myGreen
|| myBlue != aColor.myBlue
|| myAlpha != aColor.myAlpha;
}
bool DGtal::Color::operator< ( const Color aColor) const

Definition at line 94 of file Color.cpp.

References myAlpha, myBlue, myGreen, and myRed.

{
if ( myRed < aColor.myRed )
return true;
if ( myRed == aColor.myRed ) {
if ( myGreen < aColor.myGreen )
return true;
if ( myGreen == aColor.myGreen ) {
if ( myBlue < aColor.myBlue )
return true;
if ( myBlue == aColor.myBlue )
return myAlpha < aColor.myAlpha;
}
}
return false;
}
bool DGtal::Color::operator== ( const Color aColor) const

Definition at line 76 of file Color.cpp.

References myAlpha, myBlue, myGreen, and myRed.

{
return myRed == aColor.myRed
&& myGreen == aColor.myGreen
&& myBlue == aColor.myBlue
&& myAlpha == aColor.myAlpha;
}
string DGtal::Color::postscript ( ) const

Definition at line 121 of file Color.cpp.

References secured_sprintf.

{
char buffer[255];
secured_sprintf( buffer, 255, "%.4f %.4f %.4f", myRed/255.0, myGreen/255.0, myBlue/255.0 );
return buffer;
}
void DGtal::Color::red ( const unsigned char  aRedValue)
inline
unsigned char DGtal::Color::red ( ) const
inline

Definition at line 102 of file Color.ih.

{
return myRed;
}
void DGtal::Color::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 206 of file Color.cpp.

{
out << "[Color]";
}
Color & DGtal::Color::setRGBf ( float  red,
float  green,
float  blue,
float  alpha = 1.0 
)

Definition at line 54 of file Color.cpp.

{
if ( aRedValue > 1.0f ) aRedValue = 1.0f;
if ( aRedValue < 0.0f ) aRedValue = 0.0f;
myRed = static_cast<unsigned char>( 255 * aRedValue );
if ( aGreenValue > 1.0f ) aGreenValue = 1.0f;
if ( aGreenValue < 0.0f ) aGreenValue = 0.0f;
myGreen = static_cast<unsigned char>( 255 * aGreenValue );
if ( aBlueValue > 1.0f ) aBlueValue = 1.0f;
if ( aBlueValue < 0.0f ) aBlueValue = 0.0f;
myBlue = static_cast<unsigned char>( 255 * aBlueValue );
if ( aAlphaValue > 1.0f ) aAlphaValue = 1.0f;
if ( aAlphaValue < 0.0f ) aAlphaValue = 0.0f;
myAlpha = static_cast<unsigned char>( 255 * aAlphaValue );
return *this;
}
Color & DGtal::Color::setRGBi ( const unsigned char  aRedValue,
const unsigned char  aGreenValue,
const unsigned char  aBlueValue,
const unsigned char  aAlphaValue 
)
inline

Definition at line 64 of file Color.ih.

References myAlpha, myBlue, myGreen, and myRed.

{
myRed = aRedValue;
myGreen = aGreenValue;
myBlue = aBlueValue;
myAlpha = aAlphaValue;
return *this;
}
string DGtal::Color::svg ( ) const

Definition at line 129 of file Color.cpp.

References None, and secured_sprintf.

{
char buffer[255];
if ( *this == DGtal::Color::None ) return "none";
secured_sprintf( buffer, 255, "rgb(%d,%d,%d)",myRed, myGreen, myBlue );
return buffer;
}
string DGtal::Color::svgAlpha ( const char *  aPrefix) const

Return a an SVG parameter string for the opacity value.

Parameters:
prefixA prefix string to be appended to the returned string if not empty.
Returns:
An empty string if alpha == 255, otherwise the string <prefix>-opacity="<alpha-value>".

Definition at line 138 of file Color.cpp.

References None, and secured_sprintf.

{
char buffer[255];
if ( myAlpha == 255 || *this == DGtal::Color::None ) return "";
secured_sprintf( buffer, 255, " %s-opacity=\"%f\"", prefix, myAlpha/255.0f );
return buffer;
}
string DGtal::Color::tikz ( ) const

Return a string representation of the color usable in TikZ commands. Use the corresponding named color (or a mixture of a named color and black) for predefined colors. Use a mixture of red, green and blue for general colors.

Returns:
a string representation of the color usable in TikZ commands.

Definition at line 147 of file Color.cpp.

References Black, Blue, Gray, Green, Lime, Navy, None, Purple, Red, secured_sprintf, Silver, and White.

{
// see tex/generic/pgf/utilities/pgfutil-plain.def for color definitions
char buffer[255];
if ( *this == DGtal::Color::None ) return "none";
if ( *this == DGtal::Color::Black ) return "black";
if ( *this == DGtal::Color::Gray ) return "gray";
if ( *this == DGtal::Color::White ) return "white";
if ( *this == DGtal::Color::Red ) return "red";
if ( *this == DGtal::Color::Green ) return "green!50!black";
if ( *this == DGtal::Color::Lime ) return "green";
if ( *this == DGtal::Color::Blue ) return "blue";
// if ( *this == DGtal::Color::Cyan ) return "cyan";
// if ( *this == DGtal::Color::Magenta ) return "magenta";
// if ( *this == DGtal::Color::Yellow ) return "yellow";
if ( *this == DGtal::Color::Silver ) return "white!75!black";
if ( *this == DGtal::Color::Purple ) return "gray"; // ???: Is Color::Purple meant to be equal to Color::Gray?
if ( *this == DGtal::Color::Navy ) return "blue!50!black";
// if ( *this == DGtal::Color::Aqua ) return "cyan"; // ???: Is Color::Aqua meant to be equal to Color::Cyan?
secured_sprintf( buffer, 255, "{rgb,255:red,%d;green,%d;blue,%d}", myRed, myGreen, myBlue );
return buffer;
}
bool DGtal::Color::valid ( ) const
inline

Definition at line 131 of file Color.ih.

References None.

{
return (*this) != Color::None;
}

Field Documentation

const Color DGtal::Color::Aqua
static

Definition at line 213 of file Color.h.

const Color DGtal::Color::Black
static
const Color DGtal::Color::Blue
static

Definition at line 206 of file Color.h.

Referenced by DGtal::Display2DFactory::draw(), and tikz().

const Color DGtal::Color::Cyan
static

Definition at line 207 of file Color.h.

const Color DGtal::Color::Gray
static

Definition at line 201 of file Color.h.

Referenced by tikz().

const Color DGtal::Color::Green
static
Examples:
arithmetic/lower-integer-convex-hull.cpp.

Definition at line 204 of file Color.h.

Referenced by DGtal::Display2DFactory::draw(), and tikz().

const Color DGtal::Color::Lime
static

Definition at line 205 of file Color.h.

Referenced by tikz().

const Color DGtal::Color::Magenta
static

Definition at line 208 of file Color.h.

int DGtal::Color::myAlpha
private

The opacity.

Definition at line 240 of file Color.h.

Referenced by operator!=(), operator<(), operator==(), and setRGBi().

int DGtal::Color::myBlue
private

The blue component.

Definition at line 239 of file Color.h.

Referenced by Color(), operator!=(), operator<(), operator==(), and setRGBi().

int DGtal::Color::myGreen
private

The green component.

Definition at line 238 of file Color.h.

Referenced by Color(), operator!=(), operator<(), operator==(), and setRGBi().

int DGtal::Color::myRed
private

Copy constructor.

Parameters:
otherthe object to clone. Forbidden by default. Assignment.
otherthe object to copy.
Returns:
a reference on 'this'. Forbidden by default. The red component.

Definition at line 237 of file Color.h.

Referenced by Color(), operator!=(), operator<(), operator==(), and setRGBi().

const Color DGtal::Color::Navy
static

Definition at line 212 of file Color.h.

Referenced by tikz().

const Color DGtal::Color::None
static
const Color DGtal::Color::Purple
static

Definition at line 211 of file Color.h.

Referenced by tikz().

const Color DGtal::Color::Red
static
const Color DGtal::Color::Silver
static

Definition at line 210 of file Color.h.

Referenced by tikz().

const Color DGtal::Color::White
static

Definition at line 202 of file Color.h.

Referenced by DGtal::MeshFromPoints< TPoint >::MeshFromPoints(), and tikz().

const Color DGtal::Color::Yellow
static

Definition at line 209 of file Color.h.


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