Exemplo n.º 1
0
void CPlotData::setLimits()
{
    if(lines.size() == 0 || badData)
    {
        return;
    }

    QList<line_t>::const_iterator line  = lines.begin();
    if(line == lines.end()) return;
    QPolygonF::const_iterator p         = line->points.begin();

    xmin = p->x();
    xmax = p->x();
    ymin = p->y();
    ymax = p->y();

    while(line != lines.end())
    {
        QPolygonF::const_iterator p = line->points.begin();
        while(p != line->points.end())
        {
            if(p->x() > xmax) xmax = p->x();
            if(p->x() < xmin) xmin = p->x();
            if(p->y() > ymax) ymax = p->y();
            if(p->y() < ymin) ymin = p->y();
            ++p;
        }

        ++line;
    }

    xaxis->setLimits(xmin,xmax);
    yaxis->setLimits(ymin,ymax);
}
Exemplo n.º 2
0
void QgsMarkerLineSymbolLayerV2::renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context )
{
  if ( points.size() > 0 )
  {
    // calc length
    qreal length = 0;
    QPolygonF::const_iterator it = points.constBegin();
    QPointF last = *it;
    for ( ++it; it != points.constEnd(); ++it )
    {
      length += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
                     ( last.y() - it->y() ) * ( last.y() - it->y() ) );
      last = *it;
    }

    // find the segment where the central point lies
    it = points.constBegin();
    last = *it;
    qreal last_at = 0, next_at = 0;
    QPointF next;
    int segment = 0;
    for ( ++it; it != points.constEnd(); ++it )
    {
      next = *it;
      next_at += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
                      ( last.y() - it->y() ) * ( last.y() - it->y() ) );
      if ( next_at >= length / 2 )
        break; // we have reached the center
      last = *it;
      last_at = next_at;
      segment++;
    }

    // find out the central point on segment
    MyLine l( last, next ); // for line angle
    qreal k = ( length * 0.5 - last_at ) / ( next_at - last_at );
    QPointF pt = last + ( next - last ) * k;

    // draw the marker
    double origAngle = mMarker->angle();
    if ( mRotateMarker )
      mMarker->setAngle( origAngle + l.angle() * 180 / M_PI );
    mMarker->renderPoint( pt, context.feature(), context.renderContext(), -1, context.selected() );
    if ( mRotateMarker )
      mMarker->setAngle( origAngle );
  }
}
Exemplo n.º 3
0
void
ViewerGL::Implementation::drawCheckerboardTexture(const QPolygonF& polygon)
{
    ///We divide by 2 the tiles count because one texture is 4 tiles actually
    QPointF topLeft, btmRight;
    double screenW, screenH;
    {
        QMutexLocker l(&zoomCtxMutex);
        topLeft = zoomCtx.toZoomCoordinates(0, 0);
        screenW = zoomCtx.screenWidth();
        screenH = zoomCtx.screenHeight();
        btmRight = zoomCtx.toZoomCoordinates(screenW - 1, screenH - 1);
    }
    double xTilesCountF = screenW / (checkerboardTileSize * 4); //< 4 because the texture contains 4 tiles
    double yTilesCountF = screenH / (checkerboardTileSize * 4);
    GLuint savedTexture;

    GL_GPU::glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&savedTexture);
    {
        GLProtectAttrib<GL_GPU> a(GL_ENABLE_BIT);

        GL_GPU::glEnable(GL_TEXTURE_2D);
        GL_GPU::glBindTexture(GL_TEXTURE_2D, checkerboardTextureID);
        GL_GPU::glBegin(GL_POLYGON);
        for (QPolygonF::const_iterator it = polygon.begin();
             it != polygon.end();
             ++it) {
            GL_GPU::glTexCoord2d( xTilesCountF * ( it->x() - topLeft.x() )  / ( btmRight.x() - topLeft.x() ),
                          yTilesCountF * ( it->y() - btmRight.y() ) / ( topLeft.y() - btmRight.y() ) );
            GL_GPU::glVertex2d( it->x(), it->y() );
        }
        GL_GPU::glEnd();


        //glDisable(GL_SCISSOR_TEST);
    } // GLProtectAttrib a(GL_SCISSOR_BIT | GL_ENABLE_BIT);
    GL_GPU::glBindTexture(GL_TEXTURE_2D, savedTexture);
    glCheckError(GL_GPU);
}