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

Last change on this file since 2320 was 2320, checked in by ldelgass, 13 years ago

Add Molecule (ball-and-stick) and Line Integral Convolution (LIC) rendering to
vtkvis. LIC is a work in progress, and rendering LIC textures on PolyDatas?
conflicts with offscreen rendering in the main render window. However, LIC
textures on other data sets work, as the vtkImageDataLIC2D class will create
it's own render window/context for its FBOs.

  • 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) 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    static ColorMap *getElementDefault();
108
109private:
110    static ColorMap *_default;
111    static ColorMap *_volumeDefault;
112    static ColorMap *_elementDefault;
113
114    ColorMap();
115
116    void lerp(double *result, const ControlPoint& cp1, const ControlPoint& cp2, double value);
117    void lerp(double *result, const OpacityControlPoint& cp1, const OpacityControlPoint& cp2, double value);
118
119    std::string _name;
120    std::list<ControlPoint> _controlPoints;
121    std::list<OpacityControlPoint> _opacityControlPoints;
122    bool _needsBuild;
123    int _numTableEntries;
124    vtkSmartPointer<vtkColorTransferFunction> _colorTF;
125    vtkSmartPointer<vtkPiecewiseFunction> _opacityTF;
126    vtkSmartPointer<vtkLookupTable> _lookupTable;
127};
128
129}
130}
131
132#endif
Note: See TracBrowser for help on using the repository browser.