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