##// END OF EJS Templates
Mesh generation for QColorMap (4)...
Alexandre Leroux -
r995:bf7c3257108b
parent child
Show More
@@ -1,6 +1,7
1 1 #include "Visualization/VisualizationGraphHelper.h"
2 2 #include "Visualization/qcustomplot.h"
3 3
4 #include <Data/DataSeriesUtils.h>
4 5 #include <Data/ScalarSeries.h>
5 6 #include <Data/SpectrogramSeries.h>
6 7 #include <Data/VectorSeries.h>
@@ -203,43 +204,42 struct PlottablesUpdater<T,
203 204
204 205 dataSeries.lockRead();
205 206
207 // Processing spectrogram data for display in QCustomPlot
206 208 auto its = dataSeries.xAxisRange(range.m_TStart, range.m_TEnd);
207 /// @todo ALX: use iterators here
208 auto yAxis = dataSeries.yAxis();
209 209
210 // Gets properties of x-axis and y-axis to set size and range of the colormap
211 auto nbX = std::distance(its.first, its.second);
212 auto xMin = nbX != 0 ? its.first->x() : 0.;
213 auto xMax = nbX != 0 ? (its.second - 1)->x() : 0.;
210 // Computes logarithmic y-axis resolution for the spectrogram
211 auto yData = its.first->y();
212 auto yResolution = DataSeriesUtils::resolution(yData.begin(), yData.end(), true);
214 213
215 auto nbY = yAxis.size();
216 auto yMin = 0., yMax = 0.;
217 if (nbY != 0) {
218 std::tie(yMin, yMax) = yAxis.bounds();
219 }
214 // Generates mesh for colormap
215 auto mesh = DataSeriesUtils::regularMesh(
216 its.first, its.second, DataSeriesUtils::Resolution{dataSeries.xResolution()},
217 yResolution);
218
219 dataSeries.unlock();
220 220
221 colormap->data()->setSize(nbX, nbY);
222 colormap->data()->setRange(QCPRange{xMin, xMax}, QCPRange{yMin, yMax});
221 colormap->data()->setSize(mesh.m_NbX, mesh.m_NbY);
222 if (!mesh.isEmpty()) {
223 colormap->data()->setRange(
224 QCPRange{mesh.m_XMin, mesh.xMax()},
225 // y-axis range is converted to linear values
226 QCPRange{std::pow(10, mesh.m_YMin), std::pow(10, mesh.yMax())});
223 227
224 228 // Sets values
225 auto xIndex = 0;
226 for (auto it = its.first; it != its.second; ++it, ++xIndex) {
227 for (auto yIndex = 0; yIndex < nbY; ++yIndex) {
228 auto value = it->value(yIndex);
229 auto index = 0;
230 for (auto it = mesh.m_Data.begin(), end = mesh.m_Data.end(); it != end; ++it, ++index) {
231 auto xIndex = index % mesh.m_NbX;
232 auto yIndex = index / mesh.m_NbX;
229 233
230 colormap->data()->setCell(xIndex, yIndex, value);
234 colormap->data()->setCell(xIndex, yIndex, *it);
231 235
232 // Processing spectrogram data for display in QCustomPlot
233 /// For the moment, we just make the NaN values to be transparent in the colormap
234 /// @todo ALX: complete treatments (mesh generation, etc.)
235 if (std::isnan(value)) {
236 // Makes the NaN values to be transparent in the colormap
237 if (std::isnan(*it)) {
236 238 colormap->data()->setAlpha(xIndex, yIndex, 0);
237 239 }
238 240 }
239 241 }
240 242
241 dataSeries.unlock();
242
243 243 // Rescales axes
244 244 auto plot = colormap->parentPlot();
245 245
General Comments 0
You need to be logged in to leave comments. Login now