feat(sampling): add adaptive sampling toggle + interactive sampling point viewer

This commit is contained in:
DXC
2026-06-08 15:39:43 +08:00
parent e57fdb4f75
commit d22414bf7d
4 changed files with 294 additions and 5 deletions

View File

@ -12,6 +12,7 @@ from PyQt5.QtWidgets import (
)
from src.gui.components.custom_widgets import FileSelectWidget
from src.gui.dialogs import SamplingViewerDialog
from src.gui.styles import ModernStylesheet
@ -58,6 +59,10 @@ class Step7Panel(QWidget):
self.chunk_size.setValue(1000)
params_layout.addRow("处理块大小:", self.chunk_size)
self.use_adaptive_sampling = QCheckBox("启用自适应采样")
self.use_adaptive_sampling.setChecked(True)
params_layout.addRow("采样模式:", self.use_adaptive_sampling)
params_group.setLayout(params_layout)
layout.addWidget(params_group)
@ -80,15 +85,25 @@ class Step7Panel(QWidget):
self.run_btn.clicked.connect(self.run_step)
layout.addWidget(self.run_btn)
# 交互式预览按钮
self.preview_btn = QPushButton("📊 交互式预览采样点与光谱")
self.preview_btn.setEnabled(False)
self.preview_btn.clicked.connect(self._open_sampling_viewer)
layout.addWidget(self.preview_btn)
layout.addStretch()
self.setLayout(layout)
# 监听输出路径变化,实时更新预览按钮状态
self.output_file.line_edit.textChanged.connect(self._on_output_changed)
def get_config(self):
"""获取配置"""
config = {
'interval': self.interval.value(),
'sample_radius': self.sample_radius.value(),
'chunk_size': self.chunk_size.value(),
'use_adaptive_sampling': self.use_adaptive_sampling.isChecked(),
}
deglint_img_path = self.deglint_img_file.get_path()
if deglint_img_path:
@ -96,7 +111,6 @@ class Step7Panel(QWidget):
water_mask_path = self.water_mask_file.get_path()
if water_mask_path:
config['water_mask_path'] = water_mask_path
# 注意step7_generate_sampling_points 不接受 output_path 参数,输出路径由 pipeline 内部自动生成
return config
def set_config(self, config):
@ -107,6 +121,8 @@ class Step7Panel(QWidget):
self.sample_radius.setValue(config['sample_radius'])
if 'chunk_size' in config:
self.chunk_size.setValue(config['chunk_size'])
if 'use_adaptive_sampling' in config:
self.use_adaptive_sampling.setChecked(config['use_adaptive_sampling'])
if 'deglint_img_path' in config:
self.deglint_img_file.set_path(config['deglint_img_path'])
if 'water_mask_path' in config:
@ -195,6 +211,9 @@ class Step7Panel(QWidget):
os.makedirs(os.path.dirname(output_path), exist_ok=True)
self.output_file.set_path(output_path.replace('\\', '/'))
# 4. 同步更新预览按钮状态(路径可能已自动填充)
self._check_csv_exists()
def run_step(self):
"""独立运行步骤7"""
deglint_img_path = self.deglint_img_file.get_path()
@ -206,3 +225,28 @@ class Step7Panel(QWidget):
if hasattr(main_window, 'run_single_step'):
config = {'step7': self.get_config()}
main_window.run_single_step('step7', config)
def _check_csv_exists(self):
"""检查 output csv 是否存在,驱动预览按钮启停"""
csv_path = self.output_file.get_path()
enabled = bool(csv_path and os.path.isabs(csv_path) and os.path.exists(csv_path))
self.preview_btn.setEnabled(enabled)
return enabled
def _on_output_changed(self, _text=None):
"""输出路径输入框内容变化时调用_text 为 line_edit.textChanged 信号参数)"""
self._check_csv_exists()
def _open_sampling_viewer(self):
"""打开交互式采样点查看器弹窗"""
csv_path = self.output_file.get_path()
if not csv_path or not os.path.exists(csv_path):
QMessageBox.warning(
self, "文件不存在",
f"采样点 CSV 文件不存在:{csv_path}\n请先运行步骤7生成数据。"
)
return
dialog = SamplingViewerDialog(csv_path, self)
dialog.exec_()
# 弹窗关闭后再次检查状态(可能文件被覆盖等)
self._check_csv_exists()