integral_transform.cpp
Go to the documentation of this file.
1 #include "integral_transform.h"
2 #include <QFormLayout>
3 #include <QDoubleValidator>
4 
6  _widget(new QWidget()),
7  ui(new Ui::IntegralTransform),
8  _dT(0.0)
9 {
10  ui->setupUi(_widget);
11  ui->lineEditCustom->setValidator( new QDoubleValidator(0.0001, 1000, 4, ui->lineEditCustom) );
12 
13  connect(ui->buttonCompute, &QPushButton::clicked,
15 
16  connect(ui->lineEditCustom, &QLineEdit::editingFinished,
17  this, [=](){
18  _dT = ui->lineEditCustom->text().toDouble();
19  emit parametersChanged();
20  } );
21 
22  connect(ui->radioActual, &QRadioButton::toggled,
23  this, [=](bool toggled){
24  if( toggled) {
25  _dT = 0.0;
26  emit parametersChanged();
27  }
28  } );
29 
30  connect(ui->radioCustom, &QRadioButton::toggled,
31  this, [=](bool toggled){
32  if( toggled) {
33  _dT = ui->lineEditCustom->text().toDouble();
34  emit parametersChanged();
35  }
36  } );
37 }
38 
40 {
41  delete ui;
42  delete _widget;
43 }
44 
47 {
48  if( index == 0)
49  {
50  return {};
51  }
52 
53  const auto& prev = dataSource()->at(index-1);
54  const auto& p = dataSource()->at(index);
55 
56  double dt = (_dT == 0.0) ? (p.x - prev.x) : _dT;
57 
58  if( dt <= 0 )
59  {
60  return {};
61  }
62 
63  double val = (p.y + prev.y) * dt / (2.0);
64  _accumulated_value += val;
66  return out;
67 }
68 
70 {
71  const size_t data_size = dataSource()->size();
72 
73  if(!dataSource() || data_size < 2)
74  {
75  _widget->setEnabled(false);
76  }
77  return _widget;
78 }
79 
81 {
82  _accumulated_value = 0.0;
83  TimeSeriesTransform::init();
84 }
85 
86 bool IntegralTransform::xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const
87 {
88  QDomElement widget_el = doc.createElement("options");
89 
90  if( ui->radioActual->isChecked() )
91  {
92  widget_el.setAttribute("radioChecked", "radioActual");
93  }
94  else{
95  widget_el.setAttribute("radioChecked", "radioCustom");
96  }
97  widget_el.setAttribute("lineEdit", ui->lineEditCustom->text() );
98 
99  parent_element.appendChild( widget_el );
100  return true;
101 }
102 
103 bool IntegralTransform::xmlLoadState(const QDomElement &parent_element)
104 {
105  QDomElement widget_el = parent_element.firstChildElement("options");
106 
107  ui->lineEditCustom->setText( widget_el.attribute("lineEdit") );
108 
109  if( widget_el.attribute("radioChecked") == "radioActual")
110  {
111  ui->radioActual->setChecked(true);
112  }
113  else{
114  ui->radioCustom->setChecked(true);
115  }
116  return true;
117 }
118 
120 {
121  if(!dataSource() || dataSource()->size() < 2)
122  {
123  return;
124  }
125 
126  const size_t data_size = dataSource()->size();
127 
128  // calculate automatic diff
129  std::vector<double> diff;
130  diff.reserve(data_size-1);
131  double prev_t = dataSource()->at(0).x;
132  for(size_t i=1; i<data_size; i++)
133  {
134  double t = dataSource()->at(i).x;
135  double delta = t - prev_t;
136  prev_t = t;
137  diff.push_back(delta);
138  }
139 
140  size_t first = 0;
141  size_t last = diff.size();
142  if( data_size > 10 )
143  {
144  std::sort(diff.begin(), diff.end());
145  first = last / 5;
146  last = (last*4)/5;
147  }
148  double total = 0;
149  for(size_t i=first; i<last; i++) {
150  total += diff[i];
151  }
152  double estimated_dt = total / static_cast<double>(last-first);
153  ui->lineEditCustom->setText(QString::number(estimated_dt, 'g', 4));
154 
155  if( ui->radioCustom->isChecked() )
156  {
157  _dT = estimated_dt;
158  emit parametersChanged();
159  }
160 }
bool xmlLoadState(const QDomElement &parent_element) override
const Point & at(size_t index) const
Definition: plotdata.h:97
Ui::IntegralTransform * ui
void init() override
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
QWidget * optionsWidget() override
static int sort(lua_State *L)
Definition: ltablib.c:397
nonstd::optional< PlotData::Point > calculateNextPoint(size_t index) override
virtual size_t size() const
Definition: plotdata.h:92
const PlotData * dataSource() const
typename PlotDataBase< Value >::Point Point
Definition: plotdata.h:290


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:47:35