VectorSeries.cpp
83 lines
| 2.7 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r528 | #include "Data/VectorSeries.h" | ||
Alexandre Leroux
|
r603 | namespace { | ||
/** | ||||
* Flatten the three components of a vector to a single QVector that can be passed to an ArrayData | ||||
* | ||||
* Example: | ||||
* xValues = {1, 2, 3} | ||||
* yValues = {4, 5, 6} | ||||
* zValues = {7, 8, 9} | ||||
* | ||||
* result = {1, 4, 7, 2, 5, 8, 3, 6, 9} | ||||
* | ||||
* @param xValues the x-component values of the vector | ||||
* @param yValues the y-component values of the vector | ||||
* @param zValues the z-component values of the vector | ||||
* @return the single QVector | ||||
* @remarks the three components are consumed | ||||
* @sa ArrayData | ||||
*/ | ||||
QVector<double> flatten(QVector<double> xValues, QVector<double> yValues, QVector<double> zValues) | ||||
{ | ||||
if (xValues.size() != yValues.size() || xValues.size() != zValues.size()) { | ||||
/// @todo ALX : log | ||||
return {}; | ||||
} | ||||
auto result = QVector<double>{}; | ||||
result.reserve(xValues.size() * 3); | ||||
while (!xValues.isEmpty()) { | ||||
result.append({xValues.takeFirst(), yValues.takeFirst(), zValues.takeFirst()}); | ||||
} | ||||
return result; | ||||
} | ||||
} // namespace | ||||
Alexandre Leroux
|
r528 | VectorSeries::VectorSeries(QVector<double> xAxisData, QVector<double> xValuesData, | ||
QVector<double> yValuesData, QVector<double> zValuesData, | ||||
const Unit &xAxisUnit, const Unit &valuesUnit) | ||||
Alexandre Leroux
|
r603 | : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData), | ||
std::move(zValuesData)), | ||||
xAxisUnit, valuesUnit} | ||||
{ | ||||
} | ||||
VectorSeries::VectorSeries(QVector<double> xAxisData, QVector<double> valuesData, | ||||
const Unit &xAxisUnit, const Unit &valuesUnit) | ||||
Alexandre Leroux
|
r528 | : DataSeries{std::make_shared<ArrayData<1> >(std::move(xAxisData)), xAxisUnit, | ||
Alexandre Leroux
|
r603 | std::make_shared<ArrayData<2> >(std::move(valuesData), 3), valuesUnit} | ||
Alexandre Leroux
|
r528 | { | ||
} | ||||
std::unique_ptr<IDataSeries> VectorSeries::clone() const | ||||
{ | ||||
return std::make_unique<VectorSeries>(*this); | ||||
} | ||||
std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range) | ||||
{ | ||||
auto subXAxisData = QVector<double>(); | ||||
auto subXValuesData = QVector<double>(); | ||||
auto subYValuesData = QVector<double>(); | ||||
auto subZValuesData = QVector<double>(); | ||||
this->lockRead(); | ||||
{ | ||||
Alexandre Leroux
|
r566 | auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); | ||
Alexandre Leroux
|
r528 | for (auto it = bounds.first; it != bounds.second; ++it) { | ||
subXAxisData.append(it->x()); | ||||
subXValuesData.append(it->value(0)); | ||||
subYValuesData.append(it->value(1)); | ||||
subZValuesData.append(it->value(2)); | ||||
} | ||||
} | ||||
this->unlock(); | ||||
return std::make_shared<VectorSeries>(subXAxisData, subXValuesData, subYValuesData, | ||||
subZValuesData, this->xAxisUnit(), this->valuesUnit()); | ||||
} | ||||