Tulip  5.1.0
Large graphs analysis and drawing
tlp::ColorScale Class Reference

#include <ColorScale.h>

+ Inheritance diagram for tlp::ColorScale:
+ Collaboration diagram for tlp::ColorScale:

Public Member Functions

 ColorScale ()
 
 ColorScale (const std::vector< Color > &colors, const bool gradient=true)
 
 ColorScale (const std::map< float, Color > &colorMap, const bool gradient=true)
 
 ColorScale (const ColorScale &scale)
 
void clear ()
 
bool colorScaleInitialized () const
 
virtual Color getColorAtPos (const float pos) const
 
std::map< float, Color > getColorMap () const
 
unsigned int getStopsCount ()
 
bool hasRegularStops () const
 
bool isGradient () const
 
ColorScaleoperator= (const ColorScale &scale)
 
bool operator== (const ColorScale &cs) const
 
bool operator== (const std::vector< Color > &colors) const
 
virtual void setColorAtPos (const float pos, const Color &color)
 
void setColorMap (const std::map< float, Color > &colorMap)
 
void setColorMapTransparency (unsigned char transparency)
 
virtual void setColorScale (const std::vector< Color > colors, const bool gradient=true)
 
void setGradient (const bool g)
 
- Public Member Functions inherited from tlp::Observable
void addListener (Observable *const listener) const
 
void addObserver (Observable *const observer) const
 
unsigned int countListeners () const
 
unsigned int countObservers () const
 
unsigned int getReceived () const
 
unsigned int getSent () const
 
void removeListener (Observable *const listener) const
 
void removeObserver (Observable *const observerver) const
 

Protected Attributes

std::map< float, Color > colorMap
 
bool gradient
 

Additional Inherited Members

- Static Public Member Functions inherited from tlp::Observable
static tlp::node getNode (const tlp::Observable *obs)
 
static ObservablegetObject (tlp::node n)
 
static const tlp::VectorGraph & getObservableGraph ()
 
static unsigned int getScheduled (tlp::node n)
 
static void holdObservers ()
 
static bool isAlive (tlp::node n)
 
static unsigned int observersHoldCounter ()
 
static void unholdObservers ()
 
- Protected Member Functions inherited from tlp::Observable
 Observable (const Observable &)
 
tlp::Iterator< tlp::Observable * > * getObservables () const
 
bool hasOnlookers () const
 
void notifyObservers ()
 
void observableDeleted ()
 
Observableoperator= (const Observable &)
 
void sendEvent (const Event &message)
 
virtual void treatEvent (const Event &message)
 
virtual void treatEvents (const std::vector< Event > &events)
 

Detailed Description

This class represents a color scale to perform color mapping. The color scale can be either a gradient or defined by colors associated to consecutive intervals. If the color scale is a gradient, returned colors are interpolated in function of a position between 0.0 and 1.0. If the color scale is not a gradient returned colors are computed according to the interval the position belongs to.

// Creates the color scale.
tlp::ColorScale colorScale;
// Clears the color scale as the default constructor initializes a non empty one
colorScale.clear();
// Color scale initialization : from blue to red with gradient.
colorScale.setColorAtPos(0.0, tlp::Color::Blue);
colorScale.setColorAtPos(1.0, tlp::Color::Red);
// Gets the color for the position 0.5, i.e. tlp::Color(127,0,127).
tlp::Color color = colorScale.getColorAtPos(0.5);
// Reinitializes the color scale : from blue to red without gradient.
std::vector<tlp::Color> newColors;
newColors.push_back(tlp::Color::Blue);
newColors.push_back(tlp::Color::Red);
colorScale.setColorScale(newColors, false);
// Gets the color for the position 0.3, i.e. tlp::Color(0,0,255).
color = colorScale.getColorAtPos(0.3);
// Gets the color for the position 0.7, i.e. tlp::Color(255,0,0).
color = colorScale.getColorAtPos(0.7);

Definition at line 59 of file ColorScale.h.

Constructor & Destructor Documentation

tlp::ColorScale::ColorScale ( )

Initializes a color scale with a default set of colors.

tlp::ColorScale::ColorScale ( const std::vector< Color > &  colors,
const bool  gradient = true 
)

Initializes a color scale with a set of colors passed as parameter.

Parameters
colorsa vector of colors defining the color scale (first color is at position 0.0, last color at position 1.0)
gradientspecifies if the color scale should be a gradient or not
tlp::ColorScale::ColorScale ( const std::map< float, Color > &  colorMap,
const bool  gradient = true 
)

Initializes a color scale with a map of stop points and colors passed as parameter.

Since
Tulip 4.10
Parameters
colorMapa map of stop points and colors defining the color scale (The keys of the map must be between 0.0 and 1.0, other ones will be ignored.)
gradientspecifies if the color scale should be a gradient or not

Member Function Documentation

void tlp::ColorScale::clear ( )
inline

Clears the color scale.

Since
Tulip 4.10

Definition at line 98 of file ColorScale.h.

bool tlp::ColorScale::colorScaleInitialized ( ) const
inline

Returns true is the color scale was initialized.

Definition at line 148 of file ColorScale.h.

virtual Color tlp::ColorScale::getColorAtPos ( const float  pos) const
virtual

Returns the color for a given position in the color scale.

This method computes the color associated to a specific position in the color scale and returns it.

Parameters
posThis value defines the position of the color in the scale and must be between 0.0 and 1.0 (it will be clamped otherwise)
Returns
the color corresponding to the position in the scale
std::map<float, Color> tlp::ColorScale::getColorMap ( ) const
inline

Returns a map corresponding to the color scale. The index of the map is the position for the corresponding color in the color scale. The index is comprised between 0 and 1.

Definition at line 157 of file ColorScale.h.

unsigned int tlp::ColorScale::getStopsCount ( )
inline

Gets the number of stops points into the color scale.

Definition at line 106 of file ColorScale.h.

bool tlp::ColorScale::hasRegularStops ( ) const

Tests if the color scale has regular stop points, meaning the distance between each consecutive stop is constant.

Since
Tulip 4.10
bool tlp::ColorScale::isGradient ( ) const
inline

Returns true if the color scale is a gradient.

Definition at line 173 of file ColorScale.h.

bool tlp::ColorScale::operator== ( const ColorScale cs) const
inline

Tests color scale equality with another one.

Definition at line 194 of file ColorScale.h.

bool tlp::ColorScale::operator== ( const std::vector< Color > &  colors) const

Tests color scale equality with a regular one defined by a vector of colors.

virtual void tlp::ColorScale::setColorAtPos ( const float  pos,
const Color &  color 
)
virtual

Adds a color to the color scale at specific position.

This method adds a color to the color scale at a specific position.

Parameters
posthe position in the color scale (0.0 <= pos <= 1.0)
colorthe color to add at the specified position
void tlp::ColorScale::setColorMap ( const std::map< float, Color > &  colorMap)

Sets the map of stop points and colors used to perform color mapping.

Warning
The keys of the map must be between 0.0 and 1.0, other values will be ignored.
void tlp::ColorScale::setColorMapTransparency ( unsigned char  transparency)

Sets the transparency of all the colors in the underlying map.

virtual void tlp::ColorScale::setColorScale ( const std::vector< Color >  colors,
const bool  gradient = true 
)
virtual

Configures the color scale with regular stop points.

This method configures the color scale from a vector of colors and associates regular stop points to them.

Warning
If the scale was already configured the previous configuration is lost.
Parameters
colorsthe colors to use in the color scale
gradientif set to true, color scale is a gradient
void tlp::ColorScale::setGradient ( const bool  g)
inline

specify whether the color scale must be considered as a gradient

Definition at line 180 of file ColorScale.h.