source: ntrip/trunk/BNC/qwt/qwt_color_map.h@ 4621

Last change on this file since 4621 was 4271, checked in by mervart, 12 years ago
File size: 4.9 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#ifndef QWT_COLOR_MAP_H
11#define QWT_COLOR_MAP_H
12
13#include "qwt_global.h"
14#include "qwt_interval.h"
15#include <qcolor.h>
16#include <qvector.h>
17
18/*!
19 \brief QwtColorMap is used to map values into colors.
20
21 For displaying 3D data on a 2D plane the 3rd dimension is often
22 displayed using colors, like f.e in a spectrogram.
23
24 Each color map is optimized to return colors for only one of the
25 following image formats:
26
27 - QImage::Format_Indexed8\n
28 - QImage::Format_ARGB32\n
29
30 \sa QwtPlotSpectrogram, QwtScaleWidget
31*/
32
33class QWT_EXPORT QwtColorMap
34{
35public:
36 /*!
37 Format for color mapping
38 \sa rgb(), colorIndex(), colorTable()
39 */
40
41 enum Format
42 {
43 //! The map is intended to map into QRgb values.
44 RGB,
45
46 /*!
47 The map is intended to map into 8 bit values, that
48 are indices into the color table.
49 */
50 Indexed
51 };
52
53 QwtColorMap( Format = QwtColorMap::RGB );
54 virtual ~QwtColorMap();
55
56 Format format() const;
57
58 /*!
59 Map a value of a given interval into a rgb value.
60 \param interval Range for the values
61 \param value Value
62 \return rgb value, corresponding to value
63 */
64 virtual QRgb rgb( const QwtInterval &interval,
65 double value ) const = 0;
66
67 /*!
68 Map a value of a given interval into a color index
69 \param interval Range for the values
70 \param value Value
71 \return color index, corresponding to value
72 */
73 virtual unsigned char colorIndex(
74 const QwtInterval &interval, double value ) const = 0;
75
76 QColor color( const QwtInterval &, double value ) const;
77 virtual QVector<QRgb> colorTable( const QwtInterval & ) const;
78
79private:
80 Format d_format;
81};
82
83/*!
84 \brief QwtLinearColorMap builds a color map from color stops.
85
86 A color stop is a color at a specific position. The valid
87 range for the positions is [0.0, 1.0]. When mapping a value
88 into a color it is translated into this interval according to mode().
89*/
90class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
91{
92public:
93 /*!
94 Mode of color map
95 \sa setMode(), mode()
96 */
97 enum Mode
98 {
99 //! Return the color from the next lower color stop
100 FixedColors,
101
102 //! Interpolating the colors of the adjacent stops.
103 ScaledColors
104 };
105
106 QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB );
107 QwtLinearColorMap( const QColor &from, const QColor &to,
108 QwtColorMap::Format = QwtColorMap::RGB );
109
110 virtual ~QwtLinearColorMap();
111
112 void setMode( Mode );
113 Mode mode() const;
114
115 void setColorInterval( const QColor &color1, const QColor &color2 );
116 void addColorStop( double value, const QColor& );
117 QVector<double> colorStops() const;
118
119 QColor color1() const;
120 QColor color2() const;
121
122 virtual QRgb rgb( const QwtInterval &, double value ) const;
123 virtual unsigned char colorIndex(
124 const QwtInterval &, double value ) const;
125
126 class ColorStops;
127
128private:
129 // Disabled copy constructor and operator=
130 QwtLinearColorMap( const QwtLinearColorMap & );
131 QwtLinearColorMap &operator=( const QwtLinearColorMap & );
132
133 class PrivateData;
134 PrivateData *d_data;
135};
136
137/*!
138 \brief QwtAlphaColorMap variies the alpha value of a color
139*/
140class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
141{
142public:
143 QwtAlphaColorMap( const QColor & = QColor( Qt::gray ) );
144 virtual ~QwtAlphaColorMap();
145
146 void setColor( const QColor & );
147 QColor color() const;
148
149 virtual QRgb rgb( const QwtInterval &, double value ) const;
150
151private:
152 QwtAlphaColorMap( const QwtAlphaColorMap & );
153 QwtAlphaColorMap &operator=( const QwtAlphaColorMap & );
154
155 virtual unsigned char colorIndex(
156 const QwtInterval &, double value ) const;
157
158 class PrivateData;
159 PrivateData *d_data;
160};
161
162
163/*!
164 Map a value into a color
165
166 \param interval Valid interval for values
167 \param value Value
168
169 \return Color corresponding to value
170
171 \warning This method is slow for Indexed color maps. If it is
172 necessary to map many values, its better to get the
173 color table once and find the color using colorIndex().
174*/
175inline QColor QwtColorMap::color(
176 const QwtInterval &interval, double value ) const
177{
178 if ( d_format == RGB )
179 {
180 return QColor( rgb( interval, value ) );
181 }
182 else
183 {
184 const unsigned int index = colorIndex( interval, value );
185 return colorTable( interval )[index]; // slow
186 }
187}
188
189/*!
190 \return Intended format of the color map
191 \sa Format
192*/
193inline QwtColorMap::Format QwtColorMap::format() const
194{
195 return d_format;
196}
197
198#endif
Note: See TracBrowser for help on using the repository browser.