OpenWalnut  1.5.0dev
Classes | Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
WTransferFunction Class Reference

A class that stores a 1D transfer function which consists of a linear interpolation of alpha and color values. More...

#include <WTransferFunction.h>

+ Collaboration diagram for WTransferFunction:

Classes

struct  AlphaEntry
 Alpha entries represent linearly interpolated transparency values along the isovalue scale. More...
 
struct  ColorEntry
 Color entries are linearly interpolated colors along isovalues. More...
 
struct  Entry
 Prototype for a storage element. More...
 
struct  LessPred
 Templatized comparison predicate for internal searching. More...
 

Public Member Functions

 WTransferFunction ()
 Default constructor of a meaningless transfer function. More...
 
 WTransferFunction (const WTransferFunction &rhs)
 Deep copy constructor. More...
 
WTransferFunctionoperator= (const WTransferFunction &rhs)
 Deep copy operator. More...
 
bool operator== (const WTransferFunction &rhs) const
 Check equivalence of two transfer functions. More...
 
bool operator!= (const WTransferFunction &rhs) const
 Check equivalence of two transfer functions. More...
 
 ~WTransferFunction ()
 Default destuctor. More...
 
size_t numAlphas () const
 Get the number of alphas. More...
 
size_t numColors () const
 Get the number of colors. More...
 
double getOpacityScale () const
 Get the scaling factor for the opacity. More...
 
void setOpacityScale (double factor)
 Set the scaling factor for the opacity. More...
 
double getAlphaIsovalue (size_t i) const
 Get the isovalue at a given index in the alpha values. More...
 
double getColorIsovalue (size_t i) const
 The isovalue of the color at a given index. More...
 
double getAlpha (size_t i) const
 Get alpha at given index. More...
 
const WColor & getColor (size_t i) const
 Get color at given index. More...
 
void addColor (double iso, const WColor &color)
 Insert a new color point. More...
 
void addAlpha (double iso, double alpha)
 Insert a new alpha point. More...
 
void setHistogram (std::vector< double > &data)
 Set the histogram going along with the transfer function. More...
 
void removeHistogram ()
 Clears the histogram data so the gui won't show any. More...
 
const std::vector< double > & getHistogram () const
 Returns the histogram. More...
 
void sample1DTransferFunction (unsigned char *array, int width, double min, double max) const
 sample/render the transfer function linearly between min and max in an RGBA texture. More...
 

Static Public Member Functions

static WTransferFunction createFromRGBA (unsigned char const *const rgba, size_t size)
 Try to estimate a transfer function from an RGBA image. More...
 

Private Attributes

std::vector< ColorEntrym_colors
 Sorted list of colors. More...
 
std::vector< AlphaEntrym_alphas
 Sorted list of alpha values. More...
 
double m_isomin
 The smallest used iso value. More...
 
double m_isomax
 The largest used iso value. More...
 
double m_opacityScale
 Factor by which the output opacity is scaled to allow for easier specification of very small opacity values. More...
 
std::vector< double > m_histogram
 Sores a histogram. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const WTransferFunction &tf)
 Default output operator. More...
 

Detailed Description

A class that stores a 1D transfer function which consists of a linear interpolation of alpha and color values.

Definition at line 37 of file WTransferFunction.h.

Constructor & Destructor Documentation

◆ WTransferFunction() [1/2]

WTransferFunction::WTransferFunction ( )
inline

Default constructor of a meaningless transfer function.

Definition at line 43 of file WTransferFunction.h.

◆ WTransferFunction() [2/2]

WTransferFunction::WTransferFunction ( const WTransferFunction rhs)
inline

Deep copy constructor.

Parameters
rhsthe value to histogram

Definition at line 52 of file WTransferFunction.h.

◆ ~WTransferFunction()

WTransferFunction::~WTransferFunction ( )
inline

Default destuctor.

Definition at line 95 of file WTransferFunction.h.

Member Function Documentation

◆ addAlpha()

void WTransferFunction::addAlpha ( double  iso,
double  alpha 
)

Insert a new alpha point.

Parameters
isothe new iso value
alphathe new alpha value at the given iso value

Definition at line 211 of file WTransferFunction.cpp.

References m_alphas, m_colors, m_isomax, and m_isomin.

Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_TRANSFERFUNCTION >::create(), createFromRGBA(), WMTransferFunction1D::properties(), WVisualizationPropertyHandler::setColorGradient(), and WTransferFunctionWidget::updateTransferFunction().

+ Here is the caller graph for this function:

◆ addColor()

void WTransferFunction::addColor ( double  iso,
const WColor &  color 
)

Insert a new color point.

Parameters
isothe new iso value
colorthe new color at the given iso value

Definition at line 187 of file WTransferFunction.cpp.

References m_alphas, m_colors, m_isomax, and m_isomin.

Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_TRANSFERFUNCTION >::create(), createFromRGBA(), WMTransferFunction1D::properties(), WVisualizationPropertyHandler::setColorGradient(), and WTransferFunctionWidget::updateTransferFunction().

+ Here is the caller graph for this function:

◆ createFromRGBA()

WTransferFunction WTransferFunction::createFromRGBA ( unsigned char const *const  rgba,
size_t  size 
)
static

Try to estimate a transfer function from an RGBA image.

Parameters
rgbavalues between 0 and 255 representing the red, green, and blue channel
sizenumber of color entries in rgba
Returns
approximated transfer function

the threshold here is larger than for alpha, becuase we compare all colors at once

Definition at line 235 of file WTransferFunction.cpp.

References addAlpha(), and addColor().

Referenced by WTransferFunctionScene::dropEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAlpha()

double WTransferFunction::getAlpha ( size_t  i) const
inline

Get alpha at given index.

Parameters
ithe index to query
Returns
the alpha value at index i

Definition at line 166 of file WTransferFunction.h.

References m_alphas, and m_opacityScale.

Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_TRANSFERFUNCTION >::asString(), and WPropertyTransferFunctionWidget::update().

+ Here is the caller graph for this function:

◆ getAlphaIsovalue()

double WTransferFunction::getAlphaIsovalue ( size_t  i) const
inline

Get the isovalue at a given index in the alpha values.

Parameters
ithe index of the point to query
Returns
the alpha values position/isovalue at index i

Definition at line 144 of file WTransferFunction.h.

References m_alphas.

Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_TRANSFERFUNCTION >::asString(), and WPropertyTransferFunctionWidget::update().

+ Here is the caller graph for this function:

◆ getColor()

const WColor& WTransferFunction::getColor ( size_t  i) const
inline

Get color at given index.

Parameters
ithe index to query
Returns
the color at index i

Definition at line 177 of file WTransferFunction.h.

References m_colors.

Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_TRANSFERFUNCTION >::asString(), and WPropertyTransferFunctionWidget::update().

+ Here is the caller graph for this function:

◆ getColorIsovalue()

double WTransferFunction::getColorIsovalue ( size_t  i) const
inline

The isovalue of the color at a given index.

Parameters
ithe index of the point to query.
Returns
the color values position/isovalue at index i

Definition at line 155 of file WTransferFunction.h.

References m_colors.

Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_TRANSFERFUNCTION >::asString(), and WPropertyTransferFunctionWidget::update().

+ Here is the caller graph for this function:

◆ getHistogram()

const std::vector< double >& WTransferFunction::getHistogram ( ) const
inline

Returns the histogram.

Returns
a reference to the internal representation of the histogram

Definition at line 225 of file WTransferFunction.h.

References m_histogram.

Referenced by WPropertyTransferFunctionWidget::update().

+ Here is the caller graph for this function:

◆ getOpacityScale()

double WTransferFunction::getOpacityScale ( ) const
inline

Get the scaling factor for the opacity.

Returns
scaling factor

Definition at line 124 of file WTransferFunction.h.

References m_opacityScale.

◆ numAlphas()

size_t WTransferFunction::numAlphas ( ) const
inline

Get the number of alphas.

Returns
the number of alpha points

Definition at line 104 of file WTransferFunction.h.

References m_alphas.

Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_TRANSFERFUNCTION >::asString(), WMTransferFunction1D::moduleMain(), and WPropertyTransferFunctionWidget::update().

+ Here is the caller graph for this function:

◆ numColors()

size_t WTransferFunction::numColors ( ) const
inline

Get the number of colors.

Returns
the number of color points

Definition at line 114 of file WTransferFunction.h.

References m_colors.

Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_TRANSFERFUNCTION >::asString(), and WPropertyTransferFunctionWidget::update().

+ Here is the caller graph for this function:

◆ operator!=()

bool WTransferFunction::operator!= ( const WTransferFunction rhs) const

Check equivalence of two transfer functions.

Returns
negated result of operator==
Parameters
rhsthe value to compare with

Definition at line 91 of file WTransferFunction.cpp.

◆ operator=()

WTransferFunction& WTransferFunction::operator= ( const WTransferFunction rhs)
inline

Deep copy operator.

Parameters
rhsthe value to copy
Returns
reference to current object
reference to current object

Definition at line 65 of file WTransferFunction.h.

References m_alphas, m_colors, m_histogram, m_isomax, and m_isomin.

◆ operator==()

bool WTransferFunction::operator== ( const WTransferFunction rhs) const

Check equivalence of two transfer functions.

Returns
true if this object contains exactly the same data as rhs
Parameters
rhsobject to compare with

Definition at line 33 of file WTransferFunction.cpp.

References m_alphas, m_colors, m_histogram, m_isomax, and m_isomin.

◆ removeHistogram()

void WTransferFunction::removeHistogram ( )
inline

Clears the histogram data so the gui won't show any.

Definition at line 215 of file WTransferFunction.h.

References m_histogram.

Referenced by WMTransferFunction1D::moduleMain().

+ Here is the caller graph for this function:

◆ sample1DTransferFunction()

void WTransferFunction::sample1DTransferFunction ( unsigned char *  array,
int  width,
double  min,
double  max 
) const

sample/render the transfer function linearly between min and max in an RGBA texture.

Parameters
arraypointer to an allocated data structure
widthis the number of RGBA samples.
minthe lowest value to be sampled
maxthe hightes value to be sampled
Postcondition
array contains the sampled data
Precondition
array is allocated and has space for width elements

Definition at line 115 of file WTransferFunction.cpp.

References m_alphas, m_colors, m_isomax, m_isomin, and m_opacityScale.

Referenced by WMTransferFunction1D::moduleMain(), and WCsvConverter::sampleTransferFunction().

+ Here is the caller graph for this function:

◆ setHistogram()

void WTransferFunction::setHistogram ( std::vector< double > &  data)
inline

Set the histogram going along with the transfer function.

This should be changed in the future to be handled in a different way. A good option would be to introduce an object encapsulating a transfer function and histogram information.

Parameters
datathe histogram data between m_isomin and m_isomax

Definition at line 207 of file WTransferFunction.h.

References m_histogram.

Referenced by WMTransferFunction1D::moduleMain(), and WTransferFunctionWidget::updateTransferFunction().

+ Here is the caller graph for this function:

◆ setOpacityScale()

void WTransferFunction::setOpacityScale ( double  factor)
inline

Set the scaling factor for the opacity.

Parameters
factorscaling factor of opacity values

Definition at line 133 of file WTransferFunction.h.

References m_opacityScale.

Referenced by WMTransferFunction1D::moduleMain().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const WTransferFunction tf 
)
friend

Default output operator.

Currently stores values the same way as it is done in the properties. This code should only be used for debugging and you should not rely on the interface.

Parameters
tfThe transfer function to output
outThe stream to which we write
Returns
reference to out

Definition at line 355 of file WTransferFunction.cpp.

Member Data Documentation

◆ m_alphas

std::vector<AlphaEntry> WTransferFunction::m_alphas
private

Sorted list of alpha values.

Definition at line 368 of file WTransferFunction.h.

Referenced by addAlpha(), addColor(), getAlpha(), getAlphaIsovalue(), numAlphas(), operator=(), operator==(), and sample1DTransferFunction().

◆ m_colors

std::vector<ColorEntry> WTransferFunction::m_colors
private

Sorted list of colors.

Definition at line 363 of file WTransferFunction.h.

Referenced by addAlpha(), addColor(), getColor(), getColorIsovalue(), numColors(), operator=(), operator==(), and sample1DTransferFunction().

◆ m_histogram

std::vector< double > WTransferFunction::m_histogram
private

Sores a histogram.

This is used for property-handling only and does not change the transfer function at all.

Definition at line 391 of file WTransferFunction.h.

Referenced by getHistogram(), operator=(), operator==(), removeHistogram(), and setHistogram().

◆ m_isomax

double WTransferFunction::m_isomax
private

The largest used iso value.

Definition at line 378 of file WTransferFunction.h.

Referenced by addAlpha(), addColor(), operator=(), operator==(), and sample1DTransferFunction().

◆ m_isomin

double WTransferFunction::m_isomin
private

The smallest used iso value.

Definition at line 373 of file WTransferFunction.h.

Referenced by addAlpha(), addColor(), operator=(), operator==(), and sample1DTransferFunction().

◆ m_opacityScale

double WTransferFunction::m_opacityScale
private

Factor by which the output opacity is scaled to allow for easier specification of very small opacity values.

Definition at line 385 of file WTransferFunction.h.

Referenced by getAlpha(), getOpacityScale(), sample1DTransferFunction(), and setOpacityScale().


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