SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLTexColorLUT.h
Go to the documentation of this file.
1 /**
2  * \file SLTexColorLUT.h
3  * \brief Declares a color look up table functionality
4  * \date July 2017
5  * \authors Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 #ifndef SLCOLORLUT_H
12 #define SLCOLORLUT_H
13 
14 #include <SL.h>
15 #include <SLEventHandler.h>
16 #include <SLGLTexture.h>
17 #include <SLVec3.h>
18 
19 class SLScene;
20 class SLSceneView;
21 
22 //-----------------------------------------------------------------------------
23 //! Predefined color lookup tables
24 typedef enum
25 {
26  CLUT_BW, //!< black to white
27  CLUT_WB, //!< white to black
28  CLUT_WYR, //!< white to black
29  CLUT_RYGCB, //!< red to yellow to green to cyan to blue
30  CLUT_BCGYR, //!< blue to cyan to green to yellow to red
31  CLUT_RYGCBK, //!< red to yellow to green to cyan to blue to black
32  CLUT_KBCGYR, //!< black to blue to cyan to green to yellow to red
33  CLUT_RYGCBM, //!< red to yellow to green to cyan to blue to magenta
34  CLUT_MBCGYR, //!< magenta to blue to cyan to green to yellow to red
35  CLUT_DAYLIGHT, //!< daylight from sunrise to sunset with noon in the middle
36  CLUT_custom //! enum for any other custom LUT
38 //-----------------------------------------------------------------------------
39 //! Color point with color and position value between 0-1
41 {
42  SLColorLUTPoint(SLCol3f colorVal, SLfloat posVal)
43  : color(colorVal), pos(posVal) { ; }
44  SLCol3f color; // Transfer color RGB
45  SLfloat pos; // Transfer position (0-1)
46 };
47 typedef vector<SLColorLUTPoint> SLVColorLUTPoint;
48 //-----------------------------------------------------------------------------
49 //! Alpha point with alpha value and position value between 0-1
51 {
52  SLAlphaLUTPoint(SLfloat alphaVal, SLfloat posVal)
53  : alpha(alphaVal), pos(posVal) { ; }
54  SLfloat alpha; // Transfer alpha (0-1)
55  SLfloat pos; // Transfer position (0-1)
56 };
57 typedef vector<SLAlphaLUTPoint> SLVAlphaLUTPoint;
58 //-----------------------------------------------------------------------------
59 //! SLTexColorLUT defines a lookup table as an 1D texture of (256) RGBA values
60 /*! SLTexColorLUT defines an RGBA color lookup table (LUT). It can be used to
61  define a transfer function that are generated from a set of color and alpha
62  points where all in-between points are linearly interpolated.
63  Such a color/alpha lookup table is used as a transfer function e.g. in
64  volume rendering (see the shader VolumeRenderingRayCast).
65  All values (RGB color, alpha and position) are values between 0-1 and are
66  mapped to 0-255 when the texture image of size 1x256 is generated.
67 */
68 class SLTexColorLUT : public SLGLTexture
69  , public SLEventHandler
70 {
71 public:
72  SLTexColorLUT(SLAssetManager* assetMgr,
73  SLColorLUTType lutType,
74  SLuint length = 256);
75  SLTexColorLUT(SLAssetManager* assetMgr,
76  SLVAlphaLUTPoint alphaVec,
77  SLColorLUTType lutType = CLUT_RYGCB,
78  SLuint length = 256);
79  SLTexColorLUT(SLAssetManager* assetMgr,
80  SLVAlphaLUTPoint alphaValues,
81  SLVColorLUTPoint colorValues,
82  SLuint length = 256);
83 
84  // Don't forget destructor to be virtual for texture deallocation
85  virtual ~SLTexColorLUT();
86 
87  void generateTexture();
88 
89  // Setters
90  void colors(SLColorLUTType lut);
91 
92  // Getters
93  SLuint length() { return _length; }
98 
99 protected:
100  SLuint _length; //! Length of transfer function (default 256)
101  SLColorLUTType _colorLUT; //! Color LUT identifier
102  SLVColorLUTPoint _colors; //! vector of colors in TF
103  SLVAlphaLUTPoint _alphas; //! vector of alphas in TF
104 };
105 //-----------------------------------------------------------------------------
106 #endif
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
vector< SLfloat > SLVfloat
Definition: SL.h:200
vector< SLColorLUTPoint > SLVColorLUTPoint
Definition: SLTexColorLUT.h:47
SLColorLUTType
Predefined color lookup tables.
Definition: SLTexColorLUT.h:25
@ CLUT_WB
white to black
Definition: SLTexColorLUT.h:27
@ CLUT_RYGCBK
red to yellow to green to cyan to blue to black
Definition: SLTexColorLUT.h:31
@ CLUT_custom
enum for any other custom LUT
Definition: SLTexColorLUT.h:36
@ CLUT_MBCGYR
magenta to blue to cyan to green to yellow to red
Definition: SLTexColorLUT.h:34
@ CLUT_RYGCBM
red to yellow to green to cyan to blue to magenta
Definition: SLTexColorLUT.h:33
@ CLUT_DAYLIGHT
daylight from sunrise to sunset with noon in the middle
Definition: SLTexColorLUT.h:35
@ CLUT_BCGYR
blue to cyan to green to yellow to red
Definition: SLTexColorLUT.h:30
@ CLUT_RYGCB
red to yellow to green to cyan to blue
Definition: SLTexColorLUT.h:29
@ CLUT_KBCGYR
black to blue to cyan to green to yellow to red
Definition: SLTexColorLUT.h:32
@ CLUT_WYR
white to black
Definition: SLTexColorLUT.h:28
@ CLUT_BW
black to white
Definition: SLTexColorLUT.h:26
vector< SLAlphaLUTPoint > SLVAlphaLUTPoint
Definition: SLTexColorLUT.h:57
vector< SLCol3f > SLVCol3f
Definition: SLVec3.h:326
Toplevel holder of the assets meshes, materials, textures and shaders.
Virtual Eventhandler class.
Texture object for OpenGL texturing.
Definition: SLGLTexture.h:110
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
SLTexColorLUT defines a lookup table as an 1D texture of (256) RGBA values.
Definition: SLTexColorLUT.h:70
SLVAlphaLUTPoint _alphas
vector of colors in TF
SLVColorLUTPoint _colors
Color LUT identifier.
SLTexColorLUT(SLAssetManager *assetMgr, SLColorLUTType lutType, SLuint length=256)
Default ctor color LUT of a specific SLColorLUTType.
SLVColorLUTPoint & colors()
Definition: SLTexColorLUT.h:94
SLColorLUTType _colorLUT
Length of transfer function (default 256)
SLVfloat allAlphas()
Returns all alpha values of the transfer function as a float vector.
SLVCol3f allColors()
Returns all alpha values of the transfer function as a float vector.
virtual ~SLTexColorLUT()
SLuint length()
Definition: SLTexColorLUT.h:93
void generateTexture()
Generates the full 256 value LUT as 1x256 RGBA texture.
SLVAlphaLUTPoint & alphas()
Definition: SLTexColorLUT.h:95
Alpha point with alpha value and position value between 0-1.
Definition: SLTexColorLUT.h:51
SLAlphaLUTPoint(SLfloat alphaVal, SLfloat posVal)
Definition: SLTexColorLUT.h:52
Color point with color and position value between 0-1.
Definition: SLTexColorLUT.h:41
SLColorLUTPoint(SLCol3f colorVal, SLfloat posVal)
Definition: SLTexColorLUT.h:42