filterSpikeWidget.cpp 2.38 KB
Newer Older
1
/**
Langella Olivier's avatar
Langella Olivier committed
2
3
4
5
 * \file filterSpikeWidget.cpp
 * \date February 15, 2012
 * \author Edlira Nano
 */
6
7

#include "filterSpikeWidget.h"
Langella Olivier's avatar
Langella Olivier committed
8
#include "../../lib/consoleout.h"
Langella Olivier's avatar
Langella Olivier committed
9
10
#include <QLabel>
#include <QSpinBox>
11

Langella Olivier's avatar
Langella Olivier committed
12
13
FilterSpikeWidget::FilterSpikeWidget(TreatmentBoxXicFilter *treatmentBox,
                                     QWidget *parent)
Langella Olivier's avatar
Langella Olivier committed
14
  : MasschroQWidget(parent), _p_treatmentBox(treatmentBox), _half_window(5)
Langella Olivier's avatar
Langella Olivier committed
15
{
Langella Olivier's avatar
Langella Olivier committed
16
  // initialize filter
Langella Olivier's avatar
Langella Olivier committed
17
  _filter_spike = std::make_shared<pappso::FilterMorphoAntiSpike>(_half_window);
18
  treatmentBox->setFilter(_filter_spike);
Langella Olivier's avatar
Langella Olivier committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

  //	QPushButton * filterButton = new QPushButton(tr("&Filter"));
  //	filterButton->setDefault(true);
  //	_button_box = new QDialogButtonBox(Qt::Vertical);
  //	_button_box->addButton(filterButton, QDialogButtonBox::AcceptRole);
  //
  //	connect(_button_box, SIGNAL(accepted()), this, SLOT(filterXic()));

  QVBoxLayout *mainLayout = new QVBoxLayout;
  setWidgetParameters();
  mainLayout->addWidget(_half_window_group);
  // mainLayout->addWidget(_button_box);
  setLayout(mainLayout);
  setWindowTitle(tr("Spike noise filter"));

  // Trigger filter
  this->filterXic();
36
37
}

Langella Olivier's avatar
Langella Olivier committed
38
39
FilterSpikeWidget::~FilterSpikeWidget()
{
40
41
}

Langella Olivier's avatar
Langella Olivier committed
42
43
44
void
FilterSpikeWidget::setWidgetParameters()
{
45

Langella Olivier's avatar
Langella Olivier committed
46
  _half_window_group  = new QGroupBox("Spike Filter");
Langella Olivier's avatar
Langella Olivier committed
47
  QGridLayout *layout = new QGridLayout;
48

Langella Olivier's avatar
Langella Olivier committed
49
50
  QLabel *half_label = new QLabel("Spike filtering half window");
  QSpinBox *half_box = new QSpinBox;
51

Langella Olivier's avatar
Langella Olivier committed
52
53
54
  half_box->setMaximum(30);
  half_box->setWrapping(true);
  half_box->setSingleStep(1);
55
  half_box->setValue(_half_window);
Langella Olivier's avatar
Langella Olivier committed
56
57
58
  layout->addWidget(half_label, 0, 0);
  layout->addWidget(half_box, 0, 1);
  _half_window_group->setLayout(layout);
59

60
#if QT_VERSION >= 0x050000
Langella Olivier's avatar
Langella Olivier committed
61
  // Qt5 code
62

Langella Olivier's avatar
Langella Olivier committed
63
  connect(half_box,
Langella Olivier's avatar
Langella Olivier committed
64
65
          static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
          this,
Langella Olivier's avatar
Langella Olivier committed
66
          &FilterSpikeWidget::setHalfWindow);
67
#else
Langella Olivier's avatar
Langella Olivier committed
68
  // Qt4 code
69

Langella Olivier's avatar
Langella Olivier committed
70
  connect(half_box, SIGNAL(valueChanged(int)), this, SLOT(setHalfWindow(int)));
71
#endif
72
73
}

Langella Olivier's avatar
Langella Olivier committed
74
75
76
void
FilterSpikeWidget::setHalfWindow(int i)
{
Langella Olivier's avatar
Langella Olivier committed
77
78
  _half_window  = i;
  _filter_spike = std::make_shared<pappso::FilterMorphoAntiSpike>(_half_window);
Langella Olivier's avatar
Langella Olivier committed
79
  this->filterXic();
80
81
}

Langella Olivier's avatar
Langella Olivier committed
82
int
Langella Olivier's avatar
Langella Olivier committed
83
84
85
86
FilterSpikeWidget::getHalfWindow() const
{
  return _half_window;
}
87

Langella Olivier's avatar
Langella Olivier committed
88
89
90
void
FilterSpikeWidget::filterXic()
{
Langella Olivier's avatar
Langella Olivier committed
91
  _p_treatmentBox->setFilter(_filter_spike);
92
}
Benoit Valot's avatar
Benoit Valot committed
93

Langella Olivier's avatar
Langella Olivier committed
94
95
96
void
FilterSpikeWidget::writeElement(MasschroqDomDocument *domDocument) const
{
Langella Olivier's avatar
Langella Olivier committed
97
  domDocument->addSpikeFilterMethod(*_filter_spike);
Benoit Valot's avatar
Benoit Valot committed
98
}