Exemplo n.º 1
0
void VectorPlot::setupPlot(const QwtDoubleRect &rect) {
	QwtScaleDiv *hDiv = plot->axisScaleDiv(QwtPlot::xBottom);
	QwtScaleDiv *vDiv = plot->axisScaleDiv(QwtPlot::yLeft);
// In earlier qwt version some member function names are different from newer version
#if QWT_VERSION <= 0x050101
	double lLimit = std::min(hDiv->lBound(), rect.left());
	double rLimit = std::max(hDiv->hBound(), rect.right());
	double bLimit = std::min(vDiv->lBound(), rect.bottom());
	double tLimit = std::max(vDiv->hBound(), rect.top());
#else
	double lLimit = std::min(hDiv->lowerBound(), rect.left());
	double rLimit = std::max(hDiv->upperBound(), rect.right());
	double bLimit = std::min(vDiv->lowerBound(), rect.bottom());
	double tLimit = std::max(vDiv->upperBound(), rect.top());
#endif
	plot->setAxisScale(QwtPlot::xBottom, lLimit, rLimit);
	plot->setAxisScale(QwtPlot::yLeft, bLimit, tLimit);

	double xMargin = plot->invTransform(QwtPlot::xBottom, plot->margin());
	double yMargin = plot->invTransform(QwtPlot::yLeft, plot->margin());
	mBoundingRect = QwtDoubleRect(QwtDoublePoint(lLimit - xMargin, tLimit + yMargin),
								  QwtDoublePoint(rLimit + xMargin, bLimit - yMargin));

	qDebug() << "xMargin:" << xMargin;
	qDebug() << "yMargin:" << yMargin;
	qDebug() << "mBoundingRect:" << mBoundingRect;
//	mBoundingRect = rect;
}
Exemplo n.º 2
0
QList<QwtDoublePoint> QwtCircleClipper::cuttingPoints(
    Edge edge, const QwtDoublePoint &pos, double radius) const
{
    QList<QwtDoublePoint> points;

    if ( edge == Left || edge == Right )
    {
        const double x = (edge == Left) ? left() : right();
        if ( qwtAbs(pos.x() - x) < radius )
        {
            const double off = ::sqrt(qwtSqr(radius) - qwtSqr(pos.x() - x));
            const double y1 = pos.y() + off;
            if ( y1 >= top() && y1 <= bottom() )
                points += QwtDoublePoint(x, y1);
            const double y2 = pos.y() - off;
            if ( y2 >= top() && y2 <= bottom() )
                points += QwtDoublePoint(x, y2);
        }
    }
    else
    {
        const double y = (edge == Top) ? top() : bottom();
        if ( qwtAbs(pos.y() - y) < radius )
        {
            const double off = ::sqrt(qwtSqr(radius) - qwtSqr(pos.y() - y));
            const double x1 = pos.x() + off;
            if ( x1 >= left() && x1 <= right() )
                points += QwtDoublePoint(x1, y);
            const double x2 = pos.x() - off;
            if ( x2 >= left() && x2 <= right() )
                points += QwtDoublePoint(x2, y);
        }
    }
    return points;
}
Exemplo n.º 3
0
QwtDoubleRect VectorCurve::boundingRect() const {
	QwtDoubleRect rect = QwtPlotCurve::boundingRect();

	if (d_type == Graph::VectXYXY)
		rect |= vectorEnd->boundingRect();
	else
	{
		int rows = abs(d_end_row - d_start_row) + 1;
		for (int i = 0; i < rows; i++) {
			double x_i = x(i);
			double y_i = y(i);
			double angle = vectorEnd->x(i);
			double mag = vectorEnd->y(i);
			switch(d_position) {
				case Tail:
					rect |= QwtDoubleRect(x_i, y_i, mag*cos(angle), mag*sin(angle)).normalized();
					break;
				case Middle:
					{
						QwtDoubleRect rect_i(0, 0, fabs(mag*cos(angle)), fabs(mag*sin(angle)));
						rect_i.moveCenter(QwtDoublePoint(x_i, y_i));
						rect |= rect_i;
						break;
					}
				case Head:
					rect |= QwtDoubleRect(x_i, y_i, -mag*cos(angle), -mag*sin(angle)).normalized();
					break;
			}
		}
	}
	return rect;
}
Exemplo n.º 4
0
/*!
    Translate a point from pixel into plot coordinates
    \return Point in plot coordinates
    \sa QwtPlotPicker::transform()
*/
QwtDoublePoint QwtPlotPicker::invTransform(const QPoint &pos) const
{
    QwtScaleMap xMap = plot()->canvasMap(d_xAxis);
    QwtScaleMap yMap = plot()->canvasMap(d_yAxis);

    return QwtDoublePoint(
        xMap.invTransform(pos.x()),
        yMap.invTransform(pos.y())
    );
}
inline QwtDoublePoint QwtRasterData::ContourPlane::intersection(
    const Contour3DPoint& p1, const Contour3DPoint &p2) const
{
    const double h1 = p1.z() - d_z;
    const double h2 = p2.z() - d_z;

    const double x = (h2 * p1.x() - h1 * p2.x()) / (h2 - h1);
    const double y = (h2 * p1.y() - h1 * p2.y()) / (h2 - h1);

    return QwtDoublePoint(x, y);
}
Exemplo n.º 6
0
/*!
  Draw lines

  \param painter Painter
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param from index of the first point to be painted
  \param to index of the last point to be painted.
  \sa draw(), drawLines(), setCurveFitter()
*/
void QwtPolarCurve::drawLines( QPainter *painter,
                               const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
                               const QwtDoublePoint &pole, int from, int to ) const
{
  int size = to - from + 1;
  if ( size <= 0 )
    return;

  QwtPolygon polyline;
  if ( d_data->curveFitter )
  {
#if QT_VERSION < 0x040000
    QwtArray<QwtDoublePoint> points( size );
#else
    QwtPolygonF points( size );
#endif
    for ( int j = from; j <= to; j++ )
      points[j - from] = QwtDoublePoint( azimuth( j ), radius( j ) );

    points = d_data->curveFitter->fitCurve( points );

    polyline.resize( points.size() );
    for ( int i = 0; i < ( int )points.size(); i++ )
    {
      const QwtPolarPoint point( points[i].x(), points[i].y() );

      double r = radialMap.xTransform( point.radius() );
      const double a = azimuthMap.xTransform( point.azimuth() );
      polyline.setPoint( i, qwtPolar2Pos( pole, r, a ).toPoint() );
    }
  }
  else
  {
    polyline.resize( size );

    for ( int i = from; i <= to; i++ )
    {
      const QwtPolarPoint point = sample( i );

      double r = radialMap.xTransform( point.radius() );
      const double a = azimuthMap.xTransform( point.azimuth() );
      polyline.setPoint( i - from, qwtPolar2Pos( pole, r, a ).toPoint() );
    }
  }

  QRect clipRect = painter->window();
  clipRect.setRect( clipRect.x() - 1, clipRect.y() - 1,
                    clipRect.width() + 2, clipRect.height() + 2 );

  polyline = QwtClipper::clipPolygon( clipRect, polyline );

  QwtPainter::drawPolyline( painter, polyline );
}
Exemplo n.º 7
0
void LineMarker::setCoordEndPoint(const QwtDoublePoint& p)
{
if (QwtDoublePoint(d_rect.right(), d_rect.bottom()) == p)
	return;

d_rect.setRight(p.x());
d_rect.setBottom(p.y());

const QwtScaleMap &xMap = d_plot->canvasMap(xAxis());
const QwtScaleMap &yMap = d_plot->canvasMap(yAxis());

d_end = QPoint(xMap.transform(p.x()), yMap.transform(p.y()));
}
Exemplo n.º 8
0
void LineMarker::setCoordStartPoint(const QwtDoublePoint& p)
{
if (QwtDoublePoint(d_rect.left(), d_rect.top()) == p)
	return;

d_rect.setLeft(p.x());
d_rect.setTop(p.y());

const QwtScaleMap &xMap = d_plot->canvasMap(xAxis());
const QwtScaleMap &yMap = d_plot->canvasMap(yAxis());

d_start = QPoint(xMap.transform(p.x()), yMap.transform(p.y()));
}
Exemplo n.º 9
0
QwtDoublePoint QwtPolygonClipperF::intersectEdge(const QwtDoublePoint &p1, 
    const QwtDoublePoint &p2, Edge edge ) const
{
    double x=0.0, y=0.0;
    double m = 0;

    const double dy = p2.y() - p1.y();
    const double dx = p2.x() - p1.x();

    switch ( edge ) 
    {
        case Left:
            x = left();
            m = double(qwtAbs(p1.x() - x)) / qwtAbs(dx);
            y = p1.y() + int(dy * m);
            break;
        case Top:
            y = top();
            m = double(qwtAbs(p1.y() - y)) / qwtAbs(dy);
            x = p1.x() + int(dx * m);
            break;
        case Right:
            x = right();
            m = double(qwtAbs(p1.x() - x)) / qwtAbs(dx);
            y = p1.y() + int(dy * m);
            break;
        case Bottom:
            y = bottom();
            m = double(qwtAbs(p1.y() - y)) / qwtAbs(dy);
            x = p1.x() + int(dx * m);
            break;
        default:
            break;
    }

    return QwtDoublePoint(x,y);
}
Exemplo n.º 10
0
/*!
   \brief Calculate the bounding rect of the plot area

   The plot area depends on the zoom parameters.

   \param canvasRect Rectangle of the canvas
   \return Rectangle for displaying 100% of the plot
*/
QwtDoubleRect QwtPolarPlot::plotRect( const QRect &canvasRect ) const
{
  const QwtScaleDiv *sd = scaleDiv( QwtPolar::Radius );
  const QwtScaleEngine *se = scaleEngine( QwtPolar::Radius );

  const int margin = plotMarginHint();
  const QRect cr = canvasRect;
  const int radius = qwtMin( cr.width(), cr.height() ) / 2 - margin;

  QwtScaleMap map;
  map.setTransformation( se->transformation() );
  map.setPaintXInterval( 0.0, radius / d_data->zoomFactor );
#if QWT_VERSION < 0x050200
  map.setScaleInterval( sd->lBound(), sd->hBound() );
#else
  map.setScaleInterval( sd->lowerBound(), sd->upperBound() );
#endif

  double v = map.s1();
  if ( map.s1() <= map.s2() )
    v += d_data->zoomPos.radius();
  else
    v -= d_data->zoomPos.radius();
  v = map.xTransform( v );

  const QwtDoublePoint off =
    QwtPolarPoint( d_data->zoomPos.azimuth(), v ).toPoint();

  QwtDoublePoint center( cr.center().x(), cr.top() + margin + radius );
  center -= QwtDoublePoint( off.x(), -off.y() );

  QwtDoubleRect rect( 0, 0, 2 * map.p2(), 2 * map.p2() );
  rect.moveCenter( center );

  return rect;
}
//! Return Value
QwtDoublePoint QwtPlotMarker::value() const
{
    return QwtDoublePoint(d_data->xValue, d_data->yValue);
}
Exemplo n.º 12
0
QwtDoublePoint LineMarker::coordEndPoint()
{
return QwtDoublePoint(d_rect.right(), d_rect.bottom());
}
Exemplo n.º 13
0
QwtDoublePoint LineMarker::coordStartPoint()
{
return QwtDoublePoint(d_rect.left(), d_rect.top());
}
Exemplo n.º 14
0
QwtDoublePoint ArrowMarker::endPointCoord()
{
return QwtDoublePoint(d_rect.right(), d_rect.bottom());
}
Exemplo n.º 15
0
/*!
    Negates the coordinates of the point, and returns a point with the
    new coordinates. (Inversion).
*/
const QwtDoublePoint QwtDoublePoint::operator-() const
{
    return QwtDoublePoint(-d_x, -d_y);
}
Exemplo n.º 16
0
 inline QwtDoublePoint pos() const
 {
     return QwtDoublePoint(d_x, d_y);
 }
Exemplo n.º 17
0
/*!
    Divides the coordinates of the point by the given scale factor,
    and returns a point with the new coordinates.
    (Scalar division of a vector.)
*/
const QwtDoublePoint QwtDoublePoint::operator/(double factor) const
{
    return QwtDoublePoint(d_x / factor, d_y / factor);
}
Exemplo n.º 18
0
/*!
    Multiplies the coordinates of the point by the given scale factor,
    and returns a point with the new coordinates.
    (Scalar multiplication of a vector.)
*/
const QwtDoublePoint QwtDoublePoint::operator*(double factor) const
{
    return QwtDoublePoint(d_x * factor, d_y * factor);
}
Exemplo n.º 19
0
/*!
    Subtracts the coordinates of the other point from the corresponding
    coordinates of the given point, and returns a point with the new
    coordinates. (Vector subtraction.)
*/
const QwtDoublePoint QwtDoublePoint::operator-(
    const QwtDoublePoint &other) const
{
    return QwtDoublePoint(d_x - other.d_x, d_y - other.d_y);
}
Exemplo n.º 20
0
/*!
    Adds the coordinates of the point to the corresponding coordinates of
    the other point, and returns a point with the new coordinates.
    (Vector addition.)
*/
const QwtDoublePoint QwtDoublePoint::operator+(
    const QwtDoublePoint &other) const
{
    return QwtDoublePoint(d_x + other.d_x, d_y + other.d_y);
}
Exemplo n.º 21
0
QwtDoublePoint ArrowMarker::startPointCoord()
{
	return QwtDoublePoint(d_rect.left(), d_rect.top());
}
Exemplo n.º 22
0
//! Returns the center point of the rectangle.
QwtDoublePoint QwtDoubleRect::center() const
{
    return QwtDoublePoint(d_left + (d_right - d_left) / 2.0,
        d_top + (d_bottom - d_top) / 2.0);
}