Esempio n. 1
0
/*!
   Insert stepCount() number of additional points between 2 elements
   of points.

   \param points Array of points
   \return Array of points including the additional points
*/
QPolygonF QwtPolarFitter::fitCurve( const QPolygonF &points ) const
{
    if ( d_data->stepCount <= 0 || points.size() <= 1 )
        return points;

    QPolygonF fittedPoints;

    int numPoints = points.size() + ( points.size() - 1 ) * d_data->stepCount;

    fittedPoints.resize( numPoints );

    int index = 0;
    fittedPoints[index++] = points[0];
    for ( int i = 1; i < points.size(); i++ )
    {
        const QPointF &p1 = points[i-1];
        const QPointF &p2 = points[i];

        const double dx = ( p2.x() - p1.x() ) / d_data->stepCount;
        const double dy = ( p2.y() - p1.y() ) / d_data->stepCount;
        for ( int j = 1; j <= d_data->stepCount; j++ )
        {
            const double x = p1.x() + j * dx;
            const double y = p1.y() + j * dy;

            fittedPoints[index++] = QPointF( x, y );
        }
    }
    fittedPoints.resize( index );

    return fittedPoints;
}
Esempio n. 2
0
inline void GraphPolygonClipperF::addPoint(QPolygonF &pa, uint pos, const GraphDoublePoint &point) const
{
    if ( uint(pa.size()) <= pos ) 
        pa.resize(pos + 5);

    pa[(int)pos] = point;
}
Esempio n. 3
0
void GeometryPainter::_convertRingToQPolygon(const OGRLinearRing* ring, QPolygonF& qp,
  const QMatrix& m)
{
  OGRPoint p;
  qp.resize(ring->getNumPoints());
  for (int i = 0; i < ring->getNumPoints(); i++)
  {
    ring->getPoint(i, &p);
    qp[i] = QPointF(m.map(QPointF(p.getX(), p.getY())) - QPointF(0.5, 0.5));
  }
}
Esempio n. 4
0
void GraphPolygonClipperF::clipEdge(Edge edge, 
    const QPolygonF &pa, QPolygonF &cpa) const
{
    if ( pa.count() == 0 )
    {
        cpa.resize(0);
        return;
    }

    unsigned int count = 0;

    GraphDoublePoint p1 = pa[0];
    if ( insideEdge(p1, edge) )
        addPoint(cpa, count++, p1);

    const uint nPoints = pa.size();
    for ( uint i = 1; i < nPoints; i++ )
    {
        const GraphDoublePoint p2 = pa[(int)i];
        if ( insideEdge(p2, edge) )
        {
            if ( insideEdge(p1, edge) )
                addPoint(cpa, count++, p2);
            else
            {
                addPoint(cpa, count++, intersectEdge(p1, p2, edge));
                addPoint(cpa, count++, p2);
            }
        }
        else
        {
            if ( insideEdge(p1, edge) )
                addPoint(cpa, count++, intersectEdge(p1, p2, edge));
        }
        p1 = p2;
    }
    cpa.resize(count);
}
Esempio n. 5
0
void
ViewerGL::Implementation::getPolygonTextureCoordinates(const QPolygonF & polygonPoints,
                                                       const RectD & texRect,
                                                       QPolygonF & texCoords)
{
    texCoords.resize( polygonPoints.size() );
    for (int i = 0; i < polygonPoints.size(); ++i) {
        const QPointF & polygonPoint = polygonPoints.at(i);
        QPointF texCoord;
        texCoord.setX( (polygonPoint.x() - texRect.x1) / texRect.width() ); // * (right - left));
        texCoord.setY( (polygonPoint.y() - texRect.y1) / texRect.height() ); // * (top - bottom));
        texCoords[i] = texCoord;
    }
}
Esempio n. 6
0
QgsConstWkbPtr QgsSymbolV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr wkbPtr, bool clipToExtent )
{
  QgsWKBTypes::Type wkbType = wkbPtr.readHeader();
  unsigned int nPoints;
  wkbPtr >> nPoints;

  const QgsCoordinateTransform* ct = context.coordinateTransform();
  const QgsMapToPixel& mtp = context.mapToPixel();

  //apply clipping for large lines to achieve a better rendering performance
  if ( clipToExtent && nPoints > 1 )
  {
    const QgsRectangle& e = context.extent();
    double cw = e.width() / 10;
    double ch = e.height() / 10;
    QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
    wkbPtr -= 1 + 2 * sizeof( int );
    wkbPtr = QgsClipper::clippedLineWKB( wkbPtr, clipRect, pts );
  }
  else
  {
    pts.resize( nPoints );

    int skipZM = ( QgsWKBTypes::coordDimensions( wkbType ) - 2 ) * sizeof( double );
    Q_ASSERT( skipZM >= 0 );

    QPointF *ptr = pts.data();
    for ( unsigned int i = 0; i < nPoints; ++i, ++ptr )
    {
      wkbPtr >> ptr->rx() >> ptr->ry();
      wkbPtr += skipZM;
    }
  }

  //transform the QPolygonF to screen coordinates
  if ( ct )
  {
    ct->transformPolygon( pts );
  }

  QPointF *ptr = pts.data();
  for ( int i = 0; i < pts.size(); ++i, ++ptr )
  {
    mtp.transformInPlace( ptr->rx(), ptr->ry() );
  }

  return wkbPtr;
}
Esempio n. 7
0
/*!
  Draw dots

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param canvasRect Contents rect of the canvas
  \param from index of the first point to be painted
  \param to index of the last point to be painted

  \sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps()
*/
void QwtPlotCurve::drawDots( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    const bool doFill = d_data->brush.style() != Qt::NoBrush;
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    QPolygonF polyline;
    if ( doFill )
        polyline.resize( to - from + 1 );

    QPointF *points = polyline.data();

    for ( int i = from; i <= to; i++ )
    {
        const QPointF sample = d_series->sample( i );
        double xi = xMap.transform( sample.x() );
        double yi = yMap.transform( sample.y() );
        if ( doAlign )
        {
            xi = qRound( xi );
            yi = qRound( yi );
        }

        QwtPainter::drawPoint( painter, QPointF( xi, yi ) );

        if ( doFill )
        {
            points[i - from].rx() = xi;
            points[i - from].ry() = yi;
        }
    }

    if ( doFill )
    {
        if ( d_data->paintAttributes & ClipPolygons )
            polyline = QwtClipper::clipPolygonF( canvasRect, polyline );

        fillCurve( painter, xMap, yMap, polyline );
    }
}
Esempio n. 8
0
//! Internal, used by the Outline style.
void QwtPlotHistogram::flushPolygon( QPainter *painter,
    double baseLine, QPolygonF &polygon ) const
{
    if ( polygon.size() == 0 )
        return;

    if ( orientation() == Qt::Horizontal )
        polygon += QPointF( baseLine, polygon.last().y() );
    else
        polygon += QPointF( polygon.last().x(), baseLine );

    if ( d_data->brush.style() != Qt::NoBrush )
    {
        painter->setPen( Qt::NoPen );
        painter->setBrush( d_data->brush );

        if ( orientation() == Qt::Horizontal )
        {
            polygon += QPointF( polygon.last().x(), baseLine );
            polygon += QPointF( polygon.first().x(), baseLine );
        }
        else
        {
            polygon += QPointF( baseLine, polygon.last().y() );
            polygon += QPointF( baseLine, polygon.first().y() );
        }
        QwtPainter::drawPolygon( painter, polygon );
	int resize = polygon.size();
	if ( resize > 1 )
	    resize -= 2;
        polygon.resize( resize );
    }
    if ( d_data->pen.style() != Qt::NoPen )
    {
        painter->setBrush( Qt::NoBrush );
        painter->setPen( d_data->pen );
        QwtPainter::drawPolyline( painter, polygon );
    }
    polygon.clear();
}
Esempio n. 9
0
QPolygonF calcLines(const QStyleOptionSlider *dial)
{
    QPolygonF poly;
    int width = dial->rect.width();
    int height = dial->rect.height();
    qreal r = qMin(width, height) / 2;
    int bigLineSize = calcBigLineSize(int(r));

    qreal xc = width / 2 + 0.5;
    qreal yc = height / 2 + 0.5;
    const int ns = dial->tickInterval;
    if (!ns) // Invalid values may be set by Qt Designer.
        return poly;
    int notches = (dial->maximum + ns - 1 - dial->minimum) / ns;
    if (notches <= 0)
        return poly;
    if (dial->maximum < dial->minimum || dial->maximum - dial->minimum > 1000) {
        int maximum = dial->minimum + 1000;
        notches = (maximum + ns - 1 - dial->minimum) / ns;
    }

    poly.resize(2 + 2 * notches);
    int smallLineSize = bigLineSize / 2;
    for (int i = 0; i <= notches; ++i) {
        qreal angle = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches
                  : (Q_PI * 8 - i * 10 * Q_PI / notches) / 6;
        qreal s = qSin(angle);
        qreal c = qCos(angle);
        if (i == 0 || (((ns * i) % (dial->pageStep ? dial->pageStep : 1)) == 0)) {
            poly[2 * i] = QPointF(xc + (r - bigLineSize) * c,
                                  yc - (r - bigLineSize) * s);
            poly[2 * i + 1] = QPointF(xc + r * c, yc - r * s);
        } else {
            poly[2 * i] = QPointF(xc + (r - 1 - smallLineSize) * c,
                                  yc - (r - 1 - smallLineSize) * s);
            poly[2 * i + 1] = QPointF(xc + (r - 1) * c, yc -(r - 1) * s);
        }
    }
    return poly;
}
Esempio n. 10
0
/*!
  Draw a tube

  Builds 2 curves from the upper and lower limits of the intervals
  and draws them with the pen(). The area between the curves is
  filled with the brush().

  \param painter Painter
  \param xMap Maps x-values into pixel coordinates.
  \param yMap Maps y-values into pixel coordinates.
  \param canvasRect Contents rect of the canvas
  \param from Index of the first sample to be painted
  \param to Index of the last sample to be painted. If to < 0 the
         series will be painted to its last sample.

  \sa drawSeries(), drawSymbols()
*/
void QwtPlotIntervalCurve::drawTube( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    painter->save();

    const size_t size = to - from + 1;
    QPolygonF polygon( 2 * size );
    QPointF *points = polygon.data();

    for ( uint i = 0; i < size; i++ )
    {
        QPointF &minValue = points[i];
        QPointF &maxValue = points[2 * size - 1 - i];

        const QwtIntervalSample intervalSample = sample( from + i );
        if ( orientation() == Qt::Vertical )
        {
            double x = xMap.transform( intervalSample.value );
            double y1 = yMap.transform( intervalSample.interval.minValue() );
            double y2 = yMap.transform( intervalSample.interval.maxValue() );
            if ( doAlign )
            {
                x = qRound( x );
                y1 = qRound( y1 );
                y2 = qRound( y2 );
            }

            minValue.rx() = x;
            minValue.ry() = y1;
            maxValue.rx() = x;
            maxValue.ry() = y2;
        }
        else
        {
            double y = yMap.transform( intervalSample.value );
            double x1 = xMap.transform( intervalSample.interval.minValue() );
            double x2 = xMap.transform( intervalSample.interval.maxValue() );
            if ( doAlign )
            {
                y = qRound( y );
                x1 = qRound( x1 );
                x2 = qRound( x2 );
            }

            minValue.rx() = x1;
            minValue.ry() = y;
            maxValue.rx() = x2;
            maxValue.ry() = y;
        }
    }

    if ( d_data->brush.style() != Qt::NoBrush )
    {
        painter->setPen( QPen( Qt::NoPen ) );
        painter->setBrush( d_data->brush );

        if ( d_data->paintAttributes & ClipPolygons )
        {
            const qreal m = 1.0;
            const QPolygonF p = QwtClipper::clipPolygonF( 
                canvasRect.adjusted(-m, -m, m, m), polygon, true );

            QwtPainter::drawPolygon( painter, p );
        }
        else
        {
            QwtPainter::drawPolygon( painter, polygon );
        }
    }

    if ( d_data->pen.style() != Qt::NoPen )
    {
        painter->setPen( d_data->pen );
        painter->setBrush( Qt::NoBrush );

        if ( d_data->paintAttributes & ClipPolygons )
        {
            QPolygonF p;

            p.resize( size );
            qMemCopy( p.data(), points, size * sizeof( QPointF ) );
            p = QwtClipper::clipPolygonF( canvasRect, p );
            QwtPainter::drawPolyline( painter, p );

            p.resize( size );
            qMemCopy( p.data(), points + size, size * sizeof( QPointF ) );
            p = QwtClipper::clipPolygonF( canvasRect, p );
            QwtPainter::drawPolyline( painter, p );
        }
        else
        {
            QwtPainter::drawPolyline( painter, points, size );
            QwtPainter::drawPolyline( painter, points + size, size );
        }
    }

    painter->restore();
}
Esempio n. 11
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 QPointF &pole, int from, int to ) const
{
    int size = to - from + 1;
    if ( size <= 0 )
        return;

    QPolygonF polyline;
    if ( d_data->curveFitter )
    {
        QPolygonF points( size );
        for ( int j = from; j <= to; j++ )
        {
            const QwtPointPolar point = sample( j );
            points[j - from] = QPointF( point.azimuth(), point.radius() );
        }

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

        polyline.resize( points.size() );

        QPointF *polylineData = polyline.data();
        QPointF *pointsData = points.data();

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

            double r = radialMap.transform( point.radius() );
            const double a = azimuthMap.transform( point.azimuth() );

            polylineData[i] = qwtPolar2Pos( pole, r, a );
        }
    }
    else
    {
        polyline.resize( size );
        QPointF *polylineData = polyline.data();

        for ( int i = from; i <= to; i++ )
        {
            QwtPointPolar point = sample( i );
            if ( !qwtInsidePole( radialMap, point.radius() ) )
            {
                double r = radialMap.transform( point.radius() );
                const double a = azimuthMap.transform( point.azimuth() );
                polylineData[i - from] = qwtPolar2Pos( pole, r, a );
            }
            else
            {
                polylineData[i - from] = pole;
            }
        }
    }

    QRectF clipRect;
    if ( painter->hasClipping() )
        clipRect = painter->clipRegion().boundingRect();
    else
    {
        clipRect = painter->window();
        if ( !clipRect.isEmpty() )
            clipRect = painter->transform().inverted().mapRect( clipRect );
    }

    if ( !clipRect.isEmpty() )
    {
        double off = qCeil( qMax( 1.0, painter->pen().widthF() ) );
        clipRect = clipRect.toRect().adjusted( -off, -off, off, off );
        polyline = QwtClipper::clipPolygonF( clipRect, polyline );
    }

    QwtPainter::drawPolyline( painter, polyline );
    painter->drawPolyline( polyline );
}
Esempio n. 12
0
void DataCurve::loadData()
{
    Graph *g = (Graph *)plot();
    if (!g)
        return;

    int xcol = d_x_table->colIndex(d_x_column);
    int ycol = d_table->colIndex(title().text());
    if (xcol < 0 || ycol < 0) {
        remove();
        return;
    }

    int rows = d_table->numRows();
    if (d_end_row < 0 || d_end_row >= rows)
        d_end_row = rows - 1;

    int xColType = d_x_table->columnType(xcol);
    int yColType = d_table->columnType(ycol);
    int r = abs(d_end_row - d_start_row) + 1;

    QPolygonF data;
    data.reserve(r);

    QStringList xLabels, yLabels;// store text labels

    int xAxis = QwtPlot::xBottom;
    if (d_type == Graph::HorizontalBars)
        xAxis = QwtPlot::yLeft;

    QString date_time_fmt = d_table->columnFormat(xcol);
    int size = 0, from = 0;
    d_data_ranges.clear();
    for (int i = d_start_row; i <= d_end_row; i++ ) {
        QString xval = d_x_table->text(i, xcol);
        QString yval = d_table->text(i, ycol);
        if (!xval.isEmpty() && !yval.isEmpty()) {
            bool valid_data = true;
            QPointF p;
            if (xColType == Table::Text) {
                xLabels << xval;
                p.setX((double)(size + 1));
            } else if (xColType == Table::Time)
                p.setX(Table::fromTime(QTime::fromString(xval.trimmed(), date_time_fmt)));
            else if (xColType == Table::Date)
                p.setX(Table::fromDateTime(QDateTime::fromString(xval.trimmed(), date_time_fmt)));
            else
                p.setX(g->locale().toDouble(xval, &valid_data));

            if (yColType == Table::Text) {
                yLabels << yval;
                p.setY((double)(size + 1));
            } else
                p.setY(g->locale().toDouble(yval, &valid_data));

            if (valid_data) {
                data << p;
                size++;
            }
        } else if (from < size) {
            DataRange range;
            range.from = from;
            range.to = size - 1;
            d_data_ranges.push_back(range);
            from = size;
        }
    }

    if (d_data_ranges.size() && from < size) {
        DataRange range;
        range.from = from;
        range.to = size - 1;
        d_data_ranges.push_back(range);
    }

    if (!size) {
        remove();
        return;
    }
    data.resize(size);

    if (g->isWaterfallPlot()) {
        int index = g->curveIndex(this);
        int curves = g->curveCount();
        DataCurve *c = g->dataCurve(0);
        if (index > 0 && c) {
            double xmin = c->minXValue();
            double dx = index*g->waterfallXOffset()*0.01*g->canvas()->width()/(double)(curves - 1);
            d_x_offset = g->invTransform(xAxis, g->transform(xAxis, xmin) + dx) - xmin;

            double ymin = c->minYValue();
            double dy = index*g->waterfallYOffset()*0.01*g->canvas()->height()/(double)(curves - 1);
            d_y_offset = ymin - g->invTransform(yAxis(), g->transform(yAxis(), ymin) + dy);

            setZ(-index);
            setBaseline(d_y_offset);
            data.translate(d_x_offset, d_y_offset);
        } else {
            setZ(0);
            setBaseline(0.0);
        }
        if (g->grid())
            g->grid()->setZ(-g->curveCount() - 1);
    }

    double speedTol = g->getDouglasPeukerTolerance();
    if (speedTol != 0.0 && size >= g->speedModeMaxPoints()) {
        QwtWeedingCurveFitter *fitter = new QwtWeedingCurveFitter(speedTol);
        data = fitter->fitCurve(data);
        delete fitter;
    }

    if (d_type == Graph::HorizontalBars) {
        size = data.size();
        for (int i = 0; i < size; i++) {
            QPointF p = data.at(i);
            data[i] = QPointF(p.y(), p.x());
        }
    }

    setData(data);
    foreach(ErrorBarsCurve *c, d_error_bars)
        c->setData(data);

    if (xColType == Table::Text)
        g->setLabelsTextFormat(xAxis, ScaleDraw::Text, d_x_column, xLabels);
    if (yColType == Table::Text)
        g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, title().text(), yLabels);

    setRenderHint(QwtPlotItem::RenderAntialiased, g->isCurveAntialiasingEnabled(this));

    if (!d_labels_list.isEmpty()) {
        ((Graph*)plot())->updatePlot();
        loadLabels();
    }
}