source: branches/blt4/packages/vizservers/vtkvis/ColorMap.h @ 2302

Last change on this file since 2302 was 2302, checked in by gah, 13 years ago

update from trunk

File size: 3.3 KB
Line 
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>
15#include <vtkColorTransferFunction.h>
16#include <vtkPiecewiseFunction.h>
17#include <vtkLookupTable.h>
18
19namespace Rappture {
20namespace 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 */
28class ColorMap {
29public:
30    /**
31     * \brief RGB inflection point in a transfer function
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    };
56
57    /**
58     * \brief Opacity(alpha) inflection point in a transfer function
59     */
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();
88
89    vtkLookupTable *getLookupTable();
90
91    vtkSmartPointer<vtkColorTransferFunction> getColorTransferFunction(double range[2]);
92
93    vtkSmartPointer<vtkPiecewiseFunction> getOpacityTransferFunction(double range[2]);
94
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
105    static ColorMap *getDefault();
106    static ColorMap *getVolumeDefault();
107
108private:
109    static ColorMap *_default;
110    static ColorMap *_volumeDefault;
111
112    ColorMap();
113
114    void lerp(double *result, const ControlPoint& cp1, const ControlPoint& cp2, double value);
115    void lerp(double *result, const OpacityControlPoint& cp1, const OpacityControlPoint& cp2, double value);
116
117    std::string _name;
118    std::list<ControlPoint> _controlPoints;
119    std::list<OpacityControlPoint> _opacityControlPoints;
120    bool _needsBuild;
121    int _numTableEntries;
122    vtkSmartPointer<vtkColorTransferFunction> _colorTF;
123    vtkSmartPointer<vtkPiecewiseFunction> _opacityTF;
124    vtkSmartPointer<vtkLookupTable> _lookupTable;
125};
126
127}
128}
129
130#endif
Note: See TracBrowser for help on using the repository browser.