184 lines
5.4 KiB
C++
184 lines
5.4 KiB
C++
#ifndef RODANDBARPOSITIONPRESENTER_H
|
||
#define RODANDBARPOSITIONPRESENTER_H
|
||
|
||
#include <condition_variable>
|
||
#include <thread>
|
||
#include <map>
|
||
#include <mutex>
|
||
#include <memory>
|
||
|
||
#include "BasePresenter.h"
|
||
#include "IVrEyeDevice.h"
|
||
#include "ConfigManager.h"
|
||
#include "IYRodAndBarPositionStatus.h"
|
||
#include "SG_baseDataType.h"
|
||
#include "VrConvert.h"
|
||
#include "LaserDataLoader.h"
|
||
#include "CommonDialogCameraLevel.h" // 引入通用对话框的接口
|
||
#include <QImage>
|
||
#include <QPainter>
|
||
#include <QColor>
|
||
#include <QObject>
|
||
#include <QTimer>
|
||
#include <memory>
|
||
#include <cstring>
|
||
|
||
// Forward declarations
|
||
class DetectPresenter;
|
||
|
||
class RodAndBarPositionPresenter : public BasePresenter, public IVrConfigChangeNotify,
|
||
public ICameraLevelCalculator, public ICameraLevelResultSaver
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
explicit RodAndBarPositionPresenter(QObject *parent = nullptr);
|
||
~RodAndBarPositionPresenter();
|
||
|
||
// 初始化
|
||
int InitApp() override;
|
||
|
||
// 反初始化
|
||
void DeinitApp();
|
||
|
||
// 触发检测
|
||
bool TriggerDetection(int cameraIndex = -1);
|
||
|
||
// 加载文件并检测
|
||
int LoadAndDetect(const QString& fileName);
|
||
|
||
// 重连相机
|
||
void ReconnectCamera();
|
||
|
||
// 获取/设置算法参数
|
||
struct AlgoParams {
|
||
VrRodParam rodParam;
|
||
VrCornerParam cornerParam;
|
||
VrOutlierFilterParam filterParam;
|
||
VrTreeGrowParam growParam;
|
||
};
|
||
AlgoParams GetAlgoParams() const;
|
||
void SetAlgoParams(const AlgoParams& params);
|
||
|
||
// 获取算法版本
|
||
QString GetAlgoVersion() const;
|
||
|
||
// 获取配置管理器
|
||
ConfigManager* GetConfigManager() { return m_pConfigManager; }
|
||
|
||
// 手眼标定矩阵管理
|
||
CalibMatrix GetClibMatrix(int index) const;
|
||
|
||
// 实现IVrConfigChangeNotify接口
|
||
virtual void OnConfigChanged(const ConfigResult& configResult) override;
|
||
|
||
// ============ 实现 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;
|
||
|
||
protected:
|
||
// ============ 实现 BasePresenter 纯虚函数 ============
|
||
|
||
/**
|
||
* @brief 初始化算法参数(实现纯虚函数)
|
||
*/
|
||
int InitAlgoParams() override;
|
||
|
||
/**
|
||
* @brief 执行算法检测(实现纯虚函数)
|
||
* @param detectionDataCache 检测数据缓存的引用
|
||
*/
|
||
int ProcessAlgoDetection(std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& detectionDataCache) override;
|
||
|
||
/**
|
||
* @brief 获取检测数据类型(实现纯虚函数)
|
||
* 棒材定位项目只使用Position点云数据
|
||
*/
|
||
EVzResultDataType GetDetectionDataType() override {
|
||
return keResultDataType_Position;
|
||
}
|
||
|
||
/**
|
||
* @brief 相机状态变化通知(实现纯虚函数)
|
||
*/
|
||
void OnCameraStatusChanged(int cameraIndex, bool isConnected) override;
|
||
|
||
/**
|
||
* @brief 工作状态变化通知(重写虚函数)
|
||
*/
|
||
void OnWorkStatusChanged(WorkStatus status) override;
|
||
|
||
/**
|
||
* @brief 相机数量变化通知(重写虚函数)
|
||
*/
|
||
void OnCameraCountChanged(int count) override;
|
||
|
||
/**
|
||
* @brief 状态文字更新通知(重写虚函数)
|
||
*/
|
||
void OnStatusUpdate(const std::string& statusMessage) override;
|
||
|
||
// ============ 重写 BasePresenter ModbusTCP 虚函数 ============
|
||
|
||
/**
|
||
* @brief Modbus写寄存器回调(重写虚函数)
|
||
*/
|
||
void OnModbusWriteCallback(uint16_t startAddress, const uint16_t* data, uint16_t count) override;
|
||
|
||
/**
|
||
* @brief ModbusTCP服务器状态变化通知(重写虚函数)
|
||
*/
|
||
void OnModbusServerStatusChanged(bool isConnected) override;
|
||
|
||
private:
|
||
// 连接状态检查和更新
|
||
void CheckAndUpdateWorkStatus();
|
||
|
||
// 根据相机索引获取调平参数
|
||
SSG_planeCalibPara _GetCameraCalibParam(int cameraIndex);
|
||
|
||
// 发送检测结果到Modbus寄存器(index指定发送第几个棒材结果)
|
||
void _SendDetectionResultToModbus(const DetectionResult& result, int cameraIndex, int index = 0);
|
||
|
||
// 发送缓存中的下一个棒材结果
|
||
void _SendNextCachedResult();
|
||
|
||
private:
|
||
// RodAndBarPositionPresenter 特有的成员变量
|
||
ConfigManager* m_pConfigManager = nullptr;
|
||
|
||
// 检测处理器
|
||
DetectPresenter* m_pDetectPresenter = nullptr;
|
||
|
||
// 手眼标定矩阵列表(从独立文件加载,暂时保留在Presenter中)
|
||
std::vector<CalibMatrix> m_clibMatrixList;
|
||
|
||
// 多棒材结果缓存(支持写10逐个读取)
|
||
DetectionResult m_lastDetectionResult;
|
||
int m_resultIndex = 0;
|
||
std::mutex m_resultCacheMutex;
|
||
};
|
||
|
||
#endif // RODANDBARPOSITIONPRESENTER_H
|