Exemplo n.º 1
0
QgsConstWkbPtr QgsClipper::clippedLineWKB( QgsConstWkbPtr wkbPtr, const QgsRectangle& clipExtent, QPolygonF& line )
{
  QgsWKBTypes::Type wkbType = wkbPtr.readHeader();

  int nPoints;
  wkbPtr >> nPoints;

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

  if ( static_cast<int>( nPoints * ( 2 * sizeof( double ) + skipZM ) ) > wkbPtr.remaining() )
  {
    QgsDebugMsg( QString( "%1 points exceed wkb length (%2>%3)" ).arg( nPoints ).arg( nPoints * ( 2 * sizeof( double ) + skipZM ) ).arg( wkbPtr.remaining() ) );
    return QgsConstWkbPtr( nullptr, 0 );
  }

  double p0x, p0y, p1x = 0.0, p1y = 0.0; //original coordinates
  double p1x_c, p1y_c; //clipped end coordinates
  double lastClipX = 0.0, lastClipY = 0.0; //last successfully clipped coords

  line.clear();
  line.reserve( nPoints + 1 );

  for ( int i = 0; i < nPoints; ++i )
  {
    if ( i == 0 )
    {
      wkbPtr >> p1x >> p1y;
      wkbPtr += skipZM;
      continue;
    }
    else
    {
Exemplo n.º 2
0
QPolygonF read_line(uint8_t byte_order, InputIterator& itr, const frame& fr)
{
  const uint32_t count(brig::detail::ogc::read<uint32_t>(byte_order, itr));
  QPolygonF line; line.reserve(count);
  for (uint32_t i(0); i < count; ++i)
    line.push_back( read_point(byte_order, itr, fr) );
  return line;
}
Exemplo n.º 3
0
static QPolygonF toQPolygonF(const b2Vec2 *vertices, int32 vertexCount)
{
    QPolygonF polygon;
    polygon.reserve(vertexCount);

    for (int i = 0; i < vertexCount; ++i)
        polygon.append(toQPointF(vertices[i]));

    return polygon;
}
Exemplo n.º 4
0
QPolygonF b2Util::qPolygonF(const b2Vec2 *vertices, int32 vertexCount, const qreal &scaleRatio)
{
    QPolygonF polygon;
    polygon.reserve(vertexCount);

    for (int i = 0; i < vertexCount; ++i)
        polygon.append(qPointF(vertices[i], scaleRatio));

    return polygon;
}
Exemplo n.º 5
0
QPolygonF QgsCurve::asQPolygonF() const
{
  const int nb = numPoints();
  QPolygonF points;
  points.reserve( nb );
  for ( int i = 0; i < nb; ++i )
  {
    points << QPointF( xAt( i ), yAt( i ) );
  }
  return points;
}
Exemplo n.º 6
0
void CaptureWgt::drawArrow()
{
    pd->arrow->setVisible( pd->drawArrow );
    if ( pd->drawArrow )
    {
        QPointF back  = pd->arrowFrom;
        QPointF front = pd->arrowTo;
        if ( front == back )
            return;
        qreal iw = static_cast<qreal>( pd->img.size().width() );
        qreal ih = static_cast<qreal>( pd->img.size().height() );
        if ( pd->flipX )
        {
            front.setY( ih - front.y() );
            back.setY( ih - back.y() );
        }
        if ( pd->flipY )
        {
            front.setX( iw - front.x() );
            back.setX( iw - back.x() );
        }

        // ≈диничный сонаправленный вектор.
        QPointF a = front - back;
        qreal l = sqrt( a.x() * a.x() + a.y() * a.y () );
        a.setX( a.x() / l );
        a.setY( a.y() / l );
        // ≈диничный перпендикул¤рный сектор.
        QPointF b = QPointF( a.y(), -a.x() );
        // ѕараметры стрелки.
        const qreal w = 2.0; // Ўирина линии.
        const qreal h = 7.0; // Ўирина собственно треугольничка.

        QPolygonF path;
        path.reserve( 8 );
        QPen pen = QPen( Qt::darkBlue );
        pd->arrow->setPen( pen );
        QBrush brush = QBrush( QColor( 150, 150, 200, 100 ) );
        pd->arrow->setBrush( brush );
        path << ( back + w * b );
        path << ( front - h * a + w * b );
        path << ( front + h * ( b - a ) );
        path << ( front );
        path << ( front - h * ( b + a ) );
        path << ( front - h * a - w * b );
        path << ( back - w * b );
        path << ( back + w * b );
        pd->arrow->setPolygon( path );
    }
}
Exemplo n.º 7
0
QgsConstWkbPtr QgsClipper::clippedLineWKB( QgsConstWkbPtr& wkbPtr, const QgsRectangle& clipExtent, QPolygonF& line )
{
  QgsWKBTypes::Type wkbType = wkbPtr.readHeader();

  int nPoints;
  wkbPtr >> nPoints;

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

  if ( static_cast<int>( nPoints * ( 2 * sizeof( double ) + skipZM ) ) > wkbPtr.remaining() )
  {
    QgsDebugMsg( QString( "%1 points exceed wkb length (%2>%3)" ).arg( nPoints ).arg( nPoints * ( 2 * sizeof( double ) + skipZM ) ).arg( wkbPtr.remaining() ) );
    return QgsConstWkbPtr( nullptr, 0 );
  }

  double p0x, p0y, p1x = 0.0, p1y = 0.0; //original coordinates
  double p1x_c, p1y_c; //clipped end coordinates
  double lastClipX = 0.0, lastClipY = 0.0; //last successfully clipped coords

  QPolygonF pts;
  wkbPtr -= sizeof( unsigned int );
  wkbPtr >> pts;
  nPoints = pts.size();

  line.clear();
  line.reserve( nPoints + 1 );

  QPointF *ptr = pts.data();

  for ( int i = 0; i < nPoints; ++i, ++ptr )
  {
    if ( i == 0 )
    {
      p1x = ptr->rx();
      p1y = ptr->ry();
      continue;
    }
    else
    {
      p0x = p1x;
      p0y = p1y;

      p1x = ptr->rx();
      p1y = ptr->ry();

      p1x_c = p1x;
      p1y_c = p1y;
      if ( clipLineSegment( clipExtent.xMinimum(), clipExtent.xMaximum(), clipExtent.yMinimum(), clipExtent.yMaximum(),
                            p0x, p0y, p1x_c,  p1y_c ) )
      {
        bool newLine = !line.isEmpty() && ( !qgsDoubleNear( p0x, lastClipX ) || !qgsDoubleNear( p0y, lastClipY ) );
        if ( newLine )
        {
          //add edge points to connect old and new line
          connectSeparatedLines( lastClipX, lastClipY, p0x, p0y, clipExtent, line );
        }
        if ( line.size() < 1 || newLine )
        {
          //add first point
          line << QPointF( p0x, p0y );
        }

        //add second point
        lastClipX = p1x_c;
        lastClipY = p1y_c;
        line << QPointF( p1x_c,  p1y_c );
      }
    }
  }
  return wkbPtr;
}
Exemplo n.º 8
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();
    }
}