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 
9 {
10  int first_index = _ts_data->getIndexFromX(range_X.min);
11  int last_index = _ts_data->getIndexFromX(range_X.max);
12 
13  if (first_index > last_index || first_index < 0 || last_index < 0)
14  {
15  return {};
16  }
17 
18  if (first_index == 0 && last_index == plotData()->size() - 1)
19  {
20  return _ts_data->rangeY();
21  }
22 
23  double min_y = (std::numeric_limits<double>::max());
24  double max_y = (-std::numeric_limits<double>::max());
25 
26  for (size_t i = first_index; i < last_index; i++)
27  {
28  const double Y = sample(i).y();
29  min_y = std::min(min_y, Y);
30  max_y = std::max(max_y, Y);
31  }
32  return Range{ min_y, max_y };
33 }
34 
36 {
37  int index = _ts_data->getIndexFromX(t);
38  if (index < 0)
39  {
40  return {};
41  }
42  const auto& p = plotData()->at(size_t(index));
43  return QPointF(p.x, p.y);
44 }
45 
46 
48  : QwtTimeseries(&_dst_data),
49  _source_data(source_data),
50  _dst_data(source_data->name())
51 {
52 
53 }
54 
55 
57 {
58  return _transform;
59 }
60 
61 void TransformedTimeseries::setTransform(QString transform_ID)
62 {
63  if( transformName() == transform_ID)
64  {
65  return;
66  }
67  if( transform_ID.isEmpty() )
68  {
69  _transform.reset();
70  }
71  else{
72  _dst_data.clear();
73  _transform = TransformFactory::create(transform_ID.toStdString());
74  _transform->setDataSource( _source_data );
75  }
76 }
77 
78 bool TransformedTimeseries::updateCache(bool reset_old_data)
79 {
80  if( _transform )
81  {
82  if( reset_old_data )
83  {
84  _dst_data.clear();
85  _transform->init();
86  }
87  _transform->calculate( &_dst_data );
88  }
89  else{
90  // TODO: optimize ??
91  _dst_data.clear();
92  for(size_t i=0; i < _source_data->size(); i++)
93  {
95  }
96  }
97  return true;
98 }
99 
101 {
102  return ( !_transform ) ? QString() : _transform->name();
103 }
104 
106 {
107  if( size() == 0 )
108  {
109  return {};
110  }
111  auto range_x = plotData()->rangeX().value();
112  auto range_y = plotData()->rangeY().value();
113 
114  QRectF box;
115  box.setLeft(range_x.min - _time_offset);
116  box.setRight(range_x.max - _time_offset);
117  box.setTop(range_y.max);
118  box.setBottom(range_y.min);
119  return box;
120 }
121 
122 
123 QPointF QwtSeriesWrapper::sample(size_t i) const
124 {
125  const auto& p = _data->at(i);
126  return QPointF(p.x - _time_offset, p.y);
127 }
128 
130 {
131  return _data->size();
132 }
133 
135 {
136  _time_offset = offset;
137 }
138 
140 {
141  if (this->size() < 2){
142  return {};
143  }
144  else
145  {
146  auto range = _data->rangeX().value();
147  return RangeOpt({ range.min - _time_offset,
148  range.max - _time_offset });
149  }
150 }
151 
153 {
154  return _data;
155 }
const PlotData * _source_data
RangeOpt rangeY() const
Definition: plotdata.h:183
virtual RangeOpt getVisualizationRangeX()
TimeSeriesTransformPtr transform()
const Point & at(size_t index) const
Definition: plotdata.h:97
double max
Definition: plotdata.h:24
QRectF boundingRect() const override
TimeSeriesTransformPtr _transform
QPointF sample(size_t i) const override
nonstd::optional< Range > RangeOpt
Definition: plotdata.h:27
const PlotData * _ts_data
virtual RangeOpt getVisualizationRangeY(Range range_X) override
optional_constexpr14 value_type const & value() const optional_ref_qual
Definition: optional.hpp:755
virtual bool updateCache(bool reset_old_data) override
size_t size() const override
virtual nonstd::optional< QPointF > sampleFromTime(double t) override
#define min(A, B)
Definition: Log.c:64
#define max(A, B)
Definition: Socket.h:88
int getIndexFromX(double x) const
Definition: plotdata.h:545
std::shared_ptr< TimeSeriesTransform > TimeSeriesTransformPtr
void setTimeOffset(double offset)
TransformedTimeseries(const PlotData *source_data)
const char * name
virtual size_t size() const
Definition: plotdata.h:92
const PlotDataBase< double > * plotData() const
const PlotDataBase< double > * _data
void setTransform(QString transform_ID)
void pushBack(const Point &p)
Definition: plotdata.h:330
virtual RangeOpt rangeX() const
Definition: plotdata.h:164
double min
Definition: plotdata.h:23
const new_table create
Definition: sol.hpp:7100


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:48