outlier_removal.cpp
Go to the documentation of this file.
1 #include "outlier_removal.h"
2 #include "ui_outlier_removal.h"
3 
5  ui(new Ui::OutlierRemovalFilter),
6  _widget(new QWidget()),
7  _buffer(4),
8  _ring_view( _buffer.begin(), _buffer.end() )
9 {
10  ui->setupUi(_widget);
11 
12  connect(ui->spinBoxFactor, qOverload<double>(&QDoubleSpinBox::valueChanged),
13  this, [=](int){ emit parametersChanged(); } );
14 }
15 
17 {
18  delete ui;
19  delete _widget;
20 }
21 
22 
24 {
25  return _widget;
26 }
27 
28 bool OutlierRemovalFilter::xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const
29 {
30  QDomElement widget_el = doc.createElement("options");
31  widget_el.setAttribute("factor", ui->spinBoxFactor->value() );
32  parent_element.appendChild( widget_el );
33  return true;
34 }
35 
36 bool OutlierRemovalFilter::xmlLoadState(const QDomElement &parent_element)
37 {
38  QDomElement widget_el = parent_element.firstChildElement("options");
39  ui->spinBoxFactor->setValue( widget_el.attribute("value", "100.0").toDouble() );
40  return true;
41 }
42 
45 {
46  const auto& p = dataSource()->at(index);
47  _ring_view.push_back(p.y);
48 
49  if( index <= 2 )
50  {
51  return p;
52  }
53 
54  if( index == 3 ) // skip this
55  {
56  return {};
57  }
58 
59  double d1 = (_ring_view[1] - _ring_view[2]);
60  double d2 = (_ring_view[2] - _ring_view[3]);
61  if( d1*d2 < 0 ) // spike
62  {
63  double min_y = _ring_view[0];
64  double max_y = _ring_view[0];
65 
66  min_y = std::min(min_y, _ring_view[1]);
67  min_y = std::min(min_y, _ring_view[3]);
68 
69  max_y = std::max(max_y, _ring_view[1]);
70  max_y = std::max(max_y, _ring_view[3]);
71 
72  double thresh = (max_y - min_y) * ui->spinBoxFactor->value();
73 
74  double jump = std::max(std::abs(d1), std::abs(d2));
75  if( jump > thresh )
76  {
77  return {};
78  }
79  }
80  return dataSource()->at(index-1);
81 }
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
const Point & at(size_t index) const
Definition: plotdata.h:97
#define min(A, B)
Definition: Log.c:64
#define max(A, B)
Definition: Socket.h:88
nonstd::ring_span_lite::ring_span< double > _ring_view
~OutlierRemovalFilter() override
const PlotData * dataSource() const
Ui::OutlierRemovalFilter * ui
nonstd::optional< PlotData::Point > calculateNextPoint(size_t index) override
bool xmlLoadState(const QDomElement &parent_element) override
QWidget * optionsWidget() override
void push_back(value_type const &value)
Definition: ring_span.hpp:605


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