qwt_plot_spectrocurve.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #include "qwt_plot_spectrocurve.h"
11 #include "qwt_color_map.h"
12 #include "qwt_scale_map.h"
13 #include "qwt_painter.h"
14 #include "qwt_text.h"
15 
16 #include <qpainter.h>
17 
19 {
20 public:
22  colorRange( 0.0, 1000.0 ),
23  penWidth(0.0),
25  {
27  }
28 
30  {
31  delete colorMap;
32  }
33 
37  double penWidth;
39 };
40 
46  QwtPlotSeriesItem( title )
47 {
48  init();
49 }
50 
56  QwtPlotSeriesItem( QwtText( title ) )
57 {
58  init();
59 }
60 
63 {
64  delete d_data;
65 }
66 
71 {
74 
75  d_data = new PrivateData;
77 
78  setZ( 20.0 );
79 }
80 
83 {
85 }
86 
95 {
96  if ( on )
97  d_data->paintAttributes |= attribute;
98  else
99  d_data->paintAttributes &= ~attribute;
100 }
101 
107 {
108  return ( d_data->paintAttributes & attribute );
109 }
110 
116 {
117  setData( new QwtPoint3DSeriesData( samples ) );
118 }
119 
132 {
133  setData( data );
134 }
135 
148 {
149  if ( colorMap != d_data->colorMap )
150  {
151  delete d_data->colorMap;
153  }
154 
155  legendChanged();
156  itemChanged();
157 }
158 
164 {
165  return d_data->colorMap;
166 }
167 
177 {
178  if ( interval != d_data->colorRange )
179  {
180  d_data->colorRange = interval;
181 
182  legendChanged();
183  itemChanged();
184  }
185 }
186 
192 {
193  return d_data->colorRange;
194 }
195 
203 {
204  if ( penWidth < 0.0 )
205  penWidth = 0.0;
206 
207  if ( d_data->penWidth != penWidth )
208  {
210 
211  legendChanged();
212  itemChanged();
213  }
214 }
215 
221 {
222  return d_data->penWidth;
223 }
224 
238 void QwtPlotSpectroCurve::drawSeries( QPainter *painter,
239  const QwtScaleMap &xMap, const QwtScaleMap &yMap,
240  const QRectF &canvasRect, int from, int to ) const
241 {
242  if ( !painter || dataSize() <= 0 )
243  return;
244 
245  if ( to < 0 )
246  to = dataSize() - 1;
247 
248  if ( from < 0 )
249  from = 0;
250 
251  if ( from > to )
252  return;
253 
254  drawDots( painter, xMap, yMap, canvasRect, from, to );
255 }
256 
270 void QwtPlotSpectroCurve::drawDots( QPainter *painter,
271  const QwtScaleMap &xMap, const QwtScaleMap &yMap,
272  const QRectF &canvasRect, int from, int to ) const
273 {
274  if ( !d_data->colorRange.isValid() )
275  return;
276 
277  const bool doAlign = QwtPainter::roundingAlignment( painter );
278 
280  if ( format == QwtColorMap::Indexed )
282 
283  const QwtSeriesData<QwtPoint3D> *series = data();
284 
285  for ( int i = from; i <= to; i++ )
286  {
287  const QwtPoint3D sample = series->sample( i );
288 
289  double xi = xMap.transform( sample.x() );
290  double yi = yMap.transform( sample.y() );
291  if ( doAlign )
292  {
293  xi = qRound( xi );
294  yi = qRound( yi );
295  }
296 
298  {
299  if ( !canvasRect.contains( xi, yi ) )
300  continue;
301  }
302 
303  if ( format == QwtColorMap::RGB )
304  {
305  const QRgb rgb = d_data->colorMap->rgb(
306  d_data->colorRange, sample.z() );
307 
308  painter->setPen( QPen( QColor::fromRgba( rgb ), d_data->penWidth ) );
309  }
310  else
311  {
312  const unsigned char index = d_data->colorMap->colorIndex(
313  256, d_data->colorRange, sample.z() );
314 
315  painter->setPen( QPen( QColor::fromRgba( d_data->colorTable[index] ),
316  d_data->penWidth ) );
317  }
318 
319  QwtPainter::drawPoint( painter, QPointF( xi, yi ) );
320  }
321 
322  d_data->colorTable.clear();
323 }
virtual void legendChanged()
QwtPlotSpectroCurve(const QString &title=QString())
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
Definition: core.h:2081
QwtInterval & colorRange() const
virtual QVector< QRgb > colorTable256() const
A class representing an interval.
Definition: qwt_interval.h:22
For QwtPlotSpectroCurve.
Definition: qwt_plot_item.h:95
double y() const
Definition: qwt_point_3d.h:107
void setData(QwtSeriesData< QwtPoint3D > *series)
Interface for iterating over an array of 3D points.
Clip points outside the canvas rectangle.
void setColorRange(const QwtInterval &)
QwtSeriesData< QwtPoint3D > * data()
PaintAttribute
Paint attributes.
void setSamples(const QVector< QwtPoint3D > &)
The item is represented on the legend.
QwtPlotSpectroCurve::PaintAttributes paintAttributes
void init()
Initialize data members.
double z() const
Definition: qwt_point_3d.h:113
virtual uint colorIndex(int numColors, const QwtInterval &interval, double value) const
Map a value of a given interval into a color index.
QwtPoint3D class defines a 3D point in double coordinates.
Definition: qwt_point_3d.h:21
bool isValid() const
Definition: qwt_interval.h:208
A class representing a text.
Definition: qwt_text.h:51
QFlags< PaintAttribute > PaintAttributes
Paint attributes.
void setZ(double z)
Set the z value.
QwtColorMap is used to map values into colors.
Definition: qwt_color_map.h:34
bool testPaintAttribute(PaintAttribute) const
double x() const
Definition: qwt_point_3d.h:101
QwtLinearColorMap builds a color map from color stops.
Definition: qwt_color_map.h:96
A scale map.
Definition: qwt_scale_map.h:26
QwtPoint3D sample(int index) const
The map is intended to map into RGB values.
Definition: qwt_color_map.h:45
virtual void itemChanged()
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const QWT_OVERRIDE
void setColorMap(QwtColorMap *)
const QwtColorMap * colorMap() const
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
virtual int rtti() const QWT_OVERRIDE
virtual T sample(size_t i) const =0
virtual void drawDots(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
virtual size_t dataSize() const QWT_OVERRIDE
Base class for plot items representing a series of samples.
void setItemAttribute(ItemAttribute, bool on=true)
double transform(double s) const
Curve that displays 3D points as dots, where the z coordinate is mapped to a color.
virtual ~QwtPlotSpectroCurve()
Destructor.
Format format() const
void setPaintAttribute(PaintAttribute, bool on=true)
static void drawPoint(QPainter *, const QPoint &)
Wrapper for QPainter::drawPoint()
static bool roundingAlignment()
Definition: qwt_painter.h:181
const QwtText & title() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10