point_series_xy.cpp
Go to the documentation of this file.
1 #include "point_series_xy.h"
2 #include <cmath>
3 #include <cstdlib>
4 
5 PointSeriesXY::PointSeriesXY(const PlotData* x_axis, const PlotData* y_axis)
6  : QwtSeriesWrapper(&_cached_curve),
7  _x_axis(x_axis),
8  _y_axis(y_axis),
9  _cached_curve("")
10 {
11  updateCache(true);
12 }
13 
14 size_t PointSeriesXY::size() const
15 {
16  return _cached_curve.size();
17 }
18 
20 {
21  if (_cached_curve.size() == 0)
22  {
23  return {};
24  }
25 
26  int index = _y_axis->getIndexFromX(t);
27  if (index < 0)
28  {
29  return {};
30  }
31  const auto& p = _cached_curve.at(size_t(index));
32  return QPointF(p.x, p.y);
33 }
34 
36 {
37  return _cached_curve.rangeY();
38 }
39 
40 bool PointSeriesXY::updateCache(bool reset_old_data)
41 {
42  // TODO use reset_old_data
43 
45 
46  if (_x_axis == nullptr)
47  {
48  throw std::runtime_error("the X axis is null");
49  }
50 
51  const size_t data_size = std::min(_x_axis->size(), _y_axis->size());
52 
53  if (data_size == 0)
54  {
55  return true;
56  }
57 
58  const double EPS = std::numeric_limits<double>::epsilon();
59 
60  for (size_t i = 0; i < data_size; i++)
61  {
62  if (std::abs(_x_axis->at(i).x - _y_axis->at(i).x) > EPS)
63  {
64  throw std::runtime_error("X and Y axis don't share the same time axis");
65  }
66 
67  const QPointF p(_x_axis->at(i).y, _y_axis->at(i).y);
68  _cached_curve.pushBack( { p.x(), p.y() } );
69  }
70  return true;
71 }
72 
74 {
75  return _cached_curve.rangeX();
76 }
RangeOpt rangeY() const
Definition: plotdata.h:183
PointSeriesXY(const PlotData *x_axis, const PlotData *y_axis)
RangeOpt getVisualizationRangeX() override
const Point & at(size_t index) const
Definition: plotdata.h:97
size_t size() const override
bool updateCache(bool reset_old_data) override
#define min(A, B)
Definition: Log.c:64
int getIndexFromX(double x) const
Definition: plotdata.h:545
const PlotData * _y_axis
PlotDataBase< double > _cached_curve
virtual size_t size() const
Definition: plotdata.h:92
nonstd::optional< QPointF > sampleFromTime(double t) override
virtual RangeOpt rangeX() const
Definition: plotdata.h:164
void pushBack(const Point &p)
Definition: plotdata.h:202
const PlotData * _x_axis
RangeOpt getVisualizationRangeY(Range range_X) override


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10