コード例 #1
0
ファイル: mapmatrix.cpp プロジェクト: Exadios/Cumulus
// The new function using fixed point multiplication
QPolygon MapMatrix::map(const QPolygon &a) const
{
  int size = a.size();
  int64_t fx;
  int64_t fy;
  int32_t curx;
  int32_t cury;
  int32_t lastx = 0;
  int32_t lasty = 0;

  QPolygon p;

  for( int i = 0; i < size; i++ )
    {
      a.point(i, &curx, &cury);
      fx = itofp24p8( curx );
      fy = itofp24p8( cury );
      // some cheating involved; multiplication with the "wrong" macro
      // after "left shifting" the "m" value in createMatrix
      curx = fp24p8toi( mulfp8p24(m11,fx) + mulfp8p24(m21,fy) + dx);
      cury = fp24p8toi( mulfp8p24(m22,fy) + mulfp8p24(m12,fx) + dy);

      if ( (i==0) | ( ((curx - lastx) | (cury - lasty)) != 0) )
        {
          p.append(QPoint(curx, cury));
          lastx = curx;
          lasty = cury;
        }
    }

  return p;
}
コード例 #2
0
ファイル: seamcarver.cpp プロジェクト: LilyOfTheWest/image
QImage * SeamCarver::extendWidth(int w_extent,bool compression,bool afficheLignes)
{
    QPolygon *ligneBest;// = listLignesMostSuitable.first();
    QRgb color1,color2;
    int y_ligneBest;
    QPoint pp;
    int extendedSize = 0;//2*w_extent;
    if (!afficheLignes)
        extendedSize = (compression) ? -w_extent : w_extent;
    QImage *dataRet = new QImage(imgOrigine->width(),imgOrigine->height()+extendedSize,imgOrigine->format());
    ImageResizer *resizer = new ImageResizer;
    int delta_y,tmp_lect;
    QList<int> list_y_val;
    int counterExtractLignes = w_extent;
    QListIterator<QPolygon *> qit(listLignesMostSuitable);

    for (int x=0; x < imgOrigine->width() ; x++)
    {
        qit.toFront();
        list_y_val.clear();
        counterExtractLignes = w_extent;
        while ((qit.hasNext()) && (counterExtractLignes >0))
        {
            ligneBest=qit.next();
            list_y_val << (ligneBest->point(x)).y();
            counterExtractLignes--;
        }
        qSort(list_y_val);
        list_y_val << imgOrigine->height() + 1000;
        y_ligneBest = list_y_val.takeFirst();

        //        pp=ligneBest->takeFirst();
        //y_ligneBest=pp.y();
        delta_y=0;
        for (int y=0; y < imgOrigine->height() ; y++) {
            color1=imgOrigine->pixel(x,y);
            if ((afficheLignes) || (y != y_ligneBest))
            {
                int w_newPosition = y+delta_y;
                if (w_newPosition < dataRet->height())
                    dataRet->setPixel(x,w_newPosition,color1);
            } else
            {
                if (compression)
                {
                    delta_y -= 1;
                } else
                {
                    dataRet->setPixel(x,y_ligneBest+delta_y,color1);
                    color2=imgOrigine->pixel(x,y+1);
                    resizer->interpol(dataRet,x,y_ligneBest+delta_y+1,1,color1,color2,false);
                    delta_y += 1;
                }
                y_ligneBest = list_y_val.takeFirst();
            }
        }
    }
    return dataRet;
}
コード例 #3
0
ファイル: graph_clipper.cpp プロジェクト: ongbe/xchart
void GraphPolygonClipper::clipEdge(Edge edge, 
    const QPolygon &pa, QPolygon &cpa) const
{
    if ( pa.count() == 0 )
    {
        cpa.resize(0);
        return;
    }

    unsigned int count = 0;

    QPoint p1 = pa.point(0);
    if ( insideEdge(p1, edge) )
        addPoint(cpa, count++, p1);

    const uint nPoints = pa.size();
    for ( uint i = 1; i < nPoints; i++ )
    {
        const QPoint p2 = pa.point(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);
}
コード例 #4
0
ファイル: tobarchart.cpp プロジェクト: nguyentienlong/tora
void toBarChart::paintChart(QPainter *p, QRect &rect)
{
    QFontMetrics fm = p->fontMetrics();

    if (!Zooming)
    {
        if (MinAuto)
        {
            bool first = true;
            std::list<std::list<double> >::reverse_iterator i = Values.rbegin();
            if (i != Values.rend())
            {
                for (std::list<double>::iterator j = (*i).begin(); j != (*i).end(); j++)
                {
                    if (first)
                    {
                        first = false;
                        zMinValue = *j;
                    }
                    else if (zMinValue > *j)
                        zMinValue = *j;
                }
            }
        }
        if (MaxAuto)
        {
            bool first = true;
            std::list<double> total;
            std::list<bool>::iterator e = Enabled.begin();
            {
                for (std::list<std::list<double> >::iterator i = Values.begin(); i != Values.end(); i++)
                {
                    std::list<double>::iterator k = total.begin();
                    if (e == Enabled.end() || *e)
                    {
                        for (std::list<double>::iterator j = (*i).begin(); j != (*i).end(); j++)
                        {
                            if (k == total.end())
                            {
                                total.insert(total.end(), *j);
                                k = total.end();
                            }
                            else
                            {
                                *k += *j;
                                k++;
                            }
                        }
                    }
                    if (e != Enabled.end())
                        e++;
                }
            }
            for (std::list<double>::iterator i = total.begin(); i != total.end(); i++)
            {
                if (first)
                {
                    first = false;
                    zMaxValue = *i;
                }
                else if (zMaxValue < *i)
                    zMaxValue = *i;
            }
        }
        if (!MinAuto)
            zMinValue = MinValue;
        else
        {
            zMinValue = round(zMinValue, false);
            MinValue = zMinValue;
        }
        if (!MaxAuto)
            zMaxValue = MaxValue;
        else
        {
            zMaxValue = round(zMaxValue, true);
            MaxValue = zMaxValue;
        }
    }

    paintTitle(p, rect);
    paintLegend(p, rect);
    paintAxis(p, rect);

    std::list<QPolygon> Points;
    int cp = 0;
    int samples = countSamples();
    int zeroy = int(rect.height() - 2 - ( -zMinValue / (zMaxValue - zMinValue) * (rect.height() - 4)));
    if (samples > 1)
    {
        const QMatrix &mtx = p->worldMatrix();
        p->setClipRect(int(mtx.dx() + 2), int(mtx.dy() + 2), rect.width() - 3, rect.height() - 3);
        if (Zooming)
            p->drawText(2, 2, rect.width() - 4, rect.height() - 4,
                        Qt::AlignLeft | Qt::AlignTop, tr("Zoom"));
        std::list<bool>::reverse_iterator e = Enabled.rbegin();
        for (std::list<std::list<double> >::reverse_iterator i = Values.rbegin(); i != Values.rend(); i++)
        {
            if (e == Enabled.rend() || *e)
            {
                std::list<double> &val = *i;
                int count = 0;
                int skip = SkipSamples;
                QPolygon a(samples + 10);
                int x = rect.width() - 2;
                for (std::list<double>::reverse_iterator j = val.rbegin(); j != val.rend() && x >=
                        2;
                        j++)
                {
                    if (skip > 0)
                        skip--;
                    else
                    {
                        int val = int(rect.height() - 2 - ((*j - zMinValue) / (zMaxValue - zMinValue) * (rect.height() - 4)));
                        x = rect.width() - 2 - count * (rect.width() - 4) / (samples - 1);
                        a.setPoint(count, x, val);
                        count++;
                        if (count >= samples)
                            break;
                    }
                }
                a.resize(count * 2);
                Points.insert(Points.end(), a);
            }
            cp++;
            if (e != Enabled.rend())
                e++;
        }
    }

    std::map<int, int> Bottom;
    std::list<bool>::reverse_iterator e = Enabled.rbegin();
    for (std::list<QPolygon>::iterator i = Points.begin(); i != Points.end();)
    {
        while (e != Enabled.rend() && !*e)
        {
            cp--;
            e++;
        }
        if (e != Enabled.rend())
            e++;
        cp--;

        QPolygon a = *i;
        int lx = 0;
        int lb = 0;
        for (int j = 0; j < a.size() / 2; j++)
        {
            int x, y;
            a.point(j, &x, &y);
            if (Bottom.find(x) == Bottom.end())
                Bottom[x] = 0;
            if (lx != x)
                lb = Bottom[x];
            a.setPoint(a.size() - 1 - j, x, zeroy - lb);
            y -= lb;
            a.setPoint(j, x, y);
            Bottom[x] = zeroy - y;
            lx = x;
        }

        p->save();
        QBrush brush(Utils::toChartBrush(cp));
        p->setBrush(brush.color());
        p->drawPolygon(a);
        if (brush.style() != Qt::SolidPattern)
        {
            p->setBrush(QBrush(Qt::white, brush.style()));
            p->drawPolygon(a);
        }
        p->restore();
        i++;
    }
}