The generic data container for one-dimensional plottables. More...
#include </home/florent/devel/release/src/gepetto-viewer/plugins/pyqcustomplot/qcustomplot-2.0.1/qcustomplot.h>
Public Types | |
typedef QVector< DataType >::const_iterator | const_iterator |
typedef QVector< DataType >::iterator | iterator |
Public Member Functions | |
QCPDataContainer () | |
int | size () const |
bool | isEmpty () const |
bool | autoSqueeze () const |
void | setAutoSqueeze (bool enabled) |
void | set (const QCPDataContainer< DataType > &data) |
void | set (const QVector< DataType > &data, bool alreadySorted=false) |
void | add (const QCPDataContainer< DataType > &data) |
void | add (const QVector< DataType > &data, bool alreadySorted=false) |
void | add (const DataType &data) |
void | removeBefore (double sortKey) |
void | removeAfter (double sortKey) |
void | remove (double sortKeyFrom, double sortKeyTo) |
void | remove (double sortKey) |
void | clear () |
void | sort () |
void | squeeze (bool preAllocation=true, bool postAllocation=true) |
const_iterator | constBegin () const |
const_iterator | constEnd () const |
iterator | begin () |
iterator | end () |
const_iterator | findBegin (double sortKey, bool expandedRange=true) const |
const_iterator | findEnd (double sortKey, bool expandedRange=true) const |
const_iterator | at (int index) const |
QCPRange | keyRange (bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth) |
QCPRange | valueRange (bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) |
QCPDataRange | dataRange () const |
void | limitIteratorsToDataRange (const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const |
Protected Member Functions | |
void | preallocateGrow (int minimumPreallocSize) |
void | performAutoSqueeze () |
Protected Attributes | |
bool | mAutoSqueeze |
QVector< DataType > | mData |
int | mPreallocSize |
int | mPreallocIteration |
Related Functions | |
(Note that these are not member functions.) | |
template<class DataType > | |
bool | qcpLessThanSortKey (const DataType &a, const DataType &b) |
The generic data container for one-dimensional plottables.
This class template provides a fast container for data storage of one-dimensional data. The data type is specified as template parameter (called DataType in the following) and must provide some methods as described in the next section.
The data is stored in a sorted fashion, which allows very quick lookups by the sorted key as well as retrieval of ranges (see findBegin, findEnd, keyRange) using binary search. The container uses a preallocation and a postallocation scheme, such that appending and prepending data (with respect to the sort key) is very fast and minimizes reallocations. If data is added which needs to be inserted between existing keys, the merge usually can be done quickly too, using the fact that existing data is always sorted. The user can further improve performance by specifying that added data is already itself sorted by key, if he can guarantee that this is the case (see for example add(const QVector<DataType> &data, bool alreadySorted)).
The data can be accessed with the provided const iterators (constBegin, constEnd). If it is necessary to alter existing data in-place, the non-const iterators can be used (begin, end). Changing data members that are not the sort key (for most data types called key) is safe from the container's perspective.
Great care must be taken however if the sort key is modified through the non-const iterators. For performance reasons, the iterators don't automatically cause a re-sorting upon their manipulation. It is thus the responsibility of the user to leave the container in a sorted state when finished with the data manipulation, before calling any other methods on the container. A complete re-sort (e.g. after finishing all sort key manipulation) can be done by calling sort. Failing to do so can not be detected by the container efficiently and will cause both rendering artifacts and potential data loss.
Implementing one-dimensional plottables that make use of a QCPDataContainer<T> is usually done by subclassing from QCPAbstractPlottable1D<T>, which introduces an according mDataContainer member and some convenience methods.
The template parameter DataType
is the type of the stored data points. It must be trivially copyable and have the following public methods, preferably inline:
double sortKey() const
static DataType fromSortKey(double sortKey)
static bool sortKeyIsMainKey()
mainKey
below). For most plottables this is the case. It is not the case for example for QCPCurve, which uses t as sort key and key as main key. This is the reason why QCPCurve unlike QCPGraph can display parametric curves with loops.double mainKey() const
double mainValue() const
QCPRange valueRange() const
typedef QVector<DataType>::const_iterator QCPDataContainer< DataType >::const_iterator |
typedef QVector<DataType>::iterator QCPDataContainer< DataType >::iterator |
QCPDataContainer< DataType >::QCPDataContainer | ( | ) |
Constructs a QCPDataContainer used for plottable classes that represent a series of key-sorted data
void QCPDataContainer< DataType >::add | ( | const QCPDataContainer< DataType > & | data | ) |
void QCPDataContainer< DataType >::add | ( | const QVector< DataType > & | data, |
bool | alreadySorted = false |
||
) |
void QCPDataContainer< DataType >::add | ( | const DataType & | data | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Adds the provided single data point to the current data.
|
inline |
Returns a const iterator to the element with the specified index. If index points beyond the available elements in this container, returns constEnd, i.e. an iterator past the last valid element.
You can use this method to easily obtain iterators from a QCPDataRange, see the data selection page for an example.
|
inline |
|
inline |
Returns a non-const iterator to the first data point in this container.
You can manipulate the data points in-place through the non-const iterators, but great care must be taken when manipulating the sort key of a data point, see sort, or the detailed description of this class.
void QCPDataContainer< DataType >::clear | ( | ) |
Removes all data points.
|
inline |
Returns a const iterator to the first data point in this container.
|
inline |
Returns a const iterator to the element past the last data point in this container.
|
inline |
Returns a QCPDataRange encompassing the entire data set of this container. This means the begin index of the returned range is 0, and the end index is size.
|
inline |
Returns a non-const iterator to the element past the last data point in this container.
You can manipulate the data points in-place through the non-const iterators, but great care must be taken when manipulating the sort key of a data point, see sort, or the detailed description of this class.
QCPDataContainer< DataType >::const_iterator QCPDataContainer< DataType >::findBegin | ( | double | sortKey, |
bool | expandedRange = true |
||
) | const |
Returns an iterator to the data point with a (sort-)key that is equal to, just below, or just above sortKey. If expandedRange is true, the data point just below sortKey will be considered, otherwise the one just above.
This can be used in conjunction with findEnd to iterate over data points within a given key range, including or excluding the bounding data points that are just beyond the specified range.
If expandedRange is true but there are no data points below sortKey, constBegin is returned.
If the container is empty, returns constEnd.
QCPDataContainer< DataType >::const_iterator QCPDataContainer< DataType >::findEnd | ( | double | sortKey, |
bool | expandedRange = true |
||
) | const |
Returns an iterator to the element after the data point with a (sort-)key that is equal to, just above or just below sortKey. If expandedRange is true, the data point just above sortKey will be considered, otherwise the one just below.
This can be used in conjunction with findBegin to iterate over data points within a given key range, including the bounding data points that are just below and above the specified range.
If expandedRange is true but there are no data points above sortKey, constEnd is returned.
If the container is empty, constEnd is returned.
|
inline |
Returns whether this container holds no data points.
QCPRange QCPDataContainer< DataType >::keyRange | ( | bool & | foundRange, |
QCP::SignDomain | signDomain = QCP::sdBoth |
||
) |
Returns the range encompassed by the (main-)key coordinate of all data points. The output parameter foundRange indicates whether a sensible range was found. If this is false, you should not use the returned QCPRange (e.g. the data container is empty or all points have the same key).
Use signDomain to control which sign of the key coordinates should be considered. This is relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a time.
If the DataType reports that its main key is equal to the sort key (sortKeyIsMainKey), as is the case for most plottables, this method uses this fact and finds the range very quickly.
void QCPDataContainer< DataType >::limitIteratorsToDataRange | ( | const_iterator & | begin, |
const_iterator & | end, | ||
const QCPDataRange & | dataRange | ||
) | const |
Makes sure begin and end mark a data range that is both within the bounds of this data container's data, as well as within the specified dataRange. The initial range described by the passed iterators begin and end is never expanded, only contracted if necessary.
This function doesn't require for dataRange to be within the bounds of this data container's valid range.
|
protected |
|
protected |
void QCPDataContainer< DataType >::remove | ( | double | sortKeyFrom, |
double | sortKeyTo | ||
) |
Removes all data points with (sort-)keys between sortKeyFrom and sortKeyTo. if sortKeyFrom is greater or equal to sortKeyTo, the function does nothing. To remove a single data point with known (sort-)key, use remove(double sortKey).
void QCPDataContainer< DataType >::remove | ( | double | sortKey | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Removes a single data point at sortKey. If the position is not known with absolute (binary) precision, consider using remove(double sortKeyFrom, double sortKeyTo) with a small fuzziness interval around the suspected position, depeding on the precision with which the (sort-)key is known.
void QCPDataContainer< DataType >::removeAfter | ( | double | sortKey | ) |
Removes all data points with (sort-)keys greater than or equal to sortKey.
void QCPDataContainer< DataType >::removeBefore | ( | double | sortKey | ) |
Removes all data points with (sort-)keys smaller than or equal to sortKey.
void QCPDataContainer< DataType >::set | ( | const QCPDataContainer< DataType > & | data | ) |
void QCPDataContainer< DataType >::set | ( | const QVector< DataType > & | data, |
bool | alreadySorted = false |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Replaces the current data in this container with the provided data
If you can guarantee that the data points in data have ascending order with respect to the DataType's sort key, set alreadySorted to true to avoid an unnecessary sorting run.
void QCPDataContainer< DataType >::setAutoSqueeze | ( | bool | enabled | ) |
Sets whether the container automatically decides when to release memory from its post- and preallocation pools when data points are removed. By default this is enabled and for typical applications shouldn't be changed.
If auto squeeze is disabled, you can manually decide when to release pre-/postallocation with squeeze.
|
inline |
Returns the number of data points in the container.
void QCPDataContainer< DataType >::sort | ( | ) |
Re-sorts all data points in the container by their sort key.
When setting, adding or removing points using the QCPDataContainer interface (set, add, remove, etc.), the container makes sure to always stay in a sorted state such that a full resort is never necessary. However, if you choose to directly manipulate the sort key on data points by accessing and modifying it through the non-const iterators (begin, end), it is your responsibility to bring the container back into a sorted state before any other methods are called on it. This can be achieved by calling this method immediately after finishing the sort key manipulation.
void QCPDataContainer< DataType >::squeeze | ( | bool | preAllocation = true , |
bool | postAllocation = true |
||
) |
Frees all unused memory that is currently in the preallocation and postallocation pools.
Note that QCPDataContainer automatically decides whether squeezing is necessary, if setAutoSqueeze is left enabled. It should thus not be necessary to use this method for typical applications.
The parameters preAllocation and postAllocation control whether pre- and/or post allocation should be freed, respectively.
QCPRange QCPDataContainer< DataType >::valueRange | ( | bool & | foundRange, |
QCP::SignDomain | signDomain = QCP::sdBoth , |
||
const QCPRange & | inKeyRange = QCPRange() |
||
) |
Returns the range encompassed by the value coordinates of the data points in the specified key range (inKeyRange), using the full DataType::valueRange reported by the data points. The output parameter foundRange indicates whether a sensible range was found. If this is false, you should not use the returned QCPRange (e.g. the data container is empty or all points have the same value).
If inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()
), all data points are considered, without any restriction on the keys.
Use signDomain to control which sign of the value coordinates should be considered. This is relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a time.
|
related |
Returns whether the sort key of a is less than the sort key of b.
|
protected |
|
protected |
|
protected |
|
protected |