QwtRasterData defines an interface to any type of raster data. More...
#include <qwt_raster_data.h>
Classes | |
class | Contour3DPoint |
class | ContourPlane |
Public Types | |
enum | ConrecAttribute { IgnoreAllVerticesOnLevel = 1, IgnoreOutOfRange = 2 } |
Attribute to modify the contour algorithm. More... | |
typedef QMap< double, QMemArray< QwtDoublePoint > > | ContourLines |
Public Member Functions | |
QwtRasterData () | |
Constructor. | |
QwtRasterData (const QwtDoubleRect &) | |
virtual | ~QwtRasterData () |
Destructor. | |
virtual QwtRasterData * | copy () const =0 |
Clone the data. | |
virtual void | setBoundingRect (const QwtDoubleRect &) |
QwtDoubleRect | boundingRect () const |
virtual QSize | rasterHint (const QwtDoubleRect &) const |
Find the raster of the data for an area. | |
virtual void | initRaster (const QwtDoubleRect &, const QSize &raster) |
Initialize a raster. | |
virtual void | discardRaster () |
Discard a raster. | |
virtual double | value (double x, double y) const =0 |
virtual QwtDoubleInterval | range () const =0 |
virtual ContourLines | contourLines (const QwtDoubleRect &rect, const QSize &raster, const QValueList< double > &levels, int flags) const |
QwtRasterData defines an interface to any type of raster data.
QwtRasterData is an abstract interface, that is used by QwtPlotRasterItem to find the values at the pixels of its raster.
Often a raster item is used to display values from a matrix. Then the derived raster data class needs to implement some sort of resampling, that maps the raster of the matrix into the requested raster of the raster item ( depending on resolution and scales of the canvas ).
Definition at line 61 of file qwt_raster_data.h.
typedef QMap<double, QMemArray <QwtDoublePoint> > QwtRasterData::ContourLines |
Definition at line 67 of file qwt_raster_data.h.
Attribute to modify the contour algorithm.
Definition at line 71 of file qwt_raster_data.h.
{ IgnoreAllVerticesOnLevel = 1, IgnoreOutOfRange = 2 };
QwtRasterData::QwtRasterData | ( | ) |
QwtRasterData::QwtRasterData | ( | const QwtDoubleRect & | boundingRect ) |
Constructor
boundingRect | Bounding rectangle |
Definition at line 195 of file qwt_raster_data.cpp.
: d_boundingRect(boundingRect) { }
QwtRasterData::~QwtRasterData | ( | ) | [virtual] |
QwtDoubleRect QwtRasterData::boundingRect | ( | ) | const |
Definition at line 220 of file qwt_raster_data.cpp.
Referenced by QwtPlotSpectrogram::boundingRect(), and setBoundingRect().
{
return d_boundingRect;
}
QwtRasterData::ContourLines QwtRasterData::contourLines | ( | const QwtDoubleRect & | rect, |
const QSize & | raster, | ||
const QValueList< double > & | levels, | ||
int | flags | ||
) | const [virtual] |
Calculate contour lines
An adaption of CONREC, a simple contouring algorithm. http://local.wasp.uwa.edu.au/~pbourke/papers/conrec/
Definition at line 292 of file qwt_raster_data.cpp.
References QwtDoubleInterval::contains(), IgnoreAllVerticesOnLevel, int(), QwtRasterData::ContourPlane::intersect(), QwtDoubleInterval::isValid(), QwtRasterData::Contour3DPoint::setPos(), QwtRasterData::Contour3DPoint::setZ(), and QwtRasterData::Contour3DPoint::z().
Referenced by QwtPlotSpectrogram::renderContourLines().
{ ContourLines contourLines; if ( levels.size() == 0 || !rect.isValid() || !raster.isValid() ) return contourLines; const double dx = rect.width() / raster.width(); const double dy = rect.height() / raster.height(); const bool ignoreOnPlane = flags & QwtRasterData::IgnoreAllVerticesOnLevel; const QwtDoubleInterval range = this->range(); bool ignoreOutOfRange = false; if ( range.isValid() ) ignoreOutOfRange = flags & IgnoreOutOfRange; ((QwtRasterData*)this)->initRaster(rect, raster); for ( int y = 0; y < raster.height() - 1; y++ ) { enum Position { Center, TopLeft, TopRight, BottomRight, BottomLeft, NumPositions }; Contour3DPoint xy[NumPositions]; for ( int x = 0; x < raster.width() - 1; x++ ) { const QwtDoublePoint pos(rect.x() + x * dx, rect.y() + y * dy); if ( x == 0 ) { xy[TopRight].setPos(pos.x(), pos.y()); xy[TopRight].setZ( value( xy[TopRight].x(), xy[TopRight].y()) ); xy[BottomRight].setPos(pos.x(), pos.y() + dy); xy[BottomRight].setZ( value(xy[BottomRight].x(), xy[BottomRight].y()) ); } xy[TopLeft] = xy[TopRight]; xy[BottomLeft] = xy[BottomRight]; xy[TopRight].setPos(pos.x() + dx, pos.y()); xy[BottomRight].setPos(pos.x() + dx, pos.y() + dy); xy[TopRight].setZ( value(xy[TopRight].x(), xy[TopRight].y()) ); xy[BottomRight].setZ( value(xy[BottomRight].x(), xy[BottomRight].y()) ); double zMin = xy[TopLeft].z(); double zMax = zMin; double zSum = zMin; for ( int i = TopRight; i <= BottomLeft; i++ ) { const double z = xy[i].z(); zSum += z; if ( z < zMin ) zMin = z; if ( z > zMax ) zMax = z; } if ( ignoreOutOfRange ) { if ( !range.contains(zMin) || !range.contains(zMax) ) continue; } if ( zMax < levels[0] || zMin > levels[levels.size() - 1] ) { continue; } xy[Center].setPos(pos.x() + 0.5 * dx, pos.y() + 0.5 * dy); xy[Center].setZ(0.25 * zSum); const int numLevels = (int)levels.size(); for (int l = 0; l < numLevels; l++) { const double level = levels[l]; if ( level < zMin || level > zMax ) continue; #if QT_VERSION >= 0x040000 QPolygonF &lines = contourLines[level]; #else QwtArray<QwtDoublePoint> &lines = contourLines[level]; #endif const ContourPlane plane(level); QwtDoublePoint line[2]; Contour3DPoint vertex[3]; for (int m = TopLeft; m < NumPositions; m++) { vertex[0] = xy[m]; vertex[1] = xy[0]; vertex[2] = xy[m != BottomLeft ? m + 1 : TopLeft]; const bool intersects = plane.intersect(vertex, line, ignoreOnPlane); if ( intersects ) { #if QT_VERSION >= 0x040000 lines += line[0]; lines += line[1]; #else const int index = lines.size(); lines.resize(lines.size() + 2, QGArray::SpeedOptim); lines[index] = line[0]; lines[index+1] = line[1]; #endif } } } } } ((QwtRasterData*)this)->discardRaster(); return contourLines; }
virtual QwtRasterData* QwtRasterData::copy | ( | ) | const [pure virtual] |
Clone the data.
Implemented in QwtPlotSpectrogram::PrivateData::DummyData.
Referenced by QwtPlotSpectrogram::setData().
void QwtRasterData::discardRaster | ( | ) | [virtual] |
Discard a raster.
After the composition of an image QwtPlotSpectrogram calls discardRaster().
The default implementation does nothing, but if data has been loaded in initRaster(), it could deleted now.
Definition at line 254 of file qwt_raster_data.cpp.
Referenced by QwtPlotSpectrogram::renderImage().
{ }
void QwtRasterData::initRaster | ( | const QwtDoubleRect & | , |
const QSize & | raster | ||
) | [virtual] |
Initialize a raster.
Before the composition of an image QwtPlotSpectrogram calls initRaster, announcing the area and its resolution that will be requested.
The default implementation does nothing, but for data sets that are stored in files, it might be good idea to reimplement initRaster, where the data is resampled and loaded into memory.
rect | Area of the raster |
raster | Number of horizontal and vertical pixels |
Definition at line 240 of file qwt_raster_data.cpp.
Referenced by QwtPlotSpectrogram::renderImage().
{ }
virtual QwtDoubleInterval QwtRasterData::range | ( | ) | const [pure virtual] |
Implemented in QwtPlotSpectrogram::PrivateData::DummyData.
Referenced by QwtPlotSpectrogram::contourPen(), QwtPlotSpectrogram::drawContourLines(), and QwtPlotSpectrogram::renderImage().
QSize QwtRasterData::rasterHint | ( | const QwtDoubleRect & | ) | const [virtual] |
Find the raster of the data for an area.
The resolution is the number of horizontal and vertical pixels that the data can return for an area. An invalid resolution indicates that the data can return values for any detail level.
The resolution will limit the size of the image that is rendered from the data. F.e. this might be important when printing a spectrogram to a A0 printer with 600 dpi.
The default implementation returns an invalid resolution (size)
rect | In most implementations the resolution of the data doesn't depend on the requested rectangle. |
Definition at line 276 of file qwt_raster_data.cpp.
Referenced by QwtPlotSpectrogram::contourRasterSize(), QwtPlotSpectrogram::rasterHint(), and QwtPlotSpectrogram::renderImage().
{ return QSize(); // use screen resolution }
void QwtRasterData::setBoundingRect | ( | const QwtDoubleRect & | boundingRect ) | [virtual] |
Set the bounding rect ( == area, un plot coordinates )
boundingRect | Bounding rectangle |
Definition at line 211 of file qwt_raster_data.cpp.
References boundingRect().
{ d_boundingRect = boundingRect; }
virtual double QwtRasterData::value | ( | double | x, |
double | y | ||
) | const [pure virtual] |
x | X value in plot coordinates |
y | Y value in plot coordinates |
Implemented in QwtPlotSpectrogram::PrivateData::DummyData.
Referenced by QwtPlotSpectrogram::renderImage().