##// 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 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 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Charts module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 or (at your option) any later version
20 ** approved by the KDE Free Qt Foundation. The licenses are as published by
21 ** the Free Software Foundation and appearing in the file LICENSE.GPL3
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 ****************************************************************************/
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 ----------------------------------------------------------------------------*/
29 22
30 23 #include <QtWidgets/QApplication>
31 24 #include <QtWidgets/QMainWindow>
@@ -33,6 +26,11
33 26 #include <QtCharts/QColorMapSeries>
34 27 #include <QtCharts/colormapdatapart.h>
35 28
29 #include <QLineSeries>
30
31 #include "chart.h"
32 #include "chartview.h"
33
36 34 QT_CHARTS_USE_NAMESPACE
37 35
38 36 int main(int argc, char *argv[])
@@ -55,26 +53,35 int main(int argc, char *argv[])
55 53 zSeries->reserve(1028*768);
56 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 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 68 ColorMapDataPart * data = new ColorMapDataPart(xSeries,ySeries,zSeries);
66 69
67 70 QColorMapSeries *series = new QColorMapSeries();
68 71 series->append(data);
69 72
70 QChart *chart = new QChart();
73 Chart *chart = new Chart();
71 74 chart->addSeries(series);
72 chart->setTitle("Simple colormap example");
75 chart->addSeries(series2);
76
73 77 chart->createDefaultAxes();
78
79 chart->setTitle("Simple Colormap Example");
80
74 81 chart->axisX()->setGridLineVisible(false);
75 82 chart->axisY()->setGridLineVisible(false);
76 83
77 QChartView *chartView = new QChartView(chart);
84 ChartView *chartView = new ChartView(chart);
78 85 chartView->setRenderHint(QPainter::Antialiasing);
79 86
80 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 23 #include "chartcolorbaraxisy_p.h"
2 24 #include <QtCharts/QAbstractAxis>
3 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 23 #ifndef CHARTCOLORBARAXISY_H
2 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 23 //#include <QtCharts/QColorBarAxis> // TODO : fix this
2 24 #include "colorbaraxis/qcolorbaraxis.h"
3 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 23 #ifndef QCOLORBARAXIS_H
2 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 23 #ifndef QCOLORBARAXIS_P_H
2 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 23 #include <private/colormapchart_p.h>
2 24 #include <QtCharts/QColorMapSeries>
3 25 #include <private/qcolormapseries_p.h>
@@ -20,7 +42,7 ColorMapChart::ColorMapChart(QColorMapSe
20 42 m_gradientType(Rainbow),
21 43 m_colorbar(Q_NULLPTR),
22 44 m_isColorBarDrawn(false),
23 m_currentplotArea(QRectF())
45 m_currentClipRect(QRectF())
24 46 {
25 47 // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
26 48 // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
@@ -61,30 +83,73 void ColorMapChart::paint(QPainter *pain
61 83 Q_UNUSED(widget)
62 84 Q_UNUSED(option)
63 85
64 m_series->setUseOpenGL();
65
66 86 painter->save();
67
68 QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
69 painter->setClipRect(clipRect);
87 //m_series->setUseOpenGL();
70 88
71 89 QRectF plotAreaRect = m_series->chart()->plotArea();
72 if(m_currentplotArea !=plotAreaRect)
73 {
74 m_currentplotArea = plotAreaRect;
90 QRectF clipRect = mapColorMapToPlotArea();
91 painter->setClipRect(clipRect);
75 92
76 m_grid.reserve(plotAreaRect.width()*plotAreaRect.height());
77 m_grid.resize(plotAreaRect.width()*plotAreaRect.height());
93 if(m_currentClipRect !=clipRect)
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);
80
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);
81 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 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 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 153 double maxZ = m_series->maxZ();
89 154 double minZ = m_series->minZ();
90 155 double rangeZ = maxZ - minZ;
@@ -102,25 +167,6 void ColorMapChart::paint(QPainter *pain
102 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 1 INCLUDEPATH += $$PWD
2 2 DEPENDPATH += $$PWD
3
4 QMAKE_CXXFLAGS+= -fopenmp
5 QMAKE_LFLAGS += -fopenmp
3 QT+=concurrent
4 #QMAKE_CXXFLAGS+= -fopenmp
5 #QMAKE_LFLAGS += -fopenmp
6 6
7 7 SOURCES += \
8 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 23 #ifndef COLORMAPCHART_H
2 24 #define COLORMAPCHART_H
3 25
@@ -60,6 +82,9 Q_SIGNALS:
60 82 private:
61 83 inline bool isEmpty();
62 84 void addColorBar(QRectF plotAreaRect);
85
86 QRectF mapColorMapToPlotArea();
87 void fillColorMapImage(QImage &colorMapImage);
63 88 QLinearGradient createColorMapGradient(GradientType gradientType);
64 89 void changeGradient(GradientType gradientType);
65 90
@@ -72,7 +97,7 protected:
72 97 GradientType m_gradientType;
73 98 bool m_isColorBarDrawn;
74 99 QColorBarAxis *m_colorbar;
75 QRectF m_currentplotArea;
100 QRectF m_currentClipRect;
76 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 23 #include "colormapdatapart.h"
2 24
3 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 23 #ifndef COLORMAPDATAPART_H
2 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 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 23 #ifndef POINT3D_H
2 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 23 #include "qcolormapseries.h"
2 24 #include <private/qcolormapseries_p.h>
3 25 #include <private/abstractdomain_p.h>
@@ -9,7 +31,7
9 31 #include <QtGui/QPainter>
10 32
11 33 #include <cmath>
12 #include "omp.h"
34 #include <QtConcurrent>
13 35
14 36 #include "qcolorbaraxis.h"
15 37
@@ -120,10 +142,10 QColorMapSeries &QColorMapSeries::operat
120 142 from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n
121 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 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 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;
439 double dy = (m_maxY - m_minY)/(double)height;
460 m_imageHeight = 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 469 int index=0;
442
443 QVector<Point3D> cluster;
444 cluster.reserve(height*width/1000);
445
446 int x = 0;
447 int y = 0;
470 std::generate(grid.begin(),grid.end(),[&index]{return index++;});
448 471
449 for (auto cell= grid.begin();cell<grid.end();++cell)
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 }
472 QFuture<void> futureWatcher = QtConcurrent::map(grid,[this] (double &index) { return computePixelValue(index); });
463 473
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 // }
474 futureWatcher.waitForFinished();
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 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);
604 QPair<int,int> yRange = dataPart->getRange(dataPart->ySeries(),m_maxY-(ypos+1)*dy,m_maxY-ypos*dy);
615 QPair<int,int> xRange = dataPart->getRange(dataPart->timesSeries(),m_requestedMinX+xpos*dx,m_requestedMinX+(xpos+1)*dx);
616 QPair<int,int> yRange = dataPart->getRange(dataPart->ySeries(),m_requestedMaxY-(ypos+1)*dy,m_requestedMaxY-ypos*dy);
605 617
606 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 23 #ifndef QCOLORMAPSERIES_H
2 24 #define QCOLORMAPSERIES_H
3 25
@@ -48,7 +70,7 public :
48 70 QColorMapSeries &operator << (const ColorMapDataPart &dataPart);
49 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 74 // QVector<double> *getUniformGrid(int width, int height, QVector<double> &grid, Strategy lambda);
53 75
54 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 23 #ifndef QCOLORMAPSERIES_P_H
2 24 #define QCOLORMAPSERIES_P_H
3 25
@@ -31,7 +53,7 public :
31 53 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
32 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 58 Q_SIGNALS:
37 59 void updated();
@@ -54,7 +76,17 private:
54 76 double m_maxY;
55 77 double m_minZ;
56 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 88 void recomputeDataRange();
89 double computePixelValue(double &index);
58 90 double clusterStrategyLast(QVector<Point3D>& cluster);
59 91 double clusterStrategyMean(QVector<Point3D> &cluster);
60 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 23 #include <QtCharts/QColorMapLegendMarker>
2 24 #include <private/qcolormapseries_p.h>
3 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 22 #ifndef QCOLORMAPLEGENDMARKER_H
2 23 #define QCOLORMAPLEGENDMARKER_H
3 24
General Comments 0
You need to be logged in to leave comments. Login now