2026-03-28 10:49:55 +08:00
|
|
|
|
#ifndef IVRCONFIG_H
|
|
|
|
|
|
#define IVRCONFIG_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
2026-04-10 20:02:57 +08:00
|
|
|
|
#include <QString>
|
2026-03-28 10:49:55 +08:00
|
|
|
|
|
|
|
|
|
|
// 包含公共配置结构体
|
|
|
|
|
|
#include "VrCommonConfig.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 螺杆检测参数
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct VrScrewParam
|
|
|
|
|
|
{
|
|
|
|
|
|
double rodDiameter = 10.0; // 螺杆直径 (mm)
|
|
|
|
|
|
bool isHorizonScan = true; // 水平扫描模式
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 角点检测参数
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct VrCornerParam
|
|
|
|
|
|
{
|
|
|
|
|
|
double minEndingGap = 20.0;
|
|
|
|
|
|
double minEndingGap_z = 5.0;
|
|
|
|
|
|
double scale = 2.5;
|
|
|
|
|
|
double cornerTh = 60.0;
|
|
|
|
|
|
double jumpCornerTh_1 = 15.0;
|
|
|
|
|
|
double jumpCornerTh_2 = 60.0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 离群点滤波参数
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct VrOutlierFilterParam
|
|
|
|
|
|
{
|
|
|
|
|
|
double continuityTh = 20.0; // meanK
|
|
|
|
|
|
double outlierTh = 5.0; // stddevMul
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 区域生长参数
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct VrTreeGrowParam
|
|
|
|
|
|
{
|
|
|
|
|
|
double yDeviation_max = 20.0;
|
|
|
|
|
|
double zDeviation_max = 50.0;
|
|
|
|
|
|
int maxLineSkipNum = 10;
|
|
|
|
|
|
double maxSkipDistance = 20.0;
|
|
|
|
|
|
double minLTypeTreeLen = 10.0;
|
|
|
|
|
|
double minVTypeTreeLen = 10.0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 算法参数配置结构(ScrewPosition 专用)
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct VrAlgorithmParams
|
|
|
|
|
|
{
|
|
|
|
|
|
VrScrewParam screwParam;
|
|
|
|
|
|
VrCornerParam cornerParam;
|
|
|
|
|
|
VrOutlierFilterParam filterParam;
|
|
|
|
|
|
VrTreeGrowParam growParam;
|
|
|
|
|
|
VrPlaneCalibParam planeCalibParam;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 配置加载结果
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct ConfigResult
|
|
|
|
|
|
{
|
|
|
|
|
|
std::vector<DeviceInfo> cameraList; // 相机设备列表
|
|
|
|
|
|
VrDebugParam debugParam; // 调试参数
|
|
|
|
|
|
SerialConfig serialConfig; // 串口配置
|
2026-04-10 20:02:57 +08:00
|
|
|
|
uint16_t tcpPort = 7800; // TCP服务器端口
|
2026-03-28 10:49:55 +08:00
|
|
|
|
VrAlgorithmParams algorithmParams; // 算法参数
|
|
|
|
|
|
|
|
|
|
|
|
// 显式赋值构造函数,确保正确的深拷贝
|
|
|
|
|
|
ConfigResult& operator=(const ConfigResult& other) {
|
|
|
|
|
|
if (this != &other) {
|
|
|
|
|
|
cameraList = other.cameraList;
|
|
|
|
|
|
debugParam = other.debugParam;
|
|
|
|
|
|
serialConfig = other.serialConfig;
|
|
|
|
|
|
tcpPort = other.tcpPort;
|
|
|
|
|
|
algorithmParams = other.algorithmParams;
|
|
|
|
|
|
}
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 显式复制构造函数
|
|
|
|
|
|
ConfigResult(const ConfigResult& other)
|
|
|
|
|
|
: cameraList(other.cameraList)
|
|
|
|
|
|
, debugParam(other.debugParam)
|
|
|
|
|
|
, serialConfig(other.serialConfig)
|
|
|
|
|
|
, tcpPort(other.tcpPort)
|
|
|
|
|
|
, algorithmParams(other.algorithmParams) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 默认构造函数
|
|
|
|
|
|
ConfigResult() = default;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 配置加载错误代码
|
|
|
|
|
|
*/
|
|
|
|
|
|
enum LoadConfigErrorCode
|
|
|
|
|
|
{
|
|
|
|
|
|
LOAD_CONFIG_SUCCESS = 0, // 加载成功
|
|
|
|
|
|
LOAD_CONFIG_FILE_NOT_FOUND = -1, // 配置文件不存在
|
|
|
|
|
|
LOAD_CONFIG_PARSE_ERROR = -2, // 配置文件解析错误
|
|
|
|
|
|
LOAD_CONFIG_INVALID_FORMAT = -3, // 配置文件格式无效
|
|
|
|
|
|
LOAD_CONFIG_UNKNOWN_ERROR = -99 // 未知错误
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief VrConfig接口类
|
|
|
|
|
|
*/
|
|
|
|
|
|
class IVrConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 虚析构函数
|
|
|
|
|
|
*/
|
|
|
|
|
|
virtual ~IVrConfig() {}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 创建实例
|
|
|
|
|
|
* @return 实例
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool CreateInstance(IVrConfig** ppVrConfig);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 加载配置文件
|
|
|
|
|
|
* @param filePath 配置文件路径
|
|
|
|
|
|
* @param configResult 输出参数,加载的配置结果
|
|
|
|
|
|
* @return 错误代码 (LoadConfigErrorCode): 0=成功, 负值表示错误
|
|
|
|
|
|
*/
|
|
|
|
|
|
virtual int LoadConfig(const std::string& filePath, ConfigResult& configResult) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 保存配置文件
|
|
|
|
|
|
* @param filePath 配置文件路径
|
|
|
|
|
|
* @param configResult 配置结果
|
|
|
|
|
|
* @return 是否保存成功
|
|
|
|
|
|
*/
|
|
|
|
|
|
virtual bool SaveConfig(const std::string& filePath, ConfigResult& configResult) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 设置配置改变通知回调
|
|
|
|
|
|
* @param notify 通知接口指针
|
|
|
|
|
|
*/
|
|
|
|
|
|
virtual void SetConfigChangeNotify(IVrConfigChangeNotify* notify) = 0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-04-10 20:02:57 +08:00
|
|
|
|
// ============ 对外协议相关结构体 ============
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 检测类型枚举
|
|
|
|
|
|
*/
|
|
|
|
|
|
enum DetectionType {
|
|
|
|
|
|
DETECTION_TYPE_SCREW = 1, // 螺杆检测
|
|
|
|
|
|
DETECTION_TYPE_TOOL_DISK = 2 // 工具盘检测
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 螺杆检测输出结构体(螺杆顶端中心点+姿态,XYZRPY格式)
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct ScrewDetectOutput {
|
|
|
|
|
|
double x = 0.0; // X坐标
|
|
|
|
|
|
double y = 0.0; // Y坐标
|
|
|
|
|
|
double z = 0.0; // Z坐标
|
|
|
|
|
|
double roll = 0.0; // Roll角(度)
|
|
|
|
|
|
double pitch = 0.0; // Pitch角(度)
|
|
|
|
|
|
double yaw = 0.0; // Yaw角(度)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 工具盘检测输出结构体(中心点+姿态,算法后续增加接口)
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct ToolDiskDetectOutput {
|
|
|
|
|
|
double x = 0.0; // X坐标
|
|
|
|
|
|
double y = 0.0; // Y坐标
|
|
|
|
|
|
double z = 0.0; // Z坐标
|
|
|
|
|
|
double roll = 0.0; // Roll角(度)
|
|
|
|
|
|
double pitch = 0.0; // Pitch角(度)
|
|
|
|
|
|
double yaw = 0.0; // Yaw角(度)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 协议输出结果(统一的对外输出格式)
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct ProtocolDetectionOutput {
|
|
|
|
|
|
DetectionType type = DETECTION_TYPE_SCREW; // 检测类型
|
|
|
|
|
|
bool success = true; // 是否成功
|
|
|
|
|
|
int errorCode = 0; // 错误码
|
|
|
|
|
|
QString message; // 结果消息
|
|
|
|
|
|
int cameraIndex = 0; // 相机索引
|
|
|
|
|
|
qint64 timestamp = 0; // 请求时间戳(回传)
|
|
|
|
|
|
|
|
|
|
|
|
// 螺杆检测结果
|
|
|
|
|
|
std::vector<ScrewDetectOutput> screwOutputs;
|
|
|
|
|
|
|
|
|
|
|
|
// 工具盘检测结果
|
|
|
|
|
|
std::vector<ToolDiskDetectOutput> toolDiskOutputs;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-03-28 10:49:55 +08:00
|
|
|
|
#endif // IVRCONFIG_H
|