diff options
author | Stéphane Lenclud <github@lenclud.com> | 2019-04-13 12:59:22 +0200 |
---|---|---|
committer | Stéphane Lenclud <github@lenclud.com> | 2019-04-24 18:46:12 +0200 |
commit | abaf23d7043c42a07e0d71fc0a17a8264c828d48 (patch) | |
tree | b5e8f14e4730bb45d26d2858a26ac2c6cbfc23a8 /tracker-easy/tracker-easy-dialog.cpp | |
parent | ac8f7a3e7b29a5ce60ae751ee3a97e3b344c8f3f (diff) |
EasyTracker: Adding namespace. Reducing number of classes.
Diffstat (limited to 'tracker-easy/tracker-easy-dialog.cpp')
-rw-r--r-- | tracker-easy/tracker-easy-dialog.cpp | 384 |
1 files changed, 194 insertions, 190 deletions
diff --git a/tracker-easy/tracker-easy-dialog.cpp b/tracker-easy/tracker-easy-dialog.cpp index c0dd23dd..0b0dd61d 100644 --- a/tracker-easy/tracker-easy-dialog.cpp +++ b/tracker-easy/tracker-easy-dialog.cpp @@ -20,249 +20,253 @@ using namespace options; static void init_resources() { Q_INIT_RESOURCE(tracker_easy); } -EasyTrackerDialog::EasyTrackerDialog(const QString& module_name) : - s(module_name), - tracker(nullptr), - timer(this), - trans_calib(1, 2) +namespace EasyTracker { - init_resources(); - ui.setupUi(this); + Dialog::Dialog() : + s(KModuleName), + tracker(nullptr), + timer(this), + trans_calib(1, 2) + { + init_resources(); - for (const QString& str : video::camera_names()) - ui.camdevice_combo->addItem(str); + ui.setupUi(this); - tie_setting(s.camera_name, ui.camdevice_combo); - tie_setting(s.cam_res_x, ui.res_x_spin); - tie_setting(s.cam_res_y, ui.res_y_spin); - tie_setting(s.cam_fps, ui.fps_spin); + for (const QString& str : video::camera_names()) + ui.camdevice_combo->addItem(str); - tie_setting(s.threshold_slider, ui.threshold_slider); + tie_setting(s.camera_name, ui.camdevice_combo); + tie_setting(s.cam_res_x, ui.res_x_spin); + tie_setting(s.cam_res_y, ui.res_y_spin); + tie_setting(s.cam_fps, ui.fps_spin); - tie_setting(s.min_point_size, ui.mindiam_spin); - tie_setting(s.max_point_size, ui.maxdiam_spin); + tie_setting(s.threshold_slider, ui.threshold_slider); - tie_setting(s.clip_by, ui.clip_bheight_spin); - tie_setting(s.clip_bz, ui.clip_blength_spin); - tie_setting(s.clip_ty, ui.clip_theight_spin); - tie_setting(s.clip_tz, ui.clip_tlength_spin); + tie_setting(s.min_point_size, ui.mindiam_spin); + tie_setting(s.max_point_size, ui.maxdiam_spin); - tie_setting(s.cap_x, ui.cap_width_spin); - tie_setting(s.cap_y, ui.cap_height_spin); - tie_setting(s.cap_z, ui.cap_length_spin); + tie_setting(s.clip_by, ui.clip_bheight_spin); + tie_setting(s.clip_bz, ui.clip_blength_spin); + tie_setting(s.clip_ty, ui.clip_theight_spin); + tie_setting(s.clip_tz, ui.clip_tlength_spin); - tie_setting(s.m01_x, ui.m1x_spin); - tie_setting(s.m01_y, ui.m1y_spin); - tie_setting(s.m01_z, ui.m1z_spin); + tie_setting(s.cap_x, ui.cap_width_spin); + tie_setting(s.cap_y, ui.cap_height_spin); + tie_setting(s.cap_z, ui.cap_length_spin); - tie_setting(s.m02_x, ui.m2x_spin); - tie_setting(s.m02_y, ui.m2y_spin); - tie_setting(s.m02_z, ui.m2z_spin); + tie_setting(s.m01_x, ui.m1x_spin); + tie_setting(s.m01_y, ui.m1y_spin); + tie_setting(s.m01_z, ui.m1z_spin); - tie_setting(s.t_MH_x, ui.tx_spin); - tie_setting(s.t_MH_y, ui.ty_spin); - tie_setting(s.t_MH_z, ui.tz_spin); + tie_setting(s.m02_x, ui.m2x_spin); + tie_setting(s.m02_y, ui.m2y_spin); + tie_setting(s.m02_z, ui.m2z_spin); - tie_setting(s.fov, ui.fov); + tie_setting(s.t_MH_x, ui.tx_spin); + tie_setting(s.t_MH_y, ui.ty_spin); + tie_setting(s.t_MH_z, ui.tz_spin); - tie_setting(s.active_model_panel, ui.model_tabs); + tie_setting(s.fov, ui.fov); - tie_setting(s.dynamic_pose, ui.dynamic_pose); - tie_setting(s.init_phase_timeout, ui.init_phase_timeout); + tie_setting(s.active_model_panel, ui.model_tabs); - tie_setting(s.auto_threshold, ui.auto_threshold); + tie_setting(s.dynamic_pose, ui.dynamic_pose); + tie_setting(s.init_phase_timeout, ui.init_phase_timeout); - connect(ui.tcalib_button,SIGNAL(toggled(bool)), this, SLOT(startstop_trans_calib(bool))); + tie_setting(s.auto_threshold, ui.auto_threshold); - connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); - connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); + connect(ui.tcalib_button, SIGNAL(toggled(bool)), this, SLOT(startstop_trans_calib(bool))); - connect(ui.camdevice_combo, &QComboBox::currentTextChanged, this, &EasyTrackerDialog::set_camera_settings_available); - set_camera_settings_available(ui.camdevice_combo->currentText()); - connect(ui.camera_settings, &QPushButton::clicked, this, &EasyTrackerDialog::show_camera_settings); + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - connect(&timer, &QTimer::timeout, this, &EasyTrackerDialog::poll_tracker_info_impl); - timer.setInterval(250); + connect(ui.camdevice_combo, &QComboBox::currentTextChanged, this, &Dialog::set_camera_settings_available); + set_camera_settings_available(ui.camdevice_combo->currentText()); + connect(ui.camera_settings, &QPushButton::clicked, this, &Dialog::show_camera_settings); - connect(&calib_timer, &QTimer::timeout, this, &EasyTrackerDialog::trans_calib_step); - calib_timer.setInterval(35); + connect(&timer, &QTimer::timeout, this, &Dialog::poll_tracker_info_impl); + timer.setInterval(250); - poll_tracker_info_impl(); + connect(&calib_timer, &QTimer::timeout, this, &Dialog::trans_calib_step); + calib_timer.setInterval(35); - connect(this, &EasyTrackerDialog::poll_tracker_info, this, &EasyTrackerDialog::poll_tracker_info_impl, Qt::DirectConnection); + poll_tracker_info_impl(); - constexpr pt_color_type color_types[] = { - pt_color_average, - pt_color_natural, - pt_color_red_only, - pt_color_green_only, - pt_color_blue_only, - }; + connect(this, &Dialog::poll_tracker_info, this, &Dialog::poll_tracker_info_impl, Qt::DirectConnection); - for (unsigned k = 0; k < std::size(color_types); k++) - ui.blob_color->setItemData(k, int(color_types[k])); + constexpr pt_color_type color_types[] = { + pt_color_average, + pt_color_natural, + pt_color_red_only, + pt_color_green_only, + pt_color_blue_only, + }; - tie_setting(s.blob_color, ui.blob_color); + for (unsigned k = 0; k < std::size(color_types); k++) + ui.blob_color->setItemData(k, int(color_types[k])); - tie_setting(s.threshold_slider, ui.threshold_value_display, [this](const slider_value& val) { - return threshold_display_text(int(val)); - }); + tie_setting(s.blob_color, ui.blob_color); - // refresh threshold display on auto-threshold checkbox state change - tie_setting(s.auto_threshold, - this, - [this](bool) { s.threshold_slider.notify(); }); -} + tie_setting(s.threshold_slider, ui.threshold_value_display, [this](const slider_value& val) { + return threshold_display_text(int(val)); + }); -QString EasyTrackerDialog::threshold_display_text(int threshold_value) -{ - if (!s.auto_threshold) - return tr("Brightness %1/255").arg(threshold_value); - else - { - int w = s.cam_res_x, h = s.cam_res_y; + // refresh threshold display on auto-threshold checkbox state change + tie_setting(s.auto_threshold, + this, + [this](bool) { s.threshold_slider.notify(); }); + } - if (w * h <= 0) + QString Dialog::threshold_display_text(int threshold_value) + { + if (!s.auto_threshold) + return tr("Brightness %1/255").arg(threshold_value); + else { - w = 640; - h = 480; - } - - //SL: What are we suppose to do here? - double value = 0.0f; + int w = s.cam_res_x, h = s.cam_res_y; - return tr("LED radius %1 pixels").arg(value, 0, 'f', 2); - } -} + if (w * h <= 0) + { + w = 640; + h = 480; + } -void EasyTrackerDialog::startstop_trans_calib(bool start) -{ - QMutexLocker l(&calibrator_mutex); + //SL: What are we suppose to do here? + double value = 0.0f; - if (start) - { - qDebug() << "pt: starting translation calibration"; - calib_timer.start(); - trans_calib.reset(); - s.t_MH_x = 0; - s.t_MH_y = 0; - s.t_MH_z = 0; - - ui.sample_count_display->setText(QString()); + return tr("LED radius %1 pixels").arg(value, 0, 'f', 2); + } } - else + + void Dialog::startstop_trans_calib(bool start) { - calib_timer.stop(); - qDebug() << "pt: stopping translation calibration"; + QMutexLocker l(&calibrator_mutex); + + if (start) + { + qDebug() << "pt: starting translation calibration"; + calib_timer.start(); + trans_calib.reset(); + s.t_MH_x = 0; + s.t_MH_y = 0; + s.t_MH_z = 0; + + ui.sample_count_display->setText(QString()); + } + else { - auto [tmp, nsamples] = trans_calib.get_estimate(); - s.t_MH_x = int(tmp[0]); - s.t_MH_y = int(tmp[1]); - s.t_MH_z = int(tmp[2]); - - constexpr int min_yaw_samples = 15; - constexpr int min_pitch_samples = 15; - constexpr int min_samples = min_yaw_samples+min_pitch_samples; - - // Don't bother counting roll samples. Roll calibration is hard enough - // that it's a hidden unsupported feature anyway. - - QString sample_feedback; - if (nsamples[0] < min_yaw_samples) - sample_feedback = tr("%1 yaw samples. Yaw more to %2 samples for stable calibration.").arg(nsamples[0]).arg(min_yaw_samples); - else if (nsamples[1] < min_pitch_samples) - sample_feedback = tr("%1 pitch samples. Pitch more to %2 samples for stable calibration.").arg(nsamples[1]).arg(min_pitch_samples); - else + calib_timer.stop(); + qDebug() << "pt: stopping translation calibration"; { - const int nsamples_total = nsamples[0] + nsamples[1]; - sample_feedback = tr("%1 samples. Over %2, good!").arg(nsamples_total).arg(min_samples); + auto[tmp, nsamples] = trans_calib.get_estimate(); + s.t_MH_x = int(tmp[0]); + s.t_MH_y = int(tmp[1]); + s.t_MH_z = int(tmp[2]); + + constexpr int min_yaw_samples = 15; + constexpr int min_pitch_samples = 15; + constexpr int min_samples = min_yaw_samples + min_pitch_samples; + + // Don't bother counting roll samples. Roll calibration is hard enough + // that it's a hidden unsupported feature anyway. + + QString sample_feedback; + if (nsamples[0] < min_yaw_samples) + sample_feedback = tr("%1 yaw samples. Yaw more to %2 samples for stable calibration.").arg(nsamples[0]).arg(min_yaw_samples); + else if (nsamples[1] < min_pitch_samples) + sample_feedback = tr("%1 pitch samples. Pitch more to %2 samples for stable calibration.").arg(nsamples[1]).arg(min_pitch_samples); + else + { + const int nsamples_total = nsamples[0] + nsamples[1]; + sample_feedback = tr("%1 samples. Over %2, good!").arg(nsamples_total).arg(min_samples); + } + + ui.sample_count_display->setText(sample_feedback); } - - ui.sample_count_display->setText(sample_feedback); } + ui.tx_spin->setEnabled(!start); + ui.ty_spin->setEnabled(!start); + ui.tz_spin->setEnabled(!start); + + if (start) + ui.tcalib_button->setText(tr("Stop calibration")); + else + ui.tcalib_button->setText(tr("Start calibration")); } - ui.tx_spin->setEnabled(!start); - ui.ty_spin->setEnabled(!start); - ui.tz_spin->setEnabled(!start); - - if (start) - ui.tcalib_button->setText(tr("Stop calibration")); - else - ui.tcalib_button->setText(tr("Start calibration")); -} -void EasyTrackerDialog::poll_tracker_info_impl() -{ - //SL: sort this out - /* - pt_camera_info info; - if (tracker && tracker->get_cam_info(info)) + void Dialog::poll_tracker_info_impl() { - ui.caminfo_label->setText(tr("%1x%2 @ %3 FPS").arg(info.res_x).arg(info.res_y).arg(iround(info.fps))); + //SL: sort this out + /* + pt_camera_info info; + if (tracker && tracker->get_cam_info(info)) + { + ui.caminfo_label->setText(tr("%1x%2 @ %3 FPS").arg(info.res_x).arg(info.res_y).arg(iround(info.fps))); - // display point info - const int n_points = tracker->get_n_points(); - ui.pointinfo_label->setText((n_points == 3 ? tr("%1 OK!") : tr("%1 BAD!")).arg(n_points)); + // display point info + const int n_points = tracker->get_n_points(); + ui.pointinfo_label->setText((n_points == 3 ? tr("%1 OK!") : tr("%1 BAD!")).arg(n_points)); + } + else + */ + { + ui.caminfo_label->setText(tr("Tracker offline")); + ui.pointinfo_label->setText(QString()); + } } - else - */ + + void Dialog::set_camera_settings_available(const QString& /* camera_name */) { - ui.caminfo_label->setText(tr("Tracker offline")); - ui.pointinfo_label->setText(QString()); + ui.camera_settings->setEnabled(true); } -} - -void EasyTrackerDialog::set_camera_settings_available(const QString& /* camera_name */) -{ - ui.camera_settings->setEnabled(true); -} -void EasyTrackerDialog::show_camera_settings() -{ - if (tracker) + void Dialog::show_camera_settings() { - QMutexLocker l(&tracker->camera_mtx); - tracker->camera->show_dialog(); + if (tracker) + { + QMutexLocker l(&tracker->camera_mtx); + tracker->camera->show_dialog(); + } + else + (void)video::show_dialog(s.camera_name); } - else - (void)video::show_dialog(s.camera_name); -} -void EasyTrackerDialog::trans_calib_step() -{ - QMutexLocker l(&calibrator_mutex); - // TODO: Do we still need that function -} + void Dialog::trans_calib_step() + { + QMutexLocker l(&calibrator_mutex); + // TODO: Do we still need that function + } -void EasyTrackerDialog::save() -{ - s.b->save(); -} + void Dialog::save() + { + s.b->save(); + } -void EasyTrackerDialog::doOK() -{ - save(); - close(); -} + void Dialog::doOK() + { + save(); + close(); + } -void EasyTrackerDialog::doCancel() -{ - close(); -} + void Dialog::doCancel() + { + close(); + } -void EasyTrackerDialog::register_tracker(ITracker *t) -{ - tracker = static_cast<EasyTracker*>(t); - ui.tcalib_button->setEnabled(true); - poll_tracker_info(); - timer.start(); -} + void Dialog::register_tracker(ITracker *t) + { + tracker = static_cast<Tracker*>(t); + ui.tcalib_button->setEnabled(true); + poll_tracker_info(); + timer.start(); + } -void EasyTrackerDialog::unregister_tracker() -{ - tracker = nullptr; - ui.tcalib_button->setEnabled(false); - poll_tracker_info(); - timer.stop(); + void Dialog::unregister_tracker() + { + tracker = nullptr; + ui.tcalib_button->setEnabled(false); + poll_tracker_info(); + timer.stop(); + } } |