2025-09-14 14:51:38 +08:00
|
|
|
|
#ifndef LAPWELDPRESENTER_H
|
|
|
|
|
|
#define LAPWELDPRESENTER_H
|
2025-07-23 01:35:14 +08:00
|
|
|
|
|
|
|
|
|
|
#include <condition_variable>
|
2025-08-05 22:52:10 +08:00
|
|
|
|
#include <thread>
|
2025-07-23 01:35:14 +08:00
|
|
|
|
|
|
|
|
|
|
#include "IVrConfig.h"
|
|
|
|
|
|
#include "IVrEyeDevice.h"
|
2025-09-14 14:51:38 +08:00
|
|
|
|
#include "IYLapWeldStatus.h"
|
2025-07-23 01:35:14 +08:00
|
|
|
|
#include "DetectPresenter.h"
|
2025-09-21 22:20:24 +08:00
|
|
|
|
#include "TCPServerProtocol.h"
|
2025-07-23 01:35:14 +08:00
|
|
|
|
#include "VZNL_Types.h"
|
2025-09-14 14:51:38 +08:00
|
|
|
|
#include "SX_lapWeldDetection_Export.h"
|
|
|
|
|
|
#include "SG_baseDataType.h"
|
2025-07-23 01:35:14 +08:00
|
|
|
|
#include "LaserDataLoader.h"
|
|
|
|
|
|
#include "PathManager.h"
|
2025-11-19 00:23:09 +08:00
|
|
|
|
#include "ConfigMonitor.h"
|
|
|
|
|
|
#include "CommonDialogCameraLevel.h" // 引入通用对话框的接口
|
2025-07-23 01:35:14 +08:00
|
|
|
|
#include <QImage>
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
#include <QColor>
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
2025-11-19 00:23:09 +08:00
|
|
|
|
class LapWeldPresenter : public IVrConfigChangeNotify, public IConfigCommandHandler,
|
|
|
|
|
|
public ICameraLevelCalculator, public ICameraLevelResultSaver
|
2025-07-23 01:35:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
public:
|
2025-09-14 14:51:38 +08:00
|
|
|
|
LapWeldPresenter();
|
|
|
|
|
|
~LapWeldPresenter();
|
2025-07-23 01:35:14 +08:00
|
|
|
|
|
|
|
|
|
|
// 初始化
|
|
|
|
|
|
int Init();
|
|
|
|
|
|
|
|
|
|
|
|
// 设置状态回调
|
2025-09-14 14:51:38 +08:00
|
|
|
|
void SetStatusCallback(IYLapWeldStatus* status);
|
2025-07-23 01:35:14 +08:00
|
|
|
|
|
|
|
|
|
|
// 开始检测
|
|
|
|
|
|
int StartDetection(int cameraIndex = -1, bool isAuto = true); // cameraIndex: -1表示所有相机,1/2...表示特定相机
|
|
|
|
|
|
|
|
|
|
|
|
// 停止检测
|
|
|
|
|
|
int StopDetection();
|
|
|
|
|
|
|
|
|
|
|
|
// 加载调试数据进行检测
|
|
|
|
|
|
int LoadDebugDataAndDetect(const std::string& filePath);
|
|
|
|
|
|
|
|
|
|
|
|
// 为所有相机设置状态回调
|
|
|
|
|
|
void SetCameraStatusCallback(VzNL_OnNotifyStatusCBEx fNotify, void* param);
|
|
|
|
|
|
|
2025-07-26 01:10:21 +08:00
|
|
|
|
// 设置默认相机索引
|
|
|
|
|
|
void SetDefaultCameraIndex(int cameraIndex);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前默认相机索引
|
|
|
|
|
|
int GetDefaultCameraIndex() const { return m_currentCameraIndex; }
|
|
|
|
|
|
|
2025-07-23 01:35:14 +08:00
|
|
|
|
// 获取配置对象
|
|
|
|
|
|
IVrConfig* GetConfig() { return m_vrConfig; }
|
2025-07-26 01:10:21 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取相机列表
|
|
|
|
|
|
std::vector<std::pair<std::string, IVrEyeDevice*>> GetCameraList() const { return m_vrEyeDeviceList; } // 返回相机列表,包括IP地址和设备指针
|
2025-07-23 01:35:14 +08:00
|
|
|
|
|
|
|
|
|
|
// 手眼标定矩阵管理
|
|
|
|
|
|
const CalibMatrix GetClibMatrix(int index) const;
|
|
|
|
|
|
|
|
|
|
|
|
// 实现IVrConfigChangeNotify接口
|
|
|
|
|
|
virtual void OnConfigChanged(const ConfigResult& configResult) override;
|
2025-11-19 00:23:09 +08:00
|
|
|
|
|
|
|
|
|
|
// ============ 实现 IConfigCommandHandler 接口 ============
|
|
|
|
|
|
bool OnCameraExposeCommand(const CameraConfigParam& param) override;
|
|
|
|
|
|
bool OnCameraGainCommand(const CameraConfigParam& param) override;
|
|
|
|
|
|
bool OnCameraFrameRateCommand(const CameraConfigParam& param) override;
|
|
|
|
|
|
bool OnCameraSwingCommand(const SwingConfigParam& param) override;
|
|
|
|
|
|
bool OnAlgoParamCommand(const AlgoConfigParam& param) override;
|
|
|
|
|
|
bool OnCalibParamCommand(const CalibConfigParam& param) override;
|
|
|
|
|
|
bool OnFullConfigCommand(const FullConfigParam& param) override;
|
|
|
|
|
|
|
2025-08-05 22:52:10 +08:00
|
|
|
|
// 获取检测数据缓存的副本(用于保存数据)
|
|
|
|
|
|
int GetDetectIndex() const { return m_currentCameraIndex; }
|
|
|
|
|
|
|
|
|
|
|
|
int GetDetectionDataCacheSize() const { return m_detectionDataCache.size(); }
|
2025-11-19 00:23:09 +08:00
|
|
|
|
|
2025-08-05 22:52:10 +08:00
|
|
|
|
// 保存检测数据到文件(默认实现)
|
|
|
|
|
|
int SaveDetectionDataToFile(const std::string& filePath);
|
2025-11-19 00:23:09 +08:00
|
|
|
|
|
|
|
|
|
|
// ============ 实现 ICameraLevelCalculator 接口 ============
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 计算平面调平参数
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool CalculatePlaneCalibration(
|
|
|
|
|
|
const std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& scanData,
|
|
|
|
|
|
double planeCalib[9],
|
|
|
|
|
|
double& planeHeight,
|
|
|
|
|
|
double invRMatrix[9]) override;
|
|
|
|
|
|
|
|
|
|
|
|
// ============ 实现 ICameraLevelResultSaver 接口 ============
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 保存相机调平结果到配置文件
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool SaveLevelingResults(double planeCalib[9], double planeHeight, double invRMatrix[9],
|
|
|
|
|
|
int cameraIndex, const QString& cameraName) override;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 从配置文件加载相机调平结果
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool LoadLevelingResults(int cameraIndex, const QString& cameraName,
|
|
|
|
|
|
double planeCalib[9], double& planeHeight, double invRMatrix[9]) override;
|
|
|
|
|
|
|
2025-08-05 22:52:10 +08:00
|
|
|
|
static void _StaticCameraNotify(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
|
|
|
|
|
|
static void _StaticDetectionCallback(EVzResultDataType eDataType, SVzLaserLineData* pLaserLinePoint, void* pParam);
|
2025-07-23 01:35:14 +08:00
|
|
|
|
private:
|
2025-08-06 01:09:10 +08:00
|
|
|
|
|
|
|
|
|
|
// 相机协议相关方法
|
|
|
|
|
|
int InitCamera(std::vector<DeviceInfo>& cameraList);
|
|
|
|
|
|
|
2025-07-23 01:35:14 +08:00
|
|
|
|
// 算法初始化接口
|
|
|
|
|
|
int InitAlgorithmParams();
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
|
|
|
|
|
// TCP服务器相关方法
|
|
|
|
|
|
int InitTCPServer();
|
|
|
|
|
|
|
|
|
|
|
|
// TCP回调函数
|
|
|
|
|
|
void OnTCPConnectionChanged(bool connected);
|
|
|
|
|
|
bool OnTCPDetectionTrigger(bool startWork, int cameraIndex, qint64 timestamp);
|
|
|
|
|
|
|
|
|
|
|
|
// TCP连接状态检查和更新
|
2025-07-23 01:35:14 +08:00
|
|
|
|
void CheckAndUpdateWorkStatus();
|
|
|
|
|
|
|
2025-08-06 01:09:10 +08:00
|
|
|
|
// 打开相机
|
|
|
|
|
|
int _OpenDevice(int cameraIndex, const char* cameraName, const char* cameraIp, ProjectType& projectType);
|
|
|
|
|
|
|
|
|
|
|
|
bool _SinglePreDetection(int cameraIndex);
|
|
|
|
|
|
int _SingleDetection(int cameraIndex, bool isStart);
|
2025-08-05 22:52:10 +08:00
|
|
|
|
|
|
|
|
|
|
// 静态回调函数,供外部使用
|
2025-07-23 01:35:14 +08:00
|
|
|
|
void _CameraNotify(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
|
2025-08-05 22:52:10 +08:00
|
|
|
|
|
2025-07-23 01:35:14 +08:00
|
|
|
|
// 检测数据回调函数
|
2025-08-05 22:52:10 +08:00
|
|
|
|
void _DetectionCallback(EVzResultDataType eDataType, SVzLaserLineData* pLaserLinePoint, void* pParam);
|
2025-07-23 01:35:14 +08:00
|
|
|
|
|
|
|
|
|
|
// 算法检测线程
|
|
|
|
|
|
void _AlgoDetectThread();
|
|
|
|
|
|
|
|
|
|
|
|
int _DetectTask();
|
|
|
|
|
|
|
|
|
|
|
|
// 释放缓存的检测数据
|
|
|
|
|
|
void _ClearDetectionDataCache();
|
|
|
|
|
|
|
2025-09-21 22:20:24 +08:00
|
|
|
|
// 发送检测结果给TCP客户端
|
|
|
|
|
|
void _SendDetectionResultToTCP(const DetectionResult& detectionResult, int cameraIndex);
|
2025-07-23 01:35:14 +08:00
|
|
|
|
|
|
|
|
|
|
// 根据相机索引获取调平参数
|
|
|
|
|
|
SSG_planeCalibPara _GetCameraCalibParam(int cameraIndex);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
IVrConfig* m_vrConfig = nullptr;
|
2025-07-26 01:10:21 +08:00
|
|
|
|
std::vector<std::pair<std::string, IVrEyeDevice*>> m_vrEyeDeviceList;
|
2025-09-14 14:51:38 +08:00
|
|
|
|
IYLapWeldStatus* m_pStatus = nullptr;
|
2025-07-23 01:35:14 +08:00
|
|
|
|
DetectPresenter* m_pDetectPresenter = nullptr;
|
|
|
|
|
|
|
2025-09-21 22:20:24 +08:00
|
|
|
|
// TCP服务器相关
|
|
|
|
|
|
TCPServerProtocol* m_pTCPServer = nullptr;
|
|
|
|
|
|
|
2025-07-23 01:35:14 +08:00
|
|
|
|
// 连接状态标志
|
|
|
|
|
|
bool m_bCameraConnected = false; // 相机连接状态
|
2025-09-21 22:20:24 +08:00
|
|
|
|
bool m_bTCPConnected = false; // TCP连接状态
|
2025-07-23 01:35:14 +08:00
|
|
|
|
WorkStatus m_currentWorkStatus = WorkStatus::Error; // 当前工作状态
|
|
|
|
|
|
int m_currentCameraIndex = 0; // 当前使用的相机编号
|
|
|
|
|
|
|
2025-09-18 23:49:32 +08:00
|
|
|
|
std::atomic<bool> m_bAlgoDetectThreadRunning{false};
|
2025-07-23 01:35:14 +08:00
|
|
|
|
std::mutex m_algoDetectMutex;
|
|
|
|
|
|
std::condition_variable m_algoDetectCondition;
|
2025-08-05 22:52:10 +08:00
|
|
|
|
std::thread m_algoDetectThread; // 算法检测线程
|
2025-07-23 01:35:14 +08:00
|
|
|
|
|
2025-08-05 22:52:10 +08:00
|
|
|
|
// 检测数据缓存 - 统一存储两种类型的数据
|
|
|
|
|
|
std::mutex m_detectionDataMutex;
|
|
|
|
|
|
std::vector<std::pair<EVzResultDataType, SVzLaserLineData>> m_detectionDataCache; // 统一存储数据
|
2025-07-23 01:35:14 +08:00
|
|
|
|
|
|
|
|
|
|
// 算法参数成员变量
|
2025-09-16 00:02:42 +08:00
|
|
|
|
VrAlgorithmParams m_algorithmParams; // 统一的算法参数
|
2025-07-23 01:35:14 +08:00
|
|
|
|
std::vector<CalibMatrix> m_clibMatrixList; // 手眼标定矩阵列表
|
|
|
|
|
|
VrDebugParam m_debugParam; // 调试参数
|
|
|
|
|
|
|
2025-09-14 14:51:38 +08:00
|
|
|
|
ProjectType m_projectType;
|
2025-11-19 00:23:09 +08:00
|
|
|
|
|
2025-07-23 01:35:14 +08:00
|
|
|
|
// 调试数据加载器
|
|
|
|
|
|
LaserDataLoader m_dataLoader;
|
2025-11-19 00:23:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 配置监控器
|
|
|
|
|
|
ConfigMonitor m_configMonitor;
|
|
|
|
|
|
|
|
|
|
|
|
// 配置结果
|
|
|
|
|
|
ConfigResult m_configResult;
|
2025-07-23 01:35:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-14 14:51:38 +08:00
|
|
|
|
#endif // LAPWELDPRESENTER_H
|