##// END OF EJS Templates
Updates VectorSeries() to create a single QVector for ArrayData with three vectors in entry
Alexandre Leroux -
r646:5cae61f2b3b8
parent child
Show More
@@ -1,30 +1,34
1 1 #ifndef SCIQLOP_VECTORSERIES_H
2 2 #define SCIQLOP_VECTORSERIES_H
3 3
4 4 #include "CoreGlobal.h"
5 5
6 6 #include <Data/DataSeries.h>
7 7
8 8 /**
9 9 * @brief The VectorSeries class is the implementation for a data series representing a vector.
10 10 */
11 11 class SCIQLOP_CORE_EXPORT VectorSeries : public DataSeries<2> {
12 12 public:
13 13 /**
14 * Ctor. The vectors must have the same size, otherwise a ScalarSeries with no values will be
15 * created.
14 * Ctor with three vectors (one per component). The vectors must have the same size, otherwise a
15 * ScalarSeries with no values will be created.
16 16 * @param xAxisData x-axis data
17 17 * @param xvaluesData x-values data
18 18 * @param yvaluesData y-values data
19 19 * @param zvaluesData z-values data
20 20 */
21 21 explicit VectorSeries(QVector<double> xAxisData, QVector<double> xValuesData,
22 22 QVector<double> yValuesData, QVector<double> zValuesData,
23 23 const Unit &xAxisUnit, const Unit &valuesUnit);
24 24
25 /// Default Ctor
26 explicit VectorSeries(QVector<double> xAxisData, QVector<double> valuesData,
27 const Unit &xAxisUnit, const Unit &valuesUnit);
28
25 29 std::unique_ptr<IDataSeries> clone() const;
26 30
27 31 std::shared_ptr<IDataSeries> subDataSeries(const SqpRange &range) override;
28 32 };
29 33
30 34 #endif // SCIQLOP_VECTORSERIES_H
@@ -1,39 +1,83
1 1 #include "Data/VectorSeries.h"
2 2
3 namespace {
4
5 /**
6 * Flatten the three components of a vector to a single QVector that can be passed to an ArrayData
7 *
8 * Example:
9 * xValues = {1, 2, 3}
10 * yValues = {4, 5, 6}
11 * zValues = {7, 8, 9}
12 *
13 * result = {1, 4, 7, 2, 5, 8, 3, 6, 9}
14 *
15 * @param xValues the x-component values of the vector
16 * @param yValues the y-component values of the vector
17 * @param zValues the z-component values of the vector
18 * @return the single QVector
19 * @remarks the three components are consumed
20 * @sa ArrayData
21 */
22 QVector<double> flatten(QVector<double> xValues, QVector<double> yValues, QVector<double> zValues)
23 {
24 if (xValues.size() != yValues.size() || xValues.size() != zValues.size()) {
25 /// @todo ALX : log
26 return {};
27 }
28
29 auto result = QVector<double>{};
30 result.reserve(xValues.size() * 3);
31
32 while (!xValues.isEmpty()) {
33 result.append({xValues.takeFirst(), yValues.takeFirst(), zValues.takeFirst()});
34 }
35
36 return result;
37 }
38
39 } // namespace
40
3 41 VectorSeries::VectorSeries(QVector<double> xAxisData, QVector<double> xValuesData,
4 42 QVector<double> yValuesData, QVector<double> zValuesData,
5 43 const Unit &xAxisUnit, const Unit &valuesUnit)
44 : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData),
45 std::move(zValuesData)),
46 xAxisUnit, valuesUnit}
47 {
48 }
49
50 VectorSeries::VectorSeries(QVector<double> xAxisData, QVector<double> valuesData,
51 const Unit &xAxisUnit, const Unit &valuesUnit)
6 52 : DataSeries{std::make_shared<ArrayData<1> >(std::move(xAxisData)), xAxisUnit,
7 std::make_shared<ArrayData<2> >(QVector<QVector<double> >{
8 std::move(xValuesData), std::move(yValuesData), std::move(zValuesData)}),
9 valuesUnit}
53 std::make_shared<ArrayData<2> >(std::move(valuesData), 3), valuesUnit}
10 54 {
11 55 }
12 56
13 57 std::unique_ptr<IDataSeries> VectorSeries::clone() const
14 58 {
15 59 return std::make_unique<VectorSeries>(*this);
16 60 }
17 61
18 62 std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range)
19 63 {
20 64 auto subXAxisData = QVector<double>();
21 65 auto subXValuesData = QVector<double>();
22 66 auto subYValuesData = QVector<double>();
23 67 auto subZValuesData = QVector<double>();
24 68
25 69 this->lockRead();
26 70 {
27 71 auto bounds = xAxisRange(range.m_TStart, range.m_TEnd);
28 72 for (auto it = bounds.first; it != bounds.second; ++it) {
29 73 subXAxisData.append(it->x());
30 74 subXValuesData.append(it->value(0));
31 75 subYValuesData.append(it->value(1));
32 76 subZValuesData.append(it->value(2));
33 77 }
34 78 }
35 79 this->unlock();
36 80
37 81 return std::make_shared<VectorSeries>(subXAxisData, subXValuesData, subYValuesData,
38 82 subZValuesData, this->xAxisUnit(), this->valuesUnit());
39 83 }
General Comments 0
You need to be logged in to leave comments. Login now