summaryrefslogtreecommitdiffhomepage
path: root/filter-accela/ftnoir_filter_accela_dialog.cpp
blob: 594d04fd05dd4c9e6eb35cf93c9d515a9994f40f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* Copyright (c) 2012-2015 Stanislaw Halik
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 */
#include "ftnoir_filter_accela.h"
#include <cmath>
#include <QDebug>
#include <algorithm>
#include <QDoubleSpinBox>
#include "api/plugin-api.hpp"
#include "spline-widget/spline-widget.hpp"
#include <QDialog>

FilterControls::FilterControls()
{
    ui.setupUi(this);

    connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));
    connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));

    connect(ui.rotation_slider, SIGNAL(valueChanged(int)), this, SLOT(update_rot_display(int)));
    connect(ui.translation_slider, SIGNAL(valueChanged(int)), this, SLOT(update_trans_display(int)));
    connect(ui.ewma_slider, SIGNAL(valueChanged(int)), this, SLOT(update_ewma_display(int)));
    connect(ui.rot_dz_slider, SIGNAL(valueChanged(int)), this, SLOT(update_rot_dz_display(int)));
    connect(ui.trans_dz_slider, SIGNAL(valueChanged(int)), this, SLOT(update_trans_dz_display(int)));
    connect(&s.rot_nonlinearity, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_rot_nl_slider(const slider_value&)));

    tie_setting(s.rot_threshold, ui.rotation_slider);
    tie_setting(s.trans_threshold, ui.translation_slider);
    tie_setting(s.ewma, ui.ewma_slider);
    tie_setting(s.rot_deadzone, ui.rot_dz_slider);
    tie_setting(s.trans_deadzone, ui.trans_dz_slider);

    tie_setting(s.rot_nonlinearity, ui.rot_nl_slider);

    update_rot_display(ui.rotation_slider->value());
    update_trans_display(ui.translation_slider->value());
    update_ewma_display(ui.ewma_slider->value());
    update_rot_dz_display(ui.rot_dz_slider->value());
    update_trans_dz_display(ui.trans_dz_slider->value());
    update_rot_nl_slider(s.rot_nonlinearity);

    {
//#define SPLINE_ROT_DEBUG
//#define SPLINE_TRANS_DEBUG
#if defined(SPLINE_ROT_DEBUG) || defined(SPLINE_TRANS_DEBUG)
    spline rot, trans;
    s.make_splines(rot, trans);
    QDialog d;

    spline_widget r(&d);
    r.set_preview_only(true);
    r.setEnabled(false);
    r.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

#if defined(SPLINE_TRANS_DEBUG)
#   if defined(SPLINE_ROT_DEBUG)
#       error "rot xor trans"
#   endif
    r.setConfig(&trans);
#else

    r.setConfig(&rot);
#endif
    r.setFixedSize(1024, 600);
    d.show();
    d.exec();
#endif
    }
}

void FilterControls::doOK()
{
    save();
    close();
}

void FilterControls::doCancel()
{
    close();
}

void FilterControls::save()
{
    s.b->save();
}

void FilterControls::update_rot_display(int value)
{
    ui.rot_gain->setText(QString::number((value + 1) * s.mult_rot) + "°");
}

void FilterControls::update_trans_display(int value)
{
    ui.trans_gain->setText(QString::number((value + 1) * s.mult_trans) + "mm");
}

void FilterControls::update_ewma_display(int value)
{
    ui.ewma_label->setText(QString::number(value * s.mult_ewma) + "ms");
}

void FilterControls::update_rot_dz_display(int value)
{
    ui.rot_dz->setText(QString::number(value * s.mult_rot_dz) + "°");
}

void FilterControls::update_trans_dz_display(int value)
{
    ui.trans_dz->setText(QString::number(value * s.mult_trans_dz) + "mm");
}

void FilterControls::update_rot_nl_slider(const slider_value& sl)
{
    ui.rot_nl->setText("<html><head/><body><p>x<span style='vertical-align:super;'>" +
                       QString::number(sl.cur()) +
                       "</span></p></body></html>");
}