##// END OF EJS Templates
Implements spectrograms display (2)...
Alexandre Leroux -
r906:b5399b2ef3a8
parent child
Show More
@@ -177,6 +177,68 struct PlottablesUpdater<T,
177 177 };
178 178
179 179 /**
180 * Specialization of PlottablesUpdater for spectrograms
181 * @sa SpectrogramSeries
182 */
183 template <typename T>
184 struct PlottablesUpdater<T,
185 typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > {
186 static void updatePlottables(T &dataSeries, PlottablesMap &plottables, const SqpRange &range,
187 bool rescaleAxes)
188 {
189 if (plottables.empty()) {
190 qCDebug(LOG_VisualizationGraphHelper())
191 << QObject::tr("Can't update spectrogram: no colormap has been associated");
192 return;
193 }
194
195 // Gets the colormap to update (normally there is only one colormap)
196 Q_ASSERT(plottables.size() == 1);
197 auto colormap = dynamic_cast<QCPColorMap *>(plottables.at(0));
198 Q_ASSERT(colormap != nullptr);
199
200 dataSeries.lockRead();
201
202 auto its = dataSeries.xAxisRange(range.m_TStart, range.m_TEnd);
203 /// @todo ALX: use iterators here
204 auto yAxis = dataSeries.yAxis();
205
206 // Gets properties of x-axis and y-axis to set size and range of the colormap
207 auto nbX = std::distance(its.first, its.second);
208 auto xMin = nbX != 0 ? its.first->x() : 0.;
209 auto xMax = nbX != 0 ? (its.second - 1)->x() : 0.;
210
211 auto nbY = yAxis.size();
212 auto yMin = 0., yMax = 0.;
213 if (nbY != 0) {
214 std::tie(yMin, yMax) = yAxis.bounds();
215 }
216
217 colormap->data()->setSize(nbX, nbY);
218 colormap->data()->setRange(QCPRange{xMin, xMax}, QCPRange{yMin, yMax});
219
220 // Sets values
221 auto xIndex = 0;
222 for (auto it = its.first; it != its.second; ++it, ++xIndex) {
223 for (auto yIndex = 0; yIndex < nbY; ++yIndex) {
224 colormap->data()->setCell(xIndex, yIndex, it->value(yIndex));
225 }
226 }
227
228 dataSeries.unlock();
229
230 // Rescales axes
231 auto plot = colormap->parentPlot();
232
233 if (rescaleAxes) {
234 plot->rescaleAxes();
235 }
236
237 plot->replot();
238 }
239 };
240
241 /**
180 242 * Helper used to create/update plottables
181 243 */
182 244 struct IPlottablesHelper {
General Comments 0
You need to be logged in to leave comments. Login now