22 #include <qtconcurrentrun.h> 24 #define DEBUG_RENDER 0 27 #include <qelapsedtimer.h> 38 if ( QSysInfo::ByteOrder == QSysInfo::BigEndian )
40 return (ch[0] & 0x7f) == 0x7f && ch[1] > 0xf0;
44 return (ch[7] & 0x7f) == 0x7f && ch[6] > 0xf0;
178 if ( colorMap == NULL )
206 numColors = qMax( numColors, 0 );
234 const QColor &color, qreal width, Qt::PenStyle style )
459 const QRectF &area,
const QSize &imageSize )
const 461 if ( imageSize.isEmpty() ||
d_data->
data == NULL
468 if ( !intensityRange.
isValid() )
472 ? QImage::Format_ARGB32 : QImage::Format_Indexed8;
474 QImage image( imageSize, format );
486 #if !defined(QT_NO_QFUTURE) 489 if ( numThreads <= 0 )
490 numThreads = QThread::idealThreadCount();
492 if ( numThreads <= 0 )
495 const int numRows = imageSize.height() / numThreads;
498 futures.reserve( numThreads - 1 );
500 for ( uint i = 0; i < numThreads; i++ )
502 QRect tile( 0, i * numRows, image.width(), numRows );
503 if ( i == numThreads - 1 )
505 tile.setHeight( image.height() - i * numRows );
512 xMap, yMap, tile, &image );
515 for (
int i = 0; i < futures.size(); i++ )
516 futures[i].waitForFinished();
519 const QRect tile( 0, 0, image.width(), image.height() );
524 const qint64
elapsed = time.elapsed();
525 qDebug() <<
"renderImage" << imageSize <<
elapsed;
546 const QRect &tile, QImage *image )
const 549 if ( range.
width() <= 0.0 )
560 for (
int y = tile.top(); y <= tile.bottom(); y++ )
564 QRgb *line =
reinterpret_cast<QRgb *
>( image->scanLine( y ) );
567 for (
int x = tile.left(); x <= tile.right(); x++ )
577 else if ( numColors == 0 )
579 *line++ = colorMap->
rgb( range, value );
583 const uint index = colorMap->
colorIndex( numColors, range, value );
584 *line++ = rgbTable[index];
591 for (
int y = tile.top(); y <= tile.bottom(); y++ )
595 unsigned char *line = image->scanLine( y );
598 for (
int x = tile.left(); x <= tile.right(); x++ )
611 *line++ =
static_cast<unsigned char>( index );
636 const QRectF &area,
const QRect &rect )
const 638 QSize raster = rect.size() / 2;
640 const QRectF pixelRect =
pixelHint( area );
641 if ( !pixelRect.isEmpty() )
643 const QSize res(
qwtCeil( rect.width() / pixelRect.width() ),
644 qwtCeil( rect.height() / pixelRect.height() ) );
645 raster = raster.boundedTo( res );
662 const QRectF &rect,
const QSize &raster )
const 689 for (
int l = 0; l < numLevels; l++ )
694 if ( pen.style() == Qt::NoPen )
697 if ( pen.style() == Qt::NoPen )
700 painter->setPen( pen );
702 const QPolygonF &lines = contourLines[level];
703 for (
int i = 0; i < lines.size(); i += 2 )
705 const QPointF p1( xMap.
transform( lines[i].x() ),
707 const QPointF p2( xMap.
transform( lines[i+1].x() ),
728 const QRectF &canvasRect )
const 736 const int margin = 2;
737 QRectF rasterRect( canvasRect.x() - margin, canvasRect.y() - margin,
738 canvasRect.width() + 2 * margin, canvasRect.height() + 2 * margin );
746 if ( area.isEmpty() )
753 raster = raster.boundedTo( rasterRect.toRect().size() );
754 if ( raster.isValid() )
virtual void discardRaster()
Discard a raster.
virtual void legendChanged()
enum MQTTPropertyCodes value
The data is displayed using contour lines.
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
virtual QRectF pixelHint(const QRectF &) const
Pixel hint.
virtual ~QwtPlotSpectrogram()
Destructor.
virtual QVector< QRgb > colorTable256() const
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
A class representing an interval.
A class, which displays raster data.
virtual QRectF pixelHint(const QRectF &) const QWT_OVERRIDE
Pixel hint.
void setDefaultContourPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
QList< double > contourLevels
ConrecFlag
Flags to modify the contour algorithm.
void setMaxRGBTableSize(int numColors)
void setData(QwtRasterData *data)
long elapsed(START_TIME_TYPE start_time)
virtual void initRaster(const QRectF &, const QSize &raster)
Initialize a raster.
virtual int rtti() const QWT_OVERRIDE
QFlags< DisplayMode > DisplayModes
Display modes.
Ignore all vertices on the same level.
bool testConrecFlag(QwtRasterData::ConrecFlag) const
virtual QwtInterval interval(Qt::Axis) const QWT_OVERRIDE
void setDisplayMode(DisplayMode, bool on=true)
QMap< double, QPolygonF > ContourLines
Contour lines.
QPen defaultContourPen() const
virtual QwtInterval interval(Qt::Axis) const =0
The item is represented on the legend.
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const QWT_OVERRIDE
Draw the raster data.
The values are mapped to colors using a color map.
virtual QVector< QRgb > colorTable(int numColors) const
virtual uint colorIndex(int numColors, const QwtInterval &interval, double value) const
Map a value of a given interval into a color index.
virtual ContourLines contourLines(const QRectF &rect, const QSize &raster, const QList< double > &levels, ConrecFlags) const
virtual QRectF boundingRect() const QWT_OVERRIDE
void setColorMap(QwtColorMap *)
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const QWT_OVERRIDE
Draw the spectrogram.
void renderTile(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &tile, QImage *) const
Render a tile of an image.
virtual QwtRasterData::ContourLines renderContourLines(const QRectF &rect, const QSize &raster) const
Ignore all values, that are out of range.
void setZ(double z)
Set the z value.
virtual QPen contourPen(double level) const
Calculate the pen for a contour line.
QwtColorMap is used to map values into colors.
virtual QSize contourRasterSize(const QRectF &, const QRect &) const
Return the raster to be used by the CONREC contour algorithm.
static int sort(lua_State *L)
QwtRasterData::ConrecFlags conrecFlags
QwtPlotSpectrogram(const QString &title=QString())
const QwtRasterData * data() const
const QwtColorMap * colorMap() const
virtual double value(double x, double y) const =0
virtual QImage renderImage(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &area, const QSize &imageSize) const QWT_OVERRIDE
Render an image from data and color map.
QwtLinearColorMap builds a color map from color stops.
QList< double > contourLevels() const
double invTransform(double p) const
The map is intended to map into RGB values.
virtual void itemChanged()
int maxRGBTableSize() const
QVector< QRgb > colorTable
uint renderThreadCount() const
QFlags< ConrecFlag > ConrecFlags
Flags to modify the contour algorithm.
bool testAttribute(Attribute) const
QwtRasterData defines an interface to any type of raster data.
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
virtual void drawContourLines(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtRasterData::ContourLines &) const
static bool qwtIsNaN(double d)
void setItemAttribute(ItemAttribute, bool on=true)
double transform(double s) const
void setContourLevels(const QList< double > &)
double width() const
Return the width of an interval.
void setConrecFlag(QwtRasterData::ConrecFlag, bool on)
bool testDisplayMode(DisplayMode) const
const QwtText & title() const