249 lines
7.9 KiB
C
Raw Normal View History

2026-03-11 23:40:06 +08:00
#ifndef IVRCONFIG_H
#define IVRCONFIG_H
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
// 包含公共配置结构体
#include "VrCommonConfig.h"
#include "VrHandEyeCalibConfig.h"
2026-03-11 23:40:06 +08:00
/**
* @brief SHoleDetectionParams
*/
struct VrHoleDetectionParam
{
int neighborCount = 3; // 相邻点连接数
2026-03-25 11:07:14 +08:00
double angleThresholdPos = 30.0; // 正角度阈值(度)
double angleThresholdNeg = -30.0; // 负角度阈值(度)
double minPitDepth = 1.0; // 最小凹坑深度mm
double minRadius = 2.0; // 最小孔半径mm
double maxRadius = 50.0; // 最大孔半径mm
int expansionSize1 = 5; // 第一环扩展大小
int expansionSize2 = 10; // 第二环扩展大小
int minVTransitionPoints = 1; // V形端点间最小有效过渡点数
double edgeBoundaryFilterDist = 0.0; // 边缘过滤距离mm
2026-03-11 23:40:06 +08:00
};
/**
* @brief SHoleFilterParams
*/
struct VrHoleFilterParam
{
double maxEccentricity = 0.99995; // 最大离心率
double minAngularCoverage = 10.0; // 最小角度覆盖(度)
double maxRadiusFitRatio = 1.0; // 最大半径拟合比率
double minQualityScore = 0.0; // 最小质量分数
2026-03-11 23:40:06 +08:00
double maxPlaneResidual = 10.0; // 最大平面残差mm
double maxAngularGap = 90.0; // 最大角度间隙(度)
double minInlierRatio = 0.0; // 最小内点比率
double minHoleDepth = 2.5; // 最小孔深mm
2026-03-11 23:40:06 +08:00
};
/**
* @brief ESortMode
*/
enum VrHoleSortMode
{
HOLE_SORT_NONE = 0, // 不排序
HOLE_SORT_BY_RADIUS = 1, // 按半径排序(最大优先)
HOLE_SORT_BY_DEPTH = 2, // 按深度排序(最深优先)
HOLE_SORT_BY_QUALITY = 3 // 按质量分数排序(最高优先)
};
/**
* @brief 姿
*
* 姿
*/
enum VrPoseOutputOrder
{
POSE_ORDER_RPY = 0, // Roll, Pitch, Yaw默认
POSE_ORDER_RYP = 1, // Roll, Yaw, Pitch
POSE_ORDER_PRY = 2, // Pitch, Roll, Yaw
POSE_ORDER_PYR = 3, // Pitch, Yaw, Roll
POSE_ORDER_YRP = 4, // Yaw, Roll, Pitch
POSE_ORDER_YPR = 5 // Yaw, Pitch, Roll
};
/**
* @brief
*
*
*
*/
enum VrDirVectorInvert
{
DIR_INVERT_NONE = 0, // 不反向
DIR_INVERT_XY = 1, // X和Y方向反向
DIR_INVERT_XZ = 2, // X和Z方向反向
DIR_INVERT_YZ = 3 // Y和Z方向反向默认兼容原有行为
};
/**
* @brief TCP协议和坐标输出配置
*
* Doc/porotol.jpg
* - PLC-easy320: 192.168.0.88:502
* - : 192.168.0.90:502
*/
struct VrPlcRobotServerConfig
{
int tcpServerPort = 7800; // TCP协议服务端口
int poseOutputOrder = POSE_ORDER_RPY; // 姿态输出顺序默认RPY
int dirVectorInvert = DIR_INVERT_YZ; // 方向向量反向配置默认YZ反向兼容原有行为
// 显式赋值构造函数
VrPlcRobotServerConfig& operator=(const VrPlcRobotServerConfig& other) {
if (this != &other) {
tcpServerPort = other.tcpServerPort;
poseOutputOrder = other.poseOutputOrder;
dirVectorInvert = other.dirVectorInvert;
}
return *this;
}
// 显式复制构造函数
VrPlcRobotServerConfig(const VrPlcRobotServerConfig& other)
: tcpServerPort(other.tcpServerPort)
, poseOutputOrder(other.poseOutputOrder)
, dirVectorInvert(other.dirVectorInvert) {
}
// 默认构造函数
VrPlcRobotServerConfig() = default;
};
/**
* @brief
*/
struct VrAlgorithmParams
{
VrHoleDetectionParam detectionParam; // 孔洞检测参数
VrHoleFilterParam filterParam; // 孔洞过滤参数
int sortMode = HOLE_SORT_NONE; // 排序模式
VrPlaneCalibParam planeCalibParam; // 平面校准参数
// 显式赋值构造函数,确保正确的深拷贝
VrAlgorithmParams& operator=(const VrAlgorithmParams& other) {
if (this != &other) {
detectionParam = other.detectionParam;
filterParam = other.filterParam;
sortMode = other.sortMode;
planeCalibParam = other.planeCalibParam;
}
return *this;
}
// 显式复制构造函数
VrAlgorithmParams(const VrAlgorithmParams& other)
: detectionParam(other.detectionParam)
, filterParam(other.filterParam)
, sortMode(other.sortMode)
, planeCalibParam(other.planeCalibParam) {
}
// 默认构造函数
VrAlgorithmParams() = default;
};
/**
* @brief
*/
struct ConfigResult
{
std::vector<DeviceInfo> cameraList;
std::vector<DeviceInfo> deviceList;
VrAlgorithmParams algorithmParams; // 算法参数
std::vector<VrHandEyeCalibMatrix> handEyeCalibMatrixList; // 多相机手眼标定矩阵列表
VrDebugParam debugParam; // 调试参数
SerialConfig serialConfig; // 串口配置
VrPlcRobotServerConfig plcRobotServerConfig; // PLC和机械臂服务端配置
// 显式赋值构造函数,确保正确的深拷贝
ConfigResult& operator=(const ConfigResult& other) {
if (this != &other) {
cameraList = other.cameraList;
deviceList = other.deviceList;
algorithmParams = other.algorithmParams;
handEyeCalibMatrixList = other.handEyeCalibMatrixList;
debugParam = other.debugParam;
serialConfig = other.serialConfig;
plcRobotServerConfig = other.plcRobotServerConfig;
}
return *this;
}
// 显式复制构造函数
ConfigResult(const ConfigResult& other)
: cameraList(other.cameraList)
, deviceList(other.deviceList)
, algorithmParams(other.algorithmParams)
, handEyeCalibMatrixList(other.handEyeCalibMatrixList)
, debugParam(other.debugParam)
, serialConfig(other.serialConfig)
, plcRobotServerConfig(other.plcRobotServerConfig) {
}
// 默认构造函数
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;
};
#endif // IVRCONFIG_H