MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
mgx::TransferFunction Class Reference

Class defining a transfer function as linear interpolation between set values. More...

#include <TransferFunction.hpp>

Public Types

enum  Interpolation { RGB, HSV, CYCLIC_HSV }
 Type of interpolation. More...
 
typedef util::Color< float > Colorf
 Type of a color.
 
typedef std::vector< std::pair
< double, Colorf > > 
value_list
 Type of a list of value/colors.
 
typedef QMap< double, int > key_map
 Type of the mapping from the position to the index in the value list.
 

Public Member Functions

 TransferFunction (Interpolation interpolation=RGB)
 Default constructor for a transfer function. More...
 
 TransferFunction (const TransferFunction &copy)
 Copy constructor.
 
virtual ~TransferFunction ()
 Virtual destructor.
 
QString dump () const
 Store the transfer function into a string.
 
void add_rgba_point (double pos, Colorf col)
 Add a point to the interpolation with the color are RGBA.
 
void add_hsva_point (double pos, Colorf col)
 Add a point to the interpolation with the color are HSVA.
 
void remove_point (double pos)
 Remove the point at the given position (if any)
 
size_t size () const
 Returns the number of points.
 
void move_point (double old_pos, double new_pos)
 Move a point (if found)
 
double next_pos (double old_pos) const
 Position of the next point, or -1 if none.
 
double prev_pos (double old_pos) const
 Position of the previous point, or -1 if none.
 
double operator[] (int i) const
 Return the i_th point.
 
Colorf rgba_point (double position) const
 Return the RGBA point at position. More...
 
Colorf hsva_point (double position) const
 Return the RGBA point at position. More...
 
Colorf rgba (double position) const
 Returns the color at position in RGBA, linearly interpolating between specified points.
 
Colorf hsva (double position) const
 Returns the color at position in HSVA, linearly interpolating between specified points.
 
double alpha (double position) const
 Returns the transparency of the color at position, linearly interpolating between specified points.
 
bool empty () const
 Returns true if no points are defined.
 
TransferFunctionoperator= (const TransferFunction &other)
 Assignement operator for transfer function.
 
bool operator== (const TransferFunction &other) const
 Test if two transfer functions are equal. More...
 
bool operator!= (const TransferFunction &other) const
 Test if two transfer functions are different. More...
 
void reverse ()
 Reverse the control point. More...
 
void clear ()
 Erase all control points.
 
void adjust (double minValue, double maxValue)
 Adjust the control point to span exactly from minValue to maxValue.
 
Interpolation interpolation () const
 Returns the current interpolation mode.
 
void setInterpolation (Interpolation i)
 Change the interpolation mode.
 
void setPointList (const value_list &lst)
 Change all the control points at once.
 

Static Public Member Functions

static TransferFunction load (QString spec)
 Load a transfer function from a string.
 
Predefined transfer functions
static TransferFunction scale (Colorf min, Colorf max, Interpolation interpolation=RGB)
 Predefined transfer-function, scaling from min to . More...
 
static TransferFunction hue_scale ()
 Scale in hue. More...
 
static TransferFunction scale_gray ()
 Scale in gray. More...
 
static TransferFunction scale_red ()
 Scale in red. More...
 
static TransferFunction scale_green ()
 Scale in green. More...
 
static TransferFunction scale_blue ()
 Scale in blue. More...
 
static TransferFunction scale_yellow ()
 Scale in yellow. More...
 
static TransferFunction scale_cyan ()
 Scale in cyan. More...
 
static TransferFunction scale_purple ()
 Scale in purple. More...
 
static TransferFunction constant_gray ()
 Scale in transparency. More...
 
static TransferFunction constant_red ()
 Scale in transparency. More...
 
static TransferFunction constant_green ()
 Scale in transparency. More...
 
static TransferFunction constant_blue ()
 Scale in transparency. More...
 
static TransferFunction constant_yellow ()
 Scale in transparency. More...
 
static TransferFunction constant_cyan ()
 Scale in transparency. More...
 
static TransferFunction constant_purple ()
 Scale in transparency. More...
 
static TransferFunction jet ()
 Jet color scale.
 
static TransferFunction french_flag ()
 French flag color scale.
 

Static Public Attributes

static const double epsilon
 epsilon used in floating point comparisons
 

Protected Member Functions

Colorf interpolate (double position, double p1, Colorf col1, double p2, Colorf col2) const
 Internal function to interpolate color. More...
 
void update_keys ()
 Update the key map based on the value list.
 
Colorf color (double position) const
 Returns the color at position position, using a color mode in accordance with the interpolation mode.
 
void add_point (double pos, Colorf col)
 Add a control point with the color using the current color mode. More...
 

Protected Attributes

Interpolation _interpolation
 Current interpolation mode.
 
value_list values
 List of values. More...
 
key_map keys
 Mapping of the position to the index in the value list.
 
bool clamp
 If true, the colors left and right of the defined points are clamped. More...
 
Colorf exteriorColor
 Color left and right of the control points if not clamped.
 

Detailed Description

Class defining a transfer function as linear interpolation between set values.

Member Enumeration Documentation

Type of interpolation.

Enumerator
RGB 

Red-Green-Blue.

HSV 

Hue-Saturation-Value.

CYCLIC_HSV 

Like HSV but the hue is cyclic (i.e. to go from 0.9 to 0.1 you go via 0)

Constructor & Destructor Documentation

mgx::TransferFunction::TransferFunction ( Interpolation  interpolation = RGB)

Default constructor for a transfer function.

Parameters
interpolationType of interpolation

Member Function Documentation

void mgx::TransferFunction::add_point ( double  pos,
Colorf  col 
)
protected

Add a control point with the color using the current color mode.

Parameters
posPosition to add the point to
colColor added
static TransferFunction mgx::TransferFunction::constant_blue ( )
inlinestatic

Scale in transparency.

Main color is blue.

static TransferFunction mgx::TransferFunction::constant_cyan ( )
inlinestatic

Scale in transparency.

Main color is cyan.

static TransferFunction mgx::TransferFunction::constant_gray ( )
inlinestatic

Scale in transparency.

Main color is gray.

static TransferFunction mgx::TransferFunction::constant_green ( )
inlinestatic

Scale in transparency.

Main color is green.

static TransferFunction mgx::TransferFunction::constant_purple ( )
inlinestatic

Scale in transparency.

Main color is purple.

static TransferFunction mgx::TransferFunction::constant_red ( )
inlinestatic

Scale in transparency.

Main color is red.

static TransferFunction mgx::TransferFunction::constant_yellow ( )
inlinestatic

Scale in transparency.

Main color is yellow.

Colorf mgx::TransferFunction::hsva_point ( double  position) const

Return the RGBA point at position.

If the position is not a defined point, it returns Colorf(-1.0f)

static TransferFunction mgx::TransferFunction::hue_scale ( )
static

Scale in hue.

Varies hue and transparency.

Colorf mgx::TransferFunction::interpolate ( double  position,
double  p1,
Colorf  col1,
double  p2,
Colorf  col2 
) const
protected

Internal function to interpolate color.

Parameters
positionTarget position
p1Position of the color before position
col1Color at position p1
p2Position of the color after position
col2Color at position p2
bool mgx::TransferFunction::operator!= ( const TransferFunction other) const

Test if two transfer functions are different.

They are equal only if they are defined using the same control points, and use the same interpolation and border conditions.

bool mgx::TransferFunction::operator== ( const TransferFunction other) const

Test if two transfer functions are equal.

They are equal only if they are defined using the same control points, and use the same interpolation and border conditions.

void mgx::TransferFunction::reverse ( )

Reverse the control point.

Each control point is moved to 1-position.

Colorf mgx::TransferFunction::rgba_point ( double  position) const

Return the RGBA point at position.

If the position is not a defined point, it returns Colorf(-1.0f)

static TransferFunction mgx::TransferFunction::scale ( Colorf  min,
Colorf  max,
Interpolation  interpolation = RGB 
)
static

Predefined transfer-function, scaling from min to .

Parameters
minColor for 0
maxColor for 1
interpolationType of interpolation
static TransferFunction mgx::TransferFunction::scale_blue ( )
inlinestatic

Scale in blue.

Varies blue and transparency.

static TransferFunction mgx::TransferFunction::scale_cyan ( )
inlinestatic

Scale in cyan.

Varies cyan and transparency.

static TransferFunction mgx::TransferFunction::scale_gray ( )
inlinestatic

Scale in gray.

Varies gray and transparency.

static TransferFunction mgx::TransferFunction::scale_green ( )
inlinestatic

Scale in green.

Varies green and transparency.

static TransferFunction mgx::TransferFunction::scale_purple ( )
inlinestatic

Scale in purple.

Varies purple and transparency.

static TransferFunction mgx::TransferFunction::scale_red ( )
inlinestatic

Scale in red.

Varies red and transparency.

static TransferFunction mgx::TransferFunction::scale_yellow ( )
inlinestatic

Scale in yellow.

Varies yellow and transparency.

Member Data Documentation

bool mgx::TransferFunction::clamp
protected

If true, the colors left and right of the defined points are clamped.

Otherwise, they are set to the exterior color.

value_list mgx::TransferFunction::values
protected

List of values.

If the mode is HSV or CYCLIC_HSV, the colors are stored in HSVA. Otherwise, the colors are stored in RGBA.


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