19 #include <qalgorithms.h> 22 #include <qtconcurrentrun.h> 24 #define DEBUG_RENDER 0 27 #include <QElapsedTimer> 35 const uchar *ch = (
const uchar *)&d;
36 if ( QSysInfo::ByteOrder == QSysInfo::BigEndian )
38 return (ch[0] & 0x7f) == 0x7f && ch[1] > 0xf0;
42 return (ch[7] & 0x7f) == 0x7f && ch[6] > 0xf0;
176 if ( colorMap == NULL )
204 numColors = qMax( numColors, 0 );
232 const QColor &color, qreal width, Qt::PenStyle style )
457 const QRectF &area,
const QSize &imageSize )
const 459 if ( imageSize.isEmpty() ||
d_data->
data == NULL
466 if ( !intensityRange.
isValid() )
470 ? QImage::Format_ARGB32 : QImage::Format_Indexed8;
472 QImage image( imageSize, format );
484 #if !defined(QT_NO_QFUTURE) 487 if ( numThreads <= 0 )
488 numThreads = QThread::idealThreadCount();
490 if ( numThreads <= 0 )
493 const int numRows = imageSize.height() / numThreads;
495 QVector< QFuture<void> > futures;
496 futures.reserve( numThreads - 1 );
498 for ( uint
i = 0;
i < numThreads;
i++ )
500 QRect tile( 0,
i * numRows, image.width(), numRows );
501 if (
i == numThreads - 1 )
503 tile.setHeight( image.height() -
i * numRows );
508 futures += QtConcurrent::run(
510 xMap, yMap, tile, &image );
513 for (
int i = 0;
i < futures.size();
i++ )
514 futures[
i].waitForFinished();
517 const QRect tile( 0, 0, image.width(), image.height() );
522 const qint64 elapsed = time.elapsed();
523 qDebug() <<
"renderImage" << imageSize << elapsed;
544 const QRect &tile, QImage *image )
const 547 if ( range.
width() <= 0.0 )
558 for (
int y = tile.top();
y <= tile.bottom();
y++ )
562 QRgb *line =
reinterpret_cast<QRgb *
>( image->scanLine(
y ) );
565 for (
int x = tile.left();
x <= tile.right();
x++ )
575 else if ( numColors == 0 )
577 *line++ = colorMap->
rgb( range, value );
581 const uint index = colorMap->
colorIndex( numColors, range, value );
582 *line++ = rgbTable[index];
589 for (
int y = tile.top();
y <= tile.bottom();
y++ )
593 unsigned char *line = image->scanLine(
y );
596 for (
int x = tile.left();
x <= tile.right();
x++ )
609 *line++ =
static_cast<unsigned char>( index );
634 const QRectF &area,
const QRect &rect )
const 636 QSize raster = rect.size() / 2;
638 const QRectF pixelRect =
pixelHint( area );
639 if ( !pixelRect.isEmpty() )
641 const QSize res( qCeil( rect.width() / pixelRect.width() ),
642 qCeil( rect.height() / pixelRect.height() ) );
643 raster = raster.boundedTo( res );
660 const QRectF &rect,
const QSize &raster )
const 687 for (
int l = 0; l < numLevels; l++ )
692 if ( pen.style() == Qt::NoPen )
695 if ( pen.style() == Qt::NoPen )
698 painter->setPen( pen );
700 const QPolygonF &lines = contourLines[level];
701 for (
int i = 0;
i < lines.size();
i += 2 )
703 const QPointF p1( xMap.
transform( lines[
i].x() ),
705 const QPointF p2( xMap.
transform( lines[
i+1].x() ),
726 const QRectF &canvasRect )
const 734 const int margin = 2;
735 QRectF rasterRect( canvasRect.x() - margin, canvasRect.y() - margin,
736 canvasRect.width() + 2 * margin, canvasRect.height() + 2 * margin );
744 if ( area.isEmpty() )
751 raster = raster.boundedTo( rasterRect.toRect().size() );
752 if ( raster.isValid() )
virtual void discardRaster()
Discard a raster.
virtual void legendChanged()
virtual void drawContourLines(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtRasterData::ContourLines &lines) const
The data is displayed using contour lines.
virtual QRectF boundingRect() const
static void drawLine(QPainter *, double x1, double y1, double x2, double y2)
Wrapper for QPainter::drawLine()
virtual QRectF pixelHint(const QRectF &) const
Pixel hint.
virtual ~QwtPlotSpectrogram()
Destructor.
virtual QVector< QRgb > colorTable256() const
A class representing an interval.
A class, which displays raster data.
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)
virtual void initRaster(const QRectF &, const QSize &raster)
Initialize a raster.
virtual void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &rect) const
Draw the raster data.
QFlags< DisplayMode > DisplayModes
Display modes.
TFSIMD_FORCE_INLINE const tfScalar & y() const
Ignore all vertices on the same level.
bool testConrecFlag(QwtRasterData::ConrecFlag) const
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 QwtInterval interval(Qt::Axis) const
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
void setColorMap(QwtColorMap *)
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.
QwtRasterData::ConrecFlags conrecFlags
QwtPlotSpectrogram(const QString &title=QString())
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
TFSIMD_FORCE_INLINE const tfScalar & x() const
const QwtRasterData * data() const
const QwtColorMap * colorMap() const
virtual double value(double x, double y) const =0
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 draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &rect) const
Draw the spectrogram.
virtual void itemChanged()
int maxRGBTableSize() const
QVector< QRgb > colorTable
uint renderThreadCount() const
virtual QRectF pixelHint(const QRectF &) const
Pixel hint.
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
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
virtual QImage renderImage(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &area, const QSize &imageSize) const
Render an image from data and color map.
const QwtText & title() const
void renderTile(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &imageRect, QImage *image) const
Render a tile of an image.