OpenMS
MultiGradient Class Reference

A gradient of multiple colors and arbitrary distances between colors. More...

#include <OpenMS/VISUAL/MultiGradient.h>

Collaboration diagram for MultiGradient:
[legend]

Public Types

enum  InterpolationMode { IM_LINEAR , IM_STAIRS }
 Interpolation mode. More...
 

Public Member Functions

 MultiGradient ()
 Constructor. More...
 
 MultiGradient (const MultiGradient &multigradient)
 Copy constructor. More...
 
 ~MultiGradient ()
 Destructor. More...
 
MultiGradientoperator= (const MultiGradient &rhs)
 Assignment operator. More...
 
void insert (double position, QColor color)
 sets or replaces the color at position position More...
 
bool remove (double position)
 removes the color at position position More...
 
bool exists (double position)
 returns if a value for position position exists More...
 
UInt position (UInt index)
 returns the position of the index -th point More...
 
QColor color (UInt index)
 returns the color of the index -th point More...
 
QColor interpolatedColorAt (double position) const
 Returns the color as position. More...
 
QColor interpolatedColorAt (double position, double min, double max) const
 returns the color as position with the gradient stretched between min and max. More...
 
void activatePrecalculationMode (double min, double max, UInt steps)
 activates the precalculation of values (only approximate results are given) More...
 
void deactivatePrecalculationMode ()
 deactivates the precalculation of values ( and deletes the precalculated values) More...
 
Int precalculatedColorIndex (double position) const
 index of color in precalculated table by position in gradient More...
 
QColor precalculatedColorByIndex (Int index) const
 precalculated color by its index in the table More...
 
QColor precalculatedColorAt (double position) const
 Returns a precalculated color. More...
 
Size size () const
 return the number of color points More...
 
Size precalculatedSize () const
 size of precalculated colors table More...
 
void setInterpolationMode (InterpolationMode mode)
 sets the interpolation mode (default or stairs). Default is linear More...
 
InterpolationMode getInterpolationMode () const
 returns the interpolation mode More...
 
std::string toString () const
 convert to string representation More...
 
void fromString (const std::string &gradient)
 Sets the gradient by string representation. More...
 

Static Public Member Functions

static MultiGradient getDefaultGradientLinearIntensityMode ()
 Returns the default gradient for linear intensity mode. More...
 
static MultiGradient getDefaultGradientLogarithmicIntensityMode ()
 Returns the default gradient for logarithmic intensity mode. More...
 

Protected Attributes

std::map< double, QColor > pos_col_
 Map of index and color. More...
 
InterpolationMode interpolation_mode_
 Current interpolation mode. More...
 
std::vector< QColor > pre_
 Precalculated colors. More...
 
double pre_min_
 Minimum of the precalculated color range. More...
 
double pre_size_
 Width of the precalculated color range. More...
 
UInt pre_steps_
 Steps of the precalculated color range. More...
 

Detailed Description

A gradient of multiple colors and arbitrary distances between colors.

Positions associated with numbers range from 0 to 100. There is always a color associated with position 0 and 100. Stretching the gradient to a specified range, and precalculation and caching is also possible.

Member Enumeration Documentation

◆ InterpolationMode

Interpolation mode.

Enumerator
IM_LINEAR 

IM_LINEAR returns the linear interpolation (default).

IM_STAIRS 

IM_STAIRS returns the color of the next lower position.

Constructor & Destructor Documentation

◆ MultiGradient() [1/2]

Constructor.

◆ MultiGradient() [2/2]

MultiGradient ( const MultiGradient multigradient)

Copy constructor.

◆ ~MultiGradient()

Destructor.

Member Function Documentation

◆ activatePrecalculationMode()

void activatePrecalculationMode ( double  min,
double  max,
UInt  steps 
)

activates the precalculation of values (only approximate results are given)

◆ color()

QColor color ( UInt  index)

returns the color of the index -th point

Exceptions
Exception::IndexOverflowis thrown for a too large index

◆ deactivatePrecalculationMode()

void deactivatePrecalculationMode ( )

deactivates the precalculation of values ( and deletes the precalculated values)

◆ exists()

bool exists ( double  position)

returns if a value for position position exists

◆ fromString()

void fromString ( const std::string &  gradient)

Sets the gradient by string representation.

The string representation of a gradient starts with the interpolation mode: "Linear" or "Stairs" and the separator "|". It is followed by an arbitrary number of integer-color-pairs.

Such a pair consists of floating point number (0.0-100.0) followed by a comma and a "#". Then follows a color in RGB notation "#RRGGBB" and finally a semicolon.

Examples are:

  • "Linear|0,#ffff00;100,#000000"
  • "Stairs|0,#ffff00;11.5,#ffaa00;32,#ff0000;55,#aa00ff;78,#5500ff;100,#000000"

◆ getDefaultGradientLinearIntensityMode()

static MultiGradient getDefaultGradientLinearIntensityMode ( )
static

Returns the default gradient for linear intensity mode.

◆ getDefaultGradientLogarithmicIntensityMode()

static MultiGradient getDefaultGradientLogarithmicIntensityMode ( )
static

Returns the default gradient for logarithmic intensity mode.

◆ getInterpolationMode()

InterpolationMode getInterpolationMode ( ) const

returns the interpolation mode

◆ insert()

void insert ( double  position,
QColor  color 
)

sets or replaces the color at position position

◆ interpolatedColorAt() [1/2]

QColor interpolatedColorAt ( double  position) const

Returns the color as position.

If the position is higher or lower than the range [0,100] the highest, respectively the lowest, color is returned.

◆ interpolatedColorAt() [2/2]

QColor interpolatedColorAt ( double  position,
double  min,
double  max 
) const

returns the color as position with the gradient stretched between min and max.

If the position is higher or lower than the range [min,max] the highest, respectively the lowest, color is returned.

◆ operator=()

MultiGradient& operator= ( const MultiGradient rhs)

Assignment operator.

◆ position()

UInt position ( UInt  index)

returns the position of the index -th point

Exceptions
Exception::IndexOverflowis thrown for a too large index

◆ precalculatedColorAt()

QColor precalculatedColorAt ( double  position) const
inline

Returns a precalculated color.

If the position is out of the range specified in activatePrecalculationMode() the behaviour depends on the debug mode:

  • With debug information an Precondition exception is thrown
  • Without debug information array boundaries are violated, which probably causes a segmentation fault.

◆ precalculatedColorByIndex()

QColor precalculatedColorByIndex ( Int  index) const
inline

precalculated color by its index in the table

References OPENMS_PRECONDITION.

Referenced by Plot2DCanvas::heightColor_().

◆ precalculatedColorIndex()

Int precalculatedColorIndex ( double  position) const
inline

index of color in precalculated table by position in gradient

References OPENMS_PRECONDITION.

Referenced by Plot2DCanvas::precalculatedColorIndex_().

◆ precalculatedSize()

Size precalculatedSize ( ) const
inline

size of precalculated colors table

◆ remove()

bool remove ( double  position)

removes the color at position position

◆ setInterpolationMode()

void setInterpolationMode ( InterpolationMode  mode)

sets the interpolation mode (default or stairs). Default is linear

◆ size()

Size size ( ) const

return the number of color points

◆ toString()

std::string toString ( ) const

convert to string representation

Member Data Documentation

◆ interpolation_mode_

InterpolationMode interpolation_mode_
protected

Current interpolation mode.

◆ pos_col_

std::map<double, QColor> pos_col_
protected

Map of index and color.

◆ pre_

std::vector<QColor> pre_
protected

Precalculated colors.

◆ pre_min_

double pre_min_
protected

Minimum of the precalculated color range.

◆ pre_size_

double pre_size_
protected

Width of the precalculated color range.

◆ pre_steps_

UInt pre_steps_
protected

Steps of the precalculated color range.