##// END OF EJS Templates
Perf improvement on vector points interleaving....
jeandet -
r705:cbdeb4277122
parent child
Show More
@@ -1,88 +1,86
1 1 #include "Data/VectorSeries.h"
2 2
3 3 namespace {
4 4
5 5 /**
6 6 * Flatten the three components of a vector to a single QVector that can be passed to an ArrayData
7 7 *
8 8 * Example:
9 9 * xValues = {1, 2, 3}
10 10 * yValues = {4, 5, 6}
11 11 * zValues = {7, 8, 9}
12 12 *
13 13 * result = {1, 4, 7, 2, 5, 8, 3, 6, 9}
14 14 *
15 15 * @param xValues the x-component values of the vector
16 16 * @param yValues the y-component values of the vector
17 17 * @param zValues the z-component values of the vector
18 18 * @return the single QVector
19 19 * @remarks the three components are consumed
20 20 * @sa ArrayData
21 21 */
22 22 std::vector<double> flatten(std::vector<double> xValues, std::vector<double> yValues,
23 23 std::vector<double> zValues)
24 24 {
25 25 if (xValues.size() != yValues.size() || xValues.size() != zValues.size()) {
26 26 /// @todo ALX : log
27 27 return {};
28 28 }
29 29
30 30 auto result = std::vector<double>();
31 31 result.reserve(xValues.size() * 3);
32
33 while (!xValues.empty()) {
34 result.insert(result.cend(), {xValues.front(), yValues.front(), zValues.front()});
35 xValues.erase(xValues.begin());
36 yValues.erase(yValues.begin());
37 zValues.erase(zValues.begin());
38 }
32 for (int i = 0; i < xValues.size(); i++) {
33 result.push_back(xValues[i]);
34 result.push_back(yValues[i]);
35 result.push_back(zValues[i]);
36 }
39 37
40 38 return result;
41 39 }
42 40
43 41 } // namespace
44 42
45 43 VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> xValuesData,
46 44 std::vector<double> yValuesData, std::vector<double> zValuesData,
47 45 const Unit &xAxisUnit, const Unit &valuesUnit)
48 46 : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData),
49 47 std::move(zValuesData)),
50 48 xAxisUnit, valuesUnit}
51 49 {
52 50 }
53 51
54 52 VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> valuesData,
55 53 const Unit &xAxisUnit, const Unit &valuesUnit)
56 54 : DataSeries{std::make_shared<ArrayData<1> >(std::move(xAxisData)), xAxisUnit,
57 55 std::make_shared<ArrayData<2> >(std::move(valuesData), 3), valuesUnit}
58 56 {
59 57 }
60 58
61 59 std::unique_ptr<IDataSeries> VectorSeries::clone() const
62 60 {
63 61 return std::make_unique<VectorSeries>(*this);
64 62 }
65 63
66 64 std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range)
67 65 {
68 66 auto subXAxisData = std::vector<double>();
69 67 auto subXValuesData = std::vector<double>();
70 68 auto subYValuesData = std::vector<double>();
71 69 auto subZValuesData = std::vector<double>();
72 70
73 71 this->lockRead();
74 72 {
75 73 auto bounds = xAxisRange(range.m_TStart, range.m_TEnd);
76 74 for (auto it = bounds.first; it != bounds.second; ++it) {
77 75 subXAxisData.push_back(it->x());
78 76 subXValuesData.push_back(it->value(0));
79 77 subYValuesData.push_back(it->value(1));
80 78 subZValuesData.push_back(it->value(2));
81 79 }
82 80 }
83 81 this->unlock();
84 82
85 83 return std::make_shared<VectorSeries>(std::move(subXAxisData), std::move(subXValuesData),
86 84 std::move(subYValuesData), std::move(subZValuesData),
87 85 this->xAxisUnit(), this->valuesUnit());
88 86 }
General Comments 0
You need to be logged in to leave comments. Login now