[2112] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
| 2 | /* |
---|
| 3 | * Copyright (C) 2011, Purdue Research Foundation |
---|
| 4 | * |
---|
| 5 | * Author: Leif Delgass <ldelgass@purdue.edu> |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #ifndef __RAPPTURE_VTKVIS_COLORMAP_H__ |
---|
| 9 | #define __RAPPTURE_VTKVIS_COLORMAP_H__ |
---|
| 10 | |
---|
| 11 | #include <string> |
---|
| 12 | #include <list> |
---|
| 13 | #include <cstring> |
---|
| 14 | #include <vtkSmartPointer.h> |
---|
[2261] | 15 | #include <vtkColorTransferFunction.h> |
---|
| 16 | #include <vtkPiecewiseFunction.h> |
---|
[2112] | 17 | #include <vtkLookupTable.h> |
---|
| 18 | |
---|
| 19 | namespace Rappture { |
---|
| 20 | namespace VtkVis { |
---|
| 21 | |
---|
| 22 | /** |
---|
| 23 | * \brief RGBA color map table created from transfer function |
---|
| 24 | * |
---|
| 25 | * ColorMap uses linear interpolation between ControlPoints to |
---|
| 26 | * create a color lookup table for VTK |
---|
| 27 | */ |
---|
| 28 | class ColorMap { |
---|
| 29 | public: |
---|
| 30 | /** |
---|
[2194] | 31 | * \brief RGB inflection point in a transfer function |
---|
[2112] | 32 | */ |
---|
| 33 | struct ControlPoint { |
---|
| 34 | ControlPoint() : |
---|
| 35 | value(0) |
---|
| 36 | { |
---|
| 37 | memset(color, 0, sizeof(double)*3); |
---|
| 38 | } |
---|
| 39 | ControlPoint(const ControlPoint& other) : |
---|
| 40 | value(other.value) |
---|
| 41 | { |
---|
| 42 | memcpy(color, other.color, sizeof(double)*3); |
---|
| 43 | } |
---|
| 44 | ControlPoint& operator=(const ControlPoint &other) |
---|
| 45 | { |
---|
| 46 | if (this != &other) { |
---|
| 47 | value = other.value; |
---|
| 48 | memcpy(color, other.color, sizeof(double)*3); |
---|
| 49 | } |
---|
| 50 | return *this; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | double value; ///< Normalized scalar data value [0,1] |
---|
| 54 | double color[3]; ///< RGB color |
---|
| 55 | }; |
---|
[2194] | 56 | |
---|
| 57 | /** |
---|
| 58 | * \brief Opacity(alpha) inflection point in a transfer function |
---|
| 59 | */ |
---|
[2112] | 60 | struct OpacityControlPoint { |
---|
| 61 | OpacityControlPoint() : |
---|
| 62 | value(0), |
---|
| 63 | alpha(1) |
---|
| 64 | { |
---|
| 65 | } |
---|
| 66 | OpacityControlPoint(const OpacityControlPoint& other) : |
---|
| 67 | value(other.value), |
---|
| 68 | alpha(other.alpha) |
---|
| 69 | { |
---|
| 70 | } |
---|
| 71 | OpacityControlPoint& operator=(const OpacityControlPoint &other) |
---|
| 72 | { |
---|
| 73 | if (this != &other) { |
---|
| 74 | value = other.value; |
---|
| 75 | alpha = other.alpha; |
---|
| 76 | } |
---|
| 77 | return *this; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | double value; ///< Normalized scalar data value [0,1] |
---|
| 81 | double alpha; ///< Opacity |
---|
| 82 | }; |
---|
| 83 | |
---|
| 84 | ColorMap(const std::string& name); |
---|
| 85 | virtual ~ColorMap(); |
---|
| 86 | |
---|
| 87 | const std::string& getName(); |
---|
[2261] | 88 | |
---|
[2112] | 89 | vtkLookupTable *getLookupTable(); |
---|
| 90 | |
---|
[2261] | 91 | vtkSmartPointer<vtkColorTransferFunction> getColorTransferFunction(double range[2]); |
---|
| 92 | |
---|
| 93 | vtkSmartPointer<vtkPiecewiseFunction> getOpacityTransferFunction(double range[2]); |
---|
| 94 | |
---|
[2112] | 95 | void setNumberOfTableEntries(int numEntries); |
---|
| 96 | |
---|
| 97 | void addControlPoint(ControlPoint& cp); |
---|
| 98 | |
---|
| 99 | void addOpacityControlPoint(OpacityControlPoint& cp); |
---|
| 100 | |
---|
| 101 | void build(); |
---|
| 102 | |
---|
| 103 | void clear(); |
---|
| 104 | |
---|
[2261] | 105 | static ColorMap *getDefault(); |
---|
[2404] | 106 | static ColorMap *getGrayDefault(); |
---|
[2261] | 107 | static ColorMap *getVolumeDefault(); |
---|
[2320] | 108 | static ColorMap *getElementDefault(); |
---|
[2112] | 109 | |
---|
| 110 | private: |
---|
[2261] | 111 | static ColorMap *_default; |
---|
[2404] | 112 | static ColorMap *_grayDefault; |
---|
[2261] | 113 | static ColorMap *_volumeDefault; |
---|
[2320] | 114 | static ColorMap *_elementDefault; |
---|
[2261] | 115 | |
---|
[2112] | 116 | ColorMap(); |
---|
| 117 | |
---|
| 118 | void lerp(double *result, const ControlPoint& cp1, const ControlPoint& cp2, double value); |
---|
| 119 | void lerp(double *result, const OpacityControlPoint& cp1, const OpacityControlPoint& cp2, double value); |
---|
| 120 | |
---|
| 121 | std::string _name; |
---|
| 122 | std::list<ControlPoint> _controlPoints; |
---|
| 123 | std::list<OpacityControlPoint> _opacityControlPoints; |
---|
| 124 | bool _needsBuild; |
---|
| 125 | int _numTableEntries; |
---|
[2261] | 126 | vtkSmartPointer<vtkColorTransferFunction> _colorTF; |
---|
| 127 | vtkSmartPointer<vtkPiecewiseFunction> _opacityTF; |
---|
[2112] | 128 | vtkSmartPointer<vtkLookupTable> _lookupTable; |
---|
| 129 | }; |
---|
| 130 | |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | #endif |
---|