diff --git a/examples/charts/colormap/colormap.pro b/examples/charts/colormap/colormap.pro --- a/examples/charts/colormap/colormap.pro +++ b/examples/charts/colormap/colormap.pro @@ -3,4 +3,10 @@ } TARGET = colormap -SOURCES += main.cpp +SOURCES += main.cpp \ + chart.cpp \ + chartview.cpp + +HEADERS += \ + chart.h \ + chartview.h diff --git a/examples/charts/colormap/main.cpp b/examples/charts/colormap/main.cpp --- a/examples/charts/colormap/main.cpp +++ b/examples/charts/colormap/main.cpp @@ -1,31 +1,24 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Charts module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ #include #include @@ -33,6 +26,11 @@ #include #include +#include + +#include "chart.h" +#include "chartview.h" + QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) @@ -55,26 +53,35 @@ int main(int argc, char *argv[]) zSeries->reserve(1028*768); for(int i=0;i<1028*768;i++) { -// if(i%2 != 1) -// zSeries->append(0); -// else -// zSeries->append(1); zSeries->append(i); } + QLineSeries *series2 = new QLineSeries(); + + series2->append(-100, 300); + series2->append(100, 400); + series2->append(200, 50); + series2->append(300, 1000); + series2->append(400, 800); + *series2 << QPointF(500, 700) << QPointF(600, 600) << QPointF(700, 500) << QPointF(800, -100) << QPointF(1300, 50); + ColorMapDataPart * data = new ColorMapDataPart(xSeries,ySeries,zSeries); QColorMapSeries *series = new QColorMapSeries(); series->append(data); - QChart *chart = new QChart(); + Chart *chart = new Chart(); chart->addSeries(series); - chart->setTitle("Simple colormap example"); + chart->addSeries(series2); + chart->createDefaultAxes(); + + chart->setTitle("Simple Colormap Example"); + chart->axisX()->setGridLineVisible(false); chart->axisY()->setGridLineVisible(false); - QChartView *chartView = new QChartView(chart); + ChartView *chartView = new ChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); QMainWindow window; diff --git a/src/charts/axis/colorbaraxis/chartcolorbaraxisy.cpp b/src/charts/axis/colorbaraxis/chartcolorbaraxisy.cpp --- a/src/charts/axis/colorbaraxis/chartcolorbaraxisy.cpp +++ b/src/charts/axis/colorbaraxis/chartcolorbaraxisy.cpp @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #include "chartcolorbaraxisy_p.h" #include #include diff --git a/src/charts/axis/colorbaraxis/chartcolorbaraxisy_p.h b/src/charts/axis/colorbaraxis/chartcolorbaraxisy_p.h --- a/src/charts/axis/colorbaraxis/chartcolorbaraxisy_p.h +++ b/src/charts/axis/colorbaraxis/chartcolorbaraxisy_p.h @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #ifndef CHARTCOLORBARAXISY_H #define CHARTCOLORBARAXISY_H diff --git a/src/charts/axis/colorbaraxis/qcolorbaraxis.cpp b/src/charts/axis/colorbaraxis/qcolorbaraxis.cpp --- a/src/charts/axis/colorbaraxis/qcolorbaraxis.cpp +++ b/src/charts/axis/colorbaraxis/qcolorbaraxis.cpp @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + //#include // TODO : fix this #include "colorbaraxis/qcolorbaraxis.h" //#include diff --git a/src/charts/axis/colorbaraxis/qcolorbaraxis.h b/src/charts/axis/colorbaraxis/qcolorbaraxis.h --- a/src/charts/axis/colorbaraxis/qcolorbaraxis.h +++ b/src/charts/axis/colorbaraxis/qcolorbaraxis.h @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #ifndef QCOLORBARAXIS_H #define QCOLORBARAXIS_H diff --git a/src/charts/axis/colorbaraxis/qcolorbaraxis_p.h b/src/charts/axis/colorbaraxis/qcolorbaraxis_p.h --- a/src/charts/axis/colorbaraxis/qcolorbaraxis_p.h +++ b/src/charts/axis/colorbaraxis/qcolorbaraxis_p.h @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #ifndef QCOLORBARAXIS_P_H #define QCOLORBARAXIS_P_H diff --git a/src/charts/colormapchart/colormapchart.cpp b/src/charts/colormapchart/colormapchart.cpp --- a/src/charts/colormapchart/colormapchart.cpp +++ b/src/charts/colormapchart/colormapchart.cpp @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #include #include #include @@ -20,7 +42,7 @@ ColorMapChart::ColorMapChart(QColorMapSe m_gradientType(Rainbow), m_colorbar(Q_NULLPTR), m_isColorBarDrawn(false), - m_currentplotArea(QRectF()) + m_currentClipRect(QRectF()) { // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int))); // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced())); @@ -61,30 +83,73 @@ void ColorMapChart::paint(QPainter *pain Q_UNUSED(widget) Q_UNUSED(option) - m_series->setUseOpenGL(); - painter->save(); - - QRectF clipRect = QRectF(QPointF(0, 0), domain()->size()); - painter->setClipRect(clipRect); + //m_series->setUseOpenGL(); QRectF plotAreaRect = m_series->chart()->plotArea(); - if(m_currentplotArea !=plotAreaRect) - { - m_currentplotArea = plotAreaRect; + QRectF clipRect = mapColorMapToPlotArea(); + painter->setClipRect(clipRect); - m_grid.reserve(plotAreaRect.width()*plotAreaRect.height()); - m_grid.resize(plotAreaRect.width()*plotAreaRect.height()); + if(m_currentClipRect !=clipRect) + { + m_currentClipRect = clipRect; + m_grid.reserve(clipRect.width()*clipRect.height()); + m_grid.resize(clipRect.width()*clipRect.height()); - m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),m_grid, QColorMapSeries::LastPixel); - + 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); addColorBar(plotAreaRect); } - QImage colorMapImage(plotAreaRect.width(),plotAreaRect.height(),QImage::Format_RGB32); + QImage colorMapImage(clipRect.width(),clipRect.height(),QImage::Format_RGB32); //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. colorMapImage.fill(QColor(Qt::white).rgb()); + fillColorMapImage(colorMapImage); + + painter->drawImage(clipRect,colorMapImage); + painter->restore(); +} + +void ColorMapChart::addColorBar(QRectF plotAreaRect) +{ + double maxZ = m_series->maxZ(); + double minZ = m_series->minZ(); + + if(m_isColorBarDrawn) + m_series->chart()->removeAxis(m_colorbar); + + m_colorbar = new QColorBarAxis(plotAreaRect,createColorMapGradient(m_gradientType),minZ, maxZ,this); + m_series->chart()->addAxis(m_colorbar, Qt::AlignRight); + m_isColorBarDrawn = true; +} + +QRectF ColorMapChart::mapColorMapToPlotArea() +{ + QRectF plotAreaRect = m_series->chart()->plotArea(); + + double seriesMinX = m_series->minX(); + double seriesMaxX = m_series->maxX(); + double seriesMinY = m_series->minY(); + double seriesMaxY = m_series->maxY(); + + double domainMinX = domain()->minX(); + double domainMaxX = domain()->maxX(); + double domainMinY = domain()->minY(); + double domainMaxY = domain()->maxY(); + + double widthToPaint = (qMin(seriesMaxX, domainMaxX)-qMax(seriesMinX, domainMinX))*plotAreaRect.width()/(domainMaxX-domainMinX); + double heightTopaint= (qMin(seriesMaxY, domainMaxY)-qMax(seriesMinY, domainMinY))*plotAreaRect.height()/(domainMaxY-domainMinY); + + QSizeF size = QSize(widthToPaint,heightTopaint); + + double pointX = (qMax(seriesMinX,domainMinX)-domainMinX)*plotAreaRect.width()/(domainMaxX-domainMinX); + double pointY = (domainMaxY-qMin(seriesMaxY,domainMaxY))*plotAreaRect.height()/(domainMaxY-domainMinY); + + return QRectF(QPointF(pointX,pointY) ,size); +} + +void ColorMapChart::fillColorMapImage(QImage &colorMapImage) +{ double maxZ = m_series->maxZ(); double minZ = m_series->minZ(); double rangeZ = maxZ - minZ; @@ -102,25 +167,6 @@ void ColorMapChart::paint(QPainter *pain colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable)); } } - - painter->drawImage(clipRect,colorMapImage); - //This line was causing re-painting loop - //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 - - painter->restore(); -} - -void ColorMapChart::addColorBar(QRectF plotAreaRect) -{ - double maxZ = m_series->maxZ(); - double minZ = m_series->minZ(); - - if(m_isColorBarDrawn) - m_series->chart()->removeAxis(m_colorbar); - - m_colorbar = new QColorBarAxis(plotAreaRect,createColorMapGradient(m_gradientType),minZ, maxZ,this); - m_series->chart()->addAxis(m_colorbar, Qt::AlignRight); - m_isColorBarDrawn = true; } /*! diff --git a/src/charts/colormapchart/colormapchart.pri b/src/charts/colormapchart/colormapchart.pri --- a/src/charts/colormapchart/colormapchart.pri +++ b/src/charts/colormapchart/colormapchart.pri @@ -1,8 +1,8 @@ INCLUDEPATH += $$PWD DEPENDPATH += $$PWD - -QMAKE_CXXFLAGS+= -fopenmp -QMAKE_LFLAGS += -fopenmp +QT+=concurrent +#QMAKE_CXXFLAGS+= -fopenmp +#QMAKE_LFLAGS += -fopenmp SOURCES += \ $$PWD/qcolormapseries.cpp \ diff --git a/src/charts/colormapchart/colormapchart_p.h b/src/charts/colormapchart/colormapchart_p.h --- a/src/charts/colormapchart/colormapchart_p.h +++ b/src/charts/colormapchart/colormapchart_p.h @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #ifndef COLORMAPCHART_H #define COLORMAPCHART_H @@ -60,6 +82,9 @@ Q_SIGNALS: private: inline bool isEmpty(); void addColorBar(QRectF plotAreaRect); + + QRectF mapColorMapToPlotArea(); + void fillColorMapImage(QImage &colorMapImage); QLinearGradient createColorMapGradient(GradientType gradientType); void changeGradient(GradientType gradientType); @@ -72,7 +97,7 @@ protected: GradientType m_gradientType; bool m_isColorBarDrawn; QColorBarAxis *m_colorbar; - QRectF m_currentplotArea; + QRectF m_currentClipRect; QVector m_grid; }; diff --git a/src/charts/colormapchart/colormapdatapart.cpp b/src/charts/colormapchart/colormapdatapart.cpp --- a/src/charts/colormapchart/colormapdatapart.cpp +++ b/src/charts/colormapchart/colormapdatapart.cpp @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #include "colormapdatapart.h" QT_CHARTS_BEGIN_NAMESPACE diff --git a/src/charts/colormapchart/colormapdatapart.h b/src/charts/colormapchart/colormapdatapart.h --- a/src/charts/colormapchart/colormapdatapart.h +++ b/src/charts/colormapchart/colormapdatapart.h @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #ifndef COLORMAPDATAPART_H #define COLORMAPDATAPART_H diff --git a/src/charts/colormapchart/point3d.cpp b/src/charts/colormapchart/point3d.cpp --- a/src/charts/colormapchart/point3d.cpp +++ b/src/charts/colormapchart/point3d.cpp @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #include "point3d.h" diff --git a/src/charts/colormapchart/point3d.h b/src/charts/colormapchart/point3d.h --- a/src/charts/colormapchart/point3d.h +++ b/src/charts/colormapchart/point3d.h @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #ifndef POINT3D_H #define POINT3D_H diff --git a/src/charts/colormapchart/qcolormapseries.cpp b/src/charts/colormapchart/qcolormapseries.cpp --- a/src/charts/colormapchart/qcolormapseries.cpp +++ b/src/charts/colormapchart/qcolormapseries.cpp @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #include "qcolormapseries.h" #include #include @@ -9,7 +31,7 @@ #include #include -#include "omp.h" +#include #include "qcolorbaraxis.h" @@ -120,10 +142,10 @@ QColorMapSeries &QColorMapSeries::operat from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n When there are more points than pixels, \a strategy is applied to determine which to choose. */ -void QColorMapSeries::getUniformGrid(int xpos, int ypos,int width, int height, QVector &grid, QColorMapSeries::Strategy strategy) +void QColorMapSeries::getUniformGrid(double minX, double maxX, double minY, double maxY, int width, int height, QVector &grid, QColorMapSeries::Strategy strategy) { Q_D(QColorMapSeries); - d->getUniformGrid(xpos, ypos,width,height, grid, strategy); + d->getUniformGrid(minX, maxX,minY,maxY,width,height, grid, strategy); } //void QColorMapSeries::attachAxis(QAbstractAxis *axis) @@ -433,55 +455,45 @@ QAbstractAxis* QColorMapSeriesPrivate::c } -void QColorMapSeriesPrivate::getUniformGrid(int xpos, int ypos, int width, int height, QVector &grid, QColorMapSeries::Strategy strategy) +void QColorMapSeriesPrivate::getUniformGrid(double minX, double maxX, double minY, double maxY, int width, int height, QVector &grid, QColorMapSeries::Strategy strategy) { - double dx = (m_maxX - m_minX)/(double)width; - double dy = (m_maxY - m_minY)/(double)height; + m_imageHeight = height; + m_imageWidth = width; + m_strategy = strategy; + + m_requestedMinX = minX; + m_requestedMaxX = maxX; + m_requestedMinY = minY; + m_requestedMaxY = maxY; int index=0; - - QVector cluster; - cluster.reserve(height*width/1000); - - int x = 0; - int y = 0; + std::generate(grid.begin(),grid.end(),[&index]{return index++;}); - for (auto cell= grid.begin();cellbuildCluster(x,y,dx,dy,cluster); - if(strategy == QColorMapSeries::LastPixel) - *cell=this->clusterStrategyLast(cluster); - else if(strategy == QColorMapSeries::MeanPixel) - *cell=this->clusterStrategyMean(cluster); - else if(strategy == QColorMapSeries::MedianPixel) - *cell=this->clusterStrategyMedian(cluster); - index++; - } + QFuture futureWatcher = QtConcurrent::map(grid,[this] (double &index) { return computePixelValue(index); }); -//#pragma omp for -// for(int y = 0;ybuildCluster(x,y,dx,dy,cluster); -// if(strategy == QColorMapSeries::LastPixel) -// grid[width*y+x] = this->clusterStrategyLast(cluster); -// else if(strategy == QColorMapSeries::MeanPixel) -// grid[width*y+x] = this->clusterStrategyMean(cluster); -// else if(strategy == QColorMapSeries::MedianPixel) -// grid[width*y+x] = this->clusterStrategyMedian(cluster); -// } -// } + futureWatcher.waitForFinished(); } -double QColorMapSeriesPrivate::computeValuePixel() +double QColorMapSeriesPrivate::computePixelValue(double &index) { + QVector cluster; + cluster.reserve(m_imageHeight*m_imageWidth/1000); + cluster.resize(0); + double dx = (m_requestedMaxX - m_requestedMinX)/m_imageWidth; + double dy = (m_requestedMaxY - m_requestedMinY)/m_imageHeight; + int x = (int)index%m_imageWidth; + int y = (int)index/m_imageWidth; + this->buildCluster(x,y,dx,dy,cluster); + if(m_strategy == QColorMapSeries::LastPixel) + index = this->clusterStrategyLast(cluster); + else if(m_strategy == QColorMapSeries::MeanPixel) + index = this->clusterStrategyMean(cluster); + else if(m_strategy == QColorMapSeries::MedianPixel) + index = this->clusterStrategyMedian(cluster); + + return index;//not used } /*! @@ -600,8 +612,8 @@ void QColorMapSeriesPrivate::buildClust { foreach(ColorMapDataPart *dataPart, m_dataParts) { - QPair xRange = dataPart->getRange(dataPart->timesSeries(),m_minX+xpos*dx,m_minX+(xpos+1)*dx); - QPair yRange = dataPart->getRange(dataPart->ySeries(),m_maxY-(ypos+1)*dy,m_maxY-ypos*dy); + QPair xRange = dataPart->getRange(dataPart->timesSeries(),m_requestedMinX+xpos*dx,m_requestedMinX+(xpos+1)*dx); + QPair yRange = dataPart->getRange(dataPart->ySeries(),m_requestedMaxY-(ypos+1)*dy,m_requestedMaxY-ypos*dy); int timeSeriesSize = dataPart->timesSeries().size(); diff --git a/src/charts/colormapchart/qcolormapseries.h b/src/charts/colormapchart/qcolormapseries.h --- a/src/charts/colormapchart/qcolormapseries.h +++ b/src/charts/colormapchart/qcolormapseries.h @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #ifndef QCOLORMAPSERIES_H #define QCOLORMAPSERIES_H @@ -48,7 +70,7 @@ public : QColorMapSeries &operator << (const ColorMapDataPart &dataPart); QColorMapSeries &operator << (const QList &dataParts); - void getUniformGrid(int xpos, int ypos,int width, int height, QVector &grid, Strategy strategy); + void getUniformGrid(double minX, double maxX, double minY, double maxY, int width, int height, QVector &grid, QColorMapSeries::Strategy strategy); // QVector *getUniformGrid(int width, int height, QVector &grid, Strategy lambda); // virtual void attachAxis(QAbstractAxis *axis); diff --git a/src/charts/colormapchart/qcolormapseries_p.h b/src/charts/colormapchart/qcolormapseries_p.h --- a/src/charts/colormapchart/qcolormapseries_p.h +++ b/src/charts/colormapchart/qcolormapseries_p.h @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #ifndef QCOLORMAPSERIES_P_H #define QCOLORMAPSERIES_P_H @@ -31,7 +53,7 @@ public : QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; QAbstractAxis* createDefaultAxis(Qt::Orientation) const; - void getUniformGrid(int xpos, int ypos,int width, int height,QVector &grid, QColorMapSeries::Strategy strategy); + void getUniformGrid(double minX, double maxX, double minY, double maxY, int width, int height, QVector &grid, QColorMapSeries::Strategy strategy); Q_SIGNALS: void updated(); @@ -54,7 +76,17 @@ private: double m_maxY; double m_minZ; double m_maxZ; + int m_imageHeight; + int m_imageWidth; + QColorMapSeries::Strategy m_strategy; + + double m_requestedMinX; + double m_requestedMaxX; + double m_requestedMinY; + double m_requestedMaxY; + void recomputeDataRange(); + double computePixelValue(double &index); double clusterStrategyLast(QVector& cluster); double clusterStrategyMean(QVector &cluster); double clusterStrategyMedian(QVector& cluster); diff --git a/src/charts/legend/qcolormaplegendmarker.cpp b/src/charts/legend/qcolormaplegendmarker.cpp --- a/src/charts/legend/qcolormaplegendmarker.cpp +++ b/src/charts/legend/qcolormaplegendmarker.cpp @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #include #include #include diff --git a/src/charts/legend/qcolormaplegendmarker.h b/src/charts/legend/qcolormaplegendmarker.h --- a/src/charts/legend/qcolormaplegendmarker.h +++ b/src/charts/legend/qcolormaplegendmarker.h @@ -1,3 +1,24 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the ColorMapChart API +-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Hugo Winter +-- Mail : hugo.winter@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ #ifndef QCOLORMAPLEGENDMARKER_H #define QCOLORMAPLEGENDMARKER_H