anatomist 6.0.4
3D neuroimaging data viewer
gradient.h
Go to the documentation of this file.
1/**************************************************************************
2* This file is part of the Fraqtive program.
3* Copyright (C) 2005 Michal Mecinski.
4* This program is licensed under the GNU General Public License.
5**************************************************************************/
6
7#ifndef GRADIENT_H
8#define GRADIENT_H
9
10#include "spline.h"
11
12#include <qstring.h>
13#include <qcolor.h>
14
15static const int GRADIENT_LENGTH = 4096;
16
24{
25public:
30
36 Gradient(bool hsv);
37
42
43public:
49 bool isHsv() const
50 {
51 return _isHsv;
52 }
53
60 const Spline& getSpline(int index) const
61 {
62 return _spline[index];
63 }
64
71 Spline& getSpline(int index)
72 {
73 return _spline[index];
74 }
75
87 void fillGradient(QRgb* buffer, int length = GRADIENT_LENGTH, double* data = NULL, bool withAlpha = false) const;
88
92 void invert();
93
104 static QRgb hsvToRgb(double h, double s, double v)
105 {
106 double r, g, b;
107
108 double sb = 128.0 * (1.0 - s);
109 double va, vb;
110 if (v > 0.5) {
111 va = 2.0 - 2.0 * v;
112 vb = 510.0 * v - 255.0;
113 } else {
114 va = 2.0 * v;
115 vb = 0.0;
116 }
117
118 int hh = (int)(6.0 * h);
119 double f = 6.0 * h - (double)hh;
120 if (hh & 1)
121 f = 1.0 - f;
122
123 double m = (255.0 * s + sb) * va + vb;
124 double n = sb * va + vb;
125 double p = (255.0 * f * s + sb) * va + vb;
126
127 switch (hh) {
128 case 0: r = m; g = p; b = n; break;
129 case 1: r = p; g = m; b = n; break;
130 case 2: r = n; g = m; b = p; break;
131 case 3: r = n; g = p; b = m; break;
132 case 4: r = p; g = n; b = m; break;
133 case 5: r = m; g = n; b = p; break;
134 default: r = m; g = n; b = n; break;
135 }
136
137 return qRgb((int)r, (int)g, (int)b);
138 }
139
140 void fromString( const std::string & grad_def );
141
142private:
143 bool _isHsv;
144 Spline _spline[4];
145};
146
147#endif
Spline & getSpline(int index)
Get one of the splines of the gradient.
Definition gradient.h:71
~Gradient()
Destructor.
Gradient(bool hsv)
Constructor.
bool isHsv() const
Get the mode of the gradient.
Definition gradient.h:49
void invert()
Invert the gradient.
static QRgb hsvToRgb(double h, double s, double v)
Calculate a color from HSV components.
Definition gradient.h:104
void fillGradient(QRgb *buffer, int length=GRADIENT_LENGTH, double *data=NULL, bool withAlpha=false) const
Generate the color table for the gradient.
void fromString(const std::string &grad_def)
Gradient()
Constructor.
const Spline & getSpline(int index) const
Get one of the splines of the gradient.
Definition gradient.h:60
A spline used to store gradient components waveforms.
Definition spline.h:18