9#include "qwt_polar_spectrogram.h"
11#include "qwt_polar_plot.h"
12#include "qwt_color_map.h"
13#include "qwt_scale_map.h"
14#include "qwt_raster_data.h"
16#include "qwt_clipper.h"
19#include <qpainterpath.h>
22#include <qtconcurrentrun.h>
25class QwtPolarSpectrogram::TileInfo
33class QwtPolarSpectrogram::PrivateData
58 m_data =
new PrivateData;
90 if (
data != m_data->data )
123 delete m_data->colorMap;
136 return m_data->colorMap;
149 m_data->paintAttributes |= attribute;
151 m_data->paintAttributes &= ~attribute;
161 return ( m_data->paintAttributes & attribute );
176 const QPointF& pole,
double,
177 const QRectF& canvasRect )
const
179 const QRectF plotRect =
plot()->
plotRect( canvasRect.toRect() );
180 QRect imageRect = canvasRect.toRect();
184 painter->setClipRect( canvasRect );
186 QPainterPath clipPathCanvas;
187 clipPathCanvas.addEllipse( plotRect );
188 painter->setClipPath( clipPathCanvas, Qt::IntersectClip );
190 imageRect &= plotRect.toAlignedRect();
193 if ( radialInterval.
isValid() )
198 QRectF clipRect( 0, 0, 2 * radius, 2 * radius );
199 clipRect.moveCenter( pole );
201 imageRect &= clipRect.toRect();
203 QPainterPath clipPathRadial;
204 clipPathRadial.addEllipse( clipRect );
205 painter->setClipPath( clipPathRadial, Qt::IntersectClip );
208 const QImage image =
renderImage( azimuthMap, radialMap, pole, imageRect );
209 painter->drawImage( imageRect, image );
234 const QPointF& pole,
const QRect& rect )
const
236 if ( m_data->data == NULL || m_data->colorMap == NULL )
240 ? QImage::Format_ARGB32 : QImage::Format_Indexed8 );
243 if ( !intensityRange.isValid() )
255 m_data->data->
initRaster( QRectF(), QSize() );
258#if !defined( QT_NO_QFUTURE )
261 if ( numThreads <= 0 )
262 numThreads = QThread::idealThreadCount();
264 if ( numThreads <= 0 )
267 const int numRows = rect.height() / numThreads;
271 for ( uint i = 0; i < numThreads; i++ )
273 QRect tile( rect.x(), rect.y() + i * numRows, rect.width(), numRows );
274 if ( i == numThreads - 1 )
275 tile.setHeight( rect.height() - i * numRows );
278 tileInfo.imagePos = rect.topLeft();
279 tileInfo.rect = tile;
280 tileInfo.image = ℑ
282 tileInfos += tileInfo;
286 for (
int i = 0; i < tileInfos.size(); i++ )
288 if ( i == tileInfos.size() - 1 )
290 renderTileInfo( azimuthMap, radialMap, pole, &tileInfos[i] );
294 futures += QtConcurrent::run(
295#
if QT_VERSION >= 0x060000
296 &QwtPolarSpectrogram::renderTileInfo,
this,
298 this, &QwtPolarSpectrogram::renderTileInfo,
300 azimuthMap, radialMap, pole, &tileInfos[i] );
304 for (
int i = 0; i < futures.size(); i++ )
305 futures[i].waitForFinished();
308 renderTile( azimuthMap, radialMap, pole, rect.topLeft(), rect, &image );
316void QwtPolarSpectrogram::renderTileInfo(
318 const QPointF& pole, TileInfo* tileInfo )
const
321 tileInfo->imagePos, tileInfo->rect, tileInfo->image );
342 const QPointF& pole,
const QPoint& imagePos,
343 const QRect& tile, QImage* image )
const
346 if ( !intensityRange.
isValid() )
351 const int y0 = imagePos.y();
352 const int y1 = tile.top();
353 const int y2 = tile.bottom();
355 const int x0 = imagePos.x();
356 const int x1 = tile.left();
357 const int x2 = tile.right();
361 for (
int y = y1; y <= y2; y++ )
363 const double dy = pole.y() - y;
364 const double dy2 = qwtSqr( dy );
366 QRgb* line =
reinterpret_cast< QRgb*
>( image->scanLine( y - y0 ) );
369 for (
int x = x1; x <= x2; x++ )
371 const double dx = x - pole.x();
373 double a = doFastAtan ? qwtFastAtan2( dy, dx ) : qAtan2( dy, dx );
378 if ( a < azimuthMap.
p1() )
381 const double r = qSqrt( qwtSqr( dx ) + dy2 );
386 const double value = m_data->data->
value( azimuth, radius );
387 if ( qIsNaN( value ) )
393 *line++ = m_data->colorMap->
rgb( intensityRange, value );
400 for (
int y = y1; y <= y2; y++ )
402 const double dy = pole.y() - y;
403 const double dy2 = qwtSqr( dy );
405 unsigned char* line = image->scanLine( y - y0 );
407 for (
int x = x1; x <= x2; x++ )
409 const double dx = x - pole.x();
411 double a = doFastAtan ? qwtFastAtan2( dy, dx ) : qAtan2( dy, dx );
414 if ( a < azimuthMap.
p1() )
417 const double r = qSqrt( qwtSqr( dx ) + dy2 );
422 const double value = m_data->data->
value( azimuth, radius );
424 const uint index = m_data->colorMap->
colorIndex( 256, intensityRange, value );
425 *line++ =
static_cast< unsigned char >( index );
442 if ( scaleId == QwtPolar::ScaleRadius )
443 return m_data->data->
interval( Qt::YAxis );
QwtColorMap is used to map values into colors.
virtual uint colorIndex(int numColors, const QwtInterval &interval, double value) const
Map a value of a given interval into a color index.
@ RGB
The map is intended to map into RGB values.
virtual QVector< QRgb > colorTable256() const
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
A class representing an interval.
QwtLinearColorMap builds a color map from color stops.
Base class for items on a polar plot.
virtual QwtInterval boundingInterval(int scaleId) const
virtual void itemChanged()
@ Legend
The item is represented on the legend.
@ Rtti_PolarSpectrogram
For QwtPolarSpectrogram.
QwtPolarPlot * plot() const
uint renderThreadCount() const
void setItemAttribute(ItemAttribute, bool on=true)
void setZ(double z)
Set the z value.
QwtPolarSpectrogram()
Constructor.
const QwtColorMap * colorMap() const
const QwtRasterData * data() const
void setData(QwtRasterData *data)
virtual ~QwtPolarSpectrogram()
Destructor.
virtual int rtti() const override
void setColorMap(QwtColorMap *)
virtual QImage renderImage(const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap, const QPointF &pole, const QRect &rect) const
Render an image from the data and color map.
void setPaintAttribute(PaintAttribute, bool on=true)
bool testPaintAttribute(PaintAttribute) const
QFlags< PaintAttribute > PaintAttributes
virtual void renderTile(const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap, const QPointF &pole, const QPoint &imagePos, const QRect &tile, QImage *image) const
Render a sub-rectangle of an image.
virtual QwtInterval boundingInterval(int scaleId) const override
virtual void draw(QPainter *painter, const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap, const QPointF &pole, double radius, const QRectF &canvasRect) const override
QwtRasterData defines an interface to any type of raster data.
virtual void discardRaster()
Discard a raster.
virtual double value(double x, double y) const =0
virtual void initRaster(const QRectF &, const QSize &raster)
Initialize a raster.
virtual QwtInterval interval(Qt::Axis) const =0
double transform(double s) const
double invTransform(double p) const
A class representing a text.