Loading...
Searching...
No Matches
qwt_plot_spectrocurve.cpp
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_plot_spectrocurve.h"
#include "qwt_color_map.h"
#include "qwt_scale_map.h"
#include "qwt_painter.h"
#include "qwt_text.h"
#include <qpainter.h>
class QwtPlotSpectroCurve::PrivateData
{
public:
PrivateData()
: colorRange( 0.0, 1000.0 )
, penWidth( 0.0 )
, paintAttributes( QwtPlotSpectroCurve::ClipPoints )
{
colorMap = new QwtLinearColorMap();
}
~PrivateData()
{
delete colorMap;
}
QwtColorMap* colorMap;
QwtInterval colorRange;
QVector< QRgb > colorTable;
double penWidth;
QwtPlotSpectroCurve::PaintAttributes paintAttributes;
};
QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QwtText& title )
: QwtPlotSeriesItem( title )
{
init();
}
QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QString& title )
: QwtPlotSeriesItem( QwtText( title ) )
{
init();
}
QwtPlotSpectroCurve::~QwtPlotSpectroCurve()
{
delete m_data;
}
void QwtPlotSpectroCurve::init()
{
setItemAttribute( QwtPlotItem::Legend );
setItemAttribute( QwtPlotItem::AutoScale );
m_data = new PrivateData;
setData( new QwtPoint3DSeriesData() );
setZ( 20.0 );
}
int QwtPlotSpectroCurve::rtti() const
{
return QwtPlotItem::Rtti_PlotSpectroCurve;
}
void QwtPlotSpectroCurve::setPaintAttribute( PaintAttribute attribute, bool on )
{
if ( on )
m_data->paintAttributes |= attribute;
else
m_data->paintAttributes &= ~attribute;
}
bool QwtPlotSpectroCurve::testPaintAttribute( PaintAttribute attribute ) const
{
return ( m_data->paintAttributes & attribute );
}
void QwtPlotSpectroCurve::setSamples( const QVector< QwtPoint3D >& samples )
{
setData( new QwtPoint3DSeriesData( samples ) );
}
void QwtPlotSpectroCurve::setSamples(
QwtSeriesData< QwtPoint3D >* data )
{
setData( data );
}
void QwtPlotSpectroCurve::setColorMap( QwtColorMap* colorMap )
{
if ( colorMap != m_data->colorMap )
{
delete m_data->colorMap;
m_data->colorMap = colorMap;
}
legendChanged();
itemChanged();
}
const QwtColorMap* QwtPlotSpectroCurve::colorMap() const
{
return m_data->colorMap;
}
void QwtPlotSpectroCurve::setColorRange( const QwtInterval& interval )
{
if ( interval != m_data->colorRange )
{
m_data->colorRange = interval;
legendChanged();
itemChanged();
}
}
QwtInterval& QwtPlotSpectroCurve::colorRange() const
{
return m_data->colorRange;
}
void QwtPlotSpectroCurve::setPenWidth(double penWidth)
{
if ( penWidth < 0.0 )
penWidth = 0.0;
if ( m_data->penWidth != penWidth )
{
m_data->penWidth = penWidth;
legendChanged();
itemChanged();
}
}
double QwtPlotSpectroCurve::penWidth() const
{
return m_data->penWidth;
}
void QwtPlotSpectroCurve::drawSeries( QPainter* painter,
const QwtScaleMap& xMap, const QwtScaleMap& yMap,
const QRectF& canvasRect, int from, int to ) const
{
if ( !painter || dataSize() <= 0 )
return;
if ( to < 0 )
to = dataSize() - 1;
if ( from < 0 )
from = 0;
if ( from > to )
return;
drawDots( painter, xMap, yMap, canvasRect, from, to );
}
void QwtPlotSpectroCurve::drawDots( QPainter* painter,
const QwtScaleMap& xMap, const QwtScaleMap& yMap,
const QRectF& canvasRect, int from, int to ) const
{
if ( !m_data->colorRange.isValid() )
return;
const bool doAlign = QwtPainter::roundingAlignment( painter );
const QwtColorMap::Format format = m_data->colorMap->format();
if ( format == QwtColorMap::Indexed )
m_data->colorTable = m_data->colorMap->colorTable256();
const QwtSeriesData< QwtPoint3D >* series = data();
for ( int i = from; i <= to; i++ )
{
const QwtPoint3D sample = series->sample( i );
double xi = xMap.transform( sample.x() );
double yi = yMap.transform( sample.y() );
if ( doAlign )
{
xi = qRound( xi );
yi = qRound( yi );
}
if ( m_data->paintAttributes & QwtPlotSpectroCurve::ClipPoints )
{
if ( !canvasRect.contains( xi, yi ) )
continue;
}
if ( format == QwtColorMap::RGB )
{
const QRgb rgb = m_data->colorMap->rgb(
m_data->colorRange, sample.z() );
painter->setPen( QPen( QColor::fromRgba( rgb ), m_data->penWidth ) );
}
else
{
const unsigned char index = m_data->colorMap->colorIndex(
256, m_data->colorRange, sample.z() );
painter->setPen( QPen( QColor::fromRgba( m_data->colorTable[index] ),
m_data->penWidth ) );
}
QwtPainter::drawPoint( painter, QPointF( xi, yi ) );
}
m_data->colorTable.clear();
}
QVector< QRgb >
QwtArraySeriesData
Template class for data, that is organized as QVector.
Definition qwt_series_data.h:153
QwtColorMap
QwtColorMap is used to map values into colors.
Definition qwt_color_map.h:38
QwtColorMap::colorIndex
virtual uint colorIndex(int numColors, const QwtInterval &interval, double value) const
Map a value of a given interval into a color index.
Definition qwt_color_map.cpp:278
QwtColorMap::Format
Format
Definition qwt_color_map.h:46
QwtColorMap::Indexed
@ Indexed
Definition qwt_color_map.h:60
QwtColorMap::RGB
@ RGB
The map is intended to map into RGB values.
Definition qwt_color_map.h:48
QwtColorMap::colorTable256
virtual QVector< QRgb > colorTable256() const
Definition qwt_color_map.cpp:304
QwtColorMap::rgb
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
QwtInterval
A class representing an interval.
Definition qwt_interval.h:23
QwtInterval::isValid
bool isValid() const
Definition qwt_interval.h:210
QwtLinearColorMap
QwtLinearColorMap builds a color map from color stops.
Definition qwt_color_map.h:99
QwtPainter::drawPoint
static void drawPoint(QPainter *, const QPoint &)
Wrapper for QPainter::drawPoint()
Definition qwt_painter.cpp:681
QwtPainter::roundingAlignment
static bool roundingAlignment()
Definition qwt_painter.h:183
QwtPlotItem::legendChanged
virtual void legendChanged()
Definition qwt_plot_item.cpp:491
QwtPlotItem::setZ
void setZ(double z)
Set the z value.
Definition qwt_plot_item.cpp:165
QwtPlotItem::setItemAttribute
void setItemAttribute(ItemAttribute, bool on=true)
Definition qwt_plot_item.cpp:228
QwtPlotItem::Rtti_PlotSpectroCurve
@ Rtti_PlotSpectroCurve
For QwtPlotSpectroCurve.
Definition qwt_plot_item.h:96
QwtPlotItem::itemChanged
virtual void itemChanged()
Definition qwt_plot_item.cpp:481
QwtPlotItem::Legend
@ Legend
The item is represented on the legend.
Definition qwt_plot_item.h:150
QwtPlotItem::AutoScale
@ AutoScale
Definition qwt_plot_item.h:157
QwtPlotSeriesItem
Base class for plot items representing a series of samples.
Definition qwt_plot_seriesitem.h:26
QwtPlotSpectroCurve
Curve that displays 3D points as dots, where the z coordinate is mapped to a color.
Definition qwt_plot_spectrocurve.h:25
QwtPlotSpectroCurve::setColorRange
void setColorRange(const QwtInterval &)
Definition qwt_plot_spectrocurve.cpp:176
QwtPlotSpectroCurve::drawSeries
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const override
Definition qwt_plot_spectrocurve.cpp:238
QwtPlotSpectroCurve::colorMap
const QwtColorMap * colorMap() const
Definition qwt_plot_spectrocurve.cpp:163
QwtPlotSpectroCurve::setPaintAttribute
void setPaintAttribute(PaintAttribute, bool on=true)
Definition qwt_plot_spectrocurve.cpp:94
QwtPlotSpectroCurve::setSamples
void setSamples(const QVector< QwtPoint3D > &)
Definition qwt_plot_spectrocurve.cpp:115
QwtPlotSpectroCurve::setColorMap
void setColorMap(QwtColorMap *)
Definition qwt_plot_spectrocurve.cpp:147
QwtPlotSpectroCurve::~QwtPlotSpectroCurve
virtual ~QwtPlotSpectroCurve()
Destructor.
Definition qwt_plot_spectrocurve.cpp:62
QwtPlotSpectroCurve::drawDots
virtual void drawDots(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Definition qwt_plot_spectrocurve.cpp:270
QwtPlotSpectroCurve::penWidth
double penWidth() const
Definition qwt_plot_spectrocurve.cpp:220
QwtPlotSpectroCurve::colorRange
QwtInterval & colorRange() const
Definition qwt_plot_spectrocurve.cpp:191
QwtPlotSpectroCurve::QwtPlotSpectroCurve
QwtPlotSpectroCurve(const QString &title=QString())
Definition qwt_plot_spectrocurve.cpp:55
QwtPlotSpectroCurve::setPenWidth
void setPenWidth(double)
Definition qwt_plot_spectrocurve.cpp:202
QwtPlotSpectroCurve::rtti
virtual int rtti() const override
Definition qwt_plot_spectrocurve.cpp:82
QwtPlotSpectroCurve::testPaintAttribute
bool testPaintAttribute(PaintAttribute) const
Definition qwt_plot_spectrocurve.cpp:106
QwtPlotSpectroCurve::PaintAttribute
PaintAttribute
Paint attributes.
Definition qwt_plot_spectrocurve.h:29
QwtPlotSpectroCurve::ClipPoints
@ ClipPoints
Clip points outside the canvas rectangle.
Definition qwt_plot_spectrocurve.h:31
QwtPlotSpectroCurve::PaintAttributes
QFlags< PaintAttribute > PaintAttributes
Definition qwt_plot_spectrocurve.h:34
QwtPoint3D
QwtPoint3D class defines a 3D point in double coordinates.
Definition qwt_point_3d.h:23
QwtPoint3D::z
double z() const
Definition qwt_point_3d.h:115
QwtPoint3D::y
double y() const
Definition qwt_point_3d.h:109
QwtPoint3D::x
double x() const
Definition qwt_point_3d.h:103
QwtScaleMap
A scale map.
Definition qwt_scale_map.h:27
QwtScaleMap::transform
double transform(double s) const
Definition qwt_scale_map.h:137
QwtSeriesData< QwtPoint3D >
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtSeriesStore< QwtPoint3D >::sample
QwtPoint3D sample(int index) const
Definition qwt_series_store.h:158
QwtSeriesStore< QwtPoint3D >::dataSize
virtual size_t dataSize() const override
Definition qwt_series_store.h:175
QwtSeriesStore< QwtPoint3D >::data
QwtSeriesData< QwtPoint3D > * data()
Definition qwt_series_store.h:146
QwtSeriesStore< QwtPoint3D >::setData
void setData(QwtSeriesData< QwtPoint3D > *series)
Definition qwt_series_store.h:164
QwtText
A class representing a text.
Definition qwt_text.h:52