Exemplo n.º 1
0
/*!
  Draw a subset of the points

  \param painter Painter
  \param xMap Maps x-values into pixel coordinates.
  \param yMap Maps y-values into pixel coordinates.
  \param canvasRect Contents rectangle 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()
*/
void CpPlotCurve::drawDots( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    if ( !d_data->colorRange.isValid() )
        return;

    const bool doAlign = QwtPainter::roundingAlignment( painter );

    const QwtColorMap::Format format = d_data->colorMap->format();
    if ( format == QwtColorMap::Indexed )
        d_data->colorTable = d_data->colorMap->colorTable( d_data->colorRange );

    const QwtSeriesData<QwtPoint3D> *series = data();

    for ( int i = from; i <= to; i++ )
    {
        const QwtPoint3D sample = series->sample( i );

        double xi = xMap.transform( sample.x() );
        double yi = yMap.transform( sample.y() );
        if ( doAlign )
        {
            xi = qRound( xi );
            yi = qRound( yi );
        }

        if ( d_data->paintAttributes & CpPlotCurve::ClipPoints )
        {
            if ( !canvasRect.contains( xi, yi ) )
                continue;
        }

        if ( format == QwtColorMap::RGB )
        {
            const QRgb rgb = d_data->colorMap->rgb(
                d_data->colorRange, sample.z() );

            painter->setPen( QPen( QColor::fromRgba( rgb ), d_data->penWidth ) );
        }
        else
        {
            const unsigned char index = d_data->colorMap->colorIndex(
                d_data->colorRange, sample.z() );

            painter->setPen( QPen( QColor::fromRgba( d_data->colorTable[index] ), 
                d_data->penWidth ) );
        }

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

    d_data->colorTable.clear();
}
Exemplo n.º 2
0
inline QPointF QwtRasterData::ContourPlane::intersection(
    const QwtPoint3D& p1, const QwtPoint3D &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 QPointF( x, y );
}
Exemplo n.º 3
0
void
CpPlotCurve::drawLines( QPainter *painter,
     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
     const QRectF &canvasRect, int from, int to ) const
{
    if ( !d_data->colorRange.isValid() )
       return;

    const bool doAlign = QwtPainter::roundingAlignment( painter );

    const QwtColorMap::Format format = d_data->colorMap->format();
    if ( format == QwtColorMap::Indexed )
        d_data->colorTable = d_data->colorMap->colorTable( d_data->colorRange );

    const bool noDuplicates = d_data->paintAttributes & CpPlotCurve::FilterPoints;

    const QwtSeriesData<QwtPoint3D> *series = data();

    for ( int i = from; i < to; i++ )
    {
        const QwtPoint3D sample = series->sample( i );

        double xi = xMap.transform( sample.x() );
        double yi = yMap.transform( sample.y() );
        if ( doAlign )
        {
            xi = qRound( xi );
            yi = qRound( yi );
        }

        int y=i;
        double xi1 = xi;
        double yi1 = yi;
        QwtPoint3D nextSample;

        do {
            y++;
            nextSample = series->sample( y );

            xi1 = xMap.transform( nextSample.x() );
            yi1 = yMap.transform( nextSample.y() );

            if ( doAlign )
            {
                xi1 = qRound( xi1 );
                yi1 = qRound( yi1 );
            }

        } while (y < to && noDuplicates && xi1 == xi &&  yi1 == yi);

        // Next point
        i=y-1;

        if (y>=to) {
            continue ;
        }
        //qDebug() << "x" << 60*sample.x()  << 60*nextSample.x()  << "y" << sample.y()  << nextSample.y() ;


        if ( d_data->paintAttributes & CpPlotCurve::ClipPoints )
        {
            if (!canvasRect.contains( xi1, yi1 ) )
                continue;
        }


         QVector<QPointF> samples;
         samples.append(QPointF(xi, yi));
         samples.append(QPointF(xi1, yi1));

         QwtPointSeriesData *data = new QwtPointSeriesData(samples);

         // Increase width for recent poins
         int width = d_data->penWidth;
         if (sample.z()>250)
             width ++;
         if (sample.z()>500)
             width ++;
         if (sample.z()>750)
             width ++;

         // Choose color in the colorMap
         if ( format == QwtColorMap::RGB )
         {
             const QRgb rgb = d_data->colorMap->rgb(
                 d_data->colorRange, sample.z() );

             painter->setPen( QPen( QColor::fromRgba( rgb ), width ) );
         }
         else
         {
             const unsigned char index = d_data->colorMap->colorIndex(
                 d_data->colorRange, sample.z() );

             painter->setPen( QPen( QColor::fromRgba( d_data->colorTable[index] ),
                 width ) );
         }

         //qDebug() << "draw " << data->sample(0).x() << data->sample(0).y() << data->sample(1).x() << data->sample(1).y()  << "(" << sample.z() << ")" ;
         QwtPainter::drawLine(painter, data->sample(0), data->sample(1) );
     }
 }
Exemplo n.º 4
0
static inline QRectF qwtBoundingRect( const QwtPoint3D &sample )
{
    return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
}
Exemplo n.º 5
0
QDebug operator<<( QDebug debug, const QwtPoint3D &point )
{
    debug.nospace() << "QwtPoint3D(" << point.x()
        << "," << point.y() << "," << point.z() << ")";
    return debug.space();
}