QwtDoubleRect VectorCurve::boundingRect() const { QwtDoubleRect rect = QwtPlotCurve::boundingRect(); if (d_type == Graph::VectXYXY) rect |= vectorEnd->boundingRect(); else { int rows = abs(d_end_row - d_start_row) + 1; for (int i = 0; i < rows; i++) { double x_i = x(i); double y_i = y(i); double angle = vectorEnd->x(i); double mag = vectorEnd->y(i); switch(d_position) { case Tail: rect |= QwtDoubleRect(x_i, y_i, mag*cos(angle), mag*sin(angle)).normalized(); break; case Middle: { QwtDoubleRect rect_i(0, 0, fabs(mag*cos(angle)), fabs(mag*sin(angle))); rect_i.moveCenter(QwtDoublePoint(x_i, y_i)); rect |= rect_i; break; } case Head: rect |= QwtDoubleRect(x_i, y_i, -mag*cos(angle), -mag*sin(angle)).normalized(); break; } } } return rect; }
/*! Returns the bounding rectangle of the data. If there is no bounding rect, like for empty data the rectangle is invalid: QwtDoubleRect::isValid() == false */ QwtDoubleRect QwtCPointerData::boundingRect() const { const size_t sz = size(); if ( sz <= 0 ) return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid double minX, maxX, minY, maxY; const double *xIt = d_x; const double *yIt = d_y; const double *end = d_x + sz; minX = maxX = *xIt++; minY = maxY = *yIt++; while ( xIt < end ) { const double xv = *xIt++; if ( xv < minX ) minX = xv; if ( xv > maxX ) maxX = xv; const double yv = *yIt++; if ( yv < minY ) minY = yv; if ( yv > maxY ) maxY = yv; } return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); }
/*! Returns the bounding rectangle of the data. If there is no bounding rect, like for empty data the rectangle is invalid: QwtDoubleRect::isValid() == false \warning This is an slow implementation iterating over all points. It is intended to be overloaded by derived classes. In case of auto scaling boundingRect() is called for every replot, so it might be worth to implement a cache, or use x(0), x(size() - 1) for ordered data ... */ QwtDoubleRect QwtData::boundingRect() const { const size_t sz = size(); if ( sz <= 0 ) return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid double minX, maxX, minY, maxY; minX = maxX = x(0); minY = maxY = y(0); for ( size_t i = 1; i < sz; i++ ) { const double xv = x(i); if ( xv < minX ) minX = xv; if ( xv > maxX ) maxX = xv; const double yv = y(i); if ( yv < minY ) minY = yv; if ( yv > maxY ) maxY = yv; } return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); }
/*! Calculate the viewBox from an rect and boundingRect(). \param rect Rectangle in scale coordinates \return viewBox View Box, see QSvgRenderer::viewBox */ QwtDoubleRect QwtPlotSvgItem::viewBox(const QwtDoubleRect &rect) const { #if QT_VERSION >= 0x040100 const QSize sz = d_data->renderer.defaultSize(); #else #if QT_VERSION > 0x040000 const QSize sz(d_data->picture.width(), d_data->picture.height()); #else QPaintDeviceMetrics metrics(&d_data->picture); const QSize sz(metrics.width(), metrics.height()); #endif #endif const QwtDoubleRect br = boundingRect(); if ( !rect.isValid() || !br.isValid() || sz.isNull() ) return QwtDoubleRect(); QwtScaleMap xMap; xMap.setScaleInterval(br.left(), br.right()); xMap.setPaintInterval(0, sz.width()); QwtScaleMap yMap; yMap.setScaleInterval(br.top(), br.bottom()); yMap.setPaintInterval(sz.height(), 0); const double x1 = xMap.xTransform(rect.left()); const double x2 = xMap.xTransform(rect.right()); const double y1 = yMap.xTransform(rect.bottom()); const double y2 = yMap.xTransform(rect.top()); return QwtDoubleRect(x1, y1, x2 - x1, y2 - y1); }
/*! Returns the bounding rectangle of the data. If there is no bounding rect, like for empty data the rectangle is invalid: QwtDoubleRect::isValid() == false */ QwtDoubleRect QwtArrayData::boundingRect() const { const size_t sz = size(); if ( sz <= 0 ) return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid double minX, maxX, minY, maxY; QwtArray<double>::ConstIterator xIt = d_x.begin(); QwtArray<double>::ConstIterator yIt = d_y.begin(); QwtArray<double>::ConstIterator end = d_x.begin() + sz; minX = maxX = *xIt++; minY = maxY = *yIt++; while ( xIt < end ) { const double xv = *xIt++; if ( xv < minX ) minX = xv; if ( xv > maxX ) maxX = xv; const double yv = *yIt++; if ( yv < minY ) minY = yv; if ( yv > maxY ) maxY = yv; } return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); }
/*! Returns the intersection of this rectangle and rectangle other. Returns an empty rectangle if there is no intersection. */ QwtDoubleRect QwtDoubleRect::operator&(const QwtDoubleRect &other) const { if (isNull() || other.isNull()) return QwtDoubleRect(); const QwtDoubleRect r1 = normalized(); const QwtDoubleRect r2 = other.normalized(); const double minX = qwtMax(r1.left(), r2.left()); const double maxX = qwtMin(r1.right(), r2.right()); const double minY = qwtMax(r1.top(), r2.top()); const double maxY = qwtMin(r1.bottom(), r2.bottom()); return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); }
QwtDoubleRect QwtCurve::boundingRect() const { if ( d_data == NULL ) return QwtDoubleRect(1.0, -1.0, 1.0, -1.0); // invalid return d_data->boundingRect(); }
void VectorPlot::setupPlot(const QwtDoubleRect &rect) { QwtScaleDiv *hDiv = plot->axisScaleDiv(QwtPlot::xBottom); QwtScaleDiv *vDiv = plot->axisScaleDiv(QwtPlot::yLeft); // In earlier qwt version some member function names are different from newer version #if QWT_VERSION <= 0x050101 double lLimit = std::min(hDiv->lBound(), rect.left()); double rLimit = std::max(hDiv->hBound(), rect.right()); double bLimit = std::min(vDiv->lBound(), rect.bottom()); double tLimit = std::max(vDiv->hBound(), rect.top()); #else double lLimit = std::min(hDiv->lowerBound(), rect.left()); double rLimit = std::max(hDiv->upperBound(), rect.right()); double bLimit = std::min(vDiv->lowerBound(), rect.bottom()); double tLimit = std::max(vDiv->upperBound(), rect.top()); #endif plot->setAxisScale(QwtPlot::xBottom, lLimit, rLimit); plot->setAxisScale(QwtPlot::yLeft, bLimit, tLimit); double xMargin = plot->invTransform(QwtPlot::xBottom, plot->margin()); double yMargin = plot->invTransform(QwtPlot::yLeft, plot->margin()); mBoundingRect = QwtDoubleRect(QwtDoublePoint(lLimit - xMargin, tLimit + yMargin), QwtDoublePoint(rLimit + xMargin, bLimit - yMargin)); qDebug() << "xMargin:" << xMargin; qDebug() << "yMargin:" << yMargin; qDebug() << "mBoundingRect:" << mBoundingRect; // mBoundingRect = rect; }
QwtDoubleRect HistogramItem::boundingRect() const { QwtDoubleRect rect = d_data->data.boundingRect(); if ( !rect.isValid() ) return rect; if ( d_data->attributes & Xfy ) { rect = QwtDoubleRect( rect.y(), rect.x(), rect.height(), rect.width() ); if ( rect.left() > d_data->reference ) rect.setLeft( d_data->reference ); else if ( rect.right() < d_data->reference ) rect.setRight( d_data->reference ); } else { if ( rect.bottom() < d_data->reference ) rect.setBottom( d_data->reference ); else if ( rect.top() > d_data->reference ) rect.setTop( d_data->reference ); } return rect; }
QwtDoubleRect QwtPlotCurve::boundingRect() const { if ( d_xy == NULL ) return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid return d_xy->boundingRect(); }
QwtDoubleRect Matrix::boundingRect() { int rows = numRows(); int cols = numCols(); double dx = fabs(x_end - x_start)/(double)(cols - 1); double dy = fabs(y_end - y_start)/(double)(rows - 1); return QwtDoubleRect(QMIN(x_start, x_end) - 0.5*dx, QMIN(y_start, y_end) - 0.5*dy, fabs(x_end - x_start) + dx, fabs(y_end - y_start) + dy).normalized(); }
/** * Klonuje obiekt danych. * * @return kopia obiektu danych utworzona na stercie */ QwtRasterData* FeatureData::copy() const { FeatureData* data = new FeatureData(paramsArray, minParam, maxParam); data->framesCount = framesCount; data->paramsPerFrame = paramsPerFrame; data->info = info; data->ownsArray = true; data->setBoundingRect(QwtDoubleRect(0, 0, framesCount, paramsPerFrame)); return data; }
QwtDoubleRect QwtIntervalData::boundingRect() const { double minX, maxX, minY, maxY; minX = maxX = minY = maxY = 0.0; bool isValid = false; const size_t sz = size(); for ( size_t i = 0; i < sz; i++ ) { const QwtDoubleInterval intv = interval(i); if ( !intv.isValid() ) continue; const double v = value(i); if ( !isValid ) { minX = intv.minValue(); maxX = intv.maxValue(); minY = maxY = v; isValid = true; } else { if ( intv.minValue() < minX ) minX = intv.minValue(); if ( intv.maxValue() > maxX ) maxX = intv.maxValue(); if ( v < minY ) minY = v; if ( v > maxY ) maxY = v; } } if ( !isValid ) return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); }
/*! Translate a rectangle from pixel into plot coordinates \return Rectangle in plot coordinates \sa QwtPlotPicker::transform() */ QwtDoubleRect QwtPlotPicker::invTransform(const QRect &rect) const { QwtDiMap xMap = plot()->canvasMap(d_xAxis); QwtDiMap yMap = plot()->canvasMap(d_yAxis); return QwtDoubleRect( xMap.invTransform(rect.left()), xMap.invTransform(rect.right()), yMap.invTransform(rect.top()), yMap.invTransform(rect.bottom()) ); }
QwtDoubleRect LegendMarker::boundingRect() const { QRect bounding_rect = rect(); const QwtScaleMap &x_map = d_plot->canvasMap(xAxis()); const QwtScaleMap &y_map = d_plot->canvasMap(yAxis()); double left = x_map.invTransform(bounding_rect.left()); double right = x_map.invTransform(bounding_rect.right()); double top = y_map.invTransform(bounding_rect.top()); double bottom = y_map.invTransform(bounding_rect.bottom()); return QwtDoubleRect(left, top, qAbs(right-left), qAbs(bottom-top)); }
/*! Translate a rectangle from pixel into plot coordinates \return Rectangle in plot coordinates \sa QwtPlotPicker::transform() */ QwtDoubleRect QwtPlotPicker::invTransform(const QRect &rect) const { QwtScaleMap xMap = plot()->canvasMap(d_xAxis); QwtScaleMap yMap = plot()->canvasMap(d_yAxis); const double left = xMap.invTransform(rect.left()); const double right = xMap.invTransform(rect.right()); const double top = yMap.invTransform(rect.top()); const double bottom = yMap.invTransform(rect.bottom()); return QwtDoubleRect(left, top, right - left, bottom - top); }
QwtDoubleRect ArrowMarker::boundingRect() const { const QwtScaleMap &xMap = plot()->canvasMap(xAxis()); const QwtScaleMap &yMap = plot()->canvasMap(yAxis()); const int x0 = xMap.transform(d_rect.left()); const int y0 = yMap.transform(d_rect.top()); const int x1 = xMap.transform(d_rect.right()); const int y1 = yMap.transform(d_rect.bottom()); return QwtDoubleRect(x0 < x1 ? d_rect.left() : d_rect.right(), y0 < y1 ? d_rect.top() : d_rect.bottom(), qAbs(d_rect.left() - d_rect.right()), qAbs(d_rect.top() - d_rect.bottom())); }
TimeSeriesFloodPlotData::TimeSeriesFloodPlotData(TimeSeries timeSeries, QwtDoubleInterval colorMapRange) : m_timeSeries(timeSeries), m_minValue(minimum(timeSeries.values())), m_maxValue(maximum(timeSeries.values())), m_minX(timeSeries.firstReportDateTime().date().dayOfYear()), m_maxX(ceil(timeSeries.daysFromFirstReport()[timeSeries.daysFromFirstReport().size()-1]+timeSeries.firstReportDateTime().date().dayOfYear()+timeSeries.firstReportDateTime().time().totalDays())), // end day m_minY(0), // start hour m_maxY(24), // end hour m_startFractionalDay(timeSeries.firstReportDateTime().date().dayOfYear()+timeSeries.firstReportDateTime().time().totalDays()), m_colorMapRange(colorMapRange) { // data range setBoundingRect(QwtDoubleRect(m_minX, m_minY, m_maxX-m_minX, m_maxY-m_minY)); }
/*! Returns the bounding rectangle of this rectangle and rectangle other. The bounding rectangle of a nonempty rectangle and an empty or invalid rectangle is defined to be the nonempty rectangle. */ QwtDoubleRect QwtDoubleRect::operator|(const QwtDoubleRect &other) const { if ( isEmpty() ) return other; if ( other.isEmpty() ) return *this; const double minX = qwtMin(d_left, other.d_left); const double maxX = qwtMax(d_right, other.d_right); const double minY = qwtMin(d_top, other.d_top); const double maxY = qwtMax(d_bottom, other.d_bottom); return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); }
MatrixRaster::MatrixRaster (double* &matr, const int rws, const int cls): QwtRasterData(QwtDoubleRect(0.0,0.0,cls,rws)), data_array(matr), rows(rws), cols(cls) { this->initRaster(QwtDoubleRect(0.0,1.0,0.0,1.0),QSize(cls,rws)); if ((matr==NULL) || (rws==0) || (cls==0)) { from=DBL_MAX; to=1.0-DBL_MAX; } else { const unsigned int matr_size=static_cast<const unsigned int>(rws)*static_cast<const unsigned int>(cls); double tmp; to=from=matr[0]; for (unsigned int i=1u; i<matr_size; ++i) { tmp=matr[i]; from=(tmp<from)? tmp : from; to=(to<tmp)? tmp : to; } matr=NULL; } }
TimeSeriesLinePlotData::TimeSeriesLinePlotData(TimeSeries timeSeries, double fracDaysOffset) : m_timeSeries(timeSeries), m_minX(timeSeries.firstReportDateTime().date().dayOfYear()+timeSeries.firstReportDateTime().time().totalDays()), m_maxX(timeSeries.daysFromFirstReport()[timeSeries.daysFromFirstReport().size()-1]+timeSeries.firstReportDateTime().date().dayOfYear()+timeSeries.firstReportDateTime().time().totalDays()), // end day m_minY(minimum(timeSeries.values())), m_maxY(maximum(timeSeries.values())), m_size(timeSeries.values().size()) { m_boundingRect = QwtDoubleRect(m_minX, m_minY, (m_maxX - m_minX), (m_maxY - m_minY)); m_minValue = m_minY; m_maxValue = m_maxY; m_units = timeSeries.units(); m_fracDaysOffset = fracDaysOffset; // note updating in xValue does not affect scaled axis m_x = m_timeSeries.daysFromFirstReport(); m_y = m_timeSeries.values(); }
// set ranges and bounding box void VectorLinePlotData::init(){ unsigned M = m_xVector.size(); unsigned N = m_yVector.size(); if ((M <= 1) || (N <= 1) || (M != N)){ throw std::runtime_error("Incorrectly sized matrix or vector for VectorLinePlotData"); } m_size = N; m_minX = minimum(m_xVector); m_maxX = maximum(m_xVector); m_minY = minimum(m_yVector); m_maxY = maximum(m_yVector); // set the bounding box m_boundingRect = QwtDoubleRect(m_minX, m_minY, (m_maxX - m_minX), (m_maxY - m_minY)); }
//! Redraw the canvas void QwtPolarCanvas::drawContents( QPainter *painter ) { if ( d_data->paintAttributes & PaintCached && d_data->cache && d_data->cache->size() == contentsRect().size() ) { painter->drawPixmap( contentsRect().topLeft(), *d_data->cache ); } else { QwtPolarPlot *plt = plot(); if ( plt ) { const bool doAutoReplot = plt->autoReplot(); plt->setAutoReplot( false ); drawCanvas( painter, QwtDoubleRect( contentsRect() ) ); plt->setAutoReplot( doAutoReplot ); } } }
/*! Return normalized bounding rect of the axes \sa QwtPlot::autoReplot(), QwtPlot::replot(). */ QwtDoubleRect QwtPlotPicker::scaleRect() const { QwtDoubleRect rect; if ( plot() ) { const QwtScaleDiv *xs = plot()->axisScaleDiv(xAxis()); const QwtScaleDiv *ys = plot()->axisScaleDiv(yAxis()); if ( xs && ys ) { rect = QwtDoubleRect( xs->lowerBound(), ys->lowerBound(), xs->range(), ys->range() ); rect = rect.normalized(); } } return rect; }
/** * Tworzy obiekt danych, szuka zakresu wartości i kopiuje cechy z ekstraktora. * * @param extractor obiekt ekstraktora */ FeatureData::FeatureData(Aquila::Extractor* extractor): QwtRasterData(QwtDoubleRect(0, 0, extractor->getFramesCount(), extractor->getParamsPerFrame())), framesCount(extractor->getFramesCount()), paramsPerFrame(extractor->getParamsPerFrame()), canceled(false), ownsArray(false) { maxParam = std::numeric_limits<double>().min(); minParam = std::numeric_limits<double>().max(); paramsArray = new double*[framesCount]; QProgressDialog progress(QObject::tr("Generating feature chart..."), QObject::tr("Cancel"), 0, framesCount); progress.setMinimumDuration(0); progress.setWindowModality(Qt::WindowModal); for (unsigned int i = 0; i < framesCount; ++i) { if (progress.wasCanceled()) { canceled = true; break; // TODO: potential memory leak? } paramsArray[i] = new double[paramsPerFrame]; for (unsigned int j = 0; j < paramsPerFrame; ++j) { double value = extractor->getParam(i, j); if (value < minParam) minParam = value; if (value > maxParam) maxParam = value; paramsArray[i][j] = value; progress.setValue(i); qApp->processEvents(); } } info = QObject::tr("%3, %1 frames, %2 params per frame").arg(framesCount). arg(paramsPerFrame).arg(extractor->getType().c_str()); }
// set ranges and bounding box void MatrixFloodPlotData::init(){ unsigned M = m_matrix.size1(); unsigned N = m_matrix.size2(); if ((M <= 1) || (N <= 1) || (M != m_xVector.size()) || (N != m_yVector.size())){ throw std::runtime_error("Incorrectly sized matrix or vector for MatrixFloodPlotData"); } m_minX = minimum(m_xVector); m_maxX = maximum(m_xVector); m_minY = minimum(m_yVector); m_maxY = maximum(m_yVector); m_minValue = minimum(m_matrix); m_maxValue = maximum(m_matrix); // default behavior is to have entire data range considered for colormapping // override by setting colorMapRange m_colorMapRange = QwtDoubleInterval(m_minValue, m_maxValue); // set the bounding box setBoundingRect(QwtDoubleRect(m_minX, m_minY, m_maxX-m_minX, m_maxY-m_minY)); }
QwtDoubleRect QwtPlotItem::boundingRect() const { return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid }
QwtDoubleRect C2DCurveData::boundingRect() const { if (mSize <= 0) return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid if (mLastRectangle == mSize) return QwtDoubleRect(mMinX, mMinY, mMaxX - mMinX, mMaxY - mMinY); const double *xIt = mpX + mLastRectangle; const double *yIt = mpY + mLastRectangle; const double *end = mpX + mSize; mLastRectangle = mSize; // We have to remember whether we have an initial NaN bool MinXisNaN = isnan(mMinX); bool MaxXisNaN = isnan(mMaxX); bool MinYisNaN = isnan(mMinY); bool MaxYisNaN = isnan(mMaxY); while (xIt < end) { const double xv = *xIt++; if (!isnan(xv)) { if ((xv < mMinX || MinXisNaN) && xv > -std::numeric_limits< double >::infinity()) { mMinX = xv; MinXisNaN = false; } if ((xv > mMaxX || MaxXisNaN) && xv < std::numeric_limits< double >::infinity()) { mMaxX = xv; MaxXisNaN = false; } } const double yv = *yIt++; if (!isnan(yv)) { if ((yv < mMinY || MinYisNaN) && yv > -std::numeric_limits< double >::infinity()) { mMinY = yv; MinYisNaN = false; } if ((yv > mMaxY || MaxYisNaN) && yv < std::numeric_limits< double >::infinity()) { mMaxY = yv; MaxYisNaN = false; } } } if (isnan(mMinX + mMaxX + mMinY + mMaxY)) return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid // We need to avoid very small data ranges (absolute and relative) C_FLOAT64 minRange; minRange = fabs(mMinY + mMaxY) * 5e-5 + std::numeric_limits< C_FLOAT64 >::min() * 100.0; if (mMaxY - mMinY < minRange) { mMinY = mMinY - minRange * 0.5; mMaxY = mMaxY + minRange * 0.5; } if (mMinX == 0 && mMaxX == 0) return QwtDoubleRect(0.1, mMinY, -0.2, mMaxY - mMinY); // invalid X minRange = fabs(mMinX + mMaxX) * 5.e-5 + std::numeric_limits< C_FLOAT64 >::min() * 100.0; if (mMaxX - mMinX < minRange) { mMinX = mMinX - minRange * 0.5; mMaxX = mMaxX + minRange * 0.5; } return QwtDoubleRect(mMinX, mMinY, mMaxX - mMinX, mMaxY - mMinY); }
SpectrogramData(): QwtRasterData(QwtDoubleRect(-1.5, -1.5, 3.0, 3.0)) { }
static inline QwtDoubleRect boundingRect(const QwtPolygonF &polygon) { #if QT_VERSION < 0x040000 if (polygon.isEmpty()) return QwtDoubleRect(0, 0, 0, 0); register const QwtDoublePoint *pd = polygon.data(); double minx, maxx, miny, maxy; minx = maxx = pd->x(); miny = maxy = pd->y(); pd++; for (uint i = 1; i < polygon.size(); i++, pd++) { if (pd->x() < minx) minx = pd->x(); else if (pd->x() > maxx) maxx = pd->x(); if (pd->y() < miny) miny = pd->y(); else if (pd->y() > maxy) maxy = pd->y(); } return QwtDoubleRect(minx, miny, maxx - minx, maxy - miny); #else return polygon.boundingRect(); #endif }