MeVisLab Toolbox Reference
ml::TScaleShiftData< DT > Class Template Reference

Class to define a first order linear transformation. More...

#include <mlScaleShiftData.h>

Public Types

enum  ReorderMode { NoReordering = 0 , ReorderColorPlanesToInterleaved = 1 }
 Mode that indicates if copySubImage should reorder the color from planes (from x,y,z,c,t,u) to interleaved format (c,x,y,z,c,t,u). More...
 

Public Member Functions

ReorderMode getReorderMode () const
 Get the reorder mode. More...
 
void setReorderMode (ReorderMode mode)
 Set the reorder mode. More...
 
Initialization
 TScaleShiftData ()
 Default constructor, i.e., builds identity transformation. More...
 
 TScaleShiftData (const TScaleShiftData< DT > &ssd)
 Copy constructor. More...
 
 TScaleShiftData (DT scale, DT shift)
 Constructor: Sets scale and shift to define a transformation so that a scaled value v' is v' = v*scale + shift. More...
 
 TScaleShiftData (DT fromMin, DT fromMax, DT toMin, DT toMax)
 Values from interval [fromMin, fromMax] are transformed linearly into [toMin, toMax]. More...
 
Assignment.
TScaleShiftDataoperator= (const TScaleShiftData< DT > &ssd)
 Assignment operator from an existing object to get an identical copy. More...
 
Comparison.
bool operator== (const TScaleShiftData< DT > &ssd) const
 Returns true if all members are equal. More...
 
bool operator!= (const TScaleShiftData< DT > &ssd) const
 Returns true if any members differ. More...
 
Set transformation
void setScaleOffset (DT scale, DT shift)
 Sets scale and shift: values are multiplied with scale and then shift is added. More...
 
void setFromMinMaxToMinMax (DT fromMin, DT fromMax, DT toMin, DT toMax)
 Values from interval [fromMin, fromMax] are transformed linearly into [toMin, toMax]. More...
 
void setFromMinMaxToMinMax (MLDataType fromType, DT fromMin, DT fromMax, MLDataType toType, DT toMin, DT toMax)
 Values from interval [fromMin, fromMax] are transformed linearly into [toMin, toMax]. More...
 
void unset ()
 Sets default, i.e., identity transformation. More...
 
Query transformation values.
DT getScale () const
 Returns scale constant from transformation y=scale*x+offset. More...
 
DT getShift () const
 Returns addition constant shift from transformation y=scale*x+shift. More...
 

Detailed Description

template<typename DT>
class ml::TScaleShiftData< DT >

Class to define a first order linear transformation.

It is used as container for the parameters scale and shift of a linear transformation y=scale*x+shift.

Notes:

  • The transformation parameters are used in the class Host to transform voxels values before copying pages into a result image tile. So data loss can be avoided which could occur on a possible type casting when image data is converted to another data type. E.g., if float voxel data from interval [0,1] is cast to MLint16, it usually would lose precision information. By scaling it with TScaleShiftData(0, 65535,99) it is copied to another value range.
  • Since all member functions are inlined we do not need to export this class. (That would inhibit inline usage.)
  • This class is intended to be instantiated only with scalar floating point types for DT. For other types no experiences nor tests exist, although instantiations with integer types is not forbidden and could be useful on certain contexts.

Definition at line 54 of file mlScaleShiftData.h.

Member Enumeration Documentation

◆ ReorderMode

template<typename DT >
enum ml::TScaleShiftData::ReorderMode

Mode that indicates if copySubImage should reorder the color from planes (from x,y,z,c,t,u) to interleaved format (c,x,y,z,c,t,u).

Note that a SubImage with interleaved color data will not be fully functional, since it will not have correct internal strides etc. Typically ReorderMode::ReorderColorPlanesToInterleaved is used to convert color images for usage with OpenGL or other APIs that require RGBRGBRGB... or RGBARGBA... data.

Enumerator
NoReordering 

< no reodering is done

ReorderColorPlanesToInterleaved 

< reorders the color planes to interleaved format.

Definition at line 65 of file mlScaleShiftData.h.

Constructor & Destructor Documentation

◆ TScaleShiftData() [1/4]

template<typename DT >
ml::TScaleShiftData< DT >::TScaleShiftData ( )
inline

Default constructor, i.e., builds identity transformation.

Definition at line 76 of file mlScaleShiftData.h.

◆ TScaleShiftData() [2/4]

template<typename DT >
ml::TScaleShiftData< DT >::TScaleShiftData ( const TScaleShiftData< DT > &  ssd)
inline

Copy constructor.

Definition at line 84 of file mlScaleShiftData.h.

◆ TScaleShiftData() [3/4]

template<typename DT >
ml::TScaleShiftData< DT >::TScaleShiftData ( DT  scale,
DT  shift 
)
inline

Constructor: Sets scale and shift to define a transformation so that a scaled value v' is v' = v*scale + shift.

Definition at line 93 of file mlScaleShiftData.h.

◆ TScaleShiftData() [4/4]

template<typename DT >
ml::TScaleShiftData< DT >::TScaleShiftData ( DT  fromMin,
DT  fromMax,
DT  toMin,
DT  toMax 
)
inline

Values from interval [fromMin, fromMax] are transformed linearly into [toMin, toMax].

If necessary, interval borders are swapped to guarantee that minimum values are smaller or equal than maximum values. In case that fromMin and fromMax are identical, _scale is set to 1 and _shift is set to toMin - fromMin. So the only value from that interval is projected to the minimum value of the target interval. ATTENTION: This transformation defines no clipping/clamping. If values outside [fromMin, fromMax] are transformed they will be transformed to values outside [toMin, toMax].

Definition at line 107 of file mlScaleShiftData.h.

Member Function Documentation

◆ getReorderMode()

template<typename DT >
ReorderMode ml::TScaleShiftData< DT >::getReorderMode ( ) const
inline

Get the reorder mode.

Definition at line 304 of file mlScaleShiftData.h.

Referenced by ml::TSubImage< DATATYPE >::copySubImageTyped().

◆ getScale()

template<typename DT >
DT ml::TScaleShiftData< DT >::getScale ( ) const
inline

Returns scale constant from transformation y=scale*x+offset.

Definition at line 297 of file mlScaleShiftData.h.

Referenced by ml::TSubImage< DATATYPE >::copySubImageReorderColorPlanesToInterleaved(), and ml::TSubImage< DATATYPE >::copySubImageTyped().

◆ getShift()

template<typename DT >
DT ml::TScaleShiftData< DT >::getShift ( ) const
inline

Returns addition constant shift from transformation y=scale*x+shift.

Definition at line 300 of file mlScaleShiftData.h.

Referenced by ml::TSubImage< DATATYPE >::copySubImageReorderColorPlanesToInterleaved(), and ml::TSubImage< DATATYPE >::copySubImageTyped().

◆ operator!=()

template<typename DT >
bool ml::TScaleShiftData< DT >::operator!= ( const TScaleShiftData< DT > &  ssd) const
inline

Returns true if any members differ.

Definition at line 145 of file mlScaleShiftData.h.

◆ operator=()

template<typename DT >
TScaleShiftData& ml::TScaleShiftData< DT >::operator= ( const TScaleShiftData< DT > &  ssd)
inline

Assignment operator from an existing object to get an identical copy.

Definition at line 121 of file mlScaleShiftData.h.

◆ operator==()

template<typename DT >
bool ml::TScaleShiftData< DT >::operator== ( const TScaleShiftData< DT > &  ssd) const
inline

Returns true if all members are equal.

Definition at line 138 of file mlScaleShiftData.h.

References MLValuesAreEqualWOM().

◆ setFromMinMaxToMinMax() [1/2]

template<typename DT >
void ml::TScaleShiftData< DT >::setFromMinMaxToMinMax ( DT  fromMin,
DT  fromMax,
DT  toMin,
DT  toMax 
)
inline

Values from interval [fromMin, fromMax] are transformed linearly into [toMin, toMax].

If necessary then interval borders are swapped to guarantee that minimum values are smaller or equal than maximum values. In case that fromMin and fromMax are identical, _scale is set to 1 and _shift is set to toMin - fromMin. So the only value from that interval is projected to the minimum value of the target interval. ATTENTION: This transformation defines no clipping/clamping. If values outside [fromMin, fromMax] are transformed they will be transformed to values outside [toMin, toMax].

Definition at line 175 of file mlScaleShiftData.h.

References DCMTree::DT.

◆ setFromMinMaxToMinMax() [2/2]

template<typename DT >
void ml::TScaleShiftData< DT >::setFromMinMaxToMinMax ( MLDataType  fromType,
DT  fromMin,
DT  fromMax,
MLDataType  toType,
DT  toMin,
DT  toMax 
)
inline

Values from interval [fromMin, fromMax] are transformed linearly into [toMin, toMax].

If necessary then interval borders are swapped to guarantee that minimum values are smaller or equal than maximum values.

This method handles float/integer datatype combinations differently:

Float -> Integer

Adds 0.99 to the integer toMax, since that is almost the case like adding 1. and avoids having to clamp the result to the int max value. (like described in 'Zen of Graphics Programming, Michael Abrash')

Integer -> Integer

Adds 1 to the fromMax and toMax ranges (which is the same as shifting for power-of-two differences in range) when input range is greater than output range. Otherwise leave as is, so that fromMax maps to toMax.

Integer -> Float

Use range as given. Rationale: Use fromMax int value, and not fromMax+1, so that the maximum integer value will get the maximum float value (like in OpenGL, where the maximum integer value is mapped to 1.)

Float -> Float

Use range as given.

In case that fromMin and fromMax are identical, _scale is set to 1 and _shift is set to toMin - fromMin. So the only value from that interval is projected to the minimum value of the target interval. ATTENTION: This transformation defines no clipping/clamping. If values outside [fromMin, fromMax] are transformed they will be transformed to values outside [toMin, toMax].

Definition at line 231 of file mlScaleShiftData.h.

References DCMTree::DT, and MLIsIntType().

◆ setReorderMode()

template<typename DT >
void ml::TScaleShiftData< DT >::setReorderMode ( ReorderMode  mode)
inline

Set the reorder mode.

Definition at line 307 of file mlScaleShiftData.h.

◆ setScaleOffset()

template<typename DT >
void ml::TScaleShiftData< DT >::setScaleOffset ( DT  scale,
DT  shift 
)
inline

Sets scale and shift: values are multiplied with scale and then shift is added.

Definition at line 159 of file mlScaleShiftData.h.

◆ unset()

template<typename DT >
void ml::TScaleShiftData< DT >::unset ( )
inline

Sets default, i.e., identity transformation.

Definition at line 282 of file mlScaleShiftData.h.

References DCMTree::DT.


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