##// END OF EJS Templates
Fixes slowness when opening variable
Alexandre Leroux -
r768:46391f71d5a3
parent child
Show More
@@ -1,88 +1,85
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 32
33 33 while (!xValues.empty()) {
34 34 result.insert(result.cend(), {xValues.front(), yValues.front(), zValues.front()});
35 35 xValues.erase(xValues.begin());
36 36 yValues.erase(yValues.begin());
37 37 zValues.erase(zValues.begin());
38 38 }
39 39
40 40 return result;
41 41 }
42 42
43 43 } // namespace
44 44
45 45 VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> xValuesData,
46 46 std::vector<double> yValuesData, std::vector<double> zValuesData,
47 47 const Unit &xAxisUnit, const Unit &valuesUnit)
48 48 : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData),
49 49 std::move(zValuesData)),
50 50 xAxisUnit, valuesUnit}
51 51 {
52 52 }
53 53
54 54 VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> valuesData,
55 55 const Unit &xAxisUnit, const Unit &valuesUnit)
56 56 : DataSeries{std::make_shared<ArrayData<1> >(std::move(xAxisData)), xAxisUnit,
57 57 std::make_shared<ArrayData<2> >(std::move(valuesData), 3), valuesUnit}
58 58 {
59 59 }
60 60
61 61 std::unique_ptr<IDataSeries> VectorSeries::clone() const
62 62 {
63 63 return std::make_unique<VectorSeries>(*this);
64 64 }
65 65
66 66 std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range)
67 67 {
68 68 auto subXAxisData = std::vector<double>();
69 auto subXValuesData = std::vector<double>();
70 auto subYValuesData = std::vector<double>();
71 auto subZValuesData = std::vector<double>();
69 auto subValuesData = 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 subXValuesData.push_back(it->value(0));
79 subYValuesData.push_back(it->value(1));
80 subZValuesData.push_back(it->value(2));
76 subValuesData.push_back(it->value(0));
77 subValuesData.push_back(it->value(1));
78 subValuesData.push_back(it->value(2));
81 79 }
82 80 }
83 81 this->unlock();
84 82
85 return std::make_shared<VectorSeries>(std::move(subXAxisData), std::move(subXValuesData),
86 std::move(subYValuesData), std::move(subZValuesData),
83 return std::make_shared<VectorSeries>(std::move(subXAxisData), std::move(subValuesData),
87 84 this->xAxisUnit(), this->valuesUnit());
88 85 }
General Comments 0
You need to be logged in to leave comments. Login now