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), this,
13  [=](int) { emit parametersChanged(); });
14 }
15 
17 {
18  delete ui;
19  delete _widget;
20 }
21 
23 {
24  return _widget;
25 }
26 
27 bool OutlierRemovalFilter::xmlSaveState(QDomDocument& doc,
28  QDomElement& parent_element) const
29 {
30  QDomElement widget_el = doc.createElement("options");
31  widget_el.setAttribute("value", 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 
43 std::optional<PJ::PlotData::Point> OutlierRemovalFilter::calculateNextPoint(size_t index)
44 {
45  const auto& p = dataSource()->at(index);
46  _ring_view.push_back(p.y);
47 
48  if (index < 3)
49  {
50  return p;
51  }
52 
53  double d1 = (_ring_view[1] - _ring_view[2]);
54  double d2 = (_ring_view[2] - _ring_view[3]);
55  if (d1 * d2 < 0) // spike
56  {
57  double d0 = (_ring_view[0] - _ring_view[1]);
58  double thresh = ui->spinBoxFactor->value();
59 
60  double jump = std::max(std::abs(d1), std::abs(d2));
61  if (jump / std::abs(d0) > thresh)
62  {
63  return {};
64  }
65  }
66  return dataSource()->at(index - 1);
67 }
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
Override this method to save the status of the plugin to XML.
nonstd::ring_span_lite::ring_span< double > _ring_view
~OutlierRemovalFilter() override
const Point & at(size_t index) const
Definition: plotdatabase.h:192
const PlotData * dataSource() const
Ui::OutlierRemovalFilter * ui
std::optional< PlotData::Point > calculateNextPoint(size_t index) override
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
QWidget * optionsWidget() override
optionsWidget pointer to a persistent widget used to set the plugin options .
void push_back(value_type const &value)
Definition: ring_span.hpp:605


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:38