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