2026-02-11 00:53:51 +08:00

283 lines
8.9 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 IVRCONFIG_H
#define IVRCONFIG_H
#include <iostream>
#include <string>
#include <vector>
// 包含公共配置结构体
#include "VrCommonConfig.h"
// 包含SDK算法参数类型
#include "SG_baseDataType.h"
#include "bagThreadPositioning_Export.h"
/**
* @brief 线头参数(扫描信息)
* 使用 SDK 的 SSX_ScanInfo 结构
*/
struct VrThreadParam
{
bool isHorizonScan = false; // 是否水平扫描(激光线平行槽道)
bool scanFromThreadHead = true; // 是否从线头开始扫描
double stitchWidth = 1.0; // 线缝最小宽度
double operateDist = 3.0; // 落刀位置距离线距离
double mark_diameter = 18.0; // Mark外径mm
double mark_height = 18.0; // Mark高度mm
double mark_distance = 39.0; // 两个Mark的距离mm
// 转换为 SDK 结构
SSX_ScanInfo ToSDK() const {
SSX_ScanInfo info;
info.isHorizonScan = isHorizonScan;
info.scanFromThreadHead = scanFromThreadHead;
info.stitchWidth = stitchWidth;
info.operateDist = operateDist;
info.mark_diameter = mark_diameter;
info.mark_height = mark_height;
info.mark_distance = mark_distance;
return info;
}
};
/**
* @brief 角点检测参数
* 使用 SDK 的 SSG_cornerParam 结构
*/
struct VrCornerParam
{
double minEndingGap = 1.0; // Y方向最小结束间隙
double minEndingGap_z = 3.5; // Z方向最小结束间隙
double scale = 4.0; // 计算方向角的窗口比例
double cornerTh = 90.0; // 角点阈值
double jumpCornerTh_1 = 15.0; // 跳跃角点阈值1
double jumpCornerTh_2 = 60.0; // 跳跃角点阈值2
// 转换为 SDK 结构
SSG_cornerParam ToSDK() const {
SSG_cornerParam param;
param.minEndingGap = minEndingGap;
param.minEndingGap_z = minEndingGap_z;
param.scale = scale;
param.cornerTh = cornerTh;
param.jumpCornerTh_1 = jumpCornerTh_1;
param.jumpCornerTh_2 = jumpCornerTh_2;
return param;
}
};
/**
* @brief 离群点滤波参数
* 使用 SDK 的 SSG_outlierFilterParam 结构
*/
struct VrOutlierFilterParam
{
double continuityTh = 3.0; // 连续性阈值
double outlierTh = 2.0; // 离群点阈值
// 转换为 SDK 结构
SSG_outlierFilterParam ToSDK() const {
SSG_outlierFilterParam param;
param.continuityTh = continuityTh;
param.outlierTh = outlierTh;
return param;
}
};
/**
* @brief 凸起特征参数
* 使用 SDK 的 SSG_raisedFeatureParam 结构
*/
struct VrRaisedFeatureParam
{
double minJumpZ = 1.5; // Z方向最小跳跃高度
double minK = 2.0; // 最小斜率
double widthMin = 1.0; // 宽度最小值
double widthMax = 4.0; // 宽度最大值
// 转换为 SDK 结构
SSG_raisedFeatureParam ToSDK() const {
SSG_raisedFeatureParam param;
param.minJumpZ = minJumpZ;
param.minK = minK;
param.widthRange.min = widthMin;
param.widthRange.max = widthMax;
return param;
}
};
/**
* @brief 树生长参数
* 使用 SDK 的 SSG_treeGrowParam 结构
*/
struct VrTreeGrowParam
{
double yDeviation_max = 1.0; // Y方向最大偏差
double zDeviation_max = 1.0; // Z方向最大偏差
int maxLineSkipNum = -1; // 最大跳过行数
double maxSkipDistance = 5.0; // 最大跳过距离
double minLTypeTreeLen = 10.0; // L型树最小长度
double minVTypeTreeLen = 10.0; // V型树最小长度
// 转换为 SDK 结构
SSG_treeGrowParam ToSDK() const {
SSG_treeGrowParam param;
param.yDeviation_max = yDeviation_max;
param.zDeviation_max = zDeviation_max;
param.maxLineSkipNum = maxLineSkipNum;
param.maxSkipDistance = maxSkipDistance;
param.minLTypeTreeLen = minLTypeTreeLen;
param.minVTypeTreeLen = minVTypeTreeLen;
return param;
}
};
/**
* @brief 算法参数结构体(包裹拆线定位专用)
*
* 包含线激光扫描和拆线位置检测所需的参数
*/
struct VrAlgorithmParams
{
// 线头参数
VrThreadParam threadParam;
// 角点检测参数
VrCornerParam cornerParam;
// 离群点滤波参数
VrOutlierFilterParam filterParam;
// 凸起特征参数
VrRaisedFeatureParam raisedFeatureParam;
// 树生长参数
VrTreeGrowParam growParam;
// 平面标定参数(多相机)
VrPlaneCalibParam planeCalibParam;
// 显式赋值构造函数
VrAlgorithmParams& operator=(const VrAlgorithmParams& other) {
if (this != &other) {
threadParam = other.threadParam;
cornerParam = other.cornerParam;
filterParam = other.filterParam;
raisedFeatureParam = other.raisedFeatureParam;
growParam = other.growParam;
planeCalibParam = other.planeCalibParam;
}
return *this;
}
// 显式复制构造函数
VrAlgorithmParams(const VrAlgorithmParams& other)
: threadParam(other.threadParam)
, cornerParam(other.cornerParam)
, filterParam(other.filterParam)
, raisedFeatureParam(other.raisedFeatureParam)
, growParam(other.growParam)
, planeCalibParam(other.planeCalibParam) {
}
// 默认构造函数
VrAlgorithmParams() = default;
};
/**
* @brief 配置加载结果
*/
struct ConfigResult
{
std::vector<DeviceInfo> cameraList; // 相机设备列表
VrAlgorithmParams algorithmParams; // 算法参数
VrDebugParam debugParam; // 调试参数
SerialConfig serialConfig; // 串口配置
uint16_t tcpPort = 5020; // TCP服务器端口
bool modbusBigEndian = true; // ModbusTCP大小端配置true=大端false=小端)
std::string modbusIP = "192.168.2.1"; // ModbusTCP远端IP地址
uint16_t modbusPort = 502; // ModbusTCP远端端口
int modbusPollingInterval = 200; // ModbusTCP轮询间隔毫秒
// 显式赋值构造函数,确保正确的深拷贝
ConfigResult& operator=(const ConfigResult& other) {
if (this != &other) {
cameraList = other.cameraList;
algorithmParams = other.algorithmParams;
debugParam = other.debugParam;
serialConfig = other.serialConfig;
tcpPort = other.tcpPort;
modbusBigEndian = other.modbusBigEndian;
modbusIP = other.modbusIP;
modbusPort = other.modbusPort;
modbusPollingInterval = other.modbusPollingInterval;
}
return *this;
}
// 显式复制构造函数
ConfigResult(const ConfigResult& other)
: cameraList(other.cameraList)
, algorithmParams(other.algorithmParams)
, debugParam(other.debugParam)
, serialConfig(other.serialConfig)
, tcpPort(other.tcpPort)
, modbusBigEndian(other.modbusBigEndian)
, modbusIP(other.modbusIP)
, modbusPort(other.modbusPort)
, modbusPollingInterval(other.modbusPollingInterval) {
}
// 默认构造函数
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