update: 扩大ip搜索范围,修改点云可视化逻辑,添加上位机与下位机曝光值同步
This commit is contained in:
@@ -377,11 +377,11 @@ void MainWindow::setupUI()
|
||||
QHBoxLayout *exposureLayout = new QHBoxLayout();
|
||||
m_exposureSlider = new QSlider(Qt::Horizontal, exposureGroup);
|
||||
m_exposureSlider->setRange(100, 100000);
|
||||
m_exposureSlider->setValue(1000);
|
||||
m_exposureSlider->setValue(5980);
|
||||
|
||||
m_exposureSpinBox = new QSpinBox(exposureGroup);
|
||||
m_exposureSpinBox->setRange(100, 100000);
|
||||
m_exposureSpinBox->setValue(1000);
|
||||
m_exposureSpinBox->setValue(5980);
|
||||
m_exposureSpinBox->setMinimumWidth(80);
|
||||
|
||||
exposureLayout->addWidget(m_exposureSlider, 3);
|
||||
@@ -639,6 +639,18 @@ void MainWindow::setupConnections()
|
||||
connect(m_networkManager.get(), &NetworkManager::disconnected, this, &MainWindow::onNetworkDisconnected);
|
||||
connect(m_networkManager.get(), &NetworkManager::dataReceived, this, &MainWindow::onDataReceived);
|
||||
|
||||
// 接收下位机曝光值并同步到UI(连接时触发)
|
||||
connect(m_networkManager.get(), &NetworkManager::exposureReceived, this, [this](int exposureUs) {
|
||||
qDebug() << "[MainWindow] 收到曝光值同步:" << exposureUs << "us";
|
||||
m_exposureSlider->blockSignals(true);
|
||||
m_exposureSpinBox->blockSignals(true);
|
||||
m_exposureSlider->setValue(exposureUs);
|
||||
m_exposureSpinBox->setValue(exposureUs);
|
||||
m_exposureSlider->blockSignals(false);
|
||||
m_exposureSpinBox->blockSignals(false);
|
||||
addLog(QString("同步相机曝光值: %1 μs").arg(exposureUs), "INFO");
|
||||
});
|
||||
|
||||
// GVSP数据信号连接(从NetworkManager)
|
||||
connect(m_networkManager.get(), &NetworkManager::imageReceived, this, &MainWindow::onImageReceived);
|
||||
connect(m_networkManager.get(), &NetworkManager::leftImageReceived, this, &MainWindow::onLeftImageReceived);
|
||||
@@ -658,6 +670,17 @@ void MainWindow::setupConnections()
|
||||
connect(m_deviceScanner.get(), &DeviceScanner::scanProgress, this, &MainWindow::onScanProgress);
|
||||
connect(m_deviceScanner.get(), &DeviceScanner::scanFinished, this, &MainWindow::onScanFinished);
|
||||
|
||||
// 接收下位机曝光值并同步到UI
|
||||
connect(m_deviceScanner.get(), &DeviceScanner::exposureReceived, this, [this](int exposureUs) {
|
||||
m_exposureSlider->blockSignals(true);
|
||||
m_exposureSpinBox->blockSignals(true);
|
||||
m_exposureSlider->setValue(exposureUs);
|
||||
m_exposureSpinBox->setValue(exposureUs);
|
||||
m_exposureSlider->blockSignals(false);
|
||||
m_exposureSpinBox->blockSignals(false);
|
||||
addLog(QString("同步相机曝光值: %1 μs").arg(exposureUs), "INFO");
|
||||
});
|
||||
|
||||
// 设备列表选择连接
|
||||
connect(m_deviceList, &QListWidget::itemClicked, this, &MainWindow::onDeviceSelected);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "gui/PointCloudGLWidget.h"
|
||||
#include <QDebug>
|
||||
#include <QPushButton>
|
||||
#include <cmath>
|
||||
#include <cfloat>
|
||||
|
||||
@@ -24,6 +25,17 @@ PointCloudGLWidget::PointCloudGLWidget(QWidget *parent)
|
||||
, m_colorMode(0) // 默认黑白模式
|
||||
{
|
||||
setMinimumSize(400, 400);
|
||||
|
||||
// 添加重置视角按钮
|
||||
QPushButton *resetBtn = new QPushButton("重置", this);
|
||||
resetBtn->setFixedSize(60, 30);
|
||||
resetBtn->move(10, 10);
|
||||
resetBtn->setStyleSheet(
|
||||
"QPushButton { background-color: rgba(50, 50, 50, 180); color: white; border: 1px solid #555; border-radius: 4px; }"
|
||||
"QPushButton:hover { background-color: rgba(70, 70, 70, 200); }"
|
||||
"QPushButton:pressed { background-color: rgba(40, 40, 40, 220); }"
|
||||
);
|
||||
connect(resetBtn, &QPushButton::clicked, this, &PointCloudGLWidget::resetView);
|
||||
}
|
||||
|
||||
PointCloudGLWidget::~PointCloudGLWidget()
|
||||
@@ -125,9 +137,12 @@ void PointCloudGLWidget::resizeGL(int w, int h)
|
||||
{
|
||||
m_projection.setToIdentity();
|
||||
|
||||
// 使用透视投影,从相机原点看向Z轴正方向
|
||||
// 使用正交投影,避免透视变形
|
||||
float aspect = float(w) / float(h);
|
||||
m_projection.perspective(m_fov, aspect, 1.0f, 50000.0f);
|
||||
float orthoSize = m_viewDistance * 0.5f / m_zoom;
|
||||
m_projection.ortho(-orthoSize * aspect, orthoSize * aspect,
|
||||
-orthoSize, orthoSize,
|
||||
-50000.0f, 50000.0f);
|
||||
}
|
||||
|
||||
void PointCloudGLWidget::paintGL()
|
||||
@@ -138,10 +153,13 @@ void PointCloudGLWidget::paintGL()
|
||||
return;
|
||||
}
|
||||
|
||||
// 重新计算透视投影矩阵
|
||||
// 重新计算正交投影矩阵
|
||||
m_projection.setToIdentity();
|
||||
float aspect = float(width()) / float(height());
|
||||
m_projection.perspective(m_fov / m_zoom, aspect, 1.0f, 50000.0f);
|
||||
float orthoSize = m_viewDistance * 0.5f / m_zoom;
|
||||
m_projection.ortho(-orthoSize * aspect, orthoSize * aspect,
|
||||
-orthoSize, orthoSize,
|
||||
-50000.0f, 50000.0f);
|
||||
|
||||
// 设置view矩阵 - 轨道相机模式(围绕点云中心旋转)
|
||||
m_view.setToIdentity();
|
||||
@@ -238,9 +256,9 @@ void PointCloudGLWidget::updatePointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr cl
|
||||
float minZ = FLT_MAX, maxZ = -FLT_MAX;
|
||||
|
||||
for (const auto& point : cloud->points) {
|
||||
if (point.z > 0.01f) {
|
||||
if (point.z > 0.01f) { // 过滤掉无效的零点
|
||||
m_vertices.push_back(point.x);
|
||||
m_vertices.push_back(point.y);
|
||||
m_vertices.push_back(-point.y);
|
||||
m_vertices.push_back(point.z);
|
||||
|
||||
// 更新包围盒
|
||||
@@ -297,6 +315,19 @@ void PointCloudGLWidget::updatePointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr cl
|
||||
update();
|
||||
}
|
||||
|
||||
void PointCloudGLWidget::resetView()
|
||||
{
|
||||
// 重置所有视角参数到初始状态
|
||||
m_rotationX = 0.0f;
|
||||
m_rotationY = 0.0f;
|
||||
m_panOffset = QVector3D(0.0f, 0.0f, 0.0f);
|
||||
m_zoom = 1.0f;
|
||||
m_firstFrame = true; // 标记为首帧,下次更新时会重新计算视角
|
||||
|
||||
update();
|
||||
qDebug() << "[PointCloudGLWidget] 视角已重置";
|
||||
}
|
||||
|
||||
void PointCloudGLWidget::updateBuffers()
|
||||
{
|
||||
if (m_vertices.empty() || !m_vao || !m_vertexBuffer) {
|
||||
|
||||
Reference in New Issue
Block a user