##// END OF EJS Templates
fix painting coordinates and added LGPL
winter -
r7:a8e6b5a8e8d0 tip default draft
parent child
Show More
@@ -3,4 +3,10
3 }
3 }
4
4
5 TARGET = colormap
5 TARGET = colormap
6 SOURCES += main.cpp
6 SOURCES += main.cpp \
7 chart.cpp \
8 chartview.cpp
9
10 HEADERS += \
11 chart.h \
12 chartview.h
@@ -1,31 +1,24
1 /****************************************************************************
1 /*------------------------------------------------------------------------------
2 **
2 -- This file is a part of the ColorMapChart API
3 ** Copyright (C) 2016 The Qt Company Ltd.
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 ** Contact: https://www.qt.io/licensing/
4 --
5 **
5 -- This program is free software; you can redistribute it and/or modify
6 ** This file is part of the Qt Charts module of the Qt Toolkit.
6 -- it under the terms of the GNU General Public License as published by
7 **
7 -- the Free Software Foundation; either version 2 of the License, or
8 ** $QT_BEGIN_LICENSE:GPL$
8 -- (at your option) any later version.
9 ** Commercial License Usage
9 --
10 ** Licensees holding valid commercial Qt licenses may use this file in
10 -- This program is distributed in the hope that it will be useful,
11 ** accordance with the commercial license agreement provided with the
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** Software or, alternatively, in accordance with the terms contained in
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** a written agreement between you and The Qt Company. For licensing terms
13 -- GNU General Public License for more details.
14 ** and conditions see https://www.qt.io/terms-conditions. For further
14 --
15 ** information use the contact form at https://www.qt.io/contact-us.
15 -- You should have received a copy of the GNU General Public License
16 **
16 -- along with this program; if not, write to the Free Software
17 ** GNU General Public License Usage
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ** Alternatively, this file may be used under the terms of the GNU
18 -------------------------------------------------------------------------------*/
19 ** General Public License version 3 or (at your option) any later version
19 /*-- Author : Hugo Winter
20 ** approved by the KDE Free Qt Foundation. The licenses are as published by
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ** the Free Software Foundation and appearing in the file LICENSE.GPL3
21 ----------------------------------------------------------------------------*/
22 ** included in the packaging of this file. Please review the following
23 ** information to ensure the GNU General Public License requirements will
24 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25 **
26 ** $QT_END_LICENSE$
27 **
28 ****************************************************************************/
29
22
30 #include <QtWidgets/QApplication>
23 #include <QtWidgets/QApplication>
31 #include <QtWidgets/QMainWindow>
24 #include <QtWidgets/QMainWindow>
@@ -33,6 +26,11
33 #include <QtCharts/QColorMapSeries>
26 #include <QtCharts/QColorMapSeries>
34 #include <QtCharts/colormapdatapart.h>
27 #include <QtCharts/colormapdatapart.h>
35
28
29 #include <QLineSeries>
30
31 #include "chart.h"
32 #include "chartview.h"
33
36 QT_CHARTS_USE_NAMESPACE
34 QT_CHARTS_USE_NAMESPACE
37
35
38 int main(int argc, char *argv[])
36 int main(int argc, char *argv[])
@@ -55,26 +53,35 int main(int argc, char *argv[])
55 zSeries->reserve(1028*768);
53 zSeries->reserve(1028*768);
56 for(int i=0;i<1028*768;i++)
54 for(int i=0;i<1028*768;i++)
57 {
55 {
58 // if(i%2 != 1)
59 // zSeries->append(0);
60 // else
61 // zSeries->append(1);
62 zSeries->append(i);
56 zSeries->append(i);
63 }
57 }
64
58
59 QLineSeries *series2 = new QLineSeries();
60
61 series2->append(-100, 300);
62 series2->append(100, 400);
63 series2->append(200, 50);
64 series2->append(300, 1000);
65 series2->append(400, 800);
66 *series2 << QPointF(500, 700) << QPointF(600, 600) << QPointF(700, 500) << QPointF(800, -100) << QPointF(1300, 50);
67
65 ColorMapDataPart * data = new ColorMapDataPart(xSeries,ySeries,zSeries);
68 ColorMapDataPart * data = new ColorMapDataPart(xSeries,ySeries,zSeries);
66
69
67 QColorMapSeries *series = new QColorMapSeries();
70 QColorMapSeries *series = new QColorMapSeries();
68 series->append(data);
71 series->append(data);
69
72
70 QChart *chart = new QChart();
73 Chart *chart = new Chart();
71 chart->addSeries(series);
74 chart->addSeries(series);
72 chart->setTitle("Simple colormap example");
75 chart->addSeries(series2);
76
73 chart->createDefaultAxes();
77 chart->createDefaultAxes();
78
79 chart->setTitle("Simple Colormap Example");
80
74 chart->axisX()->setGridLineVisible(false);
81 chart->axisX()->setGridLineVisible(false);
75 chart->axisY()->setGridLineVisible(false);
82 chart->axisY()->setGridLineVisible(false);
76
83
77 QChartView *chartView = new QChartView(chart);
84 ChartView *chartView = new ChartView(chart);
78 chartView->setRenderHint(QPainter::Antialiasing);
85 chartView->setRenderHint(QPainter::Antialiasing);
79
86
80 QMainWindow window;
87 QMainWindow window;
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #include "chartcolorbaraxisy_p.h"
23 #include "chartcolorbaraxisy_p.h"
2 #include <QtCharts/QAbstractAxis>
24 #include <QtCharts/QAbstractAxis>
3 #include <private/chartpresenter_p.h>
25 #include <private/chartpresenter_p.h>
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #ifndef CHARTCOLORBARAXISY_H
23 #ifndef CHARTCOLORBARAXISY_H
2 #define CHARTCOLORBARAXISY_H
24 #define CHARTCOLORBARAXISY_H
3
25
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 //#include <QtCharts/QColorBarAxis> // TODO : fix this
23 //#include <QtCharts/QColorBarAxis> // TODO : fix this
2 #include "colorbaraxis/qcolorbaraxis.h"
24 #include "colorbaraxis/qcolorbaraxis.h"
3 //#include <private/qcolorbaraxis_p.h>
25 //#include <private/qcolorbaraxis_p.h>
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #ifndef QCOLORBARAXIS_H
23 #ifndef QCOLORBARAXIS_H
2 #define QCOLORBARAXIS_H
24 #define QCOLORBARAXIS_H
3
25
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #ifndef QCOLORBARAXIS_P_H
23 #ifndef QCOLORBARAXIS_P_H
2 #define QCOLORBARAXIS_P_H
24 #define QCOLORBARAXIS_P_H
3
25
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #include <private/colormapchart_p.h>
23 #include <private/colormapchart_p.h>
2 #include <QtCharts/QColorMapSeries>
24 #include <QtCharts/QColorMapSeries>
3 #include <private/qcolormapseries_p.h>
25 #include <private/qcolormapseries_p.h>
@@ -20,7 +42,7 ColorMapChart::ColorMapChart(QColorMapSe
20 m_gradientType(Rainbow),
42 m_gradientType(Rainbow),
21 m_colorbar(Q_NULLPTR),
43 m_colorbar(Q_NULLPTR),
22 m_isColorBarDrawn(false),
44 m_isColorBarDrawn(false),
23 m_currentplotArea(QRectF())
45 m_currentClipRect(QRectF())
24 {
46 {
25 // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
47 // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
26 // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
48 // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
@@ -61,30 +83,73 void ColorMapChart::paint(QPainter *pain
61 Q_UNUSED(widget)
83 Q_UNUSED(widget)
62 Q_UNUSED(option)
84 Q_UNUSED(option)
63
85
64 m_series->setUseOpenGL();
65
66 painter->save();
86 painter->save();
67
87 //m_series->setUseOpenGL();
68 QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
69 painter->setClipRect(clipRect);
70
88
71 QRectF plotAreaRect = m_series->chart()->plotArea();
89 QRectF plotAreaRect = m_series->chart()->plotArea();
72 if(m_currentplotArea !=plotAreaRect)
90 QRectF clipRect = mapColorMapToPlotArea();
73 {
91 painter->setClipRect(clipRect);
74 m_currentplotArea = plotAreaRect;
75
92
76 m_grid.reserve(plotAreaRect.width()*plotAreaRect.height());
93 if(m_currentClipRect !=clipRect)
77 m_grid.resize(plotAreaRect.width()*plotAreaRect.height());
94 {
95 m_currentClipRect = clipRect;
96 m_grid.reserve(clipRect.width()*clipRect.height());
97 m_grid.resize(clipRect.width()*clipRect.height());
78
98
79 m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),m_grid, QColorMapSeries::LastPixel);
99 m_series->getUniformGrid(qMax(m_series->minX(),domain()->minX()),qMin(m_series->maxX(),domain()->maxX()),qMax(m_series->minY(),domain()->minY()),qMin(m_series->maxY(),domain()->maxY()), clipRect.width(),clipRect.height(),m_grid, QColorMapSeries::LastPixel);
80
81 addColorBar(plotAreaRect);
100 addColorBar(plotAreaRect);
82 }
101 }
83
102
84 QImage colorMapImage(plotAreaRect.width(),plotAreaRect.height(),QImage::Format_RGB32);
103 QImage colorMapImage(clipRect.width(),clipRect.height(),QImage::Format_RGB32);
85 //http://doc.qt.io/qt-4.8/qimage.html#details :Warning: This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter.
104 //http://doc.qt.io/qt-4.8/qimage.html#details :Warning: This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter.
86 colorMapImage.fill(QColor(Qt::white).rgb());
105 colorMapImage.fill(QColor(Qt::white).rgb());
87
106
107 fillColorMapImage(colorMapImage);
108
109 painter->drawImage(clipRect,colorMapImage);
110 painter->restore();
111 }
112
113 void ColorMapChart::addColorBar(QRectF plotAreaRect)
114 {
115 double maxZ = m_series->maxZ();
116 double minZ = m_series->minZ();
117
118 if(m_isColorBarDrawn)
119 m_series->chart()->removeAxis(m_colorbar);
120
121 m_colorbar = new QColorBarAxis(plotAreaRect,createColorMapGradient(m_gradientType),minZ, maxZ,this);
122 m_series->chart()->addAxis(m_colorbar, Qt::AlignRight);
123 m_isColorBarDrawn = true;
124 }
125
126 QRectF ColorMapChart::mapColorMapToPlotArea()
127 {
128 QRectF plotAreaRect = m_series->chart()->plotArea();
129
130 double seriesMinX = m_series->minX();
131 double seriesMaxX = m_series->maxX();
132 double seriesMinY = m_series->minY();
133 double seriesMaxY = m_series->maxY();
134
135 double domainMinX = domain()->minX();
136 double domainMaxX = domain()->maxX();
137 double domainMinY = domain()->minY();
138 double domainMaxY = domain()->maxY();
139
140 double widthToPaint = (qMin(seriesMaxX, domainMaxX)-qMax(seriesMinX, domainMinX))*plotAreaRect.width()/(domainMaxX-domainMinX);
141 double heightTopaint= (qMin(seriesMaxY, domainMaxY)-qMax(seriesMinY, domainMinY))*plotAreaRect.height()/(domainMaxY-domainMinY);
142
143 QSizeF size = QSize(widthToPaint,heightTopaint);
144
145 double pointX = (qMax(seriesMinX,domainMinX)-domainMinX)*plotAreaRect.width()/(domainMaxX-domainMinX);
146 double pointY = (domainMaxY-qMin(seriesMaxY,domainMaxY))*plotAreaRect.height()/(domainMaxY-domainMinY);
147
148 return QRectF(QPointF(pointX,pointY) ,size);
149 }
150
151 void ColorMapChart::fillColorMapImage(QImage &colorMapImage)
152 {
88 double maxZ = m_series->maxZ();
153 double maxZ = m_series->maxZ();
89 double minZ = m_series->minZ();
154 double minZ = m_series->minZ();
90 double rangeZ = maxZ - minZ;
155 double rangeZ = maxZ - minZ;
@@ -102,25 +167,6 void ColorMapChart::paint(QPainter *pain
102 colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable));
167 colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable));
103 }
168 }
104 }
169 }
105
106 painter->drawImage(clipRect,colorMapImage);
107 //This line was causing re-painting loop
108 //update();//Qt docs: Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may get infinite recursion. The update() function never causes recursion
109
110 painter->restore();
111 }
112
113 void ColorMapChart::addColorBar(QRectF plotAreaRect)
114 {
115 double maxZ = m_series->maxZ();
116 double minZ = m_series->minZ();
117
118 if(m_isColorBarDrawn)
119 m_series->chart()->removeAxis(m_colorbar);
120
121 m_colorbar = new QColorBarAxis(plotAreaRect,createColorMapGradient(m_gradientType),minZ, maxZ,this);
122 m_series->chart()->addAxis(m_colorbar, Qt::AlignRight);
123 m_isColorBarDrawn = true;
124 }
170 }
125
171
126 /*!
172 /*!
@@ -1,8 +1,8
1 INCLUDEPATH += $$PWD
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3 QT+=concurrent
4 QMAKE_CXXFLAGS+= -fopenmp
4 #QMAKE_CXXFLAGS+= -fopenmp
5 QMAKE_LFLAGS += -fopenmp
5 #QMAKE_LFLAGS += -fopenmp
6
6
7 SOURCES += \
7 SOURCES += \
8 $$PWD/qcolormapseries.cpp \
8 $$PWD/qcolormapseries.cpp \
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #ifndef COLORMAPCHART_H
23 #ifndef COLORMAPCHART_H
2 #define COLORMAPCHART_H
24 #define COLORMAPCHART_H
3
25
@@ -60,6 +82,9 Q_SIGNALS:
60 private:
82 private:
61 inline bool isEmpty();
83 inline bool isEmpty();
62 void addColorBar(QRectF plotAreaRect);
84 void addColorBar(QRectF plotAreaRect);
85
86 QRectF mapColorMapToPlotArea();
87 void fillColorMapImage(QImage &colorMapImage);
63 QLinearGradient createColorMapGradient(GradientType gradientType);
88 QLinearGradient createColorMapGradient(GradientType gradientType);
64 void changeGradient(GradientType gradientType);
89 void changeGradient(GradientType gradientType);
65
90
@@ -72,7 +97,7 protected:
72 GradientType m_gradientType;
97 GradientType m_gradientType;
73 bool m_isColorBarDrawn;
98 bool m_isColorBarDrawn;
74 QColorBarAxis *m_colorbar;
99 QColorBarAxis *m_colorbar;
75 QRectF m_currentplotArea;
100 QRectF m_currentClipRect;
76 QVector<double> m_grid;
101 QVector<double> m_grid;
77 };
102 };
78
103
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #include "colormapdatapart.h"
23 #include "colormapdatapart.h"
2
24
3 QT_CHARTS_BEGIN_NAMESPACE
25 QT_CHARTS_BEGIN_NAMESPACE
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #ifndef COLORMAPDATAPART_H
23 #ifndef COLORMAPDATAPART_H
2 #define COLORMAPDATAPART_H
24 #define COLORMAPDATAPART_H
3
25
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #include "point3d.h"
23 #include "point3d.h"
2
24
3
25
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #ifndef POINT3D_H
23 #ifndef POINT3D_H
2 #define POINT3D_H
24 #define POINT3D_H
3
25
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #include "qcolormapseries.h"
23 #include "qcolormapseries.h"
2 #include <private/qcolormapseries_p.h>
24 #include <private/qcolormapseries_p.h>
3 #include <private/abstractdomain_p.h>
25 #include <private/abstractdomain_p.h>
@@ -9,7 +31,7
9 #include <QtGui/QPainter>
31 #include <QtGui/QPainter>
10
32
11 #include <cmath>
33 #include <cmath>
12 #include "omp.h"
34 #include <QtConcurrent>
13
35
14 #include "qcolorbaraxis.h"
36 #include "qcolorbaraxis.h"
15
37
@@ -120,10 +142,10 QColorMapSeries &QColorMapSeries::operat
120 from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n
142 from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n
121 When there are more points than pixels, \a strategy is applied to determine which to choose.
143 When there are more points than pixels, \a strategy is applied to determine which to choose.
122 */
144 */
123 void QColorMapSeries::getUniformGrid(int xpos, int ypos,int width, int height, QVector<double> &grid, QColorMapSeries::Strategy strategy)
145 void QColorMapSeries::getUniformGrid(double minX, double maxX, double minY, double maxY, int width, int height, QVector<double> &grid, QColorMapSeries::Strategy strategy)
124 {
146 {
125 Q_D(QColorMapSeries);
147 Q_D(QColorMapSeries);
126 d->getUniformGrid(xpos, ypos,width,height, grid, strategy);
148 d->getUniformGrid(minX, maxX,minY,maxY,width,height, grid, strategy);
127 }
149 }
128
150
129 //void QColorMapSeries::attachAxis(QAbstractAxis *axis)
151 //void QColorMapSeries::attachAxis(QAbstractAxis *axis)
@@ -433,55 +455,45 QAbstractAxis* QColorMapSeriesPrivate::c
433 }
455 }
434
456
435
457
436 void QColorMapSeriesPrivate::getUniformGrid(int xpos, int ypos, int width, int height, QVector<double> &grid, QColorMapSeries::Strategy strategy)
458 void QColorMapSeriesPrivate::getUniformGrid(double minX, double maxX, double minY, double maxY, int width, int height, QVector<double> &grid, QColorMapSeries::Strategy strategy)
437 {
459 {
438 double dx = (m_maxX - m_minX)/(double)width;
460 m_imageHeight = height;
439 double dy = (m_maxY - m_minY)/(double)height;
461 m_imageWidth = width;
462 m_strategy = strategy;
463
464 m_requestedMinX = minX;
465 m_requestedMaxX = maxX;
466 m_requestedMinY = minY;
467 m_requestedMaxY = maxY;
440
468
441 int index=0;
469 int index=0;
442
470 std::generate(grid.begin(),grid.end(),[&index]{return index++;});
443 QVector<Point3D> cluster;
444 cluster.reserve(height*width/1000);
445
446 int x = 0;
447 int y = 0;
448
471
449 for (auto cell= grid.begin();cell<grid.end();++cell)
472 QFuture<void> futureWatcher = QtConcurrent::map(grid,[this] (double &index) { return computePixelValue(index); });
450 {
451 x = index%width;
452 y = index/width;
453 cluster.resize(0);
454 this->buildCluster(x,y,dx,dy,cluster);
455 if(strategy == QColorMapSeries::LastPixel)
456 *cell=this->clusterStrategyLast(cluster);
457 else if(strategy == QColorMapSeries::MeanPixel)
458 *cell=this->clusterStrategyMean(cluster);
459 else if(strategy == QColorMapSeries::MedianPixel)
460 *cell=this->clusterStrategyMedian(cluster);
461 index++;
462 }
463
473
464 //#pragma omp for
474 futureWatcher.waitForFinished();
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 }
475 }
480
476
481 double QColorMapSeriesPrivate::computeValuePixel()
477 double QColorMapSeriesPrivate::computePixelValue(double &index)
482 {
478 {
479 QVector<Point3D> cluster;
480 cluster.reserve(m_imageHeight*m_imageWidth/1000);
481 cluster.resize(0);
483
482
483 double dx = (m_requestedMaxX - m_requestedMinX)/m_imageWidth;
484 double dy = (m_requestedMaxY - m_requestedMinY)/m_imageHeight;
484
485
486 int x = (int)index%m_imageWidth;
487 int y = (int)index/m_imageWidth;
488 this->buildCluster(x,y,dx,dy,cluster);
489 if(m_strategy == QColorMapSeries::LastPixel)
490 index = this->clusterStrategyLast(cluster);
491 else if(m_strategy == QColorMapSeries::MeanPixel)
492 index = this->clusterStrategyMean(cluster);
493 else if(m_strategy == QColorMapSeries::MedianPixel)
494 index = this->clusterStrategyMedian(cluster);
495
496 return index;//not used
485 }
497 }
486
498
487 /*!
499 /*!
@@ -600,8 +612,8 void QColorMapSeriesPrivate::buildClust
600 {
612 {
601 foreach(ColorMapDataPart *dataPart, m_dataParts)
613 foreach(ColorMapDataPart *dataPart, m_dataParts)
602 {
614 {
603 QPair<int,int> xRange = dataPart->getRange(dataPart->timesSeries(),m_minX+xpos*dx,m_minX+(xpos+1)*dx);
615 QPair<int,int> xRange = dataPart->getRange(dataPart->timesSeries(),m_requestedMinX+xpos*dx,m_requestedMinX+(xpos+1)*dx);
604 QPair<int,int> yRange = dataPart->getRange(dataPart->ySeries(),m_maxY-(ypos+1)*dy,m_maxY-ypos*dy);
616 QPair<int,int> yRange = dataPart->getRange(dataPart->ySeries(),m_requestedMaxY-(ypos+1)*dy,m_requestedMaxY-ypos*dy);
605
617
606 int timeSeriesSize = dataPart->timesSeries().size();
618 int timeSeriesSize = dataPart->timesSeries().size();
607
619
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #ifndef QCOLORMAPSERIES_H
23 #ifndef QCOLORMAPSERIES_H
2 #define QCOLORMAPSERIES_H
24 #define QCOLORMAPSERIES_H
3
25
@@ -48,7 +70,7 public :
48 QColorMapSeries &operator << (const ColorMapDataPart &dataPart);
70 QColorMapSeries &operator << (const ColorMapDataPart &dataPart);
49 QColorMapSeries &operator << (const QList<ColorMapDataPart *> &dataParts);
71 QColorMapSeries &operator << (const QList<ColorMapDataPart *> &dataParts);
50
72
51 void getUniformGrid(int xpos, int ypos,int width, int height, QVector<double> &grid, Strategy strategy);
73 void getUniformGrid(double minX, double maxX, double minY, double maxY, int width, int height, QVector<double> &grid, QColorMapSeries::Strategy strategy);
52 // QVector<double> *getUniformGrid(int width, int height, QVector<double> &grid, Strategy lambda);
74 // QVector<double> *getUniformGrid(int width, int height, QVector<double> &grid, Strategy lambda);
53
75
54 // virtual void attachAxis(QAbstractAxis *axis);
76 // virtual void attachAxis(QAbstractAxis *axis);
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #ifndef QCOLORMAPSERIES_P_H
23 #ifndef QCOLORMAPSERIES_P_H
2 #define QCOLORMAPSERIES_P_H
24 #define QCOLORMAPSERIES_P_H
3
25
@@ -31,7 +53,7 public :
31 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
53 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
32 QAbstractAxis* createDefaultAxis(Qt::Orientation) const;
54 QAbstractAxis* createDefaultAxis(Qt::Orientation) const;
33
55
34 void getUniformGrid(int xpos, int ypos,int width, int height,QVector<double> &grid, QColorMapSeries::Strategy strategy);
56 void getUniformGrid(double minX, double maxX, double minY, double maxY, int width, int height, QVector<double> &grid, QColorMapSeries::Strategy strategy);
35
57
36 Q_SIGNALS:
58 Q_SIGNALS:
37 void updated();
59 void updated();
@@ -54,7 +76,17 private:
54 double m_maxY;
76 double m_maxY;
55 double m_minZ;
77 double m_minZ;
56 double m_maxZ;
78 double m_maxZ;
79 int m_imageHeight;
80 int m_imageWidth;
81 QColorMapSeries::Strategy m_strategy;
82
83 double m_requestedMinX;
84 double m_requestedMaxX;
85 double m_requestedMinY;
86 double m_requestedMaxY;
87
57 void recomputeDataRange();
88 void recomputeDataRange();
89 double computePixelValue(double &index);
58 double clusterStrategyLast(QVector<Point3D>& cluster);
90 double clusterStrategyLast(QVector<Point3D>& cluster);
59 double clusterStrategyMean(QVector<Point3D> &cluster);
91 double clusterStrategyMean(QVector<Point3D> &cluster);
60 double clusterStrategyMedian(QVector<Point3D>& cluster);
92 double clusterStrategyMedian(QVector<Point3D>& cluster);
@@ -1,3 +1,25
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
22
1 #include <QtCharts/QColorMapLegendMarker>
23 #include <QtCharts/QColorMapLegendMarker>
2 #include <private/qcolormapseries_p.h>
24 #include <private/qcolormapseries_p.h>
3 #include <private/qcolormaplegendmarker_p.h>
25 #include <private/qcolormaplegendmarker_p.h>
@@ -1,3 +1,24
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the ColorMapChart API
3 -- Copyright (C) 2016, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Hugo Winter
20 -- Mail : hugo.winter@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
1 #ifndef QCOLORMAPLEGENDMARKER_H
22 #ifndef QCOLORMAPLEGENDMARKER_H
2 #define QCOLORMAPLEGENDMARKER_H
23 #define QCOLORMAPLEGENDMARKER_H
3
24
General Comments 0
You need to be logged in to leave comments. Login now