update: 扩大ip搜索范围,修改点云可视化逻辑,添加上位机与下位机曝光值同步

This commit is contained in:
2026-02-06 14:47:42 +08:00
parent 03c7cb58da
commit 04a5ec269f
12 changed files with 204 additions and 59 deletions

View File

@@ -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) {