#include "dialogalgoarg.h" #include "ui_dialogalgoarg.h" #include "BagThreadPositionPresenter.h" #include "StyledMessageBox.h" DialogAlgoArg::DialogAlgoArg(QWidget *parent) : QDialog(parent) , ui(new Ui::DialogAlgoArg) , m_presenter(nullptr) { ui->setupUi(this); setWindowTitle("算法参数设置"); } DialogAlgoArg::~DialogAlgoArg() { delete ui; } void DialogAlgoArg::SetPresenter(BagThreadPositionPresenter* presenter) { m_presenter = presenter; loadParams(); } void DialogAlgoArg::loadParams() { if (!m_presenter) { return; } auto params = m_presenter->GetAlgoParams(); // 拆线参数 ui->chkHorizonScan->setChecked(params.threadParam.isHorizonScan); ui->chkScanFromThreadHead->setChecked(params.threadParam.scanFromThreadHead); ui->spinStitchWidth->setValue(params.threadParam.stitchWidth); ui->spinOperateDist->setValue(params.threadParam.operateDist); ui->spinMarkDiameter->setValue(params.threadParam.mark_diameter); ui->spinMarkHeight->setValue(params.threadParam.mark_height); ui->spinMarkDistance->setValue(params.threadParam.mark_distance); // 角点检测参数 (VrCornerParam) ui->spinCornerTh->setValue(params.cornerParam.cornerTh); ui->spinScale->setValue(params.cornerParam.scale); ui->spinMinEndingGap->setValue(params.cornerParam.minEndingGap); ui->spinMinEndingGapZ->setValue(params.cornerParam.minEndingGap_z); ui->spinJumpCornerTh1->setValue(params.cornerParam.jumpCornerTh_1); ui->spinJumpCornerTh2->setValue(params.cornerParam.jumpCornerTh_2); // 滤波参数 (VrOutlierFilterParam) ui->spinContinuityTh->setValue(params.filterParam.continuityTh); ui->spinOutlierTh->setValue(params.filterParam.outlierTh); // 树生长参数 (VrTreeGrowParam) ui->spinMaxLineSkipNum->setValue(params.growParam.maxLineSkipNum); ui->spinYDeviationMax->setValue(params.growParam.yDeviation_max); ui->spinMaxSkipDistance->setValue(params.growParam.maxSkipDistance); ui->spinZDeviationMax->setValue(params.growParam.zDeviation_max); ui->spinMinLTypeTreeLen->setValue(params.growParam.minLTypeTreeLen); ui->spinMinVTypeTreeLen->setValue(params.growParam.minVTypeTreeLen); } void DialogAlgoArg::saveParams() { if (!m_presenter) { return; } auto params = m_presenter->GetAlgoParams(); // 拆线参数 params.threadParam.isHorizonScan = ui->chkHorizonScan->isChecked(); params.threadParam.scanFromThreadHead = ui->chkScanFromThreadHead->isChecked(); params.threadParam.stitchWidth = ui->spinStitchWidth->value(); params.threadParam.operateDist = ui->spinOperateDist->value(); params.threadParam.mark_diameter = ui->spinMarkDiameter->value(); params.threadParam.mark_height = ui->spinMarkHeight->value(); params.threadParam.mark_distance = ui->spinMarkDistance->value(); // 角点检测参数 (VrCornerParam) params.cornerParam.cornerTh = ui->spinCornerTh->value(); params.cornerParam.scale = ui->spinScale->value(); params.cornerParam.minEndingGap = ui->spinMinEndingGap->value(); params.cornerParam.minEndingGap_z = ui->spinMinEndingGapZ->value(); params.cornerParam.jumpCornerTh_1 = ui->spinJumpCornerTh1->value(); params.cornerParam.jumpCornerTh_2 = ui->spinJumpCornerTh2->value(); // 滤波参数 (VrOutlierFilterParam) params.filterParam.continuityTh = ui->spinContinuityTh->value(); params.filterParam.outlierTh = ui->spinOutlierTh->value(); // 树生长参数 (VrTreeGrowParam) params.growParam.maxLineSkipNum = ui->spinMaxLineSkipNum->value(); params.growParam.yDeviation_max = ui->spinYDeviationMax->value(); params.growParam.maxSkipDistance = ui->spinMaxSkipDistance->value(); params.growParam.zDeviation_max = ui->spinZDeviationMax->value(); params.growParam.minLTypeTreeLen = ui->spinMinLTypeTreeLen->value(); params.growParam.minVTypeTreeLen = ui->spinMinVTypeTreeLen->value(); m_presenter->SetAlgoParams(params); } void DialogAlgoArg::resetParams() { // 重置为默认值(根据测试代码的默认值) ui->chkHorizonScan->setChecked(false); ui->chkScanFromThreadHead->setChecked(true); ui->spinStitchWidth->setValue(1.0); ui->spinOperateDist->setValue(3.0); ui->spinMarkDiameter->setValue(6.0); ui->spinMarkHeight->setValue(3.5); ui->spinMarkDistance->setValue(53.0); // 角点检测参数默认值 ui->spinCornerTh->setValue(90.0); ui->spinScale->setValue(4.0); ui->spinMinEndingGap->setValue(1.0); ui->spinMinEndingGapZ->setValue(3.5); ui->spinJumpCornerTh1->setValue(15.0); ui->spinJumpCornerTh2->setValue(60.0); // 滤波参数默认值 ui->spinContinuityTh->setValue(3.0); ui->spinOutlierTh->setValue(2.0); // 树生长参数默认值 ui->spinMaxLineSkipNum->setValue(-1); ui->spinYDeviationMax->setValue(1.0); ui->spinMaxSkipDistance->setValue(5.0); ui->spinZDeviationMax->setValue(1.0); ui->spinMinLTypeTreeLen->setValue(10.0); ui->spinMinVTypeTreeLen->setValue(10.0); } void DialogAlgoArg::on_btnOK_clicked() { saveParams(); accept(); } void DialogAlgoArg::on_btnCancel_clicked() { reject(); } void DialogAlgoArg::on_btnApply_clicked() { saveParams(); StyledMessageBox::information(this, "提示", "参数已应用并保存到配置文件"); } void DialogAlgoArg::on_btnReset_clicked() { auto ret = StyledMessageBox::question(this, "确认重置", "确定要重置为默认参数吗?\n重置后需要点击\"应用\"或\"确定\"才会保存。"); if (ret == QMessageBox::Yes) { resetParams(); } }