Tulip  6.0.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 ColorScale &scale)
 
 ColorScale (const std::map< float, Color > &colorMap, const bool gradient=true)
 
 ColorScale (const std::vector< Color > &colors, const bool gradient=true)
 
void clear ()
 
bool colorScaleInitialized () const
 
virtual Color getColorAtPos (const float pos) const
 
const std::map< float, Color > & getColorMap () const
 
unsigned int getStopsCount ()
 
bool hasRegularStops () const
 
bool isGradient () const
 
bool operator!= (const ColorScale &cs) 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 &listener) const
 
void addListener (Observable *const listener) const
 
void addObserver (Observable &observer) 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 &listener) const
 
void removeListener (Observable *const listener) const
 
void removeObserver (Observable &observer) const
 
void removeObserver (Observable *const observer) const
 

Protected Attributes

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

Additional Inherited Members

- Static Public Member Functions inherited from tlp::Observable
static void disableEventNotification ()
 
static void enableEventNotification ()
 
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 &)
 
bool hasOnlookers () const
 
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);
This class represents a color scale to perform color mapping. The color scale can be either a gradien...
Definition: ColorScale.h:62
virtual void setColorScale(const std::vector< Color > &colors, const bool gradient=true)
Configures the color scale with regular stop points.
virtual void setColorAtPos(const float pos, const Color &color)
Adds a color to the color scale at specific position.
virtual Color getColorAtPos(const float pos) const
Returns the color for a given position in the color scale.
void clear()
Clears the color scale.
Definition: ColorScale.h:102

Definition at line 62 of file ColorScale.h.

Constructor & Destructor Documentation

◆ ColorScale() [1/3]

tlp::ColorScale::ColorScale ( )

Initializes a color scale with a default set of colors.

◆ ColorScale() [2/3]

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

◆ ColorScale() [3/3]

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

◆ clear()

void tlp::ColorScale::clear ( )
inline

Clears the color scale.

Since
Tulip 4.10

Definition at line 102 of file ColorScale.h.

◆ colorScaleInitialized()

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

Returns true is the color scale was initialized.

Definition at line 154 of file ColorScale.h.

◆ getColorAtPos()

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

◆ getColorMap()

const 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 164 of file ColorScale.h.

◆ getStopsCount()

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

Gets the number of stops points into the color scale.

Definition at line 110 of file ColorScale.h.

◆ hasRegularStops()

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

◆ isGradient()

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

Returns true if the color scale is a gradient.

Definition at line 180 of file ColorScale.h.

◆ operator!=()

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

Tests color scale difference with another one.

Definition at line 209 of file ColorScale.h.

◆ operator==() [1/2]

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

Tests color scale equality with another one.

Definition at line 201 of file ColorScale.h.

◆ operator==() [2/2]

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

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

◆ setColorAtPos()

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

◆ setColorMap()

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.

◆ setColorMapTransparency()

void tlp::ColorScale::setColorMapTransparency ( unsigned char  transparency)

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

◆ setColorScale()

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

◆ setGradient()

void tlp::ColorScale::setGradient ( const bool  g)
inline

specify whether the color scale must be considered as a gradient

Definition at line 187 of file ColorScale.h.