diff --git a/core/include/Data/VectorSeries.h b/core/include/Data/VectorSeries.h index 634039c..99d49cd 100644 --- a/core/include/Data/VectorSeries.h +++ b/core/include/Data/VectorSeries.h @@ -11,8 +11,8 @@ class SCIQLOP_CORE_EXPORT VectorSeries : public DataSeries<2> { public: /** - * Ctor. The vectors must have the same size, otherwise a ScalarSeries with no values will be - * created. + * Ctor with three vectors (one per component). The vectors must have the same size, otherwise a + * ScalarSeries with no values will be created. * @param xAxisData x-axis data * @param xvaluesData x-values data * @param yvaluesData y-values data @@ -22,6 +22,10 @@ public: QVector yValuesData, QVector zValuesData, const Unit &xAxisUnit, const Unit &valuesUnit); + /// Default Ctor + explicit VectorSeries(QVector xAxisData, QVector valuesData, + const Unit &xAxisUnit, const Unit &valuesUnit); + std::unique_ptr clone() const; std::shared_ptr subDataSeries(const SqpRange &range) override; diff --git a/core/src/Data/VectorSeries.cpp b/core/src/Data/VectorSeries.cpp index a8091b2..b7c9bf7 100644 --- a/core/src/Data/VectorSeries.cpp +++ b/core/src/Data/VectorSeries.cpp @@ -1,12 +1,56 @@ #include "Data/VectorSeries.h" +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 flatten(QVector xValues, QVector yValues, QVector zValues) +{ + if (xValues.size() != yValues.size() || xValues.size() != zValues.size()) { + /// @todo ALX : log + return {}; + } + + auto result = QVector{}; + result.reserve(xValues.size() * 3); + + while (!xValues.isEmpty()) { + result.append({xValues.takeFirst(), yValues.takeFirst(), zValues.takeFirst()}); + } + + return result; +} + +} // namespace + VectorSeries::VectorSeries(QVector xAxisData, QVector xValuesData, QVector yValuesData, QVector zValuesData, const Unit &xAxisUnit, const Unit &valuesUnit) + : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData), + std::move(zValuesData)), + xAxisUnit, valuesUnit} +{ +} + +VectorSeries::VectorSeries(QVector xAxisData, QVector valuesData, + const Unit &xAxisUnit, const Unit &valuesUnit) : DataSeries{std::make_shared >(std::move(xAxisData)), xAxisUnit, - std::make_shared >(QVector >{ - std::move(xValuesData), std::move(yValuesData), std::move(zValuesData)}), - valuesUnit} + std::make_shared >(std::move(valuesData), 3), valuesUnit} { }