MorphoGraphX
|
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 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. | |
TransferFunction & | operator= (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. | |
Class defining a transfer function as linear interpolation between set values.
mgx::TransferFunction::TransferFunction | ( | Interpolation | interpolation = RGB | ) |
Default constructor for a transfer function.
interpolation | Type of interpolation |
|
protected |
Add a control point with the color using the current color mode.
pos | Position to add the point to |
col | Color added |
|
inlinestatic |
Scale in transparency.
Main color is blue.
|
inlinestatic |
Scale in transparency.
Main color is cyan.
|
inlinestatic |
Scale in transparency.
Main color is gray.
|
inlinestatic |
Scale in transparency.
Main color is green.
|
inlinestatic |
Scale in transparency.
Main color is purple.
|
inlinestatic |
Scale in transparency.
Main color is red.
|
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 |
Scale in hue.
Varies hue and transparency.
|
protected |
Internal function to interpolate color.
position | Target position |
p1 | Position of the color before position |
col1 | Color at position p1 |
p2 | Position of the color after position |
col2 | Color 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 |
Predefined transfer-function, scaling from min
to .
min | Color for 0 |
max | Color for 1 |
interpolation | Type of interpolation |
|
inlinestatic |
Scale in blue.
Varies blue and transparency.
|
inlinestatic |
Scale in cyan.
Varies cyan and transparency.
|
inlinestatic |
Scale in gray.
Varies gray and transparency.
|
inlinestatic |
Scale in green.
Varies green and transparency.
|
inlinestatic |
Scale in purple.
Varies purple and transparency.
|
inlinestatic |
Scale in red.
Varies red and transparency.
|
inlinestatic |
Scale in yellow.
Varies yellow and transparency.
|
protected |
If true, the colors left and right of the defined points are clamped.
Otherwise, they are set to the exterior color.
|
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.