@@ -158,4 +158,39 DataSeriesUtils::Mesh DataSeriesUtils::regularMesh(DataSeriesIterator begin, Dat | |||||
158 | std::tie(nbY, yMin, yStep) = meshProperties( |
|
158 | std::tie(nbY, yMin, yStep) = meshProperties( | |
159 | yData.begin(), yData.end(), [](const auto &it) { return *it; }, yResolution.m_Val); |
|
159 | yData.begin(), yData.end(), [](const auto &it) { return *it; }, yResolution.m_Val); | |
160 |
|
160 | |||
|
161 | // Generates mesh according to the x-axis and y-axis steps | |||
|
162 | Mesh result{nbX, xMin, xStep, nbY, yMin, yStep}; | |||
|
163 | ||||
|
164 | for (auto meshXIndex = 0; meshXIndex < nbX; ++meshXIndex) { | |||
|
165 | auto meshX = xMin + meshXIndex * xStep; | |||
|
166 | // According to current x-axis of the mesh, finds in the data series the interval in which | |||
|
167 | // the data is or gets closer (without exceeding it). | |||
|
168 | // An interval is defined by a value and extends to +/- 50% of the resolution. For example, | |||
|
169 | // for a value of 3 and a resolution of 1, the associated interval is [2.5, 3.5]. | |||
|
170 | auto xIt = std::lower_bound(begin, end, meshX, | |||
|
171 | [xResolution](const auto &it, const auto &val) { | |||
|
172 | return it.x() - xResolution.m_Val / 2. < val; | |||
|
173 | }) | |||
|
174 | - 1; | |||
|
175 | ||||
|
176 | // When the corresponding entry of the data series is found, generates the values of the | |||
|
177 | // mesh by retrieving the values of the entry, for each y-axis value of the mesh | |||
|
178 | auto values = xIt->values(); | |||
|
179 | ||||
|
180 | for (auto meshYIndex = 0; meshYIndex < nbY; ++meshYIndex) { | |||
|
181 | auto meshY = yMin + meshYIndex * yStep; | |||
|
182 | ||||
|
183 | auto yBegin = yData.begin(); | |||
|
184 | auto yIt = std::lower_bound(yBegin, yData.end(), meshY, | |||
|
185 | [yResolution](const auto &it, const auto &val) { | |||
|
186 | return it - yResolution.m_Val / 2. < val; | |||
|
187 | }) | |||
|
188 | - 1; | |||
|
189 | ||||
|
190 | auto valueIndex = std::distance(yBegin, yIt); | |||
|
191 | result.m_Data[result.m_NbX * meshYIndex + meshXIndex] = values.at(valueIndex); | |||
|
192 | } | |||
|
193 | } | |||
|
194 | ||||
|
195 | return result; | |||
161 | } |
|
196 | } |
General Comments 0
You need to be logged in to leave comments.
Login now