10#include "qwt_raster_data.h"
11#include "qwt_point_3d.h"
12#include "qwt_interval.h"
20class QwtRasterData::ContourPlane
23 explicit inline ContourPlane(
double z ):
28 inline bool intersect(
const QwtPoint3D vertex[3],
29 QPointF line[2],
bool ignoreOnPlane )
const;
31 inline double z()
const {
return m_z; }
34 inline int compare(
double z )
const;
35 inline QPointF intersection(
41inline bool QwtRasterData::ContourPlane::intersect(
43 bool ignoreOnPlane )
const
48 const int eq1 = compare( vertex[0].z() );
49 const int eq2 = compare( vertex[1].z() );
50 const int eq3 = compare( vertex[2].z() );
65 static const int tab[3][3][3] =
68 { { 0, 0, 8 }, { 0, 2, 5 }, { 7, 6, 9 } },
69 { { 0, 3, 4 }, { 1, 10, 1 }, { 4, 3, 0 } },
70 { { 9, 6, 7 }, { 5, 2, 0 }, { 8, 0, 0 } }
73 const int edgeType = tab[eq1 + 1][eq2 + 1][eq3 + 1];
94 line[1] = intersection( vertex[1], vertex[2] );
99 line[1] = intersection( vertex[2], vertex[0] );
104 line[1] = intersection( vertex[0], vertex[1] );
108 line[0] = intersection( vertex[0], vertex[1] );
109 line[1] = intersection( vertex[1], vertex[2] );
113 line[0] = intersection( vertex[1], vertex[2] );
114 line[1] = intersection( vertex[2], vertex[0] );
118 line[0] = intersection( vertex[2], vertex[0] );
119 line[1] = intersection( vertex[0], vertex[1] );
141inline int QwtRasterData::ContourPlane::compare(
double z )
const
152inline QPointF QwtRasterData::ContourPlane::intersection(
155 const double h1 = p1.
z() - m_z;
156 const double h2 = p2.
z() - m_z;
158 const double x = ( h2 * p1.
x() - h1 * p2.
x() ) / ( h2 - h1 );
159 const double y = ( h2 * p1.
y() - h1 * p2.
y() ) / ( h2 - h1 );
161 return QPointF( x, y );
164class QwtRasterData::PrivateData
173 m_data =
new PrivateData();
192 m_data->attributes |= attribute;
194 m_data->attributes &= ~attribute;
203 return m_data->attributes & attribute;
287 const QRectF& rect,
const QSize& raster,
292 if ( levels.size() == 0 || !rect.isValid() || !raster.isValid() )
295 const double dx = rect.width() / raster.width();
296 const double dy = rect.height() / raster.height();
298 const bool ignoreOnPlane =
302 bool ignoreOutOfRange =
false;
309 for (
int y = 0; y < raster.height() - 1; y++ )
325 for (
int x = 0; x < raster.width() - 1; x++ )
327 const QPointF pos( rect.x() + x * dx, rect.y() + y * dy );
331 xy[TopRight].
setX( pos.x() );
332 xy[TopRight].
setY( pos.y() );
334 value( xy[TopRight].x(), xy[TopRight].y() )
337 xy[BottomRight].
setX( pos.x() );
338 xy[BottomRight].
setY( pos.y() + dy );
339 xy[BottomRight].
setZ(
340 value( xy[BottomRight].x(), xy[BottomRight].y() )
344 xy[TopLeft] = xy[TopRight];
345 xy[BottomLeft] = xy[BottomRight];
347 xy[TopRight].
setX( pos.x() + dx );
348 xy[TopRight].
setY( pos.y() );
349 xy[BottomRight].
setX( pos.x() + dx );
350 xy[BottomRight].
setY( pos.y() + dy );
353 value( xy[TopRight].x(), xy[TopRight].y() )
355 xy[BottomRight].
setZ(
356 value( xy[BottomRight].x(), xy[BottomRight].y() )
359 double zMin = xy[TopLeft].
z();
363 for (
int i = TopRight; i <= BottomLeft; i++ )
365 const double z = xy[i].
z();
374 if ( qIsNaN( zSum ) )
380 if ( ignoreOutOfRange )
386 if ( zMax < levels[0] ||
387 zMin > levels[levels.size() - 1] )
392 xy[Center].
setX( pos.x() + 0.5 * dx );
393 xy[Center].
setY( pos.y() + 0.5 * dy );
394 xy[Center].
setZ( 0.25 * zSum );
396 const int numLevels = levels.size();
397 for (
int l = 0; l < numLevels; l++ )
399 const double level = levels[l];
400 if ( level < zMin || level > zMax )
403 const ContourPlane plane( level );
408 for (
int m = TopLeft; m < NumPositions; m++ )
412 vertex[2] = xy[m != BottomLeft ? m + 1 : TopLeft];
414 const bool intersects =
415 plane.intersect( vertex, line, ignoreOnPlane );
A class representing an interval.
bool contains(double value) const
QwtPoint3D class defines a 3D point in double coordinates.
void setY(double y)
Sets the y-coordinate of the point to the value specified by y.
void setZ(double y)
Sets the z-coordinate of the point to the value specified by z.
void setX(double x)
Sets the x-coordinate of the point to the value specified by x.
QwtRasterData defines an interface to any type of raster data.
virtual QRectF pixelHint(const QRectF &) const
Pixel hint.
bool testAttribute(Attribute) const
QwtRasterData()
Constructor.
QFlags< ConrecFlag > ConrecFlags
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.
QFlags< Attribute > Attributes
virtual ContourLines contourLines(const QRectF &rect, const QSize &raster, const QList< double > &levels, ConrecFlags) const
virtual ~QwtRasterData()
Destructor.
void setAttribute(Attribute, bool on=true)
Attribute
Raster data attributes.
virtual QwtInterval interval(Qt::Axis) const =0
@ IgnoreOutOfRange
Ignore all values, that are out of range.
@ IgnoreAllVerticesOnLevel
Ignore all vertices on the same level.