135 lines
4.5 KiB
C++
135 lines
4.5 KiB
C++
#ifndef BELTTEARINGPRESENTER_H
|
|
#define BELTTEARINGPRESENTER_H
|
|
|
|
#include <QObject>
|
|
#include <QTimer>
|
|
#include <QMap>
|
|
#include <deque>
|
|
#include <mutex>
|
|
#include <opencv2/opencv.hpp>
|
|
#include "IVrEyeDevice.h"
|
|
#include "../../SDK/beltTearing/Inc/beltTearingDetection_Export.h"
|
|
#include "IVrBeltTearingConfig.h"
|
|
#include "VZNL_Common.h"
|
|
#include "VZNL_Types.h"
|
|
#include "VrLog.h"
|
|
#include "IYTCPServer.h"
|
|
#include "ImageProcessingWorker.h"
|
|
|
|
// 假设ByteDataType枚举定义
|
|
enum class ByteDataType : quint8 {
|
|
Text = 1,
|
|
Image = 2
|
|
};
|
|
|
|
class BeltTearingPresenter : public QObject, public IVrBeltTearingConfigChangeNotify
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit BeltTearingPresenter(QObject *parent = nullptr);
|
|
~BeltTearingPresenter();
|
|
|
|
// 配置相关方法
|
|
bool loadConfiguration(const QString& configFilePath);
|
|
void applyAlgorithmParameters(const BeltTearingAlgorithmParams& params);
|
|
|
|
// 初始化TCP服务器
|
|
bool startServer(quint16 port = 0); // port = 0 表示使用配置文件中的端口
|
|
void stopServer();
|
|
|
|
// 相机相关方法
|
|
bool initializeCamera();
|
|
void startCamera();
|
|
void stopCamera();
|
|
|
|
// 获取配置信息
|
|
quint16 getServerPort() const { return m_configResult.serverPort; }
|
|
const BeltTearingConfigResult& getConfig() const { return m_configResult; }
|
|
|
|
// 获取版本信息
|
|
static QString getVersionString();
|
|
static QString getProductName();
|
|
static QString getBuildInfo();
|
|
|
|
// IVrBeltTearingConfigChangeNotify接口实现
|
|
void OnConfigChanged(const BeltTearingConfigResult& configResult) override;
|
|
|
|
void sendTestData(std::string fileName);
|
|
|
|
private slots:
|
|
void onCameraInitTimer();
|
|
void onImageGenerated(const QImage& image);
|
|
|
|
private:
|
|
// TCP服务器回调函数
|
|
static void OnServerRecv(const TCPClient* pClient, const char* pData, const unsigned int nLen);
|
|
static void OnServerEvent(const TCPClient* pClient, TCPServerEventType eventType);
|
|
|
|
// TCP服务器相关
|
|
IYTCPServer *m_tcpServer;
|
|
QMap<QString, const TCPClient*> m_clients;
|
|
quint16 m_port;
|
|
|
|
// 配置相关
|
|
IVrBeltTearingConfig *m_config;
|
|
BeltTearingConfigResult m_configResult;
|
|
QString m_configFilePath;
|
|
|
|
// 相机相关
|
|
IVrEyeDevice *m_eyeDevice;
|
|
QTimer *m_cameraInitTimer;
|
|
QString m_cameraIP;
|
|
bool m_cameraInitialized;
|
|
bool m_cameraDetecting;
|
|
|
|
// SDK算法相关
|
|
std::atomic<bool> m_bInitAlgo{false};
|
|
std::vector<SSG_hLineProInfo> m_hLineWorkers;
|
|
SSG_beltTearingParam m_algorithmParam;
|
|
|
|
// 激光线队列管理
|
|
std::deque<SVzLaserLineData> m_laserLineQueue; // 激光线数据队列
|
|
std::mutex m_queueMutex; // 队列访问互斥锁
|
|
unsigned long long m_lineCounter; // 新增线条计数器
|
|
static const int MAX_QUEUE_SIZE = 200; // 最大队列大小
|
|
static const int IMAGE_GENERATION_INTERVAL = 10; // 每10条线生成一次图像
|
|
|
|
// 相机状态回调函数
|
|
static void OnStatusCallback(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
|
|
|
|
// 点云数据回调函数
|
|
static void OnPointCloudCallback(EVzResultDataType eDataType, SVzLaserLineData* pLaserLinePoint, void* pParam);
|
|
|
|
// 处理点云数据
|
|
void processPointCloudData(const SVzLaserLineData* pLaserLine);
|
|
|
|
// 发送算法结果
|
|
void sendTearingResults(const std::vector<SSG_beltTearingInfo>& results);
|
|
|
|
// 激光线队列管理方法
|
|
void addLaserLineToQueue(const SVzLaserLineData* laserLine);
|
|
|
|
// 图像生成和发送
|
|
void sendImageToClients(const QImage& image);
|
|
|
|
// 工具方法
|
|
QString generateClientId(const TCPClient* client);
|
|
|
|
// 实例方法(非静态)
|
|
void handleServerRecv(const TCPClient* pClient, const char* pData, const unsigned int nLen);
|
|
void handleServerEvent(const TCPClient* pClient, TCPServerEventType eventType);
|
|
|
|
// 获取单例实例(用于静态回调)
|
|
static BeltTearingPresenter* s_instance;
|
|
|
|
// 图像处理工作线程
|
|
ImageProcessingWorker* m_imageWorker;
|
|
|
|
// 配置与SDK参数转换函数
|
|
SSG_beltTearingParam configToSDKParam(const BeltTearingConfigResult& config) const;
|
|
BeltTearingConfigResult sdkToConfigParam(const SSG_beltTearingParam& sdkParam) const;
|
|
};
|
|
|
|
#endif // BELTTEARINGPRESENTER_H
|