-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathcolorgradient.sip
171 lines (137 loc) · 5.71 KB
/
colorgradient.sip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/** PyQt5 binding for QCustomPlot v2.0.0
*
* Authors: Dmitry Voronin, Giuseppe Corbelli
* License: MIT
*
* QCustomPlot author: Emanuel Eichhammer
* QCustomPlot Website/Contact: http://www.qcustomplot.com
*/
%MappedType QMap<double, QColor>
{
%TypeHeaderCode
// Include the library interface to the type being mapped.
#include <QMap>
#include <QColor>
%End
%ConvertFromTypeCode
PyObject *d = PyDict_New();
if (!d)
return 0;
QMap<double, QColor>::const_iterator it = sipCpp->constBegin();
QMap<double, QColor>::const_iterator end = sipCpp->constEnd();
while (it != end)
{
PyObject *kobj = PyFloat_FromDouble(it.key());
if (!kobj)
{
Py_DECREF(d);
return 0;
}
QColor *v = new QColor(it.value());
PyObject *vobj = sipConvertFromNewType(v, sipType_QColor,
sipTransferObj);
if (!vobj)
{
delete v;
Py_DECREF(kobj);
Py_DECREF(d);
return 0;
}
int rc = PyDict_SetItem(d, kobj, vobj);
Py_DECREF(vobj);
Py_DECREF(kobj);
if (rc < 0)
{
Py_DECREF(d);
return 0;
}
++it;
}
return d;
%End
%ConvertToTypeCode
if (!sipIsErr)
return PyDict_Check(sipPy);
QMap<double, QColor> *qm = new QMap<double, QColor>;
SIP_SSIZE_T pos = 0;
PyObject *kobj, *vobj;
while (PyDict_Next(sipPy, &pos, &kobj, &vobj))
{
PyErr_Clear();
double k = PyFloat_AsDouble(kobj);
if (PyErr_Occurred())
{
PyErr_Format(PyExc_TypeError,
"a key has type '%s' but 'float' is expected",
Py_TYPE(kobj)->tp_name);
delete qm;
*sipIsErr = 1;
return 0;
}
int vstate;
QColor* v = reinterpret_cast<QColor*>(
sipForceConvertToType(
vobj, sipType_QColor, sipTransferObj, SIP_NOT_NONE, &vstate, sipIsErr
)
);
if (*sipIsErr)
{
PyErr_Format(PyExc_TypeError,
"a value has type '%s' but 'QColor' is expected",
Py_TYPE(vobj)->tp_name);
sipReleaseType(v, sipType_QColor, vstate);
delete qm;
return 0;
}
qm->insert(k, *v);
sipReleaseType(v, sipType_QColor, vstate);
}
*sipCppPtr = qm;
return sipGetState(sipTransferObj);
%End
};
class QCPColorGradient
{
%TypeHeaderCode
#include <QCustomPlot/src/colorgradient.h>
%End
public:
enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated
,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance)
};
enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation)
,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation)
,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation)
,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation)
,gpCandy ///< Blue over pink to white
,gpGeography ///< Colors suitable to represent different elevations on geographical maps
,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates)
,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white
,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values
,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates)
,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates)
,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic)
};
QCPColorGradient();
QCPColorGradient(GradientPreset preset);
bool operator==(const QCPColorGradient &other) const;
bool operator!=(const QCPColorGradient &other) const;
// getters:
int levelCount() const;
QMap<double, QColor> colorStops() const;
ColorInterpolation colorInterpolation() const;
bool periodic() const;
// setters:
void setLevelCount(int n);
void setColorStops(const QMap<double, QColor> &colorStops);
void setColorStopAt(double position, const QColor &color);
void setColorInterpolation(ColorInterpolation interpolation);
void setPeriodic(bool enabled);
// non-property methods:
void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false);
void colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false);
QRgb color(double position, const QCPRange &range, bool logarithmic=false);
void loadPreset(GradientPreset preset);
void clearColorStops();
QCPColorGradient inverted() const;
};