source: trunk/packages/vizservers/vtkvis/ColorMap.h @ 3177

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (C) 2004-2012  HUBzero Foundation, LLC
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 *getGrayDefault();
107    static ColorMap *getVolumeDefault();
108    static ColorMap *getElementDefault();
109
110private:
111    static ColorMap *_default;
112    static ColorMap *_grayDefault;
113    static ColorMap *_volumeDefault;
114    static ColorMap *_elementDefault;
115
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;
126    vtkSmartPointer<vtkColorTransferFunction> _colorTF;
127    vtkSmartPointer<vtkPiecewiseFunction> _opacityTF;
128    vtkSmartPointer<vtkLookupTable> _lookupTable;
129};
130
131}
132}
133
134#endif
Note: See TracBrowser for help on using the repository browser.