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  if (widget_el.isNull())
40  {
41  return false;
42  }
43  ui->spinBoxFactor->setValue(widget_el.attribute("value", "100.0").toDouble());
44  return true;
45 }
46 
47 std::optional<PJ::PlotData::Point> OutlierRemovalFilter::calculateNextPoint(size_t index)
48 {
49  const auto& p = dataSource()->at(index);
50  _ring_view.push_back(p.y);
51 
52  if (index < 3)
53  {
54  return p;
55  }
56 
57  double d1 = (_ring_view[1] - _ring_view[2]);
58  double d2 = (_ring_view[2] - _ring_view[3]);
59  if (d1 * d2 < 0) // spike
60  {
61  double d0 = (_ring_view[0] - _ring_view[1]);
62  double thresh = ui->spinBoxFactor->value();
63 
64  double jump = std::max(std::abs(d1), std::abs(d2));
65  if (jump / std::abs(d0) > thresh)
66  {
67  return {};
68  }
69  }
70  return dataSource()->at(index - 1);
71 }
OutlierRemovalFilter::~OutlierRemovalFilter
~OutlierRemovalFilter() override
Definition: outlier_removal.cpp:16
OutlierRemovalFilter::xmlLoadState
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
Definition: outlier_removal.cpp:36
OutlierRemovalFilter::ui
Ui::OutlierRemovalFilter * ui
Definition: outlier_removal.h:40
Ui
Definition: cheatsheet_dialog.h:6
OutlierRemovalFilter::_ring_view
nonstd::ring_span_lite::ring_span< double > _ring_view
Definition: outlier_removal.h:43
OutlierRemovalFilter::calculateNextPoint
std::optional< PlotData::Point > calculateNextPoint(size_t index) override
Definition: outlier_removal.cpp:47
OutlierRemovalFilter::_widget
QWidget * _widget
Definition: outlier_removal.h:41
OutlierRemovalFilter::OutlierRemovalFilter
OutlierRemovalFilter()
Definition: outlier_removal.cpp:4
OutlierRemovalFilter::optionsWidget
QWidget * optionsWidget() override
optionsWidget pointer to a persistent widget used to set the plugin options .
Definition: outlier_removal.cpp:22
PJ::TransformFunction_SISO::dataSource
const PlotData * dataSource() const
Definition: transform_function.cpp:113
OutlierRemovalFilter::xmlSaveState
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
Override this method to save the status of the plugin to XML.
Definition: outlier_removal.cpp:27
PJ::PlotDataBase::at
const Point & at(size_t index) const
Definition: plotdatabase.h:193
nonstd::ring_span_lite::ring_span::push_back
void push_back(value_type const &value)
Definition: ring_span.hpp:639
outlier_removal.h
OutlierRemovalFilter
Definition: outlier_removal.h:16


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45