GrabBag/App/WheelMeasure/WheelMeasureConfig/Inc/IVrWheelMeasureConfig.h
2025-12-27 09:34:02 +08:00

245 lines
7.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef IVRWHEELMEASURECONFIG_H
#define IVRWHEELMEASURECONFIG_H
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <QtCore/QMetaType>
#include <QtCore/QString>
#include <QtGui/QImage>
/**
* @brief 数据类型枚举
*/
enum class WheelMeasureDataType {
Text = 0x01,
Image = 0x02,
ReadConfig = 0x03,
WriteConfig = 0x04,
};
/**
* @brief 服务器信息结构
*/
struct WheelServerInfo
{
std::string name; // 服务器名称
std::string ip; // 服务器IP地址
int port = 5800; // 服务器端口
};
/**
* @brief 相机配置参数
*/
struct WheelCameraParam
{
int cameraIndex = 0; // 相机索引1-based
std::string name = ""; // 相机名称
std::string cameraIP = ""; // 相机IP地址
bool enabled = true; // 是否启用
// 相机工作参数(参考 GrabBag
double exposure = 100.0; // 曝光时间 (微秒)
double gain = 1.0; // 增益值
double frameRate = 500.0; // 帧率
double swingSpeed = 30.0; // 摆动速度
double swingStartAngle = 0.0; // 开始角度
double swingStopAngle = 76.0; // 结束角度
};
/**
* @brief 相机调平参数
*/
struct WheelCameraPlaneCalibParam
{
int cameraIndex = 0; // 相机索引
std::string cameraName = ""; // 相机名称
double planeCalib[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; // 旋转矩阵(将点云旋转到水平)
double planeHeight = -1; // 地面高度
double invRMatrix[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; // 逆旋转矩阵(回到原坐标系)
bool isCalibrated = false; // 是否已标定
};
/**
* @brief 角点参数
*/
struct WheelCornerParam
{
double minEndingGap = 20.0; // y方向最短结束间隙
double minEndingGap_z = 20.0; // z方向最短结束间隙
double scale = 50.0; // 计算方向角的窗口比例
double cornerTh = 60.0; // 空角阈值,大于此阈值为有效空点
double jumpCornerTh_1 = 10.0; // 判断空角是否为跳变的阈值
double jumpCornerTh_2 = 60.0; // 判断空角是否为跳变的阈值
};
/**
* @brief 线段参数
*/
struct WheelLineSegParam
{
double segGapTh_y = 5.0; // y方向最短段间隙阈值
double segGapTh_z = 10.0; // z方向最短段间隙阈值
double maxDist = 1.0; // 最大距离
};
/**
* @brief 离群点过滤参数
*/
struct WheelOutlierFilterParam
{
double continuityTh = 20.0; // 连续性阈值
double outlierTh = 5.0; // 离群点阈值
};
/**
* @brief 树生长参数
*/
struct WheelTreeGrowParam
{
double yDeviation_max = 5.0; // 生长时允许的最大Y偏差
double zDeviation_max = 2.0; // 生长时允许的最大Z偏差
int maxLineSkipNum = 10; // 生长时允许的最大跳线数
double maxSkipDistance = 5.0; // 当maxLineSkipNum为-1时使用
double minLTypeTreeLen = 100.0; // 最少的L型节点数目
double minVTypeTreeLen = 100.0; // 最少的V型节点数目
};
/**
* @brief 车轮拱高测量算法参数
*/
struct WheelMeasureAlgorithmParams
{
WheelCornerParam cornerParam; // 角点参数
WheelLineSegParam lineSegParam; // 线段参数
WheelOutlierFilterParam filterParam; // 离群点过滤参数
WheelTreeGrowParam growParam; // 树生长参数
};
/**
* @brief 调试参数
*/
struct WheelDebugParam
{
bool enableDebug = false; // 是否开启调试模式
bool saveDebugImage = false; // 是否保存调试图像
bool printDetailLog = false; // 是否打印详细日志
std::string debugOutputPath = ""; // 调试输出路径
};
/**
* @brief 配置加载结果
*/
struct WheelMeasureConfigResult
{
std::vector<WheelCameraParam> cameras; // 相机列表
std::vector<WheelCameraPlaneCalibParam> planeCalibParams; // 相机调平参数列表
std::vector<WheelServerInfo> servers; // 服务器列表
WheelMeasureAlgorithmParams algorithmParams; // 算法参数
WheelDebugParam debugParam; // 调试参数
int serverPort = 5900; // 服务器端口
int tcpPort = 5800; // TCP协议端口
// 构造函数
WheelMeasureConfigResult() {}
};
/**
* @brief 测量结果数据
*/
struct WheelMeasureData
{
int id = 0; // 测量ID
double archToCenterHeight = 0.0; // 拱高到中心的高度
double wheelArchPosX = 0.0; // 拱点X坐标
double wheelArchPosY = 0.0; // 拱点Y坐标
double wheelArchPosZ = 0.0; // 拱点Z坐标
double wheelUpPosX = 0.0; // 上点X坐标
double wheelUpPosY = 0.0; // 上点Y坐标
double wheelUpPosZ = 0.0; // 上点Z坐标
double wheelDownPosX = 0.0; // 下点X坐标
double wheelDownPosY = 0.0; // 下点Y坐标
double wheelDownPosZ = 0.0; // 下点Z坐标
QString timestamp = ""; // 时间戳
};
/**
* @brief 测量结果
*/
struct WheelMeasureResult
{
QString cameraName = ""; // 相机名称
QString aliasName = ""; // 别名
QImage image; // 图像
bool bImageValid = false; // 图像是否有效
bool bResultValid = false; // 结果是否有效
std::vector<WheelMeasureData> result; // 测量结果列表
};
/**
* @brief 配置改变通知接口
*/
class IVrWheelMeasureConfigChangeNotify
{
public:
virtual ~IVrWheelMeasureConfigChangeNotify() {}
/**
* @brief 配置数据改变通知
* @param configResult 新的配置数据
*/
virtual void OnConfigChanged(const WheelMeasureConfigResult& configResult) = 0;
};
/**
* @brief WheelMeasureConfig接口类
*/
class IVrWheelMeasureConfig
{
public:
/**
* @brief 虚析构函数
*/
virtual ~IVrWheelMeasureConfig() = default;
/**
* @brief 创建实例
* @return 实例
*/
static bool CreateInstance(IVrWheelMeasureConfig** ppVrConfig);
/**
* @brief 加载配置文件
* @param filePath 配置文件路径
* @return 加载的配置结果
*/
virtual WheelMeasureConfigResult LoadConfig(const std::string& filePath) = 0;
/**
* @brief 保存配置文件
* @param filePath 配置文件路径
* @param configResult 配置结果
* @return 是否保存成功
*/
virtual bool SaveConfig(const std::string& filePath, WheelMeasureConfigResult& configResult) = 0;
/**
* @brief 设置配置改变通知回调
* @param notify 通知接口指针
*/
virtual void SetConfigChangeNotify(IVrWheelMeasureConfigChangeNotify* notify) = 0;
};
// 声明元类型以便在QVariant中使用
Q_DECLARE_METATYPE(WheelServerInfo)
Q_DECLARE_METATYPE(WheelCameraParam)
Q_DECLARE_METATYPE(WheelCameraPlaneCalibParam)
Q_DECLARE_METATYPE(WheelMeasureConfigResult)
Q_DECLARE_METATYPE(WheelMeasureData)
Q_DECLARE_METATYPE(WheelMeasureResult)
#endif // IVRWHEELMEASURECONFIG_H