MCPcopy Create free account
hub / github.com/ZhuYanzhen1/miniFOC / getOptimizedLineData

Method getOptimizedLineData

tools/qcustomplot.cpp:21661–21739  ·  view source on GitHub ↗

! \internal Returns via \a lineData the data points that need to be visualized for this graph when plotting graph lines, taking into consideration the currently visible axis ranges and, if \ref setAdaptiveSampling is enabled, local point densities. The considered data can be restricted further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref getDataSegme

Source from the content-addressed store, hash-verified

21659 \see getOptimizedScatterData
21660*/
21661void QCPGraph::getOptimizedLineData(QVector<QCPGraphData> *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const
21662{
21663 if (!lineData) return;
21664 QCPAxis *keyAxis = mKeyAxis.data();
21665 QCPAxis *valueAxis = mValueAxis.data();
21666 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; }
21667 if (begin == end) return;
21668
21669 int dataCount = int(end-begin);
21670 int maxCount = (std::numeric_limits<int>::max)();
21671 if (mAdaptiveSampling)
21672 {
21673 double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key));
21674 if (2*keyPixelSpan+2 < static_cast<double>((std::numeric_limits<int>::max)()))
21675 maxCount = int(2*keyPixelSpan+2);
21676 }
21677
21678 if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average
21679 {
21680 QCPGraphDataContainer::const_iterator it = begin;
21681 double minValue = it->value;
21682 double maxValue = it->value;
21683 QCPGraphDataContainer::const_iterator currentIntervalFirstPoint = it;
21684 int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction
21685 int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey
21686 double currentIntervalStartKey = keyAxis->pixelToCoord(int(keyAxis->coordToPixel(begin->key)+reversedRound));
21687 double lastIntervalEndKey = currentIntervalStartKey;
21688 double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates
21689 bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes)
21690 int intervalDataCount = 1;
21691 ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect
21692 while (it != end)
21693 {
21694 if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary
21695 {
21696 if (it->value < minValue)
21697 minValue = it->value;
21698 else if (it->value > maxValue)
21699 maxValue = it->value;
21700 ++intervalDataCount;
21701 } else // new pixel interval started
21702 {
21703 if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster
21704 {
21705 if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point
21706 lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value));
21707 lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue));
21708 lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue));
21709 if (it->key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point
21710 lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.8, (it-1)->value));
21711 } else
21712 lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value));
21713 lastIntervalEndKey = (it-1)->key;
21714 minValue = it->value;
21715 maxValue = it->value;
21716 currentIntervalFirstPoint = it;
21717 currentIntervalStartKey = keyAxis->pixelToCoord(int(keyAxis->coordToPixel(it->key)+reversedRound));
21718 if (keyEpsilonVariable)

Callers

nothing calls this directly

Calls 8

dataMethod · 0.80
coordToPixelMethod · 0.80
pixelToCoordMethod · 0.80
appendMethod · 0.80
rangeMethod · 0.80
clearMethod · 0.60
beginMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected