@@ -1,18 +1,21 | |||
|
1 | 1 | INCLUDEPATH += $$PWD |
|
2 | 2 | DEPENDPATH += $$PWD |
|
3 | 3 | |
|
4 | QMAKE_CXXFLAGS+= -fopenmp | |
|
5 | QMAKE_LFLAGS += -fopenmp | |
|
6 | ||
|
4 | 7 | SOURCES += \ |
|
5 | 8 | $$PWD/qcolormapseries.cpp \ |
|
6 | 9 | $$PWD/colormapchart.cpp \ |
|
7 | 10 | $$PWD/colormapdatapart.cpp \ |
|
8 | 11 | $$PWD/point3d.cpp |
|
9 | 12 | |
|
10 | 13 | PRIVATE_HEADERS += \ |
|
11 | 14 | $$PWD/qcolormapseries_p.h \ |
|
12 | 15 | $$PWD/colormapchart_p.h |
|
13 | 16 | |
|
14 | 17 | PUBLIC_HEADERS += \ |
|
15 | 18 | $$PWD/qcolormapseries.h \ |
|
16 | 19 | $$PWD/point3d.h \ |
|
17 | 20 | $$PWD/colormapdatapart.h |
|
18 | 21 |
@@ -1,627 +1,645 | |||
|
1 | 1 | #include "qcolormapseries.h" |
|
2 | 2 | #include <private/qcolormapseries_p.h> |
|
3 | 3 | #include <private/abstractdomain_p.h> |
|
4 | 4 | #include <QtCharts/QValueAxis> |
|
5 | 5 | #include <private/colormapchart_p.h> |
|
6 | 6 | #include <QtCharts/QColorMapLegendMarker> |
|
7 | 7 | #include <private/charthelpers_p.h> |
|
8 | 8 | #include <private/qchart_p.h> |
|
9 | 9 | #include <QtGui/QPainter> |
|
10 | 10 | |
|
11 | //#include <algorithm> | |
|
12 | 11 | #include <cmath> |
|
12 | #include "omp.h" | |
|
13 | 13 | |
|
14 | 14 | #include "qcolorbaraxis.h" |
|
15 | 15 | |
|
16 | 16 | QT_CHARTS_BEGIN_NAMESPACE |
|
17 | 17 | |
|
18 | 18 | /*! |
|
19 | 19 | \internal |
|
20 | 20 | |
|
21 | 21 | Constructs empty series object which is a child of \a parent. |
|
22 | 22 | When series object is added to QChart instance ownerships is transferred. |
|
23 | 23 | */ |
|
24 | 24 | QColorMapSeries::QColorMapSeries(QObject *parent) |
|
25 | 25 | : QAbstractSeries(*new QColorMapSeriesPrivate(this), parent) |
|
26 | 26 | { |
|
27 | 27 | } |
|
28 | 28 | |
|
29 | 29 | /*! |
|
30 | 30 | \internal |
|
31 | 31 | |
|
32 | 32 | Constructs empty series object which is a child of \a parent. |
|
33 | 33 | When series object is added to QChart instance ownerships is transferred. |
|
34 | 34 | */ |
|
35 | 35 | QColorMapSeries::QColorMapSeries(QColorMapSeriesPrivate &d, QObject *parent) |
|
36 | 36 | : QAbstractSeries(d, parent) |
|
37 | 37 | { |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | /*! |
|
42 | 42 | Destroys the object. Series added to QChart instances are owned by those, |
|
43 | 43 | and are destroyed when QChart instances are destroyed. |
|
44 | 44 | */ |
|
45 | 45 | QColorMapSeries::~QColorMapSeries() |
|
46 | 46 | { |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \fn virtual SeriesType QBoxPlotSeries::type() const |
|
51 | 51 | \brief Returns type of series. |
|
52 | 52 | \sa QAbstractSeries, SeriesType |
|
53 | 53 | */ |
|
54 | 54 | QAbstractSeries::SeriesType QColorMapSeries::type() const |
|
55 | 55 | { |
|
56 | 56 | return QAbstractSeries::SeriesTypeColorMap; |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | Adds data part \a dataPart to the series.\n |
|
62 | 62 | If \a copy is true, adds a copy of the data part instead. |
|
63 | 63 | */ |
|
64 | 64 | void QColorMapSeries::append(ColorMapDataPart* dataPart, bool copy) |
|
65 | 65 | { |
|
66 | 66 | Q_D(QColorMapSeries); |
|
67 | 67 | if(copy) |
|
68 | 68 | d->m_dataParts << new ColorMapDataPart(dataPart); |
|
69 | 69 | else |
|
70 | 70 | d->m_dataParts << dataPart; |
|
71 | 71 | d->recomputeDataRange(); |
|
72 | 72 | emit dataPartAdded(d->m_dataParts.count() - 1); |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | This is an overloaded function.\n |
|
77 | 77 | Adds data parts \a dataParts to the series.\n |
|
78 | 78 | If \a copy is true, adds a copy of the data part instead. |
|
79 | 79 | */ |
|
80 | 80 | void QColorMapSeries::append(const QList<ColorMapDataPart*> &dataParts, bool copy) |
|
81 | 81 | { |
|
82 | 82 | foreach (ColorMapDataPart* dataPart , dataParts) |
|
83 | 83 | append(dataPart,copy); |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | Returns number of data parts within series. |
|
89 | 89 | */ |
|
90 | 90 | int QColorMapSeries::count() const |
|
91 | 91 | { |
|
92 | 92 | Q_D(const QColorMapSeries); |
|
93 | 93 | return d->m_dataParts.count(); |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | |
|
97 | 97 | /*! |
|
98 | 98 | Stream operator for adding a data part \a point to the series. |
|
99 | 99 | \sa append() |
|
100 | 100 | */ |
|
101 | 101 | QColorMapSeries &QColorMapSeries::operator <<(const ColorMapDataPart &dataPart) |
|
102 | 102 | { |
|
103 | 103 | append(new ColorMapDataPart(dataPart)); |
|
104 | 104 | return *this; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | Stream operator for adding a vector of data parts \a dataParts to the series. |
|
109 | 109 | \sa append() |
|
110 | 110 | */ |
|
111 | 111 | QColorMapSeries &QColorMapSeries::operator <<(const QList<ColorMapDataPart*> &dataParts) |
|
112 | 112 | { |
|
113 | 113 | append(dataParts); |
|
114 | 114 | return *this; |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | /*! |
|
118 | 118 | Returns a ColorMapData part containing a uniform grid of data points to be mapped in a ColorMapChart.\n |
|
119 | 119 | The rectangle of data returned is determined by \a width and \height,\n |
|
120 | 120 | from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n |
|
121 | 121 | When there are more points than pixels, \a strategy is applied to determine which to choose. |
|
122 | 122 | */ |
|
123 | 123 | void QColorMapSeries::getUniformGrid(int xpos, int ypos,int width, int height, QVector<double> &grid, QColorMapSeries::Strategy strategy) |
|
124 | 124 | { |
|
125 | 125 | Q_D(QColorMapSeries); |
|
126 | 126 | d->getUniformGrid(xpos, ypos,width,height, grid, strategy); |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | //void QColorMapSeries::attachAxis(QAbstractAxis *axis) |
|
130 | 130 | //{ |
|
131 | 131 | // axis = static_cast<QColorBarAxis*>(); |
|
132 | 132 | // if(axis) |
|
133 | 133 | // { |
|
134 | 134 | |
|
135 | 135 | // } |
|
136 | 136 | // else |
|
137 | 137 | // { |
|
138 | 138 | // QAbstractSeries::attachAxis(axis); |
|
139 | 139 | // } |
|
140 | 140 | //} |
|
141 | 141 | |
|
142 | 142 | /*! |
|
143 | 143 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
144 | 144 | pen from chart theme is used. |
|
145 | 145 | \sa QChart::setTheme() |
|
146 | 146 | */ |
|
147 | 147 | void QColorMapSeries::setPen(const QPen &pen) |
|
148 | 148 | { |
|
149 | 149 | Q_D(QColorMapSeries); |
|
150 | 150 | if (d->m_pen != pen) |
|
151 | 151 | { |
|
152 | 152 | //bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
153 | 153 | d->m_pen = pen; |
|
154 | 154 | emit d->updated(); |
|
155 | 155 | // if (emitColorChanged) |
|
156 | 156 | // emit colorChanged(pen.color()); |
|
157 | 157 | emit penChanged(pen); |
|
158 | 158 | } |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | QPen QColorMapSeries::pen() const |
|
162 | 162 | { |
|
163 | 163 | Q_D(const QColorMapSeries); |
|
164 | 164 | if (d->m_pen == QChartPrivate::defaultPen()) |
|
165 | 165 | return QPen(); |
|
166 | 166 | else |
|
167 | 167 | return d->m_pen; |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | /*! |
|
171 | 171 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
172 | 172 | from chart theme setting is used. |
|
173 | 173 | \sa QChart::setTheme() |
|
174 | 174 | */ |
|
175 | 175 | void QColorMapSeries::setBrush(const QBrush &brush) |
|
176 | 176 | { |
|
177 | 177 | Q_D(QColorMapSeries); |
|
178 | 178 | if (d->m_brush != brush) |
|
179 | 179 | { |
|
180 | 180 | d->m_brush = brush; |
|
181 | 181 | emit d->updated(); |
|
182 | 182 | } |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | QBrush QColorMapSeries::brush() const |
|
186 | 186 | { |
|
187 | 187 | Q_D(const QColorMapSeries); |
|
188 | 188 | if (d->m_brush == QChartPrivate::defaultBrush()) |
|
189 | 189 | return QBrush(); |
|
190 | 190 | else |
|
191 | 191 | return d->m_brush; |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | //void QColorMapSeries::setColor(const QColor &color) |
|
195 | 195 | //{ |
|
196 | 196 | // QPen p = pen(); |
|
197 | 197 | // if (p.color() != color) |
|
198 | 198 | // { |
|
199 | 199 | // p.setColor(color); |
|
200 | 200 | // setPen(p); |
|
201 | 201 | // } |
|
202 | 202 | //} |
|
203 | 203 | |
|
204 | 204 | //QColor QColorMapSeries::color() const |
|
205 | 205 | //{ |
|
206 | 206 | // return pen().color(); |
|
207 | 207 | //} |
|
208 | 208 | |
|
209 | 209 | //void QColorMapSeries::setPointsVisible(bool visible) |
|
210 | 210 | //{ |
|
211 | 211 | // Q_D(QColorMapSeries); |
|
212 | 212 | // if (d->m_pointsVisible != visible) |
|
213 | 213 | // { |
|
214 | 214 | // d->m_pointsVisible = visible; |
|
215 | 215 | // emit d->updated(); |
|
216 | 216 | // } |
|
217 | 217 | //} |
|
218 | 218 | |
|
219 | 219 | //bool QColorMapSeries::pointsVisible() const |
|
220 | 220 | //{ |
|
221 | 221 | // Q_D(const QColorMapSeries); |
|
222 | 222 | // return d->m_pointsVisible; |
|
223 | 223 | //} |
|
224 | 224 | |
|
225 | 225 | //void QColorMapSeries::setPointLabelsFormat(const QString &format) |
|
226 | 226 | //{ |
|
227 | 227 | // Q_D(QColorMapSeries); |
|
228 | 228 | // if (d->m_pointLabelsFormat != format) |
|
229 | 229 | // { |
|
230 | 230 | // d->m_pointLabelsFormat = format; |
|
231 | 231 | // emit pointLabelsFormatChanged(format); |
|
232 | 232 | // } |
|
233 | 233 | //} |
|
234 | 234 | |
|
235 | 235 | //QString QColorMapSeries::pointLabelsFormat() const |
|
236 | 236 | //{ |
|
237 | 237 | // Q_D(const QColorMapSeries); |
|
238 | 238 | // return d->m_pointLabelsFormat; |
|
239 | 239 | //} |
|
240 | 240 | |
|
241 | 241 | //void QColorMapSeries::setPointLabelsVisible(bool visible) |
|
242 | 242 | //{ |
|
243 | 243 | // Q_D(QColorMapSeries); |
|
244 | 244 | // if (d->m_pointLabelsVisible != visible) |
|
245 | 245 | // { |
|
246 | 246 | // d->m_pointLabelsVisible = visible; |
|
247 | 247 | // emit pointLabelsVisibilityChanged(visible); |
|
248 | 248 | // } |
|
249 | 249 | //} |
|
250 | 250 | |
|
251 | 251 | //bool QColorMapSeries::pointLabelsVisible() const |
|
252 | 252 | //{ |
|
253 | 253 | // Q_D(const QColorMapSeries); |
|
254 | 254 | // return d->m_pointLabelsVisible; |
|
255 | 255 | //} |
|
256 | 256 | |
|
257 | 257 | //void QColorMapSeries::setPointLabelsFont(const QFont &font) |
|
258 | 258 | //{ |
|
259 | 259 | // Q_D(QColorMapSeries); |
|
260 | 260 | // if (d->m_pointLabelsFont != font) { |
|
261 | 261 | // d->m_pointLabelsFont = font; |
|
262 | 262 | // emit pointLabelsFontChanged(font); |
|
263 | 263 | // } |
|
264 | 264 | //} |
|
265 | 265 | |
|
266 | 266 | //QFont QColorMapSeries::pointLabelsFont() const |
|
267 | 267 | //{ |
|
268 | 268 | // Q_D(const QColorMapSeries); |
|
269 | 269 | // return d->m_pointLabelsFont; |
|
270 | 270 | //} |
|
271 | 271 | |
|
272 | 272 | //void QColorMapSeries::setPointLabelsColor(const QColor &color) |
|
273 | 273 | //{ |
|
274 | 274 | // Q_D(QColorMapSeries); |
|
275 | 275 | // if (d->m_pointLabelsColor != color) { |
|
276 | 276 | // d->m_pointLabelsColor = color; |
|
277 | 277 | // emit pointLabelsColorChanged(color); |
|
278 | 278 | // } |
|
279 | 279 | //} |
|
280 | 280 | |
|
281 | 281 | //QColor QColorMapSeries::pointLabelsColor() const |
|
282 | 282 | //{ |
|
283 | 283 | // Q_D(const QColorMapSeries); |
|
284 | 284 | // if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color()) |
|
285 | 285 | // return QPen().color(); |
|
286 | 286 | // else |
|
287 | 287 | // return d->m_pointLabelsColor; |
|
288 | 288 | //} |
|
289 | 289 | |
|
290 | 290 | //void QColorMapSeries::setPointLabelsClipping(bool enabled) |
|
291 | 291 | //{ |
|
292 | 292 | // Q_D(QColorMapSeries); |
|
293 | 293 | // if (d->m_pointLabelsClipping != enabled) { |
|
294 | 294 | // d->m_pointLabelsClipping = enabled; |
|
295 | 295 | // emit pointLabelsClippingChanged(enabled); |
|
296 | 296 | // } |
|
297 | 297 | //} |
|
298 | 298 | |
|
299 | 299 | //bool QColorMapSeries::pointLabelsClipping() const |
|
300 | 300 | //{ |
|
301 | 301 | // Q_D(const QColorMapSeries); |
|
302 | 302 | // return d->m_pointLabelsClipping; |
|
303 | 303 | //} |
|
304 | 304 | /*! |
|
305 | 305 | Returns the minimum value of the series on the X axis. |
|
306 | 306 | */ |
|
307 | 307 | double QColorMapSeries::minX() |
|
308 | 308 | { |
|
309 | 309 | Q_D(QColorMapSeries); |
|
310 | 310 | return d->m_minX; |
|
311 | 311 | } |
|
312 | 312 | |
|
313 | 313 | /*! |
|
314 | 314 | Returns the minimum value of the series on the Y axis. |
|
315 | 315 | */ |
|
316 | 316 | double QColorMapSeries::minY() |
|
317 | 317 | { |
|
318 | 318 | Q_D(QColorMapSeries); |
|
319 | 319 | return d->m_minY; |
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | /*! |
|
323 | 323 | Returns the minimum value of the series on the Z axis. |
|
324 | 324 | */ |
|
325 | 325 | double QColorMapSeries::minZ() |
|
326 | 326 | { |
|
327 | 327 | Q_D(QColorMapSeries); |
|
328 | 328 | return d->m_minZ; |
|
329 | 329 | } |
|
330 | 330 | |
|
331 | 331 | /*! |
|
332 | 332 | Returns the maximum value of the series on the X axis. |
|
333 | 333 | */ |
|
334 | 334 | double QColorMapSeries::maxX() |
|
335 | 335 | { |
|
336 | 336 | Q_D(QColorMapSeries); |
|
337 | 337 | return d->m_maxX; |
|
338 | 338 | } |
|
339 | 339 | |
|
340 | 340 | /*! |
|
341 | 341 | Returns the maximum value of the series on the Y axis. |
|
342 | 342 | */ |
|
343 | 343 | double QColorMapSeries::maxY() |
|
344 | 344 | { |
|
345 | 345 | Q_D(QColorMapSeries); |
|
346 | 346 | return d->m_maxY; |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | /*! |
|
350 | 350 | Returns the maximum value of the series on the Z axis. |
|
351 | 351 | */ |
|
352 | 352 | double QColorMapSeries::maxZ() |
|
353 | 353 | { |
|
354 | 354 | Q_D(QColorMapSeries); |
|
355 | 355 | return d->m_maxZ; |
|
356 | 356 | } |
|
357 | 357 | |
|
358 | 358 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
359 | 359 | |
|
360 | 360 | QColorMapSeriesPrivate::QColorMapSeriesPrivate(QColorMapSeries *q) |
|
361 | 361 | : QAbstractSeriesPrivate(q), |
|
362 | 362 | m_pen(QChartPrivate::defaultPen()), |
|
363 | 363 | m_brush(QChartPrivate::defaultBrush()), |
|
364 | 364 | m_pointsVisible(false), |
|
365 | 365 | m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")), //TODO : change |
|
366 | 366 | m_pointLabelsVisible(false), |
|
367 | 367 | m_pointLabelsFont(QChartPrivate::defaultFont()), |
|
368 | 368 | m_pointLabelsColor(QChartPrivate::defaultPen().color()), |
|
369 | 369 | m_pointLabelsClipping(true) |
|
370 | 370 | { |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | void QColorMapSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
374 | 374 | { |
|
375 | 375 | Q_Q(QColorMapSeries); |
|
376 | 376 | ColorMapChart *colormap = new ColorMapChart(q,parent); |
|
377 | 377 | m_item.reset(colormap); |
|
378 | 378 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
379 | 379 | } |
|
380 | 380 | |
|
381 | 381 | void QColorMapSeriesPrivate::initializeDomain() |
|
382 | 382 | { |
|
383 | 383 | domain()->setRange(m_minX, m_maxX, m_minY, m_maxY); |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | void QColorMapSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
387 | 387 | { |
|
388 | 388 | // Q_Q(QColorMapSeries); |
|
389 | 389 | |
|
390 | 390 | // const QList<QGradient> gradients = theme->seriesGradients(); |
|
391 | 391 | // const QList<QColor> colors = theme->seriesColors(); |
|
392 | 392 | |
|
393 | 393 | // if (forced || QChartPrivate::defaultPen() == m_pen) { |
|
394 | 394 | // QPen pen; |
|
395 | 395 | // pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); |
|
396 | 396 | // pen.setWidthF(2); |
|
397 | 397 | // q->setPen(pen); |
|
398 | 398 | // } |
|
399 | 399 | |
|
400 | 400 | // if (forced || QChartPrivate::defaultBrush() == m_brush) { |
|
401 | 401 | // QBrush brush(colors.at(index % colors.size())); |
|
402 | 402 | // q->setBrush(brush); |
|
403 | 403 | // } |
|
404 | 404 | |
|
405 | 405 | // if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { |
|
406 | 406 | // QColor color = theme->labelBrush().color(); |
|
407 | 407 | // q->setPointLabelsColor(color); |
|
408 | 408 | // } |
|
409 | 409 | } |
|
410 | 410 | |
|
411 | 411 | QList<QLegendMarker*> QColorMapSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
412 | 412 | { |
|
413 | 413 | Q_Q(QColorMapSeries); |
|
414 | 414 | QList<QLegendMarker*> list; |
|
415 | 415 | return list << new QColorMapLegendMarker(q,legend); |
|
416 | 416 | } |
|
417 | 417 | |
|
418 | 418 | void QColorMapSeriesPrivate::initializeAxes() |
|
419 | 419 | { |
|
420 | 420 | |
|
421 | 421 | } |
|
422 | 422 | |
|
423 | 423 | QAbstractAxis::AxisType QColorMapSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
424 | 424 | { |
|
425 | 425 | Q_UNUSED(orientation); |
|
426 | 426 | return QAbstractAxis::AxisTypeValue; |
|
427 | 427 | } |
|
428 | 428 | |
|
429 | 429 | QAbstractAxis* QColorMapSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
430 | 430 | { |
|
431 | 431 | Q_UNUSED(orientation); |
|
432 | 432 | return new QValueAxis; |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | |
|
436 | 436 | void QColorMapSeriesPrivate::getUniformGrid(int xpos, int ypos, int width, int height, QVector<double> &grid, QColorMapSeries::Strategy strategy) |
|
437 | 437 | { |
|
438 | 438 | double dx = (m_maxX - m_minX)/(double)width; |
|
439 | 439 | double dy = (m_maxY - m_minY)/(double)height; |
|
440 | 440 | |
|
441 | int x=0; | |
|
442 | int y=0; | |
|
441 | int index=0; | |
|
443 | 442 | |
|
444 | 443 | QVector<Point3D> cluster; |
|
445 | 444 | cluster.reserve(height*width/1000); |
|
446 | 445 | |
|
446 | int x = 0; | |
|
447 | int y = 0; | |
|
448 | ||
|
447 | 449 | for (auto cell= grid.begin();cell<grid.end();++cell) |
|
448 | 450 | { |
|
451 | x = index%width; | |
|
452 | y = index/width; | |
|
449 | 453 | cluster.resize(0); |
|
450 | 454 | this->buildCluster(x,y,dx,dy,cluster); |
|
451 | 455 | if(strategy == QColorMapSeries::LastPixel) |
|
452 | 456 | *cell=this->clusterStrategyLast(cluster); |
|
453 | 457 | else if(strategy == QColorMapSeries::MeanPixel) |
|
454 | 458 | *cell=this->clusterStrategyMean(cluster); |
|
455 | 459 | else if(strategy == QColorMapSeries::MedianPixel) |
|
456 | 460 | *cell=this->clusterStrategyMedian(cluster); |
|
457 | if(x<width-1) | |
|
458 | { | |
|
459 | x++; | |
|
461 | index++; | |
|
460 | 462 |
|
|
461 | else | |
|
463 | ||
|
464 | //#pragma omp for | |
|
465 | // for(int y = 0;y<height;y++) | |
|
466 | // { | |
|
467 | // for(int x =0;x<width;x++) | |
|
468 | // { | |
|
469 | // cluster.resize(0); | |
|
470 | // this->buildCluster(x,y,dx,dy,cluster); | |
|
471 | // if(strategy == QColorMapSeries::LastPixel) | |
|
472 | // grid[width*y+x] = this->clusterStrategyLast(cluster); | |
|
473 | // else if(strategy == QColorMapSeries::MeanPixel) | |
|
474 | // grid[width*y+x] = this->clusterStrategyMean(cluster); | |
|
475 | // else if(strategy == QColorMapSeries::MedianPixel) | |
|
476 | // grid[width*y+x] = this->clusterStrategyMedian(cluster); | |
|
477 | // } | |
|
478 | // } | |
|
479 | } | |
|
480 | ||
|
481 | double QColorMapSeriesPrivate::computeValuePixel() | |
|
462 | 482 | { |
|
463 | x=0; | |
|
464 | y++; | |
|
465 | } | |
|
466 | } | |
|
483 | ||
|
484 | ||
|
467 | 485 | } |
|
468 | 486 | |
|
469 | 487 | /*! |
|
470 | 488 | Recompute the data range on X, Y and Z axes each time a ColorMapDataPart is added to the series.\n |
|
471 | 489 | The minimum distance between 2 adjacent values on X and Y axis is added to the maximum on X and Y respectively\n |
|
472 | 490 | in order to take account of the width of the last element. |
|
473 | 491 | */ |
|
474 | 492 | void QColorMapSeriesPrivate::recomputeDataRange() |
|
475 | 493 | { |
|
476 | 494 | //TODO : if non empty |
|
477 | 495 | m_minX = m_dataParts.first()->timesSeries().first(); |
|
478 | 496 | m_maxX = m_dataParts.last()->timesSeries().last(); |
|
479 | 497 | |
|
480 | 498 | m_minY = m_dataParts.last()->ySeries().last(); |
|
481 | 499 | m_maxY = m_dataParts.last()->ySeries().first(); |
|
482 | 500 | m_minZ = m_dataParts.first()->dataSeries().first(); |
|
483 | 501 | m_maxZ = m_dataParts.last()->dataSeries().last(); |
|
484 | 502 | double minDeltaX=m_maxX-m_minX; |
|
485 | 503 | double minDeltaY=m_minY-m_maxY; |
|
486 | 504 | foreach(ColorMapDataPart* datapart, m_dataParts) |
|
487 | 505 | { |
|
488 | 506 | m_minY = qMin(datapart->ySeries().first(),m_minY); |
|
489 | 507 | m_maxY = qMax(datapart->ySeries().last(),m_maxY); |
|
490 | 508 | for(int i=1;i<datapart->timesSeries().size();i++) |
|
491 | 509 | { |
|
492 | 510 | double newDeltaX=datapart->timesSeries()[i]-datapart->timesSeries()[i-1]; |
|
493 | 511 | minDeltaX=qMin(minDeltaX,newDeltaX); |
|
494 | 512 | } |
|
495 | 513 | for(int i=1;i<datapart->ySeries().size();i++) |
|
496 | 514 | { |
|
497 | 515 | double newDeltaY=datapart->ySeries()[i]-datapart->ySeries()[i-1]; |
|
498 | 516 | minDeltaY=qMin(minDeltaY,newDeltaY); |
|
499 | 517 | } |
|
500 | 518 | |
|
501 | 519 | for (int i = 0; i < datapart->dataSeries().count(); i++) |
|
502 | 520 | { |
|
503 | 521 | double z = datapart->dataSeries().at(i); |
|
504 | 522 | m_minZ = qMin(m_minZ, z); |
|
505 | 523 | m_maxZ = qMax(m_maxZ, z); |
|
506 | 524 | } |
|
507 | 525 | } |
|
508 | 526 | m_maxX+=minDeltaX; |
|
509 | 527 | m_maxY+=minDeltaY; |
|
510 | 528 | } |
|
511 | 529 | |
|
512 | 530 | /*! |
|
513 | 531 | Returns the last value (bottom right Z value) of a \a cluster of points passed as argument. |
|
514 | 532 | */ |
|
515 | 533 | double QColorMapSeriesPrivate::clusterStrategyLast(QVector<Point3D>& cluster) |
|
516 | 534 | { |
|
517 | 535 | if(!cluster.isEmpty()) |
|
518 | 536 | return cluster.last().value(); |
|
519 | 537 | return 0; |
|
520 | 538 | } |
|
521 | 539 | |
|
522 | 540 | /*! |
|
523 | 541 | Returns the mean value (mean Z value) of a \a cluster of points passed as argument. |
|
524 | 542 | */ |
|
525 | 543 | double QColorMapSeriesPrivate::clusterStrategyMean(QVector<Point3D>& cluster) |
|
526 | 544 | { |
|
527 | 545 | if(!cluster.isEmpty()) |
|
528 | 546 | { |
|
529 | 547 | double sum=0; |
|
530 | 548 | int count =0; |
|
531 | 549 | for(int i =0;i<cluster.size();i++) |
|
532 | 550 | { |
|
533 | 551 | if(!isnan(Point3D(cluster.at(i)).value())) |
|
534 | 552 | { |
|
535 | 553 | sum+= Point3D(cluster.at(i)).value(); |
|
536 | 554 | count++; |
|
537 | 555 | } |
|
538 | 556 | } |
|
539 | 557 | return (sum/count); |
|
540 | 558 | } |
|
541 | 559 | return 0; |
|
542 | 560 | } |
|
543 | 561 | |
|
544 | 562 | /*! |
|
545 | 563 | Returns the median value (median Z value) of a \a cluster of points passed as argument. |
|
546 | 564 | */ |
|
547 | 565 | double QColorMapSeriesPrivate::clusterStrategyMedian(QVector<Point3D>& cluster) |
|
548 | 566 | { |
|
549 | 567 | if(!cluster.isEmpty()) |
|
550 | 568 | { |
|
551 | 569 | QVector<double> *copy = new QVector<double>(); |
|
552 | 570 | |
|
553 | 571 | for(int i =0;i<cluster.size();i++) |
|
554 | 572 | { |
|
555 | 573 | if(!isnan(Point3D(cluster.at(i)).value())) |
|
556 | 574 | copy->append(Point3D(cluster.at(i)).value()); |
|
557 | 575 | } |
|
558 | 576 | |
|
559 | 577 | if(!copy->isEmpty()) |
|
560 | 578 | { |
|
561 | 579 | std::sort(copy->begin(), copy->end()); |
|
562 | 580 | |
|
563 | 581 | if(copy->count() & 1) // odd |
|
564 | 582 | { |
|
565 | 583 | int middle = (copy->count()+1)/2; |
|
566 | 584 | return copy->at(middle-1); |
|
567 | 585 | } |
|
568 | 586 | else //even |
|
569 | 587 | { |
|
570 | 588 | int middle = copy->count()/2; |
|
571 | 589 | return (copy->at(middle-1)+copy->at(middle))/2; |
|
572 | 590 | } |
|
573 | 591 | } |
|
574 | 592 | } |
|
575 | 593 | return 0; |
|
576 | 594 | } |
|
577 | 595 | |
|
578 | 596 | /*! |
|
579 | 597 | Computes which data points correspond to the given position and returns the in a \a cluster. |
|
580 | 598 | */ |
|
581 | 599 | void QColorMapSeriesPrivate::buildCluster(int xpos, int ypos, double dx, double dy, QVector<Point3D>& cluster) |
|
582 | 600 | { |
|
583 | 601 | foreach(ColorMapDataPart *dataPart, m_dataParts) |
|
584 | 602 | { |
|
585 | 603 | QPair<int,int> xRange = dataPart->getRange(dataPart->timesSeries(),m_minX+xpos*dx,m_minX+(xpos+1)*dx); |
|
586 | 604 | QPair<int,int> yRange = dataPart->getRange(dataPart->ySeries(),m_maxY-(ypos+1)*dy,m_maxY-ypos*dy); |
|
587 | 605 | |
|
588 | 606 | int timeSeriesSize = dataPart->timesSeries().size(); |
|
589 | 607 | |
|
590 | 608 | if(xRange.first != xRange.second && yRange.first != yRange.second) |
|
591 | 609 | { |
|
592 | 610 | for(int i =xRange.first+1;i<xRange.second;i++) |
|
593 | 611 | { |
|
594 | 612 | qreal xval=dataPart->timesSeries()[i]; |
|
595 | 613 | for(int j=yRange.first+1;j<yRange.second;j++) |
|
596 | 614 | { |
|
597 | 615 | qreal yval=dataPart->ySeries()[j]; |
|
598 | 616 | qreal val=dataPart->dataSeries()[ i + (timeSeriesSize * j)]; |
|
599 | 617 | cluster.append(Point3D(xval,yval,val)); |
|
600 | 618 | } |
|
601 | 619 | } |
|
602 | 620 | } |
|
603 | 621 | } |
|
604 | 622 | } |
|
605 | 623 | |
|
606 | 624 | |
|
607 | 625 | void QColorMapSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options, |
|
608 | 626 | int duration, QEasingCurve &curve) |
|
609 | 627 | { |
|
610 | 628 | // ColorMapChart *item = static_cast<ColorMapChart *>(m_item.data()); |
|
611 | 629 | // Q_ASSERT(item); |
|
612 | 630 | // if (item->animation()) |
|
613 | 631 | // item->animation()->stopAndDestroyLater(); |
|
614 | 632 | |
|
615 | 633 | // if (options.testFlag(QChart::SeriesAnimations)) |
|
616 | 634 | // item->setAnimation(new XYAnimation(item, duration, curve)); |
|
617 | 635 | // else |
|
618 | 636 | // item->setAnimation(0); |
|
619 | 637 | QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); |
|
620 | 638 | } |
|
621 | 639 | |
|
622 | 640 | |
|
623 | 641 | |
|
624 | 642 | #include "moc_qcolormapseries.cpp" |
|
625 | 643 | #include "moc_qcolormapseries_p.cpp" |
|
626 | 644 | |
|
627 | 645 | QT_CHARTS_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now