VectorSeries.cpp
85 lines
| 2.8 KiB
| text/x-c
|
CppLexer
|
r528 | #include "Data/VectorSeries.h" | ||
|
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 | ||||
*/ | ||||
|
r644 | std::vector<double> flatten(std::vector<double> xValues, std::vector<double> yValues, | ||
std::vector<double> zValues) | ||||
|
r603 | { | ||
if (xValues.size() != yValues.size() || xValues.size() != zValues.size()) { | ||||
/// @todo ALX : log | ||||
return {}; | ||||
} | ||||
|
r644 | auto result = std::vector<double>(); | ||
|
r603 | result.reserve(xValues.size() * 3); | ||
|
r644 | while (!xValues.empty()) { | ||
result.insert(result.cend(), {xValues.front(), yValues.front(), zValues.front()}); | ||||
xValues.erase(xValues.begin()); | ||||
yValues.erase(yValues.begin()); | ||||
zValues.erase(zValues.begin()); | ||||
|
r603 | } | ||
return result; | ||||
} | ||||
} // namespace | ||||
|
r644 | VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> xValuesData, | ||
std::vector<double> yValuesData, std::vector<double> zValuesData, | ||||
|
r528 | const Unit &xAxisUnit, const Unit &valuesUnit) | ||
|
r603 | : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData), | ||
std::move(zValuesData)), | ||||
xAxisUnit, valuesUnit} | ||||
{ | ||||
} | ||||
|
r644 | VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> valuesData, | ||
|
r603 | const Unit &xAxisUnit, const Unit &valuesUnit) | ||
|
r528 | : DataSeries{std::make_shared<ArrayData<1> >(std::move(xAxisData)), xAxisUnit, | ||
|
r603 | std::make_shared<ArrayData<2> >(std::move(valuesData), 3), valuesUnit} | ||
|
r528 | { | ||
} | ||||
std::unique_ptr<IDataSeries> VectorSeries::clone() const | ||||
{ | ||||
return std::make_unique<VectorSeries>(*this); | ||||
} | ||||
std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range) | ||||
{ | ||||
|
r644 | auto subXAxisData = std::vector<double>(); | ||
|
r709 | auto subValuesData = std::vector<double>(); | ||
|
r528 | |||
this->lockRead(); | ||||
{ | ||||
|
r566 | auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); | ||
|
r528 | for (auto it = bounds.first; it != bounds.second; ++it) { | ||
|
r644 | subXAxisData.push_back(it->x()); | ||
|
r709 | subValuesData.push_back(it->value(0)); | ||
subValuesData.push_back(it->value(1)); | ||||
subValuesData.push_back(it->value(2)); | ||||
|
r528 | } | ||
} | ||||
this->unlock(); | ||||
|
r709 | return std::make_shared<VectorSeries>(std::move(subXAxisData), std::move(subValuesData), | ||
|
r644 | this->xAxisUnit(), this->valuesUnit()); | ||
|
r528 | } | ||