Exemplo n.º 1
0
void Plot::setMode( int style )
{
    if ( style == Tube )
    {
        d_intervalCurve->setStyle( QwtPlotIntervalCurve::Tube );
        d_intervalCurve->setSymbol( NULL );
        d_intervalCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    }
    else
    {
        d_intervalCurve->setStyle( QwtPlotIntervalCurve::NoCurve );

        QColor c( d_intervalCurve->brush().color().rgb() ); // skip alpha

        QwtIntervalSymbol *errorBar =
            new QwtIntervalSymbol( QwtIntervalSymbol::Bar );
        errorBar->setWidth( 8 ); // should be something even
        errorBar->setPen( c );

        d_intervalCurve->setSymbol( errorBar );
        d_intervalCurve->setRenderHint( QwtPlotItem::RenderAntialiased, false );
    }

    replot();
}
Exemplo n.º 2
0
/*!
  Draw symbols for a subset of the samples

  \param painter Painter
  \param symbol Interval symbol
  \param xMap x map
  \param yMap y map
  \param canvasRect Contents rect of the canvas
  \param from Index of the first sample to be painted
  \param to Index of the last sample to be painted

  \sa setSymbol(), drawSeries(), drawTube()
*/
void QwtPlotIntervalCurve::drawSymbols(
    QPainter *painter, const QwtIntervalSymbol &symbol,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    painter->save();

    QPen pen = symbol.pen();
    pen.setCapStyle( Qt::FlatCap );

    painter->setPen( pen );
    painter->setBrush( symbol.brush() );

    const QRectF &tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect);

    const double xMin = tr.left();
    const double xMax = tr.right();
    const double yMin = tr.top();
    const double yMax = tr.bottom();

    const bool doClip = d_data->paintAttributes & ClipPolygons;

    for ( int i = from; i <= to; i++ )
    {
        const QwtIntervalSample s = sample( i );

        if ( orientation() == Qt::Vertical )
        {
            if ( !doClip || qwtIsVSampleInside( s, xMin, xMax, yMin, yMax ) )
            {
                const double x = xMap.transform( s.value );
                const double y1 = yMap.transform( s.interval.minValue() );
                const double y2 = yMap.transform( s.interval.maxValue() );

                symbol.draw( painter, orientation(),
                    QPointF( x, y1 ), QPointF( x, y2 ) );
            }
        }
        else
        {
            if ( !doClip || qwtIsHSampleInside( s, xMin, xMax, yMin, yMax ) )
            {
                const double y = yMap.transform( s.value );
                const double x1 = xMap.transform( s.interval.minValue() );
                const double x2 = xMap.transform( s.interval.maxValue() );

                symbol.draw( painter, orientation(),
                    QPointF( x1, y ), QPointF( x2, y ) );
            }
        }
    }

    painter->restore();
}
Exemplo n.º 3
0
void QmitkPlotWidget::SetErrorPen(unsigned int curveId, const QPen &pen)
{
  std::get<1>(m_PlotCurveVector[curveId])->setPen(pen);
  QwtIntervalSymbol *errorBar = new QwtIntervalSymbol(QwtIntervalSymbol::Bar);
  errorBar->setPen(pen);
  std::get<1>(m_PlotCurveVector[curveId])->setSymbol(errorBar);
  std::get<2>(m_PlotCurveVector[curveId])->setPen(pen);
  errorBar = new QwtIntervalSymbol(QwtIntervalSymbol::Bar);
  errorBar->setPen(pen);
  std::get<2>(m_PlotCurveVector[curveId])->setSymbol(errorBar);
}
Exemplo n.º 4
0
int qfit::plotLinearData()
{
    /* standard data */
    data_plot = new QwtPlotCurve("data");
    data_plot->setSamples(&xdata.at(0), &ydata.at(0), xdata.size());
    data_plot->setSymbol(new QwtSymbol(QwtSymbol::XCross, Qt::NoBrush, QPen(Qt::black), QSize(8, 8)));
    data_plot->setStyle(QwtPlotCurve::NoCurve);
    data_plot->setRenderHint(QwtPlotItem::RenderAntialiased);

    /* error bars */
    range_plot = new QwtPlotIntervalCurve("range");

    QVector<QwtIntervalSample> range(xdata.size());
    for(int i = 0; i < (int)xdata.size(); i++) {
        range[i] = QwtIntervalSample(xdata.at(i), ydata.at(i) - yerrors.at(i), ydata.at(i) + yerrors.at(i));
    }

    QwtIntervalSymbol *errorbar = new QwtIntervalSymbol(QwtIntervalSymbol::Bar);
    errorbar->setPen(QPen(Qt::black, 1));
    range_plot->setSamples(range);
    range_plot->setSymbol(errorbar);
    range_plot->setStyle(QwtPlotIntervalCurve::NoCurve);

    /* model */
    FitTools::LinearFitResult tmp = fit->getLinearResult();
    double x[2], y[2];
    x[0] = xdata.at(0);
    x[1] = xdata.back();
    y[0] = tmp.m * x[0] + tmp.q;
    y[1] = tmp.m * x[1] + tmp.q;

    model_plot = new QwtPlotCurve("y=mx+q");
    model_plot->setSamples(x, y, 2);
    model_plot->setPen(QPen(Qt::red, 1));
    model_plot->setRenderHint(QwtPlotItem::RenderAntialiased);

    data_plot->attach(qwtPlot);
    range_plot->attach(qwtPlot);
    model_plot->attach(qwtPlot);
    return(0);
}
Exemplo n.º 5
0
void QmitkPlotWidget::SetErrorStyleSymbols(unsigned int curveId, bool drawSmybols)
{
  if (drawSmybols)
  {
    std::get<1>(m_PlotCurveVector[curveId])->setStyle(QwtPlotIntervalCurve::NoCurve);
    QwtIntervalSymbol *errorBar = new QwtIntervalSymbol(QwtIntervalSymbol::Bar);
    errorBar->setPen(std::get<1>(m_PlotCurveVector[curveId])->pen());
    std::get<1>(m_PlotCurveVector[curveId])->setSymbol(errorBar);
    std::get<2>(m_PlotCurveVector[curveId])->setStyle(QwtPlotIntervalCurve::NoCurve);
    errorBar = new QwtIntervalSymbol(QwtIntervalSymbol::Bar);
    errorBar->setPen(std::get<2>(m_PlotCurveVector[curveId])->pen());
    std::get<2>(m_PlotCurveVector[curveId])->setSymbol(errorBar);
  }
  else
  {
    std::get<1>(m_PlotCurveVector[curveId])->setStyle(QwtPlotIntervalCurve::Tube);
    std::get<1>(m_PlotCurveVector[curveId])->setSymbol(nullptr);
    std::get<2>(m_PlotCurveVector[curveId])->setStyle(QwtPlotIntervalCurve::Tube);
    std::get<2>(m_PlotCurveVector[curveId])->setSymbol(nullptr);
  }
}
Exemplo n.º 6
0
bool QmitkPlotWidget::AddErrorIntervalCurve(unsigned int curveId,
                                            const DataVector &lessError,
                                            const DataVector &moreError,
                                            bool isXError)
{
  const QwtSeriesData<QPointF> *curveSeriesData = std::get<0>(this->m_PlotCurveVector[curveId])->data();

  size_t size = curveSeriesData->size();

  if (size != lessError.size() || size != moreError.size())
  {
    std::cerr << "Sizes of data arrays don't match." << std::endl;
    return false;
  }

  QVector<QwtIntervalSample> samples;
  QwtIntervalSample *sample;
  QwtPlotIntervalCurve *curve;

  if (isXError)
  {
    curve = std::get<1>(m_PlotCurveVector[curveId]);
  }
  else
  {
    curve = std::get<2>(m_PlotCurveVector[curveId]);
  }

  for (unsigned int index = 0; index < size; ++index)
  {
    qreal xValue = curveSeriesData->sample(index).x();
    qreal yValue = curveSeriesData->sample(index).y();
    if (isXError)
    {
      sample = new QwtIntervalSample(xValue, xValue - lessError[index], xValue + moreError[index]);
    }
    else
    {
      sample = new QwtIntervalSample(xValue, yValue - lessError[index], yValue + moreError[index]);
    }
    samples.push_back(*sample);
  }

  curve->setSamples(samples);
  curve->setStyle(QwtPlotIntervalCurve::NoCurve);

  QwtIntervalSymbol *errorBar = new QwtIntervalSymbol(QwtIntervalSymbol::Bar);
  errorBar->setPen(QPen(Qt::black));
  curve->setSymbol(errorBar);

  if (isXError)
  {
    curve->setOrientation(Qt::Horizontal);
  }
  else
  {
    curve->setOrientation(Qt::Vertical);
  }

  return true;
}