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 *y_axis, const PlotData *x_axis):
6  DataSeriesBase( &_cached_curve ),
7  _x_axis(x_axis),
8  _y_axis(y_axis),
9  _cached_curve("")
10 {
11  updateCache();
12 }
13 
15 {
16  if( this->size() < 2 )
17  return PlotData::RangeTimeOpt();
18  else{
19  return PlotData::RangeTimeOpt( { _bounding_box.left() ,
20  _bounding_box.right()} );
21  }
22 }
23 
25 {
26  if( _cached_curve.size() == 0 )
27  {
28  return {};
29  }
30 
31  int index = _y_axis->getIndexFromX(t);
32  if(index <0)
33  {
34  return {};
35  }
36  const auto& p = _cached_curve.at( size_t(index) );
37  return QPointF(p.x, p.y);
38 }
39 
41 {
42  //TODO: improve?
43  return PlotData::RangeValueOpt( { _bounding_box.bottom(),
44  _bounding_box.top() } );
45 }
46 
48 {
49  if( _x_axis == nullptr )
50  {
51  throw std::runtime_error("the X axis is null");
52  }
53 
54  const size_t data_size = std::min(_x_axis->size(), _y_axis->size());
55 
56  if(data_size == 0)
57  {
58  _bounding_box = QRectF();
60  return true;
61  }
62 
63  double min_y =( std::numeric_limits<double>::max() );
64  double max_y =(-std::numeric_limits<double>::max() );
65  double min_x =( std::numeric_limits<double>::max() );
66  double max_x =(-std::numeric_limits<double>::max() );
67 
68  _cached_curve.resize( data_size );
69 
70  const double EPS = std::numeric_limits<double>::epsilon();
71 
72  for (size_t i=0; i<data_size; i++ )
73  {
74  if( Abs( _x_axis->at(i).x - _y_axis->at(i).x ) > EPS)
75  {
76  _bounding_box = QRectF();
78  throw std::runtime_error("X and Y axis don't share the same time axis");
79  }
80 
81  const QPointF p(_x_axis->at(i).y,
82  _y_axis->at(i).y );
83 
84  _cached_curve.at(i) = { p.x(), p.y() };
85 
86  min_x = std::min( min_x, p.x() );
87  max_x = std::max( max_x, p.x() );
88  min_y = std::min( min_y, p.y() );
89  max_y = std::max( max_y, p.y() );
90  }
91 
92  _bounding_box.setLeft( min_x );
93  _bounding_box.setRight( max_x );
94  _bounding_box.setBottom( min_y );
95  _bounding_box.setTop( max_y );
96 
97  return true;
98 }
PointSeriesXY(const PlotData *y_axis, const PlotData *x_axis)
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
double Abs(double val)
Definition: plotdata.h:19
void resize(size_t new_size)
Definition: plotdata.h:124
void clear()
Definition: plotdata.h:301
const PlotData * _y_axis
QRectF _bounding_box
Definition: series_data.h:62
PlotData::RangeValueOpt getVisualizationRangeY(PlotData::RangeTime range_X) override
virtual size_t size() const
Definition: plotdata.h:308
nonstd::optional< RangeValue > RangeValueOpt
Definition: plotdata.h:39
nonstd::optional< QPointF > sampleFromTime(double t) override
PlotData::RangeTimeOpt getVisualizationRangeX() override
nonstd::optional< RangeTime > RangeTimeOpt
Definition: plotdata.h:38
int i
const PlotData * _x_axis
bool updateCache() override
PlotData _cached_curve


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