Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_color_map.h
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (4 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_color_map.h (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_color_map.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_interval.h"15 14 #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 */ 15 16 class QwtInterval; 17 18 #if QT_VERSION < 0x060000 19 template< typename T > class QVector; 20 #endif 21 22 /*! 23 \brief QwtColorMap is used to map values into colors. 24 25 For displaying 3D data on a 2D plane the 3rd dimension is often 26 displayed using colors, like f.e in a spectrogram. 27 28 Each color map is optimized to return colors for only one of the 29 following image formats: 30 31 - QImage::Format_Indexed8\n 32 - QImage::Format_ARGB32\n 33 34 \sa QwtPlotSpectrogram, QwtScaleWidget 35 */ 32 36 33 37 class QWT_EXPORT QwtColorMap 34 38 { 35 public: 39 public: 36 40 /*! 37 41 Format for color mapping 38 42 \sa rgb(), colorIndex(), colorTable() 39 */ 43 */ 40 44 41 45 enum Format … … 45 49 46 50 /*! 47 The map is intended to map into 8 bit values, that 48 are indices into the color table. 51 Map values into 8 bit values, that 52 are used as indexes into the color table. 53 54 Indexed color maps are used to generate QImage::Format_Indexed8 55 images. The calculation of the color index is usually faster 56 and the resulting image has a lower memory footprint. 57 58 \sa colorIndex(), colorTable() 49 59 */ 50 60 Indexed 51 61 }; 52 62 53 QwtColorMap( Format = QwtColorMap::RGB ); 63 explicit QwtColorMap( Format = QwtColorMap::RGB ); 54 64 virtual ~QwtColorMap(); 55 65 66 void setFormat( Format ); 56 67 Format format() const; 57 68 … … 62 73 \param value Value 63 74 \return RGB value, corresponding to value 64 */65 virtual QRgb rgb( const QwtInterval &interval,66 double value ) const = 0;67 68 /*!69 Map a value of a given interval into a color index70 71 \param interval Range for the values72 \param value Value73 \return color index, corresponding to value74 75 */ 75 virtual unsigned char colorIndex( 76 const QwtInterval &interval, double value ) const = 0; 77 78 QColor color( const QwtInterval &, double value ) const; 79 virtual QVector<QRgb> colorTable( const QwtInterval & ) const; 80 81 private: 82 Format d_format; 83 }; 84 85 /*! 86 \brief QwtLinearColorMap builds a color map from color stops. 87 88 A color stop is a color at a specific position. The valid 89 range for the positions is [0.0, 1.0]. When mapping a value 90 into a color it is translated into this interval according to mode(). 91 */ 92 class QWT_EXPORT QwtLinearColorMap: public QwtColorMap 93 { 94 public: 76 virtual QRgb rgb( const QwtInterval& interval, double value ) const = 0; 77 78 virtual uint colorIndex( int numColors, 79 const QwtInterval& interval, double value ) const; 80 81 QColor color( const QwtInterval&, double value ) const; 82 virtual QVector< QRgb > colorTable( int numColors ) const; 83 virtual QVector< QRgb > colorTable256() const; 84 85 private: 86 Q_DISABLE_COPY(QwtColorMap) 87 88 Format m_format; 89 }; 90 91 /*! 92 \brief QwtLinearColorMap builds a color map from color stops. 93 94 A color stop is a color at a specific position. The valid 95 range for the positions is [0.0, 1.0]. When mapping a value 96 into a color it is translated into this interval according to mode(). 97 */ 98 class QWT_EXPORT QwtLinearColorMap : public QwtColorMap 99 { 100 public: 95 101 /*! 96 102 Mode of color map 97 103 \sa setMode(), mode() 98 */ 104 */ 99 105 enum Mode 100 106 { … … 106 112 }; 107 113 108 QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB ); 109 QwtLinearColorMap( const QColor &color1, const QColor &color2, 114 explicit QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB ); 115 116 QwtLinearColorMap( const QColor& from, const QColor& to, 110 117 QwtColorMap::Format = QwtColorMap::RGB ); 111 118 … … 115 122 Mode mode() const; 116 123 117 void setColorInterval( const QColor &color1, const QColor&color2 );124 void setColorInterval( const QColor& color1, const QColor& color2 ); 118 125 void addColorStop( double value, const QColor& ); 119 QVector< double> colorStops() const;126 QVector< double > colorStops() const; 120 127 121 128 QColor color1() const; 122 129 QColor color2() const; 123 130 124 virtual QRgb rgb( const QwtInterval &, double value ) const; 125 virtual unsigned char colorIndex( 126 const QwtInterval &, double value ) const; 131 virtual QRgb rgb( const QwtInterval&, 132 double value ) const QWT_OVERRIDE; 133 134 virtual uint colorIndex( int numColors, 135 const QwtInterval&, double value ) const QWT_OVERRIDE; 127 136 128 137 class ColorStops; 129 138 130 private: 131 // Disabled copy constructor and operator= 132 QwtLinearColorMap( const QwtLinearColorMap & ); 133 QwtLinearColorMap &operator=( const QwtLinearColorMap & ); 134 135 class PrivateData; 136 PrivateData *d_data; 137 }; 138 139 /*! 140 \brief QwtAlphaColorMap varies the alpha value of a color 141 */ 142 class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap 143 { 144 public: 145 QwtAlphaColorMap( const QColor & = QColor( Qt::gray ) ); 139 private: 140 class PrivateData; 141 PrivateData* m_data; 142 }; 143 144 /*! 145 \brief QwtAlphaColorMap varies the alpha value of a color 146 */ 147 class QWT_EXPORT QwtAlphaColorMap : public QwtColorMap 148 { 149 public: 150 explicit QwtAlphaColorMap( const QColor& = QColor( Qt::gray ) ); 146 151 virtual ~QwtAlphaColorMap(); 147 152 148 void setColor( const QColor & ); 153 void setAlphaInterval( int alpha1, int alpha2 ); 154 155 int alpha1() const; 156 int alpha2() const; 157 158 void setColor( const QColor& ); 149 159 QColor color() const; 150 160 151 virtual QRgb rgb( const QwtInterval &, double value ) const; 152 153 private: 154 QwtAlphaColorMap( const QwtAlphaColorMap & ); 155 QwtAlphaColorMap &operator=( const QwtAlphaColorMap & ); 156 157 virtual unsigned char colorIndex( 158 const QwtInterval &, double value ) const; 159 160 class PrivateData; 161 PrivateData *d_data; 162 }; 163 161 virtual QRgb rgb( const QwtInterval&, 162 double value ) const QWT_OVERRIDE; 163 164 private: 165 class PrivateData; 166 PrivateData* m_data; 167 }; 168 169 /*! 170 \brief QwtHueColorMap varies the hue value of the HSV color model. 171 172 QwtHueColorMap can be used to set up a color map easily, that runs cyclic over 173 all colors. Each cycle has 360 different steps. 174 175 The values for value and saturation are in the range of 0 to 255 and doesn't 176 depend on the data value to be mapped. 177 178 \sa QwtSaturationValueColorMap 179 */ 180 class QWT_EXPORT QwtHueColorMap : public QwtColorMap 181 { 182 public: 183 explicit QwtHueColorMap( QwtColorMap::Format = QwtColorMap::RGB ); 184 virtual ~QwtHueColorMap(); 185 186 void setHueInterval( int hue1, int hue2 ); // direction ? 187 void setSaturation( int saturation ); 188 void setValue( int value ); 189 void setAlpha( int alpha ); 190 191 int hue1() const; 192 int hue2() const; 193 int saturation() const; 194 int value() const; 195 int alpha() const; 196 197 virtual QRgb rgb( const QwtInterval&, 198 double value ) const QWT_OVERRIDE; 199 200 private: 201 class PrivateData; 202 PrivateData* m_data; 203 }; 204 205 /*! 206 \brief QwtSaturationValueColorMap varies the saturation and/or value for a given 207 hue in the HSV color model. 208 209 Value and saturation are in the range of 0 to 255 while hue is in the range 210 of 0 to 259. 211 212 \sa QwtHueColorMap 213 */ 214 class QWT_EXPORT QwtSaturationValueColorMap : public QwtColorMap 215 { 216 public: 217 QwtSaturationValueColorMap(); 218 virtual ~QwtSaturationValueColorMap(); 219 220 void setHue( int hue ); 221 void setSaturationInterval( int sat1, int sat2 ); 222 void setValueInterval( int value1, int value2 ); 223 void setAlpha( int alpha ); 224 225 int hue() const; 226 int saturation1() const; 227 int saturation2() const; 228 int value1() const; 229 int value2() const; 230 int alpha() const; 231 232 virtual QRgb rgb( const QwtInterval&, 233 double value ) const QWT_OVERRIDE; 234 235 private: 236 class PrivateData; 237 PrivateData* m_data; 238 }; 164 239 165 240 /*! … … 170 245 171 246 \return Color corresponding to value 172 173 \warning This method is slow for Indexed color maps. If it is 174 necessary to map many values, its better to get the 175 color table once and find the color using colorIndex(). 176 */ 177 inline QColor QwtColorMap::color( 178 const QwtInterval &interval, double value ) const 179 { 180 if ( d_format == RGB ) 181 { 182 return QColor::fromRgba( rgb( interval, value ) ); 183 } 184 else 185 { 186 const unsigned int index = colorIndex( interval, value ); 187 188 const QVector<QRgb> rgbTable = colorTable( interval ); 189 return rgbTable[index]; // slow 190 } 247 */ 248 inline QColor QwtColorMap::color( const QwtInterval& interval, double value ) const 249 { 250 return QColor::fromRgba( rgb( interval, value ) ); 191 251 } 192 252 … … 194 254 \return Intended format of the color map 195 255 \sa Format 196 */ 256 */ 197 257 inline QwtColorMap::Format QwtColorMap::format() const 198 258 { 199 return d_format;259 return m_format; 200 260 } 201 261
Note:
See TracChangeset
for help on using the changeset viewer.
