Esempio n. 1
0
static inline long double qwtIntervalWidthL( const QwtInterval &interval )
{
    if ( !interval.isValid() )
        return 0.0;

    return static_cast<long double>( interval.maxValue() )
        - static_cast<long double>( interval.minValue() );
}
Esempio n. 2
0
/*!
   \brief Calculate a scale division for an interval

   \param x1 First interval limit
   \param x2 Second interval limit
   \param maxMajorSteps Maximum for the number of major steps
   \param maxMinorSteps Maximum number of minor steps
   \param stepSize Step size. If stepSize == 0, the engine
                   calculates one.

   \return Calculated scale division
*/
QwtScaleDiv QwtLogScaleEngine::divideScale( double x1, double x2,
    int maxMajorSteps, int maxMinorSteps, double stepSize ) const
{
    QwtInterval interval = QwtInterval( x1, x2 ).normalized();
    interval = interval.limited( LOG_MIN, LOG_MAX );

    if ( interval.width() <= 0 )
        return QwtScaleDiv();

    const double logBase = base();

    if ( interval.maxValue() / interval.minValue() < logBase )
    {
        // scale width is less than one decade -> build linear scale

        QwtLinearScaleEngine linearScaler;
        linearScaler.setAttributes( attributes() );
        linearScaler.setReference( reference() );
        linearScaler.setMargins( lowerMargin(), upperMargin() );

        if ( stepSize != 0.0 )
        {
            if ( stepSize < 0.0 )
                stepSize = -qPow( logBase, -stepSize );
            else
                stepSize = qPow( logBase, stepSize );
        }

        return linearScaler.divideScale( x1, x2,
            maxMajorSteps, maxMinorSteps, stepSize );
    }

    stepSize = qAbs( stepSize );
    if ( stepSize == 0.0 )
    {
        if ( maxMajorSteps < 1 )
            maxMajorSteps = 1;

        stepSize = divideInterval( 
            qwtLogInterval( logBase, interval ).width(), maxMajorSteps );
        if ( stepSize < 1.0 )
            stepSize = 1.0; // major step must be >= 1 decade
    }

    QwtScaleDiv scaleDiv;
    if ( stepSize != 0.0 )
    {
        QList<double> ticks[QwtScaleDiv::NTickTypes];
        buildTicks( interval, stepSize, maxMinorSteps, ticks );

        scaleDiv = QwtScaleDiv( interval, ticks );
    }

    if ( x1 > x2 )
        scaleDiv.invert();

    return scaleDiv;
}
Esempio n. 3
0
Plot::Plot( QWidget *parent ):
    QwtPlot( parent ),
    d_formatType( 0 ),
    d_alpha(255)
{
    d_spectrogram = new QwtPlotSpectrogram();
    d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count
    d_spectrogram->setCachePolicy( QwtPlotRasterItem::PaintCache );

    QList<double> contourLevels;
    for ( double level = 0.5; level < 10.0; level += 1.0 )
        contourLevels += level;
    d_spectrogram->setContourLevels( contourLevels );

    d_spectrogram->setData( new SpectrogramData() );
    d_spectrogram->attach( this );

    const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );

    // A color bar on the right axis
    QwtScaleWidget *rightAxis = axisWidget( QwtPlot::yRight );
    rightAxis->setTitle( "Intensity" );
    rightAxis->setColorBarEnabled( true );

    setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
    enableAxis( QwtPlot::yRight );

    plotLayout()->setAlignCanvasToScales( true );

    setColorMap( Plot::RGBMap );

    // LeftButton for the zooming
    // MidButton for the panning
    // RightButton: zoom out by 1
    // Ctrl+RighButton: zoom out to full size

    QwtPlotZoomer* zoomer = new MyZoomer( canvas() );
    zoomer->setMousePattern( QwtEventPattern::MouseSelect2,
        Qt::RightButton, Qt::ControlModifier );
    zoomer->setMousePattern( QwtEventPattern::MouseSelect3,
        Qt::RightButton );

    QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
    panner->setAxisEnabled( QwtPlot::yRight, false );
    panner->setMouseButton( Qt::MidButton );

    // Avoid jumping when labels with more/less digits
    // appear/disappear when scrolling vertically

    const QFontMetrics fm( axisWidget( QwtPlot::yLeft )->font() );
    QwtScaleDraw *sd = axisScaleDraw( QwtPlot::yLeft );
    sd->setMinimumExtent( fm.width( "100.00" ) );

    const QColor c( Qt::darkBlue );
    zoomer->setRubberBandPen( c );
    zoomer->setTrackerPen( c );
}
static inline bool qwtIsSampleInside( const QwtOHLCSample &sample,
    double tMin, double tMax, double vMin, double vMax )
{
    const double t = sample.time;
    const QwtInterval interval = sample.boundingInterval();

    const bool isOffScreen = ( t < tMin ) || ( t > tMax )
        || ( interval.maxValue() < vMin ) || ( interval.minValue() > vMax );

    return !isOffScreen;
}
Esempio n. 5
0
void matrixofpixels::PixPlotSpect(int TypeOfSpec,QwtMatrixRasterData *rasterpixdata)
{
    changeitems();
    MapPlot->setData(rasterpixdata);
    MapPlot->setRenderThreadCount(0);
    setAxisAutoScale(this->xTop);
    setAxisAutoScale(this->xBottom);



    switch (TypeOfSpec)
    {
    case 1:
        MapPlot->setColorMap(new ColorMap(BLUERED));
        break;
    case 2:
        MapPlot->setColorMap(new ColorMap(BLACKWHITE));
        break;
    default:
        MapPlot->setColorMap(new ColorMap(BLUERED));
    }

    MapPlot->attach(/*MainPlot*/this);

    const QwtInterval zInterval = MapPlot->data()->interval(Qt::ZAxis);

    setAxisScale(QwtPlot::xBottom, 0, Npix);
    setAxisMaxMinor(QwtPlot::xBottom, 0);
    setAxisScale(QwtPlot::yLeft, 0, Npix);
    setAxisMaxMinor(QwtPlot::yLeft, 0);

    //rightAxis = new QwtScaleWidget();
    QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight);

    //rightAxis = axisWidget(QwtPlot::yRight);
    rightAxis->setColorBarEnabled(true);
    rightAxis->setColorBarWidth(20);
    rightAxis->setColorMap(zInterval, new ColorMap(TypeOfSpec) );
    //ColorMap(TypeOfSpec);

    plotLayout()->setAlignCanvasToScales(true);

    setAxisScale(QwtPlot::yRight,zInterval.minValue(),zInterval.maxValue());
    enableAxis(QwtPlot::yRight);
    replot();
    setAutoFillBackground(true);

    /**
      setAutoFillBackground(true); - autozapolnenie, ctobi isklyuchit'
    nalozjeniya graphikov
    */

}
Esempio n. 6
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::setZoomWindow(const QwtInterval& leftAxis, const QwtInterval& rightAxis, const QwtInterval& timeAxis)
{
    {
        QRectF zoomWindow;
        zoomWindow.setLeft(timeAxis.minValue());
        zoomWindow.setRight(timeAxis.maxValue());
        zoomWindow.setTop(leftAxis.maxValue());
        zoomWindow.setBottom(leftAxis.minValue());

        m_zoomerLeft->zoom(zoomWindow);
    }

    {
        QRectF zoomWindow;
        zoomWindow.setLeft(timeAxis.minValue());
        zoomWindow.setRight(timeAxis.maxValue());
        zoomWindow.setTop(rightAxis.maxValue());
        zoomWindow.setBottom(rightAxis.minValue());

        m_zoomerRight->zoom(zoomWindow);
    }
}
/*!
   \return Bounding rectangle of the data
   \sa QwtPlotRasterItem::interval()
*/
QRectF QwtPlotRasterItem::boundingRect() const
{
    const QwtInterval intervalX = interval( Qt::XAxis );
    const QwtInterval intervalY = interval( Qt::YAxis );

    if ( !intervalX.isValid() && !intervalY.isValid() )
        return QRectF(); // no bounding rect

    QRectF r;

    if ( intervalX.isValid() )
    {
        r.setLeft( intervalX.minValue() );
        r.setRight( intervalX.maxValue() );
    }
    else
    {
        const float max = std::numeric_limits<float>::max();

        r.setLeft( -0.5 * max );
        r.setWidth( max );
    }

    if ( intervalY.isValid() )
    {
        r.setTop( intervalY.minValue() );
        r.setBottom( intervalY.maxValue() );
    }
    else
    {
        const float max = std::numeric_limits<float>::max();

        r.setTop( -0.5 * max );
        r.setHeight( max );
    }

    return r.normalized();
}
Esempio n. 8
0
/*!
  Check if an interval "contains" a value

  \param interval Interval
  \param value Value

  \return True, when the value is inside the interval
*/
bool QwtScaleEngine::contains(
    const QwtInterval &interval, double value ) const
{
    if ( !interval.isValid() )
        return false;

    if ( qwtFuzzyCompare( value, interval.minValue(), interval.width() ) < 0 )
        return false;

    if ( qwtFuzzyCompare( value, interval.maxValue(), interval.width() ) > 0 )
        return false;

    return true;
}
Esempio n. 9
0
void QwtPolarPlot::updateScale( int scaleId )
{
    if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
        return;

    ScaleData &d = d_data->scaleData[scaleId];

    double minValue = d.minValue;
    double maxValue = d.maxValue;
    double stepSize = d.stepSize;

    if ( scaleId == QwtPolar::ScaleRadius && d.doAutoScale )
    {
        QwtInterval interval;

        const QwtPolarItemList& itmList = itemList();
        for ( QwtPolarItemIterator it = itmList.begin();
                it != itmList.end(); ++it )
        {
            const QwtPolarItem *item = *it;
            if ( item->testItemAttribute( QwtPolarItem::AutoScale ) )
                interval |= item->boundingInterval( scaleId );
        }

        minValue = interval.minValue();
        maxValue = interval.maxValue();

        d.scaleEngine->autoScale( d.maxMajor,
                                  minValue, maxValue, stepSize );
        d.scaleDiv.invalidate();
    }

    if ( !d.scaleDiv.isValid() )
    {
        d.scaleDiv = d.scaleEngine->divideScale(
            minValue, maxValue, d.maxMajor, d.maxMinor, stepSize );
    }

    const QwtInterval interval = visibleInterval();

    const QwtPolarItemList& itmList = itemList();
    for ( QwtPolarItemIterator it = itmList.begin();
            it != itmList.end(); ++it )
    {
        QwtPolarItem *item = *it;
        item->updateScaleDiv( *scaleDiv( QwtPolar::Azimuth ),
            *scaleDiv( QwtPolar::Radius ), interval );
    }
}
Esempio n. 10
0
/*!
   \brief Calculate major ticks for an interval

   \param interval Interval
   \param stepSize Step size

   \return Calculated ticks
*/
QList<double> QwtLogScaleEngine::buildMajorTicks(
    const QwtInterval &interval, double stepSize ) const
{
    double width = qwtLogInterval( base(), interval ).width();

    int numTicks = qRound( width / stepSize ) + 1;
    if ( numTicks > 10000 )
        numTicks = 10000;

    const double lxmin = ::log( interval.minValue() );
    const double lxmax = ::log( interval.maxValue() );
    const double lstep = ( lxmax - lxmin ) / double( numTicks - 1 );

    QList<double> ticks;

    ticks += interval.minValue();

    for ( int i = 1; i < numTicks - 1; i++ )
        ticks += qExp( lxmin + double( i ) * lstep );

    ticks += interval.maxValue();

    return ticks;
}
Esempio n. 11
0
/*!
   \brief Calculate major ticks for an interval

   \param interval Interval
   \param stepSize Step size

   \return Calculated ticks
*/
QList<double> QwtLinearScaleEngine::buildMajorTicks(
    const QwtInterval &interval, double stepSize ) const
{
    int numTicks = qRound( interval.width() / stepSize ) + 1;
    if ( numTicks > 10000 )
        numTicks = 10000;

    QList<double> ticks;

    ticks += interval.minValue();
    for ( int i = 1; i < numTicks - 1; i++ )
        ticks += interval.minValue() + i * stepSize;
    ticks += interval.maxValue();

    return ticks;
}
Esempio n. 12
0
Plot::Plot( QWidget *parent, const QwtInterval &interval ):
    QwtPlot( parent )
{
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis ++ )
        setAxisScale( axis, interval.minValue(), interval.maxValue() );

    setCanvasBackground( QColor( Qt::darkBlue ) );
    plotLayout()->setAlignCanvasToScales( true );

    // grid
    QwtPlotGrid *grid = new QwtPlotGrid;
    //grid->enableXMin(true);
    grid->setMajorPen( Qt::white, 0, Qt::DotLine );
    grid->setMinorPen( Qt::gray, 0 , Qt::DotLine );
    grid->attach( this );

    const int numEllipses = 10;

    for ( int i = 0; i < numEllipses; i++ )
    {
        const double x = interval.minValue() +
            qrand() % qRound( interval.width() );
        const double y = interval.minValue() +
            qrand() % qRound( interval.width() );
        const double r = interval.minValue() +
            qrand() % qRound( interval.width() / 6 );

        const QRectF area( x - r, y - r , 2 * r, 2 * r );

        RectItem *item = new RectItem( RectItem::Ellipse );
        item->setRenderHint( QwtPlotItem::RenderAntialiased, true );
        item->setRect( area );
        item->setPen( QPen( Qt::yellow ) );
        item->attach( this );
    }

    TextItem *textItem = new TextItem();
    textItem->setText( "Navigation Example" );
    textItem->attach( this );

    d_rectOfInterest = new RectItem( RectItem::Rect );
    d_rectOfInterest->setPen( Qt::NoPen );
    QColor c = Qt::gray;
    c.setAlpha( 100 );
    d_rectOfInterest->setBrush( QBrush( c ) );
    d_rectOfInterest->attach( this );
}
Esempio n. 13
0
void Spectrogramplot::setZAxisScale(double zMin, double zMax)
{
  zMin_ = zMin;
  zMax_ = zMax;
  data_->setInterval( Qt::ZAxis, QwtInterval( zMin_, zMax_ ) );

  //Set up the intensity bar on the right
  const QwtInterval zInterval = spectrogram_->data()->interval( Qt::ZAxis );
  QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight);
  rightAxis->setColorBarEnabled(true);
  rightAxis->setColorMap( zInterval, new ColorMap());
  setAxisScale(QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
  enableAxis(QwtPlot::yRight);

  plotLayout()->setAlignCanvasToScales(true);
  replot();
}
Esempio n. 14
0
static inline bool isCombinable( const QwtInterval &d1,
    const QwtInterval &d2 )
{
    if ( d1.isValid() && d2.isValid() )
    {
        if ( d1.maxValue() == d2.minValue() )
        {
            if ( !( d1.borderFlags() & QwtInterval::ExcludeMaximum
                && d2.borderFlags() & QwtInterval::ExcludeMinimum ) )
            {
                return true;
            }
        }
    }

    return false;
}
Esempio n. 15
0
void SaxsviewImage::setFrame(SaxsviewFrame *frame) {
  if (p->frame)
    p->frame->detach();

  p->frame = frame;
  frame->attach(this);

  if (frame->data()) {
    const QwtInterval range = p->frame->data()->interval(Qt::ZAxis);
    axisWidget(QwtPlot::yRight)->setColorBarInterval(range);
    setAxisScale(QwtPlot::yRight, range.minValue(), range.maxValue());
  }

  setZoomBase(p->frame->boundingRect());

  replot();
}
Esempio n. 16
0
/*!
  Draw the spectrogram

  \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 radius Radius of the complete plot area in painter coordinates
  \param canvasRect Contents rect of the canvas in painter coordinates
*/
void QwtPolarSpectrogram::draw( QPainter *painter,
    const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    const QPointF &pole, double,
    const QRectF &canvasRect ) const
{
    const QRectF plotRect = plot()->plotRect( canvasRect.toRect() );

    QRegion clipRegion( canvasRect.toRect() );
    if ( qwtNeedsClipping( plotRect, canvasRect ) )
    {
        // For large plotRects the ellipse becomes a huge polygon.
        // So we better clip only, when we really need to.

        clipRegion &= QRegion( plotRect.toRect(), QRegion::Ellipse );
    }

    QRect imageRect = canvasRect.toRect();

    if ( painter->hasClipping() )
        imageRect &= painter->clipRegion().boundingRect();

    const QwtInterval radialInterval =
        boundingInterval( QwtPolar::ScaleRadius );
    if ( radialInterval.isValid() )
    {
        const double radius = radialMap.transform( radialInterval.maxValue() ) -
                              radialMap.transform( radialInterval.minValue() );

        QRectF r( 0, 0, 2 * radius, 2 * radius );
        r.moveCenter( pole );

        clipRegion &= QRegion( r.toRect(), QRegion::Ellipse );;

        imageRect &= r.toRect();
    }

    const QImage image = renderImage( azimuthMap, radialMap, pole, imageRect );

    painter->save();
    painter->setClipRegion( clipRegion );

    painter->drawImage( imageRect, image );

    painter->restore();
}
Esempio n. 17
0
Plot::Plot( QWidget *parent ):
    QwtPlot( parent )
{
    QwtPlotCanvas *canvas = new QwtPlotCanvas();
    canvas->setBorderRadius( 10 );
    setCanvas( canvas );

#if 0
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen( Qt::DotLine );
    grid->attach( this );
#endif

    d_spectrogram = new QwtPlotSpectrogram();
    d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count

    d_spectrogram->setColorMap( new ColorMap() );

    d_spectrogram->setData( new RasterData() );
    d_spectrogram->attach( this );

    const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );
    // A color bar on the right axis
    QwtScaleWidget *rightAxis = axisWidget( QwtPlot::yRight );
    rightAxis->setColorBarEnabled( true );
    rightAxis->setColorBarWidth( 40 );
    rightAxis->setColorMap( zInterval, new ColorMap() );

    setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
    enableAxis( QwtPlot::yRight );

    plotLayout()->setAlignCanvasToScales( true );

    setAxisScale( QwtPlot::xBottom, 0.0, 3.0 );
    setAxisMaxMinor( QwtPlot::xBottom, 0 );
    setAxisScale( QwtPlot::yLeft, 0.0, 3.0 );
    setAxisMaxMinor( QwtPlot::yLeft, 0 );

    QwtPlotMagnifier *magnifier = new QwtPlotMagnifier( canvas );
    magnifier->setAxisEnabled( QwtPlot::yRight, false );

    QwtPlotPanner *panner = new QwtPlotPanner( canvas );
    panner->setAxisEnabled( QwtPlot::yRight, false );
}
Esempio n. 18
0
/*!
  Map a value of a given interval into a color index, between 0 and 255

  \param interval Range for all values
  \param value Value to map into a color index
*/
unsigned char QwtLinearColorMap::colorIndex(
    const QwtInterval &interval, double value ) const
{
    const double width = interval.width();

    if ( qIsNaN(value) || width <= 0.0 || value <= interval.minValue() )
        return 0;

    if ( value >= interval.maxValue() )
        return ( unsigned char )255;

    const double ratio = ( value - interval.minValue() ) / width;

    unsigned char index;
    if ( d_data->mode == FixedColors )
        index = ( unsigned char )( ratio * 255 ); // always floor
    else
        index = ( unsigned char )qRound( ratio * 255 );

    return index;
}
Esempio n. 19
0
/*!
  \brief Align an interval to a step size

  The limits of an interval are aligned that both are integer
  multiples of the step size.

  \param interval Interval
  \param stepSize Step size

  \return Aligned interval
*/
QwtInterval QwtLinearScaleEngine::align(
    const QwtInterval &interval, double stepSize ) const
{
    double x1 = interval.minValue();
    double x2 = interval.maxValue();

    if ( -DBL_MAX + stepSize <= x1 )
    {
        const double x = QwtScaleArithmetic::floorEps( x1, stepSize );
        if ( qwtFuzzyCompare( x1, x, stepSize ) != 0 )
            x1 = x;
    }

    if ( DBL_MAX - stepSize >= x2 )
    {
        const double x = QwtScaleArithmetic::ceilEps( x2, stepSize );
        if ( qwtFuzzyCompare( x2, x, stepSize ) != 0 )
            x2 = x;
    }

    return QwtInterval( x1, x2 );
}
Esempio n. 20
0
/*!
  \brief Draw the raster data
  \param painter Painter
  \param xMap X-Scale Map
  \param yMap Y-Scale Map
  \param canvasRect Contents rectangle of the plot canvas
*/
void QwtPlotRasterItem::draw( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect ) const
{
    if ( canvasRect.isEmpty() || d_data->alpha == 0 )
        return;

    const bool doCache = qwtUseCache( d_data->cache.policy, painter );

    const QwtInterval xInterval = interval( Qt::XAxis );
    const QwtInterval yInterval = interval( Qt::YAxis );

    /*
        Scaling an image always results in a loss of
        precision/quality. So we always render the image in
        paint device resolution.
    */

    QwtScaleMap xxMap, yyMap;
    qwtTransformMaps( painter->transform(), xMap, yMap, xxMap, yyMap );

    QRectF paintRect = painter->transform().mapRect( canvasRect );
    QRectF area = QwtScaleMap::invTransform( xxMap, yyMap, paintRect );

    const QRectF br = boundingRect();
    if ( br.isValid() && !br.contains( area ) )
    {
        area &= br;
        if ( !area.isValid() )
            return;

        paintRect = QwtScaleMap::transform( xxMap, yyMap, area );
    }

    QRectF imageRect;
    QImage image;

    QRectF pixelRect = pixelHint(area);
    if ( !pixelRect.isEmpty() )
    {
        // pixel in target device resolution 
        const double dx = qAbs( xxMap.invTransform( 1 ) - xxMap.invTransform( 0 ) );
        const double dy = qAbs( yyMap.invTransform( 1 ) - yyMap.invTransform( 0 ) );

        if ( dx > pixelRect.width() && dy > pixelRect.height() )
        {
            /*
              When the resolution of the data pixels is higher than
              the resolution of the target device we render in
              target device resolution.
             */
            pixelRect = QRectF();
        }
    }

    if ( pixelRect.isEmpty() )
    {
        if ( QwtPainter::roundingAlignment( painter ) )
        {
            // we want to have maps, where the boundaries of
            // the aligned paint rectangle exactly match the area

            paintRect = qwtAlignRect(paintRect);
            qwtAdjustMaps(xxMap, yyMap, area, paintRect);
        }

        // When we have no information about position and size of
        // data pixels we render in resolution of the paint device.

        image = compose(xxMap, yyMap, 
            area, paintRect, paintRect.size().toSize(), doCache);
        if ( image.isNull() )
            return;

        // Remove pixels at the boundaries, when explicitly
        // excluded in the intervals

        imageRect = qwtStripRect(paintRect, area, 
            xxMap, yyMap, xInterval, yInterval);

        if ( imageRect != paintRect )
        {
            const QRect r( 
                qRound( imageRect.x() - paintRect.x()),
                qRound( imageRect.y() - paintRect.y() ),
                qRound( imageRect.width() ),
                qRound( imageRect.height() ) );
                
            image = image.copy(r);
        }   
    }
    else
    {
        if ( QwtPainter::roundingAlignment( painter ) )
            paintRect = qwtAlignRect(paintRect);

        // align the area to the data pixels
        QRectF imageArea = qwtExpandToPixels(area, pixelRect);

        if ( imageArea.right() == xInterval.maxValue() &&
            !( xInterval.borderFlags() & QwtInterval::ExcludeMaximum ) )
        {
            imageArea.adjust(0, 0, pixelRect.width(), 0);
        }
        if ( imageArea.bottom() == yInterval.maxValue() &&
            !( yInterval.borderFlags() & QwtInterval::ExcludeMaximum ) )
        {
            imageArea.adjust(0, 0, 0, pixelRect.height() );
        }

        QSize imageSize;
        imageSize.setWidth( qRound( imageArea.width() / pixelRect.width() ) );
        imageSize.setHeight( qRound( imageArea.height() / pixelRect.height() ) );
        image = compose(xxMap, yyMap, 
            imageArea, paintRect, imageSize, doCache );
        if ( image.isNull() )
            return;

        imageRect = qwtStripRect(paintRect, area, 
            xxMap, yyMap, xInterval, yInterval);

        if ( ( image.width() > 1 || image.height() > 1 ) &&
            testPaintAttribute( PaintInDeviceResolution ) )
        {
            // Because of rounding errors the pixels 
            // need to be expanded manually to rectangles of 
            // different sizes

            image = qwtExpandImage(image, xxMap, yyMap, 
                imageArea, area, paintRect, xInterval, yInterval );
        }
    }

    painter->save();
    painter->setWorldTransform( QTransform() );
    
    QwtPainter::drawImage( painter, imageRect, image );

    painter->restore();
}
Esempio n. 21
0
void Plot2DHistogram::drawColumn (QPainter * painter, const QwtColumnRect & rect,
        const QwtIntervalSample & sample) const{
    QBrush brush( m_defaultColor );
    if ( !m_colored ){
        painter->setPen( m_defaultColor);
    }
    else {
        QColor sampleColor(m_defaultColor);
        if ( m_pipeline ){
            QwtInterval xRange = sample.interval;
            double midPt = (xRange.minValue() + xRange.maxValue()) / 2;
            std::array<double,3> normRGB;
            m_pipeline->convert( midPt, normRGB );
            if ( normRGB[0] >= 0 && normRGB[1] >= 0 && normRGB[2] >= 0 ){
                sampleColor.setRgbF(normRGB[0], normRGB[1], normRGB[2]);
            }
        }
        painter->setPen( sampleColor );
        brush.setColor( sampleColor );
    }
    painter->setBrush( brush );
    QRectF r = rect.toRect();
    if ( QwtPainter::roundingAlignment( painter ) ){
        r.setLeft( qRound( r.left() ) );
        r.setRight( qRound( r.right() ) );
        r.setTop( qRound( r.top() ) );
        r.setBottom( qRound( r.bottom() ) );
    }
    if ( m_drawStyle == Carta::Data::PlotStyles::PLOT_STYLE_FILL ){
        QwtPainter::fillRect( painter, r, brush );
    }
    else if ( m_drawStyle == Carta::Data::PlotStyles::PLOT_STYLE_LINE ){
        double middle = ( r.left() + r.right() ) / 2;
        QwtPainter::drawLine( painter, middle, r.bottom(), middle, r.top() );
    }
    else if ( m_drawStyle != Carta::Data::PlotStyles::PLOT_STYLE_OUTLINE ){
            qCritical() << "Unrecognized draw style="<< m_drawStyle;
    }


    if ( m_drawStyle == Carta::Data::PlotStyles::PLOT_STYLE_OUTLINE ||
            ( m_drawStyle == Carta::Data::PlotStyles::PLOT_STYLE_FILL && m_colored ) ){
        //Draw a black outline for colored fill style
        if ( m_drawStyle == Carta::Data::PlotStyles::PLOT_STYLE_FILL && m_colored ){
            QColor outlineC( "black" );
            painter->setPen( outlineC );
        }

        //Draw the top
        double top = r.top();
        double right = r.right();
        QwtPainter::drawLine( painter, r.left(), top, r.right(), top );
        //Draw the left vertical line
        QwtPainter::drawLine( painter, r.left(), m_lastY, r.left(), top );
        //Store the top for the next call.
        if ( top > 0 ){
            m_lastY = top;
        }
        if ( right > 0 ){
            m_lastX = right;
        }
    }
}
Esempio n. 22
0
SpectrogramPlot::SpectrogramPlot( QWidget *parent ) : QwtPlot(parent)
                                                    , impl_( new impl( this ) )
{
    impl_->spectrogram_->setRenderThreadCount( 0 ); // use system specific thread count
    
    impl_->spectrogram_->setColorMap( new ColorMap() );
    impl_->spectrogram_->setCachePolicy( QwtPlotRasterItem::PaintCache );

    impl_->spectrogram_->setData( impl_->drawable_ );
    impl_->spectrogram_->attach( this );

    impl_->marker_->attach( this );

    // QList<double> contourLevels;
    // for ( double level = 0.5; level < 10.0; level += 1.0 )
    //     contourLevels += level;
    // impl_->spectrogram_->setContourLevels( contourLevels );

    const QwtInterval zInterval = impl_->spectrogram_->data()->interval( Qt::ZAxis );
    // A color bar on the right axis
    QwtScaleWidget *rightAxis = axisWidget( QwtPlot::yRight );
    rightAxis->setTitle( "Intensity" );
    rightAxis->setColorBarEnabled( true );

    // rightAxis->setColorMap( zInterval, new ColorMap() );
    setAxisZMax( 10.0 );

    //setAxisScale( QwtPlot::xBottom, 0, 64 );
    //setAxisScale( QwtPlot::yLeft,  64, 0 );
    axisScaleEngine( QwtPlot::xBottom )->setAttribute( QwtScaleEngine::Floating, true );
    axisScaleEngine( QwtPlot::yLeft )->setAttribute( QwtScaleEngine::Floating, true );
    axisScaleEngine( QwtPlot::yLeft )->setAttribute( QwtScaleEngine::Inverted, true );
    
	setAxisScale(QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue());
    enableAxis( QwtPlot::yRight );

    plotLayout()->setAlignCanvasToScales( true );
    replot();

    if ( auto zoomer = new adplot::Zoomer( QwtPlot::xBottom, QwtPlot::yLeft, canvas() ) ) {
        const QColor c( 0xe0, 0xff, 0xff, 0x40 ); // lightcyan
        zoomer->setRubberBandPen( c );
        zoomer->setTrackerPen( c );
        zoomer->setTrackerMode( QwtPlotPicker::ActiveOnly );
    }

    QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
    panner->setAxisEnabled( QwtPlot::yRight, false );
    panner->setMouseButton( Qt::MidButton );

    if ( auto picker = new adplot::Picker( canvas() ) ) {

        //picker->setStateMachine( new QwtPickerClickPointMachine() );
        picker->setStateMachine( new QwtPickerDragRectMachine() );
        picker->setRubberBand( QwtPicker::RectRubberBand );
        picker->setRubberBandPen( QColor( Qt::red ) );
        picker->setTrackerPen( QColor( Qt::white ) );
        
        picker->setMousePattern( QwtEventPattern::MouseSelect1, Qt::RightButton );
        picker->setTrackerMode( QwtPicker::AlwaysOff );
        picker->setEnabled( true );
        
        connect( picker, static_cast<void( QwtPlotPicker::* )( const QPointF& )>( &QwtPlotPicker::selected ), 
                 this, [this] ( const QPointF& p ) {
                     impl_->marker_->setRect( p ); replot();
                     emit cellSelected( impl_->marker_->rect() );
                 } );

        connect( picker, static_cast<void( QwtPlotPicker::* )( const QRectF& )>( &QwtPlotPicker::selected ), 
                 this, [this] ( const QRectF& rc ) {
                     impl_->marker_->setRect( rc ); replot();
                     emit cellSelected( impl_->marker_->rect() );                     
                 } );        
    }

    QFont font;
    qtwrapper::font::setFont( font, qtwrapper::fontSizeSmall, qtwrapper::fontAxisLabel );
    setAxisFont( QwtPlot::xBottom, font );
    setAxisFont( QwtPlot::yLeft, font );

    // Set fixed 'extent' for axis in order to avoid jumping when labels with more/less digits
    // appear/disappear when scrolling vertically

    const QFontMetrics fm( axisWidget( QwtPlot::yLeft )->font() );
    QwtScaleDraw *sd = axisScaleDraw( QwtPlot::yLeft );
    sd->setMinimumExtent( fm.width( "888.0" ) );

    setContextMenuPolicy( Qt::CustomContextMenu );

}
Esempio n. 23
0
  /**
   * ScatterPlotDataConstructor
   *
   * @param xCube The x-axis cube
   * @param xCubeBand The x-axis cube's band to get DN values from
   * @param xBinCount The resolution of the x-axis
   * @param yCube The y-axis cube
   * @param yCubeBand The y-axis cube's band to get DN values from
   * @param yBinCount The resolution of the y-axis
   * @param sampleRange The sample range to gather the histogram from, this is
   *                    the same for the x cube and y cube.
   * @param lineRange The line range to gather the histogram from, this is
   *                  the same for the x cube and y cube.
   */
  ScatterPlotData::ScatterPlotData(
      Cube *xCube, int xCubeBand, int xBinCount,
      Cube *yCube, int yCubeBand, int yBinCount,
      QwtInterval sampleRange, QwtInterval lineRange) : QwtRasterData(),
      m_xDnToBinStretch(new Stretch), m_yDnToBinStretch(new Stretch),
      m_counts(
        new QVector< QVector<int> >(yBinCount, QVector<int>(xBinCount))),
      m_alarmedBins(new QMap<int, bool>) {
    int startLine = qRound(lineRange.minValue());
    int endLine = qRound(lineRange.maxValue());
    ASSERT(xCube->lineCount() == yCube->lineCount());

    Histogram *xCubeHist = new Histogram(*xCube, xCubeBand, NULL,
        sampleRange.minValue(), lineRange.minValue(),
        sampleRange.maxValue(), lineRange.maxValue(),
        xBinCount, true);
    m_xCubeMin = xCubeHist->Minimum();
    m_xCubeMax = xCubeHist->Maximum();


    Histogram *yCubeHist = new Histogram(*yCube, yCubeBand, NULL,
        sampleRange.minValue(), lineRange.minValue(),
        sampleRange.maxValue(), lineRange.maxValue(),
        yBinCount, true);
    m_yCubeMin = yCubeHist->Minimum();
    m_yCubeMax = yCubeHist->Maximum();


    m_xDnToBinStretch->AddPair(m_xCubeMin, 0);
    m_xDnToBinStretch->AddPair(m_xCubeMax, xBinCount - 1);

    m_yDnToBinStretch->AddPair(m_yCubeMin, 0);
    m_yDnToBinStretch->AddPair(m_yCubeMax, yBinCount - 1);

    m_maxCount = 0;

    Brick brick1((int)(sampleRange.maxValue() - sampleRange.minValue() + 1),
                 1, 1, xCube->pixelType());
    Brick brick2((int)(sampleRange.maxValue() - sampleRange.minValue() + 1),
                 1, 1, yCube->pixelType());
    ASSERT(xCube->sampleCount() == yCube->sampleCount());
    ASSERT(brick1.size() == brick2.size());

    for (int line = startLine; line <= endLine; line++) {
      brick1.SetBasePosition(qRound(sampleRange.minValue()), line, xCubeBand);
      xCube->read(brick1);

      brick2.SetBasePosition(qRound(sampleRange.minValue()), line, yCubeBand);
      yCube->read(brick2);

      for (int i = 0; i < brick1.size(); i++) {
        double xDn = brick1[i];
        double yDn = brick2[i];

        if (!IsSpecial(xDn) && !IsSpecial(yDn)) {
          double x = m_xDnToBinStretch->Map(xDn);
          double y = m_yDnToBinStretch->Map(yDn);

          if (!IsSpecial(x) && !IsSpecial(y)) {
            int roundedX = qRound(x);
            int roundedY = qRound(y);

            if (roundedX >= 0 && roundedX < xBinCount &&
                roundedY >= 0 && roundedY < yBinCount) {
              int value = (*m_counts)[roundedY][roundedX] + 1;
              (*m_counts)[roundedY][roundedX] = value;

              m_maxCount = qMax(m_maxCount, value);
            }
          }
        }
      }
    }

    setInterval(Qt::XAxis, QwtInterval(m_xCubeMin, m_xCubeMax));
    setInterval(Qt::YAxis, QwtInterval(m_yCubeMin, m_yCubeMax));
    setInterval(Qt::ZAxis, QwtInterval(0, m_maxCount));
  }
Esempio n. 24
0
Phase::Phase(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Phase)
{
    ui->setupUi(this);
    ui->HdoubleSpinBox->setDecimals(6);
    ui->HdoubleSpinBox->setValue(0.2644);

    connect(ui->HdoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(drawPhase()));
    connect(ui->execute, SIGNAL(clicked()), this, SLOT(drawPhase()));

    ui->f0LineEdit->setText(QString::number(4.4e9));
    ui->fmLineEdit->setText(QString::number(150));
    ui->df0LineEdit->setText(QString::number(50e6));

    double f0 = ui->f0LineEdit->text().toDouble();
    double fm = ui->fmLineEdit->text().toDouble();
    double df0 = ui->df0LineEdit->text().toDouble();


    ui->qwtPolarPlot->setPlotBackground( Qt::white );

    // markers
    QwtPolarMarker *marker1 = new QwtPolarMarker();
    marker1->setSymbol( new QwtSymbol( QwtSymbol::Triangle, QBrush( Qt::red ), QPen( Qt::white ), QSize( 8, 8 ) ) );
    marker1->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );

    //QwtText text( "Marker" );
    //text.setColor( Qt::black );
    //QColor bg( Qt::white );
    //bg.setAlpha( 200 );
    //text.setBackgroundBrush( QBrush( bg ) );

    //marker->setLabel( text );
    marker1->attach(ui->qwtPolarPlot);

    QwtPolarMarker *marker11= new QwtPolarMarker();
    marker11->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::red ), QPen( Qt::white ), QSize( 7, 7 ) ) );
    marker11->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker11->attach(ui->qwtPolarPlot);

    QwtPolarMarker *marker2= new QwtPolarMarker();
    marker2->setSymbol( new QwtSymbol( QwtSymbol::Triangle, QBrush( Qt::darkGreen ), QPen( Qt::white ), QSize( 8, 8 ) ) );
    marker2->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker2->attach(ui->qwtPolarPlot);

    QwtPolarMarker *marker22= new QwtPolarMarker();
    marker22->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::darkGreen ), QPen( Qt::white ), QSize( 7, 7 ) ) );
    marker22->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker22->attach(ui->qwtPolarPlot);

    QwtPolarMarker *marker3= new QwtPolarMarker();
    marker3->setSymbol( new QwtSymbol( QwtSymbol::Triangle, QBrush( Qt::darkBlue ), QPen( Qt::white ), QSize( 8, 8 ) ) );
    marker3->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker3->attach(ui->qwtPolarPlot);

    QwtPolarMarker *marker33= new QwtPolarMarker();
    marker33->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::darkBlue ), QPen( Qt::white ), QSize( 7, 7 ) ) );
    marker33->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker33->attach(ui->qwtPolarPlot);

    d_curve = new QwtPolarCurve();
    c_curve = new QwtPolarCurve();
    e_curve = new QwtPolarCurve();

    double H = ui->HdoubleSpinBox->value();

    double angleF0 = countPhase0(H,f0);
    d_curve->setData( new PhaseData( radialInterval, azimuthInterval, numPoints, angleF0 ) );
    d_curve->setTitle(QString("fi0 = %1° (%2)").arg(QString::number(angleF0- floor(angleF0/360)*360)).arg(floor(angleF0/360)));

    double angleFm = countPhaseM(H,f0,df0);
    c_curve->setData( new PhaseData( radialInterval, azimuthInterval, numPoints, angleF0 + angleFm ) );
    c_curve->setTitle(QString("+fim = %1° (%2)").arg(QString::number((angleF0- floor(angleF0/360)*360) + angleFm)).arg("fi0+" + QString::number(angleFm) + "°"));

    e_curve->setData( new PhaseData( radialInterval, azimuthInterval, numPoints, angleF0 - angleFm ) );
    e_curve->setTitle(QString("-fim = %1° (%2)").arg(QString::number((angleF0- floor(angleF0/360)*360) - angleFm)).arg("fi0-" + QString::number(angleFm) + "°"));

    const QwtInterval azimuth2Interval(angleF0, angleF0+angleFm);
    const QwtInterval azimuth3Interval(angleF0-angleFm, angleF0);
    double F1 = (angleF0 - floor(angleF0/360)*360)+(qRound(H)*360);
    const QwtInterval azimuth1Interval(0, F1);

    f_curve = new QwtPolarCurve();
    f_curve->setData(new SpiralData( radial2Interval, azimuth2Interval, 400, angleF0 ) );
    f_curve->attach(ui->qwtPolarPlot);

    g_curve = new QwtPolarCurve();
    g_curve->setData(new SpiralData2( radial3Interval, azimuth3Interval, 400, angleF0 ) );
    g_curve->attach(ui->qwtPolarPlot);

    a_curve = new QwtPolarCurve();
    a_curve->setData(new SpiralData( radial1Interval, azimuth1Interval, 800, angleF0 ) );
    a_curve->attach(ui->qwtPolarPlot);

    marker1->setPosition(QwtPointPolar(angleF0+angleFm, radial2Interval.maxValue()));
    marker11->setPosition(QwtPointPolar(angleF0, radial2Interval.minValue()));
    marker2->setPosition(QwtPointPolar(angleF0-angleFm, radial3Interval.maxValue()-0.15));
    marker22->setPosition(QwtPointPolar(angleF0, radial3Interval.minValue()-0.15));
    marker3->setPosition(QwtPointPolar(angleF0, radial1Interval.maxValue()));
    marker33->setPosition(QwtPointPolar(angleF0, radial1Interval.minValue()));

    QPen spiral3Pen(Qt::darkBlue);
    spiral3Pen.setWidth(2);
    a_curve->setPen(spiral3Pen);


    QPen curve1Pen(Qt::darkBlue);
    curve1Pen.setWidth(3);
    d_curve->setPen(curve1Pen);

    QPen curve2Pen(Qt::red);
    curve2Pen.setWidth(3);
    curve2Pen.setStyle(Qt::DashDotLine);
    c_curve->setPen(curve2Pen);

    QPen curve3Pen(Qt::darkGreen);
    curve3Pen.setWidth(3);
    curve3Pen.setStyle(Qt::DashDotLine);

    QPen spiral1Pen(Qt::red);
    spiral1Pen.setWidth(2);
    f_curve->setPen(spiral1Pen);

    QPen spiral2Pen(Qt::darkGreen);
    spiral2Pen.setWidth(2);
    g_curve->setPen(spiral2Pen);

    e_curve->setPen(curve3Pen);

    d_curve->attach(ui->qwtPolarPlot);
    c_curve->attach(ui->qwtPolarPlot);
    e_curve->attach(ui->qwtPolarPlot);

    d_grid = new QwtPolarGrid();
    d_grid->setPen( QPen( Qt::black ) );

    QPen minorPen( Qt::gray );
    minorPen.setStyle( Qt::DotLine );
    d_grid->setMinorGridPen( minorPen );

    d_grid->showGrid(true);
    d_grid->showMinorGrid(true);

    d_grid->setAxisPen( QwtPolar::AxisAzimuth, QPen( Qt::black ) );
    d_grid->showAxis( QwtPolar::AxisAzimuth, true );
    d_grid->showAxis( QwtPolar::AxisLeft, true );
    d_grid->showAxis( QwtPolar::AxisRight, true );
    d_grid->showAxis( QwtPolar::AxisTop, true );
    d_grid->showAxis( QwtPolar::AxisBottom, true );
    d_grid->showGrid( QwtPolar::Azimuth, true );
    d_grid->showGrid( QwtPolar::Radius, true );

    d_grid->attach(ui->qwtPolarPlot);

    QwtLegend *legend = new QwtLegend;
    ui->qwtPolarPlot->insertLegend( legend,  QwtPolarPlot::BottomLegend );
}
Esempio n. 25
0
void Phase::drawPhase()
{
    ui->qwtPolarPlot->detachItems(QwtPolarItem::Rtti_PolarItem, false);
    d_grid->attach(ui->qwtPolarPlot);

    double H = ui->HdoubleSpinBox->value();
    double f0 = ui->f0LineEdit->text().toDouble();
    //double fm = ui->fmLineEdit->text().toDouble();
    double df0 = ui->df0LineEdit->text().toDouble();

    double angleF0 = countPhase0(H,f0);
    d_curve->setData( new PhaseData( radialInterval, azimuthInterval, numPoints, angleF0 ) );
    d_curve->setTitle(QString("fi0 = %1° (%2)").arg(QString::number(angleF0- floor(angleF0/360)*360)).arg(floor(angleF0/360)));
    d_curve->attach(ui->qwtPolarPlot);
    qDebug() << "angle F0 = " << angleF0;

    double angleFm = countPhaseM(H,f0,df0);
    c_curve->setData( new PhaseData( radialInterval, azimuthInterval, numPoints, angleF0 + angleFm ) );
    c_curve->setTitle(QString("+fim = %1° (%2)").arg(QString::number((angleF0- floor(angleF0/360)*360) + angleFm)).arg("fi0+" + QString::number(angleFm) + "°"));
    c_curve->attach(ui->qwtPolarPlot);
    qDebug() << "angle Fm = " << angleFm;

    e_curve->setData( new PhaseData( radialInterval, azimuthInterval, numPoints, angleF0 - angleFm) );
    e_curve->setTitle(QString("-fim = %1° (%2)").arg(QString::number((angleF0- floor(angleF0/360)*360) - angleFm)).arg("fi0-" + QString::number(angleFm) + "°"));
    e_curve->attach(ui->qwtPolarPlot);

    const QwtInterval azimuth2Interval(angleF0, angleF0+angleFm);
    const QwtInterval azimuth3Interval(angleF0-angleFm, angleF0);

    double F1 = (angleF0 - floor(angleF0/360)*360)+(qRound(H)*360);
    const QwtInterval azimuth1Interval(0, F1);

    a_curve->setData(new SpiralData( radial1Interval, azimuth1Interval, 10000, angleF0 ));
    a_curve->attach(ui->qwtPolarPlot);

    f_curve->setData(new SpiralData( radial2Interval, azimuth2Interval, 400, angleF0 ));
    f_curve->attach(ui->qwtPolarPlot);
    g_curve->setData(new SpiralData2( radial3Interval, azimuth3Interval, 1000, angleF0 ));
    g_curve->attach(ui->qwtPolarPlot);
    qDebug() << angleF0;

    QwtPolarMarker *marker1 = new QwtPolarMarker();
    marker1->setSymbol( new QwtSymbol( QwtSymbol::Triangle, QBrush( Qt::red ), QPen( Qt::white ), QSize( 8, 8 ) ) );
    marker1->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker1->setPosition(QwtPointPolar(angleF0+angleFm, radial2Interval.maxValue()));
    marker1->attach(ui->qwtPolarPlot);

    QwtPolarMarker *marker11= new QwtPolarMarker();
    marker11->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::red ), QPen( Qt::white ), QSize( 7, 7 ) ) );
    marker11->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker11->setPosition(QwtPointPolar(angleF0, radial2Interval.minValue()));
    marker11->attach(ui->qwtPolarPlot);

    QwtPolarMarker *marker2= new QwtPolarMarker();
    marker2->setSymbol( new QwtSymbol( QwtSymbol::Triangle, QBrush( Qt::darkGreen ), QPen( Qt::white ), QSize( 8, 8 ) ) );
    marker2->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker2->setPosition(QwtPointPolar(angleF0-angleFm, radial3Interval.maxValue()-0.15));
    marker2->attach(ui->qwtPolarPlot);

    QwtPolarMarker *marker22= new QwtPolarMarker();
    marker22->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::darkGreen ), QPen( Qt::white ), QSize( 7, 7 ) ) );
    marker22->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker22->setPosition(QwtPointPolar(angleF0, radial3Interval.minValue()-0.15));
    marker22->attach(ui->qwtPolarPlot);

    QwtPolarMarker *marker3= new QwtPolarMarker();
    marker3->setSymbol( new QwtSymbol( QwtSymbol::Triangle, QBrush( Qt::darkBlue ), QPen( Qt::white ), QSize( 8, 8 ) ) );
    marker3->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker3->setPosition(QwtPointPolar(angleF0, radial1Interval.maxValue()));
    marker3->attach(ui->qwtPolarPlot);

    QwtPolarMarker *marker33= new QwtPolarMarker();
    marker33->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::darkBlue ), QPen( Qt::white ), QSize( 7, 7 ) ) );
    marker33->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
    marker33->setPosition(QwtPointPolar(angleF0, radial1Interval.minValue()));
    marker33->attach(ui->qwtPolarPlot);

    ui->qwtPolarPlot->replot();
}
Esempio n. 26
0
/*!
  Draw circles

  \param painter Painter
  \param canvasRect Contents rect of the canvas in painter coordinates
  \param pole Position of the pole in painter coordinates
  \param radialMap Maps radius values into painter coordinates.
  \param values Radial values, indicating the distances from the pole
*/
void QwtPolarGrid::drawCircles(
    QPainter *painter, const QRectF &canvasRect,
    const QPointF &pole, const QwtScaleMap &radialMap,
    const QList<double> &values ) const
{
    for ( int i = 0; i < int( values.size() ); i++ )
    {
        const double val = values[i];

        const GridData &gridData =
            d_data->gridData[QwtPolar::Radius];

        bool skipLine = false;
        if ( testDisplayFlag( SmartScaleDraw ) )
        {
            const AxisData &axis = d_data->axisData[QwtPolar::AxisAzimuth];
            if ( axis.isVisible &&
                axis.scaleDraw->hasComponent( QwtAbstractScaleDraw::Backbone ) )
            {
                if ( isClose( val, gridData.scaleDiv.upperBound() ) )
                    skipLine = true;
            }
        }

        if ( isClose( val, gridData.scaleDiv.lowerBound() ) )
            skipLine = true;

        if ( !skipLine )
        {
            const double radius = radialMap.transform( val );

            QRectF outerRect( 0, 0, 2 * radius, 2 * radius );
            outerRect.moveCenter( pole );

            if ( testDisplayFlag( ClipGridLines ) )
            {
                /*
                    Qt4 is horrible slow, when painting primitives,
                    with coordinates far outside the visible area.
                    We need to clip.
                */

                const QVector<QwtInterval> angles =
                    QwtClipper::clipCircle( canvasRect, pole, radius );
                for ( int i = 0; i < angles.size(); i++ )
                {
                    const QwtInterval intv = angles[i];
                    if ( intv.minValue() == 0 && intv.maxValue() == 2 * M_PI )
                        QwtPainter::drawEllipse( painter, outerRect );
                    else
                    {
                        const double from = intv.minValue() / M_PI * 180;
                        const double to = intv.maxValue() / M_PI * 180;
                        double span = to - from;
                        if ( span < 0.0 )
                            span += 360.0;

                        painter->drawArc( outerRect,
                            qRound( from * 16 ), qRound( span * 16 ) );
                    }
                }
            }
            else
            {
                QwtPainter::drawEllipse( painter, outerRect );
            }
        }
    }
}
Esempio n. 27
0
/*!
   Update the axis scale draw geometries

   \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 radius Radius of the complete plot area in painter coordinates

   \sa updateScaleDiv()
*/
void QwtPolarGrid::updateScaleDraws(
    const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    const QPointF &pole, double radius ) const
{
    const QPoint p = pole.toPoint();

    const QwtInterval interval =
        d_data->gridData[QwtPolar::ScaleRadius].scaleDiv.interval();

    const int min = radialMap.transform( interval.minValue() );
    const int max = radialMap.transform( interval.maxValue() );
    const int l = max - min;

    for ( int axisId = 0; axisId < QwtPolar::AxesCount; axisId++ )
    {
        AxisData &axis = d_data->axisData[axisId];

        if ( axisId == QwtPolar::AxisAzimuth )
        {
            QwtRoundScaleDraw *scaleDraw =
                static_cast<QwtRoundScaleDraw *>( axis.scaleDraw );

            scaleDraw->setRadius( qRound( radius ) );
            scaleDraw->moveCenter( p );

            double from = ::fmod( 90.0 - azimuthMap.p1() * 180.0 / M_PI, 360.0 );
            if ( from < 0.0 )
                from += 360.0;

            scaleDraw->setAngleRange( from, from - 360.0 );

            const QwtTransform *transform = azimuthMap.transformation();
            if ( transform )
                scaleDraw->setTransformation( transform->copy() );
            else
                scaleDraw->setTransformation( NULL );
        }
        else
        {
            QwtScaleDraw *scaleDraw =
                static_cast<QwtScaleDraw *>( axis.scaleDraw );

            switch( axisId )
            {
                case QwtPolar::AxisLeft:
                {
                    scaleDraw->move( p.x() - min, p.y() );
                    scaleDraw->setLength( -l );
                    break;
                }
                case QwtPolar::AxisRight:
                {
                    scaleDraw->move( p.x() + min, p.y() );
                    scaleDraw->setLength( l );
                    break;
                }
                case QwtPolar::AxisTop:
                {
                    scaleDraw->move( p.x(), p.y() - max );
                    scaleDraw->setLength( l );
                    break;
                }
                case QwtPolar::AxisBottom:
                {
                    scaleDraw->move( p.x(), p.y() + max );
                    scaleDraw->setLength( -l );
                    break;
                }
            }
            const QwtTransform *transform = radialMap.transformation();
            if ( transform )
                scaleDraw->setTransformation( transform->copy() );
            else
                scaleDraw->setTransformation( NULL );
        }
    }
}
Esempio n. 28
0
/*!
    Align and divide an interval

   \param maxNumSteps Max. number of steps
   \param x1 First limit of the interval (In/Out)
   \param x2 Second limit of the interval (In/Out)
   \param stepSize Step size (Out)

   \sa QwtScaleEngine::setAttribute()
*/
void QwtLogScaleEngine::autoScale( int maxNumSteps,
    double &x1, double &x2, double &stepSize ) const
{
    if ( x1 > x2 )
        qSwap( x1, x2 );

    const double logBase = base();

    QwtInterval interval( x1 / qPow( logBase, lowerMargin() ),
        x2 * qPow( logBase, upperMargin() ) );

    if ( interval.maxValue() / interval.minValue() < logBase )
    {
        // scale width is less than one step -> try to build a linear scale

        QwtLinearScaleEngine linearScaler;
        linearScaler.setAttributes( attributes() );
        linearScaler.setReference( reference() );
        linearScaler.setMargins( lowerMargin(), upperMargin() );

        linearScaler.autoScale( maxNumSteps, x1, x2, stepSize );

        QwtInterval linearInterval = QwtInterval( x1, x2 ).normalized();
        linearInterval = linearInterval.limited( LOG_MIN, LOG_MAX );

        if ( linearInterval.maxValue() / linearInterval.minValue() < logBase )
        {
            // the aligned scale is still less than one step
            if ( stepSize < 0.0 )
                stepSize = -qwtLog( logBase, qAbs( stepSize ) );
            else
                stepSize = qwtLog( logBase, stepSize );

            return;
        }
    }

    double logRef = 1.0;
    if ( reference() > LOG_MIN / 2 )
        logRef = qMin( reference(), LOG_MAX / 2 );

    if ( testAttribute( QwtScaleEngine::Symmetric ) )
    {
        const double delta = qMax( interval.maxValue() / logRef,
            logRef / interval.minValue() );
        interval.setInterval( logRef / delta, logRef * delta );
    }

    if ( testAttribute( QwtScaleEngine::IncludeReference ) )
        interval = interval.extend( logRef );

    interval = interval.limited( LOG_MIN, LOG_MAX );

    if ( interval.width() == 0.0 )
        interval = buildInterval( interval.minValue() );

    stepSize = divideInterval( qwtLogInterval( logBase, interval ).width(), 
        qMax( maxNumSteps, 1 ) );
    if ( stepSize < 1.0 )
        stepSize = 1.0;

    if ( !testAttribute( QwtScaleEngine::Floating ) )
        interval = align( interval, stepSize );

    x1 = interval.minValue();
    x2 = interval.maxValue();

    if ( testAttribute( QwtScaleEngine::Inverted ) )
    {
        qSwap( x1, x2 );
        stepSize = -stepSize;
    }
}
Esempio n. 29
0
void QwtPolarGrid::updateScaleDiv( const QwtScaleDiv &azimuthScaleDiv,
    const QwtScaleDiv &radialScaleDiv, const QwtInterval &interval )
{
    GridData &radialGrid = d_data->gridData[QwtPolar::Radius];

    const QwtPolarPlot *plt = plot();
    if ( plt && testGridAttribute( AutoScaling ) )
    {
        const QwtScaleEngine *se = plt->scaleEngine( QwtPolar::Radius );
        radialGrid.scaleDiv = se->divideScale(
            interval.minValue(), interval.maxValue(),
            plt->scaleMaxMajor( QwtPolar::Radius ),
            plt->scaleMaxMinor( QwtPolar::Radius ), 0 );
    }
    else
    {
        if ( radialGrid.scaleDiv != radialScaleDiv )
            radialGrid.scaleDiv = radialScaleDiv;
    }

    GridData &azimuthGrid = d_data->gridData[QwtPolar::Azimuth];
    if ( azimuthGrid.scaleDiv != azimuthScaleDiv )
    {
        azimuthGrid.scaleDiv = azimuthScaleDiv;
    }

    bool hasOrigin = false;
    for ( int axisId = 0; axisId < QwtPolar::AxesCount; axisId++ )
    {
        AxisData &axis = d_data->axisData[axisId];
        if ( axis.isVisible && axis.scaleDraw )
        {
            if ( axisId == QwtPolar::AxisAzimuth )
            {
                axis.scaleDraw->setScaleDiv( azimuthGrid.scaleDiv );
                if ( testDisplayFlag( SmartScaleDraw ) )
                {
                    axis.scaleDraw->enableComponent(
                        QwtAbstractScaleDraw::Ticks, !azimuthGrid.isVisible );
                }
            }
            else
            {
                QwtScaleDiv sd = radialGrid.scaleDiv;

                QList<double> ticks = sd.ticks( QwtScaleDiv::MajorTick );

                if ( testDisplayFlag( SmartOriginLabel ) )
                {
                    bool skipOrigin = hasOrigin;
                    if ( !skipOrigin )
                    {
                        if ( axisId == QwtPolar::AxisLeft
                            || axisId == QwtPolar::AxisRight )
                        {
                            if ( d_data->axisData[QwtPolar::AxisBottom].isVisible )
                                skipOrigin = true;
                        }
                        else
                        {
                            if ( d_data->axisData[QwtPolar::AxisLeft].isVisible )
                                skipOrigin = true;
                        }
                    }
                    if ( ticks.size() > 0 && ticks.first() == sd.lowerBound() )
                    {
                        if ( skipOrigin )
                            ticks.removeFirst();
                        else
                            hasOrigin = true;
                    }
                }

                if ( testDisplayFlag( HideMaxRadiusLabel ) )
                {
                    if ( ticks.size() > 0 && ticks.last() == sd.upperBound() )
                        ticks.removeLast();
                }

                sd.setTicks( QwtScaleDiv::MajorTick, ticks );
                axis.scaleDraw->setScaleDiv( sd );

                if ( testDisplayFlag( SmartScaleDraw ) )
                {
                    axis.scaleDraw->enableComponent(
                        QwtAbstractScaleDraw::Ticks, !radialGrid.isVisible );
                }

            }
        }
    }
}
Esempio n. 30
0
static inline QwtInterval qwtPowInterval( double base, const QwtInterval &interval ) 
{
    return QwtInterval( qPow( base, interval.minValue() ),
            qPow( base, interval.maxValue() ) );
}