Index: plot.cpp
===================================================================
--- plot.cpp (revision 2046)
+++ plot.cpp (working copy)
@@ -8,6 +8,8 @@
#include <qwt_plot_panner.h>
#include <qwt_plot_layout.h>
#include <qwt_plot_renderer.h>
+#include <qnumeric.h> // for qIsNan
+#include <qglobal.h> // for qAbs
#include "plot.h"
@@ -63,13 +65,43 @@
}
};
+{
+public:
+ ~HSVColorMap () {}
+ QRgb rgb( const QwtInterval &interval, double value ) const
+ {
+ if (qIsNaN (value)) return qRgba (0, 0, 0, 0);
+
+ const double width = interval.width();
+
+ double ratio = 0.0;
+ if ( width > 0.0 )
+ ratio = ( value - interval.minValue() ) / width;
+
+ if ( ratio < 0.0 ) ratio = 0.0; // under lowest end of min!
+ if ( ratio > 1.0 ) ratio = 1.0; // over highest end of max!
+
+ if (_from.hsvHueF () > _to.hsvHueF ())
+ return QColor::fromHsvF ((_from.
hsvHueF () - _to.
hsvHueF ()) * (1.0 - ratio
),
1.0,
1.0).
rgb ();
+ else return QColor::fromHsvF ((_to.
hsvHueF () - _from.
hsvHueF ()) * ratio,
1.0,
1.0).
rgb ();
+ }
+
+ void setColorInterval
( const QColor &from,
const QColor &to
) + {
+ _from = from;
+ _to = to;
+ }
+ unsigned char colorIndex (const QwtInterval &, double) const { return 0; } // nop
+
+private:
+};
+
{
d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count
- d_spectrogram->setColorMap( new ColorMap() );
+ d_spectrogram
->setColorMap
( new HSVColorMap
(QColor::fromHsv (300,
255,
255),
QColor::fromHsv (1,
255,
255)));
d_spectrogram->setData( new SpectrogramData() );
@@ -85,7 +117,7 @@
rightAxis->setTitle( "Intensity" );
rightAxis->setColorBarEnabled( true );
- rightAxis->setColorMap( zInterval, new ColorMap() );
+ rightAxis
->setColorMap
( zInterval,
new HSVColorMap
(QColor::fromHsv (300,
255,
255),
QColor::fromHsv (1,
255,
255)) );
setAxisScale
( QwtPlot::yRight, zInterval.
minValue(), zInterval.
maxValue() );
Index: plot.cpp
===================================================================
--- plot.cpp (revision 2046)
+++ plot.cpp (working copy)
@@ -8,6 +8,8 @@
#include <qwt_plot_panner.h>
#include <qwt_plot_layout.h>
#include <qwt_plot_renderer.h>
+#include <qnumeric.h> // for qIsNan
+#include <qglobal.h> // for qAbs
#include "plot.h"
class MyZoomer: public QwtPlotZoomer
@@ -63,13 +65,43 @@
}
};
+class HSVColorMap : public QwtColorMap
+{
+public:
+ HSVColorMap( QwtColorMap::Format format = QwtColorMap::RGB ) : QwtColorMap (format), _from (Qt::blue), _to (Qt::red) {}
+ HSVColorMap( const QColor &from, const QColor &to, QwtColorMap::Format format = QwtColorMap::RGB ) : QwtColorMap (format), _from (from), _to (to) {}
+ ~HSVColorMap () {}
+ QRgb rgb( const QwtInterval &interval, double value ) const
+ {
+ if (qIsNaN (value)) return qRgba (0, 0, 0, 0);
+
+ const double width = interval.width();
+
+ double ratio = 0.0;
+ if ( width > 0.0 )
+ ratio = ( value - interval.minValue() ) / width;
+
+ if ( ratio < 0.0 ) ratio = 0.0; // under lowest end of min!
+ if ( ratio > 1.0 ) ratio = 1.0; // over highest end of max!
+
+ if (_from.hsvHueF () > _to.hsvHueF ())
+ return QColor::fromHsvF ((_from.hsvHueF () - _to.hsvHueF ()) * (1.0 - ratio), 1.0, 1.0).rgb ();
+ else return QColor::fromHsvF ((_to.hsvHueF () - _from.hsvHueF ()) * ratio, 1.0, 1.0).rgb ();
+ }
+
+ void setColorInterval( const QColor &from, const QColor &to )
+ {
+ _from = from;
+ _to = to;
+ }
+ unsigned char colorIndex (const QwtInterval &, double) const { return 0; } // nop
+
+private:
+ QColor _from;
+ QColor _to;
+};
+
Plot::Plot( QWidget *parent ):
QwtPlot( parent )
{
d_spectrogram = new QwtPlotSpectrogram();
d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count
- d_spectrogram->setColorMap( new ColorMap() );
+ d_spectrogram->setColorMap( new HSVColorMap(QColor::fromHsv (300, 255, 255), QColor::fromHsv (1, 255, 255)));
d_spectrogram->setCachePolicy( QwtPlotRasterItem::PaintCache );
d_spectrogram->setData( new SpectrogramData() );
@@ -85,7 +117,7 @@
QwtScaleWidget *rightAxis = axisWidget( QwtPlot::yRight );
rightAxis->setTitle( "Intensity" );
rightAxis->setColorBarEnabled( true );
- rightAxis->setColorMap( zInterval, new ColorMap() );
+ rightAxis->setColorMap( zInterval, new HSVColorMap(QColor::fromHsv (300, 255, 255), QColor::fromHsv (1, 255, 255)) );
setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
enableAxis( QwtPlot::yRight );
To copy to clipboard, switch view to plain text mode
Bookmarks