@@ -81,6 +81,43 void DataSeriesUtils::fillDataHoles(std::vector<double> &xAxisData, std::vector< | |||
|
81 | 81 | } |
|
82 | 82 | } |
|
83 | 83 | } |
|
84 | ||
|
85 | namespace { | |
|
86 | ||
|
87 | /** | |
|
88 | * Generates axis's mesh properties according to data and resolution | |
|
89 | * @param begin the iterator pointing to the beginning of the data | |
|
90 | * @param end the iterator pointing to the end of the data | |
|
91 | * @param fun the function to retrieve data from the data iterators | |
|
92 | * @param resolution the resolution to use for the axis' mesh | |
|
93 | * @return a tuple representing the mesh properties : <nb values, min value, value step> | |
|
94 | */ | |
|
95 | template <typename Iterator, typename IteratorFun> | |
|
96 | std::tuple<int, double, double> meshProperties(Iterator begin, Iterator end, IteratorFun fun, | |
|
97 | double resolution) | |
|
98 | { | |
|
99 | // Computes the gap between min and max data. This will be used to determinate the step between | |
|
100 | // each data of the mesh | |
|
101 | auto min = fun(begin); | |
|
102 | auto max = fun(end - 1); | |
|
103 | auto gap = max - min; | |
|
104 | ||
|
105 | // Computes the step trying to use the fixed resolution. If the resolution doesn't separate the | |
|
106 | // values evenly , it is recalculated. | |
|
107 | // For example, for a resolution of 2.0: | |
|
108 | // - for interval [0; 8] => resolution is valid, the generated mesh will be [0, 2, 4, 6, 8] | |
|
109 | // - for interval [0; 9] => it's impossible to create a regular mesh with this resolution | |
|
110 | // The resolution is recalculated and is worth 1.8. The generated mesh will be [0, 1.8, 3.6, | |
|
111 | // 5.4, 7.2, 9] | |
|
112 | auto nbVal = static_cast<int>(std::ceil(gap / resolution)); | |
|
113 | auto step = gap / nbVal; | |
|
114 | ||
|
115 | // last data is included in the total number of values | |
|
116 | return std::make_tuple(nbVal + 1, min, step); | |
|
117 | } | |
|
118 | ||
|
119 | } // namespace | |
|
120 | ||
|
84 | 121 | DataSeriesUtils::Mesh DataSeriesUtils::regularMesh(DataSeriesIterator begin, DataSeriesIterator end, |
|
85 | 122 | Resolution xResolution, Resolution yResolution) |
|
86 | 123 | { |
@@ -113,4 +150,12 DataSeriesUtils::Mesh DataSeriesUtils::regularMesh(DataSeriesIterator begin, Dat | |||
|
113 | 150 | std::for_each(yData.begin(), yData.end(), [](auto &val) { val = std::log10(val); }); |
|
114 | 151 | } |
|
115 | 152 | |
|
153 | // Computes mesh properties | |
|
154 | int nbX, nbY; | |
|
155 | double xMin, xStep, yMin, yStep; | |
|
156 | std::tie(nbX, xMin, xStep) | |
|
157 | = meshProperties(begin, end, [](const auto &it) { return it->x(); }, xResolution.m_Val); | |
|
158 | std::tie(nbY, yMin, yStep) = meshProperties( | |
|
159 | yData.begin(), yData.end(), [](const auto &it) { return *it; }, yResolution.m_Val); | |
|
160 | ||
|
116 | 161 | } |
General Comments 0
You need to be logged in to leave comments.
Login now