cgv
Loading...
Searching...
No Matches
cgv::media::transfer_function Class Reference

Implementation of a color_scale with a continuous input domain that maps explicit domain values to color and opacity using piecewise constant, piecewise linear or piecewise smooth (b-splines) interpolation. More...

#include <transfer_function.h>

Inheritance diagram for cgv::media::transfer_function:
cgv::media::color_scale

Public Types

enum class  InterpolationMode { kStep , kLinear , kSmooth }
 The interpolation modes supported by the transfer function. More...
 
using color_type = cgv::rgb
 The used color type.
 
using opacity_type = float
 The used opacity type.
 
using color_point_type = std::pair< float, color_type >
 The used color control point type.
 
using opacity_point_type = std::pair< float, opacity_type >
 The used opacity control point type.
 

Public Member Functions

 transfer_function ()
 Construct using default arguments.
 
 transfer_function (std::initializer_list< color_point_type > colors)
 Construct from a sequence of color control points.
 
 transfer_function (std::initializer_list< color_point_type > colors, std::initializer_list< opacity_point_type > opacities)
 Construct from separate sequences of color and opacity control points.
 
bool is_opaque () const override
 Return whether the color scale maps to opacity.
 
bool is_discrete () const override
 See color_scale::is_discrete().
 
bool empty () const
 Check whether the transfer function is empty.
 
void set_color_points (const std::vector< color_point_type > &colors)
 Set the color function to use the given control points.
 
void set_color_points_from_scheme (const cgv::media::continuous_color_scheme &scheme, size_t n)
 Set the color function to use n uniformly sampled points from the given color scheme.
 
void set_opacity_points (const std::vector< opacity_point_type > &opacities)
 Set the opacity function to use the given control points.
 
void add_color_point (float x, const color_type &color)
 Add a color point at position x.
 
void add_opacity_point (float x, float opacity)
 Add an opacity point at position x.
 
bool remove_color_point (float x)
 Remove the color point at position x if it exists.
 
bool remove_opacity_point (float x)
 Remove the opacity point at position x if it exists.
 
void set_domain (cgv::vec2 domain) override
 Set the domain.
 
void rescale (cgv::vec2 domain)
 Rescale the color and opactiy functions to the new domain.
 
float normalize_value (float value) const override
 See color_scale::normalize_value().
 
cgv::rgba map_value (float value) const override
 See color_scale::map_value().
 
cgv::rgb get_mapped_color (float value) const override
 See color_scale::get_mapped_color().
 
float get_mapped_opacity (float value) const override
 See color_scale::get_mapped_opacity().
 
std::vector< cgv::rgbaquantize (size_t count) const override
 See color_scale::quantize().
 
std::vector< cgv::rgbquantize_color (size_t count) const
 Quantize the color function only.
 
std::vector< float > quantize_opacity (size_t count) const
 Quantize the opacity function only.
 
std::vector< float > get_ticks (size_t request_count) const override
 See color_scale::get_ticks().
 
void clear ()
 Clear all color and opacity control points.
 
void clear_color_points ()
 Clear color control points only.
 
void clear_opacity_points ()
 Clear opacity control points only.
 
const std::vector< color_point_type > & get_color_points () const
 Get the color control points.
 
const std::vector< opacity_point_type > & get_opacity_points () const
 Get the opacity control points.
 
void set_interpolation (InterpolationMode interpolation)
 Set the interpolation mode of the color and opacity function.
 
void set_color_interpolation (InterpolationMode interpolation)
 Set the interpolation mode of the color function.
 
InterpolationMode get_color_interpolation () const
 Get the interpolation mode of the color function.
 
void set_opacity_interpolation (InterpolationMode interpolation)
 Set the interpolation mode of the opacity function.
 
InterpolationMode set_opacity_interpolation () const
 Get the interpolation mode of the opacity function.
 
- Public Member Functions inherited from cgv::media::color_scale
virtual ~color_scale ()
 Destruct this color scale.
 
cgv::vec2 get_domain () const
 Get the input domain of scalars that will be mapped.
 
virtual void set_clamped (bool clamped)
 Set whether the input values are clamped to the domain before mapping.
 
bool is_clamped () const
 Get whether the input values are clamped to the domain before mapping.
 
virtual void set_reversed (bool reverse)
 Set whether the output color ramp is reversed.
 
bool is_reversed () const
 Get whether the output color ramp is reversed.
 
virtual void set_unknown_color (cgv::rgba color)
 Set the color returned for scalars outside the domain if clamping is disabled.
 
cgv::rgba get_unknown_color () const
 Get the color returned for scalars outside the domain if clamping is disabled.
 
virtual cgv::rgba get_indexed_color (size_t index) const
 Map a discrete index through the lookup table and return a RGBA color.
 
virtual size_t get_indexed_color_count () const
 return the number of available indexed colors.
 
cgv::data::time_point get_modified_time () const
 Get the time point of the last modification of this object.
 

Additional Inherited Members

- Protected Member Functions inherited from cgv::media::color_scale
void modified ()
 Update the object's modified time.
 
bool is_unknown (float value) const
 Test whether the value is outside the domain according to the mapping options.
 
float map_range_safe (float value, float in_left, float in_right, float out_left, float out_right) const
 Remap a scalar value from an input range to and output range while safely handling empty ranges.
 

Detailed Description

Implementation of a color_scale with a continuous input domain that maps explicit domain values to color and opacity using piecewise constant, piecewise linear or piecewise smooth (b-splines) interpolation.

Control points of the color and opacity function can be controlled independent of each other.

Definition at line 21 of file transfer_function.h.

Member Typedef Documentation

◆ color_point_type

The used color control point type.

Definition at line 35 of file transfer_function.h.

◆ color_type

The used color type.

Definition at line 31 of file transfer_function.h.

◆ opacity_point_type

The used opacity control point type.

Definition at line 37 of file transfer_function.h.

◆ opacity_type

The used opacity type.

Definition at line 33 of file transfer_function.h.

Member Enumeration Documentation

◆ InterpolationMode

The interpolation modes supported by the transfer function.

Definition at line 24 of file transfer_function.h.

Constructor & Destructor Documentation

◆ transfer_function() [1/3]

cgv::media::transfer_function::transfer_function ( )
inline

Construct using default arguments.

Definition at line 40 of file transfer_function.h.

◆ transfer_function() [2/3]

cgv::media::transfer_function::transfer_function ( std::initializer_list< color_point_type colors)

Construct from a sequence of color control points.

Sets the domain to the range governed by the control points.

Parameters
colorsThe control points.

Definition at line 9 of file transfer_function.cxx.

References set_color_points().

◆ transfer_function() [3/3]

cgv::media::transfer_function::transfer_function ( std::initializer_list< color_point_type colors,
std::initializer_list< opacity_point_type opacities 
)

Construct from separate sequences of color and opacity control points.

Sets the domain to excatly cover the minimum and maximum position among all color and opacity control points. Additional control points are added to the ends of the individual piecwise functions if necessary.

Parameters
colorsThe color control points.
opacitiesThe opacity control points.

Definition at line 13 of file transfer_function.cxx.

References set_color_points(), and set_opacity_points().

Member Function Documentation

◆ add_color_point()

void cgv::media::transfer_function::add_color_point ( float  x,
const color_type color 
)

Add a color point at position x.

Will replace the previous color point at position x if it exists.

Parameters
xThe control point position.
colorThe control point color.

Definition at line 40 of file transfer_function.cxx.

References remove_color_point().

Referenced by set_domain().

◆ add_opacity_point()

void cgv::media::transfer_function::add_opacity_point ( float  x,
float  opacity 
)

Add an opacity point at position x.

Will replace the previous opacity point at position x if it exists. The opacity is clamped to [0,1].

Parameters
xThe control point position.
opacityThe control point color.

Definition at line 47 of file transfer_function.cxx.

References remove_opacity_point().

Referenced by set_domain().

◆ clear()

void cgv::media::transfer_function::clear ( )

Clear all color and opacity control points.

Definition at line 208 of file transfer_function.cxx.

◆ clear_color_points()

void cgv::media::transfer_function::clear_color_points ( )

Clear color control points only.

Definition at line 214 of file transfer_function.cxx.

◆ clear_opacity_points()

void cgv::media::transfer_function::clear_opacity_points ( )

Clear opacity control points only.

Definition at line 219 of file transfer_function.cxx.

◆ empty()

bool cgv::media::transfer_function::empty ( ) const
inline

Check whether the transfer function is empty.

Returns
true if both color and opacity functions have no control points.

Definition at line 72 of file transfer_function.h.

◆ get_color_interpolation()

InterpolationMode cgv::media::transfer_function::get_color_interpolation ( ) const
inline

Get the interpolation mode of the color function.

Parameters
interpolationThe interpolation mode.

Definition at line 199 of file transfer_function.h.

◆ get_color_points()

const std::vector< color_point_type > & cgv::media::transfer_function::get_color_points ( ) const
inline

Get the color control points.

Returns
The control points.

Definition at line 175 of file transfer_function.h.

◆ get_mapped_color()

cgv::rgb cgv::media::transfer_function::get_mapped_color ( float  value) const
overridevirtual

◆ get_mapped_opacity()

float cgv::media::transfer_function::get_mapped_opacity ( float  value) const
overridevirtual

See color_scale::get_mapped_opacity().

Reimplemented from cgv::media::color_scale.

Definition at line 157 of file transfer_function.cxx.

Referenced by map_value(), and set_domain().

◆ get_opacity_points()

const std::vector< opacity_point_type > & cgv::media::transfer_function::get_opacity_points ( ) const
inline

Get the opacity control points.

Returns
The control points.

Definition at line 182 of file transfer_function.h.

◆ get_ticks()

std::vector< float > cgv::media::transfer_function::get_ticks ( size_t  request_count) const
overridevirtual

◆ is_discrete()

bool cgv::media::transfer_function::is_discrete ( ) const
inlineoverridevirtual

See color_scale::is_discrete().

Returns
False.

Implements cgv::media::color_scale.

Definition at line 65 of file transfer_function.h.

◆ is_opaque()

bool cgv::media::transfer_function::is_opaque ( ) const
inlineoverridevirtual

Return whether the color scale maps to opacity.

Returns
True if the opacity function is not empty, false otherwise.

Reimplemented from cgv::media::color_scale.

Definition at line 59 of file transfer_function.h.

◆ map_value()

◆ normalize_value()

float cgv::media::transfer_function::normalize_value ( float  value) const
overridevirtual

◆ quantize()

std::vector< cgv::rgba > cgv::media::transfer_function::quantize ( size_t  count) const
overridevirtual

◆ quantize_color()

std::vector< cgv::rgb > cgv::media::transfer_function::quantize_color ( size_t  count) const

Quantize the color function only.

See quantize().

Definition at line 176 of file transfer_function.cxx.

References cgv::media::color_scale::is_reversed(), and quantize().

Referenced by quantize().

◆ quantize_opacity()

std::vector< float > cgv::media::transfer_function::quantize_opacity ( size_t  count) const

Quantize the opacity function only.

See quantize().

Definition at line 186 of file transfer_function.cxx.

References cgv::media::color_scale::is_reversed(), and quantize().

Referenced by quantize().

◆ remove_color_point()

bool cgv::media::transfer_function::remove_color_point ( float  x)

Remove the color point at position x if it exists.

Parameters
xThe position of the control point to be removed.
Returns
True if a point was removed, false otherwise.

Definition at line 54 of file transfer_function.cxx.

References cgv::media::color_scale::modified().

Referenced by add_color_point().

◆ remove_opacity_point()

bool cgv::media::transfer_function::remove_opacity_point ( float  x)

Remove the opacity point at position x if it exists.

Parameters
xThe position of the control point to be removed.
Returns
True if a point was removed, false otherwise.

Definition at line 62 of file transfer_function.cxx.

References cgv::media::color_scale::modified().

Referenced by add_opacity_point().

◆ rescale()

void cgv::media::transfer_function::rescale ( cgv::vec2  domain)

Rescale the color and opactiy functions to the new domain.

All control point positions are updated proportionally to fit inside the new domain.

Parameters
domainThe new domain.

Definition at line 117 of file transfer_function.cxx.

References cgv::media::color_scale::get_domain(), cgv::media::color_scale::map_range_safe(), and cgv::media::color_scale::set_domain().

◆ set_color_interpolation()

void cgv::media::transfer_function::set_color_interpolation ( InterpolationMode  interpolation)

Set the interpolation mode of the color function.

Parameters
interpolationThe interpolation mode.

Definition at line 232 of file transfer_function.cxx.

References cgv::media::color_scale::modified().

◆ set_color_points()

void cgv::media::transfer_function::set_color_points ( const std::vector< color_point_type > &  colors)

Set the color function to use the given control points.

Extends the domain if the new control points are outside the current domain.

Parameters
colorsThe control points.

Definition at line 18 of file transfer_function.cxx.

Referenced by set_color_points_from_scheme(), transfer_function(), and transfer_function().

◆ set_color_points_from_scheme()

void cgv::media::transfer_function::set_color_points_from_scheme ( const cgv::media::continuous_color_scheme scheme,
size_t  n 
)

Set the color function to use n uniformly sampled points from the given color scheme.

Will set the domain to [0,1]. See also set_color_points().

Parameters
schemeThe color scheme.
nThe number of poitns to sample.

Definition at line 25 of file transfer_function.cxx.

References cgv::media::continuous_color_scheme::quantize(), set_color_points(), cgv::utils::subdivision_sequence(), and cgv::utils::zip().

◆ set_domain()

void cgv::media::transfer_function::set_domain ( cgv::vec2  domain)
overridevirtual

Set the domain.

All control points outside of the new domain will be removed. New control points will be created at the ends of the new domain if they don't already exist. Affects color and opacity functions.

Parameters
domainThe new domain.

Reimplemented from cgv::media::color_scale.

Definition at line 70 of file transfer_function.cxx.

References add_color_point(), add_opacity_point(), cgv::media::color_scale::get_domain(), get_mapped_color(), get_mapped_opacity(), and cgv::media::color_scale::modified().

◆ set_interpolation()

void cgv::media::transfer_function::set_interpolation ( InterpolationMode  interpolation)

Set the interpolation mode of the color and opacity function.

Parameters
interpolationThe interpolation mode.

Definition at line 224 of file transfer_function.cxx.

References cgv::media::color_scale::modified().

◆ set_opacity_interpolation() [1/2]

InterpolationMode cgv::media::transfer_function::set_opacity_interpolation ( ) const
inline

Get the interpolation mode of the opacity function.

Parameters
interpolationThe interpolation mode.

Definition at line 211 of file transfer_function.h.

◆ set_opacity_interpolation() [2/2]

void cgv::media::transfer_function::set_opacity_interpolation ( InterpolationMode  interpolation)

Set the interpolation mode of the opacity function.

Parameters
interpolationThe interpolation mode.

Definition at line 239 of file transfer_function.cxx.

References cgv::media::color_scale::modified().

◆ set_opacity_points()

void cgv::media::transfer_function::set_opacity_points ( const std::vector< opacity_point_type > &  opacities)

Set the opacity function to use the given control points.

Extends the domain if the new control points are outside the current domain. Opacity values are clamped to [0,1].

Parameters
opacitiesThe control points.

Definition at line 32 of file transfer_function.cxx.

Referenced by transfer_function().


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