##// END OF EJS Templates
Merge pull request 296 from SCIQLOP-Initialisation develop...
leroux -
r769:ac71c472785a merge master
parent child
Show More
@@ -1,86 +1,83
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 for (int i = 0; i < xValues.size(); i++) {
32 for (int i = 0; i < xValues.size(); i++) {
33 result.push_back(xValues[i]);
33 result.push_back(xValues[i]);
34 result.push_back(yValues[i]);
34 result.push_back(yValues[i]);
35 result.push_back(zValues[i]);
35 result.push_back(zValues[i]);
36 }
36 }
37
37
38 return result;
38 return result;
39 }
39 }
40
40
41 } // namespace
41 } // namespace
42
42
43 VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> xValuesData,
43 VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> xValuesData,
44 std::vector<double> yValuesData, std::vector<double> zValuesData,
44 std::vector<double> yValuesData, std::vector<double> zValuesData,
45 const Unit &xAxisUnit, const Unit &valuesUnit)
45 const Unit &xAxisUnit, const Unit &valuesUnit)
46 : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData),
46 : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData),
47 std::move(zValuesData)),
47 std::move(zValuesData)),
48 xAxisUnit, valuesUnit}
48 xAxisUnit, valuesUnit}
49 {
49 {
50 }
50 }
51
51
52 VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> valuesData,
52 VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> valuesData,
53 const Unit &xAxisUnit, const Unit &valuesUnit)
53 const Unit &xAxisUnit, const Unit &valuesUnit)
54 : DataSeries{std::make_shared<ArrayData<1> >(std::move(xAxisData)), xAxisUnit,
54 : DataSeries{std::make_shared<ArrayData<1> >(std::move(xAxisData)), xAxisUnit,
55 std::make_shared<ArrayData<2> >(std::move(valuesData), 3), valuesUnit}
55 std::make_shared<ArrayData<2> >(std::move(valuesData), 3), valuesUnit}
56 {
56 {
57 }
57 }
58
58
59 std::unique_ptr<IDataSeries> VectorSeries::clone() const
59 std::unique_ptr<IDataSeries> VectorSeries::clone() const
60 {
60 {
61 return std::make_unique<VectorSeries>(*this);
61 return std::make_unique<VectorSeries>(*this);
62 }
62 }
63
63
64 std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range)
64 std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range)
65 {
65 {
66 auto subXAxisData = std::vector<double>();
66 auto subXAxisData = std::vector<double>();
67 auto subXValuesData = std::vector<double>();
67 auto subValuesData = std::vector<double>();
68 auto subYValuesData = std::vector<double>();
69 auto subZValuesData = std::vector<double>();
70
68
71 this->lockRead();
69 this->lockRead();
72 {
70 {
73 auto bounds = xAxisRange(range.m_TStart, range.m_TEnd);
71 auto bounds = xAxisRange(range.m_TStart, range.m_TEnd);
74 for (auto it = bounds.first; it != bounds.second; ++it) {
72 for (auto it = bounds.first; it != bounds.second; ++it) {
75 subXAxisData.push_back(it->x());
73 subXAxisData.push_back(it->x());
76 subXValuesData.push_back(it->value(0));
74 subValuesData.push_back(it->value(0));
77 subYValuesData.push_back(it->value(1));
75 subValuesData.push_back(it->value(1));
78 subZValuesData.push_back(it->value(2));
76 subValuesData.push_back(it->value(2));
79 }
77 }
80 }
78 }
81 this->unlock();
79 this->unlock();
82
80
83 return std::make_shared<VectorSeries>(std::move(subXAxisData), std::move(subXValuesData),
81 return std::make_shared<VectorSeries>(std::move(subXAxisData), std::move(subValuesData),
84 std::move(subYValuesData), std::move(subZValuesData),
85 this->xAxisUnit(), this->valuesUnit());
82 this->xAxisUnit(), this->valuesUnit());
86 }
83 }
General Comments 0
You need to be logged in to leave comments. Login now