detectionZivyWidget.cpp 5.88 KB
Newer Older
1
/**
Benoit Valot's avatar
Benoit Valot committed
2
3
4
5
 * \file detectionZivyWidget.cpp
 * \date February 29, 2012
 * \author Edlira Nano
 */
6
7

#include "detectionZivyWidget.h"
Langella Olivier's avatar
Langella Olivier committed
8
9
#include "../../lib/consoleout.h"
#include <QDoubleSpinBox>
10
11
12
13
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
#include <QSpinBox>
Langella Olivier's avatar
Langella Olivier committed
14
#include <QVBoxLayout>
15
16
#include <limits>

Langella Olivier's avatar
Langella Olivier committed
17
18
DetectionZivyWidget::DetectionZivyWidget(TreatmentBoxXicDetect *treatmentBox,
                                         QWidget *parent)
Langella Olivier's avatar
Langella Olivier committed
19
  : MasschroQWidget(parent),
Langella Olivier's avatar
Langella Olivier committed
20
21
22
23
    _smoothing_filter_half_window(1),
    _minmax_filter_half_window(3),
    _maxmin_filter_half_window(2),
    _threshold_on_max(2000),
Langella Olivier's avatar
Langella Olivier committed
24
25
    _threshold_on_min(1000),
    _p_treatmentBox(treatmentBox)
Langella Olivier's avatar
Langella Olivier committed
26
{
Langella Olivier's avatar
Langella Olivier committed
27
28
29
30
31
32
33
34
35
36
37
38
  // initialize detection
  initializeDetectionMethod();

  QVBoxLayout *mainLayout = new QVBoxLayout;
  setWidgetParameters();
  mainLayout->addWidget(_parameter_group);
  // mainLayout->addWidget(_button_box);
  setLayout(mainLayout);
  setWindowTitle(tr("Zivy peak detection"));

  // Trigger Detect
  detectPeaks();
39
40
}

Langella Olivier's avatar
Langella Olivier committed
41
42
DetectionZivyWidget::~DetectionZivyWidget()
{
Langella Olivier's avatar
Langella Olivier committed
43
  mcqout() << "delete detection widget" << endl;
44
45
}

Langella Olivier's avatar
Langella Olivier committed
46
47
48
void
DetectionZivyWidget::initializeDetectionMethod()
{
Langella Olivier's avatar
Langella Olivier committed
49
50
51
52
53
54
  _detection_method =
    std::make_shared<pappso::TraceDetectionZivy>(_smoothing_filter_half_window,
                                                 _minmax_filter_half_window,
                                                 _maxmin_filter_half_window,
                                                 _threshold_on_max,
                                                 _threshold_on_min);
55
56
}

Langella Olivier's avatar
Langella Olivier committed
57
58
59
60
void
DetectionZivyWidget::setWidgetParameters()
{
  _parameter_group    = new QGroupBox("Peak detection");
Langella Olivier's avatar
Langella Olivier committed
61
62
63
64
65
66
  QFormLayout *layout = new QFormLayout;

  QSpinBox *smooth_box = new QSpinBox;
  smooth_box->setMaximum(20);
  smooth_box->setWrapping(true);
  smooth_box->setSingleStep(1);
Langella Olivier's avatar
Langella Olivier committed
67
  smooth_box->setValue(_smoothing_filter_half_window);
Langella Olivier's avatar
Langella Olivier committed
68
69
70
71
72
73
  layout->addRow(tr("Smoothing filter half window"), smooth_box);

  QSpinBox *minmax_box = new QSpinBox;
  minmax_box->setMaximum(20);
  minmax_box->setWrapping(true);
  minmax_box->setSingleStep(1);
Langella Olivier's avatar
Langella Olivier committed
74
  minmax_box->setValue(_minmax_filter_half_window);
Langella Olivier's avatar
Langella Olivier committed
75
76
77
78
79
80
  layout->addRow(tr("MinMax close filter half window"), minmax_box);

  QSpinBox *maxmin_box = new QSpinBox;
  maxmin_box->setMaximum(20);
  maxmin_box->setWrapping(true);
  maxmin_box->setSingleStep(1);
Langella Olivier's avatar
Langella Olivier committed
81
  maxmin_box->setValue(_maxmin_filter_half_window);
Langella Olivier's avatar
Langella Olivier committed
82
83
84
85
86
87
88
  layout->addRow(tr("MaxMin open filter half window"), maxmin_box);

  QDoubleSpinBox *thresholdmax_box = new QDoubleSpinBox;
  thresholdmax_box->setMaximum(1E9);
  thresholdmax_box->setDecimals(0);
  thresholdmax_box->setWrapping(true);
  thresholdmax_box->setSingleStep(1000);
Langella Olivier's avatar
Langella Olivier committed
89
  thresholdmax_box->setValue(_threshold_on_max);
Langella Olivier's avatar
Langella Olivier committed
90
91
92
93
94
95
96
  layout->addRow(tr("Threshold on Max"), thresholdmax_box);

  QDoubleSpinBox *thresholdmin_box = new QDoubleSpinBox;
  thresholdmin_box->setMaximum(1E9);
  thresholdmin_box->setDecimals(0);
  thresholdmin_box->setWrapping(true);
  thresholdmin_box->setSingleStep(1000);
Langella Olivier's avatar
Langella Olivier committed
97
  thresholdmin_box->setValue(_threshold_on_min);
Langella Olivier's avatar
Langella Olivier committed
98
99
100
  layout->addRow(tr("Threshold on Min"), thresholdmin_box);

  _parameter_group->setLayout(layout);
101
102

#if QT_VERSION >= 0x050000
Langella Olivier's avatar
Langella Olivier committed
103
104
  // Qt5 code
  connect(smooth_box,
Langella Olivier's avatar
Langella Olivier committed
105
106
          static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
          this,
Langella Olivier's avatar
Langella Olivier committed
107
108
109
          &DetectionZivyWidget::setSmoothingFilterHalfWindow);

  connect(minmax_box,
Langella Olivier's avatar
Langella Olivier committed
110
111
          static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
          this,
Langella Olivier's avatar
Langella Olivier committed
112
113
114
          &DetectionZivyWidget::setMinMaxFilterHalfWindow);

  connect(maxmin_box,
Langella Olivier's avatar
Langella Olivier committed
115
116
          static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
          this,
Langella Olivier's avatar
Langella Olivier committed
117
118
          &DetectionZivyWidget::setMaxMinFilterHalfWindow);

Langella Olivier's avatar
Langella Olivier committed
119
120
121
122
123
124
125
126
127
128
129
  connect(thresholdmax_box,
          static_cast<void (QDoubleSpinBox::*)(double)>(
            &QDoubleSpinBox::valueChanged),
          this,
          &DetectionZivyWidget::setThresholdOnMax);

  connect(thresholdmin_box,
          static_cast<void (QDoubleSpinBox::*)(double)>(
            &QDoubleSpinBox::valueChanged),
          this,
          &DetectionZivyWidget::setThresholdOnMin);
130
#else
Langella Olivier's avatar
Langella Olivier committed
131
  // Qt4 code
Langella Olivier's avatar
Langella Olivier committed
132
133
134
  connect(smooth_box,
          SIGNAL(valueChanged(int)),
          this,
Langella Olivier's avatar
Langella Olivier committed
135
          SLOT(setSmoothingFilterHalfWindow(int)));
136

Langella Olivier's avatar
Langella Olivier committed
137
138
139
  connect(minmax_box,
          SIGNAL(valueChanged(int)),
          this,
Langella Olivier's avatar
Langella Olivier committed
140
          SLOT(setMinMaxFilterHalfWindow(int)));
141

Langella Olivier's avatar
Langella Olivier committed
142
143
144
  connect(maxmin_box,
          SIGNAL(valueChanged(int)),
          this,
Langella Olivier's avatar
Langella Olivier committed
145
          SLOT(setMaxMinFilterHalfWindow(int)));
146

Langella Olivier's avatar
Langella Olivier committed
147
148
149
  connect(thresholdmax_box,
          SIGNAL(valueChanged(double)),
          this,
Langella Olivier's avatar
Langella Olivier committed
150
          SLOT(setThresholdOnMax(double)));
151

Langella Olivier's avatar
Langella Olivier committed
152
153
154
  connect(thresholdmin_box,
          SIGNAL(valueChanged(double)),
          this,
Langella Olivier's avatar
Langella Olivier committed
155
          SLOT(setThresholdOnMin(double)));
156
#endif
Benoit Valot's avatar
Benoit Valot committed
157
}
158

Langella Olivier's avatar
Langella Olivier committed
159
160
161
void
DetectionZivyWidget::setSmoothingFilterHalfWindow(int i)
{
Langella Olivier's avatar
Langella Olivier committed
162
  _smoothing_filter_half_window = i;
Langella Olivier's avatar
Langella Olivier committed
163
164
  _detection_method->setFilterMorphoMean(
    pappso::FilterMorphoMean(_smoothing_filter_half_window));
Langella Olivier's avatar
Langella Olivier committed
165
  detectPeaks();
166
167
}

Langella Olivier's avatar
Langella Olivier committed
168
169
170
void
DetectionZivyWidget::setMinMaxFilterHalfWindow(int i)
{
Langella Olivier's avatar
Langella Olivier committed
171
  _minmax_filter_half_window = i;
Langella Olivier's avatar
Langella Olivier committed
172
173
  _detection_method->setFilterMorphoMinMax(
    pappso::FilterMorphoMinMax(_minmax_filter_half_window));
Langella Olivier's avatar
Langella Olivier committed
174
  detectPeaks();
175
176
}

Langella Olivier's avatar
Langella Olivier committed
177
178
179
void
DetectionZivyWidget::setMaxMinFilterHalfWindow(int i)
{
Langella Olivier's avatar
Langella Olivier committed
180
  _maxmin_filter_half_window = i;
Langella Olivier's avatar
Langella Olivier committed
181
182
  _detection_method->setFilterMorphoMaxMin(
    pappso::FilterMorphoMaxMin(_maxmin_filter_half_window));
Langella Olivier's avatar
Langella Olivier committed
183
  detectPeaks();
184
185
}

Langella Olivier's avatar
Langella Olivier committed
186
187
188
void
DetectionZivyWidget::setThresholdOnMin(double d)
{
Langella Olivier's avatar
Langella Olivier committed
189
190
191
  _threshold_on_min = d;
  _detection_method->setDetectionThresholdOnMaxmin(_threshold_on_min);
  detectPeaks();
192
193
}

Langella Olivier's avatar
Langella Olivier committed
194
195
196
void
DetectionZivyWidget::setThresholdOnMax(double d)
{
Langella Olivier's avatar
Langella Olivier committed
197
198
199
  _threshold_on_max = d;
  _detection_method->setDetectionThresholdOnMinmax(_threshold_on_max);
  detectPeaks();
200
201
}

Langella Olivier's avatar
Langella Olivier committed
202
203
204
void
DetectionZivyWidget::detectPeaks()
{
Langella Olivier's avatar
Langella Olivier committed
205
  _p_treatmentBox->setPeakDetectionBase(_detection_method);
206
}
Benoit Valot's avatar
Benoit Valot committed
207

Langella Olivier's avatar
Langella Olivier committed
208
209
210
void
DetectionZivyWidget::writeElement(MasschroqDomDocument *domDocument) const
{
Langella Olivier's avatar
Langella Olivier committed
211
  domDocument->addDetectionZivyMethod(*_detection_method);
Benoit Valot's avatar
Benoit Valot committed
212
}