timeseries_qwt.cpp
Go to the documentation of this file.
1 #include "timeseries_qwt.h"
2 #include <limits>
3 #include <stdexcept>
4 #include <QMessageBox>
5 #include <QPushButton>
6 #include <QString>
7 
8 TimeseriesQwt::TimeseriesQwt(const PlotData *source_data, const PlotData *transformed_data):
9  DataSeriesBase( transformed_data ),
10  _source_data(source_data),
11  _cached_data("")
12 {
13 }
14 
16 {
17  int first_index = transformedData()->getIndexFromX( range_X.min );
18  int last_index = transformedData()->getIndexFromX( range_X.max );
19 
20  if( first_index > last_index || first_index <0 || last_index <0 )
21  {
22  return PlotData::RangeValueOpt();
23  }
24 
25 
26  if( first_index == 0 && last_index == transformedData()->size()-1)
27  {
28  return PlotData::RangeValueOpt( { _bounding_box.bottom(),
29  _bounding_box.top() } );
30  }
31 
32  double min_y =( std::numeric_limits<double>::max() );
33  double max_y =(-std::numeric_limits<double>::max() );
34 
35  for (size_t i = first_index; i < last_index; i++)
36  {
37  const double Y = sample(i).y();
38  min_y = std::min( min_y, Y );
39  max_y = std::max( max_y, Y );
40  }
41  return PlotData::RangeValueOpt( { min_y, max_y } );
42 }
43 
44 
46 {
47  int index = transformedData()->getIndexFromX(t);
48  if( index < 0 )
49  {
51  }
52  const auto& p = transformedData()->at( size_t(index) );
53  return QPointF(p.x, p.y);
54 }
55 
56 
58 {
60  return true;
61 }
62 
64 {
65  size_t data_size = _source_data->size();
66 
67  if( data_size <= 1)
68  {
70  _bounding_box = QRectF();
71  return true;
72  }
73 
74  data_size = data_size - 1;
75  _cached_data.resize( data_size );
76 
77  for (size_t i=0; i < data_size; i++ )
78  {
79  const auto& p0 = _source_data->at( i );
80  const auto& p1 = _source_data->at( i+1 );
81  const auto delta = p1.x - p0.x;
82  const auto vel = (p1.y - p0.y) /delta;
83  QPointF p( (p1.x + p0.x)*0.5, vel);
84  _cached_data[i] = { p.x(), p.y() };
85  }
86 
88  return true;
89 }
90 
92 {
93  size_t data_size = _source_data->size();
94 
95  if( data_size <= 2)
96  {
98  _bounding_box = QRectF();
99  return true;
100  }
101 
102  data_size = data_size - 2;
103  _cached_data.resize( data_size );
104 
105  for (size_t i=0; i < data_size; i++ )
106  {
107  const auto& p0 = _source_data->at( i );
108  const auto& p1 = _source_data->at( i+1 );
109  const auto& p2 = _source_data->at( i+2 );
110  const auto delta = (p2.x - p0.x) *0.5;
111  const auto acc = ( p2.y - 2.0* p1.y + p0.y)/(delta*delta);
112  QPointF p( (p2.x + p0.x)*0.5, acc );
113  _cached_data[i] = { p.x(), p.y() };
114  }
115 
117  return true;
118 }
const PlotData * _source_data
PlotData::RangeValueOpt getVisualizationRangeY(PlotData::RangeTime range_X) override
const Point & at(size_t index) const
Definition: plotdata.h:288
virtual size_t size() const override
Definition: series_data.h:22
int getIndexFromX(Time x) const
Definition: plotdata.h:242
const PlotData * transformedData() const
Definition: series_data.h:59
PlotData _cached_data
nonstd::optional< QPointF > sampleFromTime(double t) override
TimeseriesQwt(const PlotData *source_data, const PlotData *transformed_data)
TFSIMD_FORCE_INLINE const tfScalar & x() const
void resize(size_t new_size)
Definition: plotdata.h:124
void calculateBoundingBox()
Definition: series_data.h:70
void clear()
Definition: plotdata.h:301
QRectF _bounding_box
Definition: series_data.h:62
bool updateCache() override
virtual size_t size() const
Definition: plotdata.h:308
bool updateCache() override
nonstd::optional< RangeValue > RangeValueOpt
Definition: plotdata.h:39
virtual QPointF sample(size_t i) const override
Definition: series_data.h:16
bool updateCache() override
int i


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:18