182 lines
5.4 KiB
C++
182 lines
5.4 KiB
C++
#ifndef IVRCONFIG_H
|
||
#define IVRCONFIG_H
|
||
|
||
#include <iostream>
|
||
#include <string>
|
||
#include <vector>
|
||
#include <utility>
|
||
#include <algorithm>
|
||
#include <cstring>
|
||
|
||
// 包含公共配置结构体
|
||
#include "VrCommonConfig.h"
|
||
|
||
/**
|
||
* @brief 离群点滤波参数
|
||
*/
|
||
struct VrOutlierFilterParam
|
||
{
|
||
double continuityTh = 20.0; // 连续性阈值,噪声滤除。当相邻点的z跳变大于此门限时,检查是否为噪声
|
||
double outlierTh = 5.0; // 离群点判断阈值,若长度小于此值,视为噪声
|
||
};
|
||
|
||
/**
|
||
* @brief 线段分割参数
|
||
*/
|
||
struct VrLineSegParam
|
||
{
|
||
double distScale = 3.0; // 计算方向角的窗口比例因子
|
||
double segGapTh_y = 3.0; // Y方向间隔阈值,大于此值认为是分段
|
||
double segGapTh_z = 10.0; // Z方向间隔阈值,大于此值认为是分段
|
||
};
|
||
|
||
/**
|
||
* @brief 树生长参数
|
||
*/
|
||
struct VrTreeGrowParam
|
||
{
|
||
int maxLineSkipNum = 10; // 生长时允许跳过的最大线条数
|
||
double yDeviation_max = 10.0; // 生长时允许的最大Y偏差
|
||
double maxSkipDistance = 10.0; // 最大跳跃距离
|
||
double zDeviation_max = 10.0; // 生长时允许的最大Z偏差
|
||
double minLTypeTreeLen = 100.0; // L型树的最小长度
|
||
double minVTypeTreeLen = 100.0; // V型树的最小长度
|
||
};
|
||
|
||
/**
|
||
* @brief 工件孔参数
|
||
*/
|
||
struct VrWorkpieceHoleParam
|
||
{
|
||
int workpieceType = 0; // 工件类型
|
||
double holeDiameter = 6.0; // 孔直径 (mm)
|
||
double holeDist_L = 40.0; // 孔间距_长 (mm)
|
||
double holeDist_W = 32.0; // 孔间距_宽 (mm)
|
||
};
|
||
|
||
/**
|
||
* @brief 算法参数配置结构
|
||
*/
|
||
struct VrAlgorithmParams
|
||
{
|
||
VrOutlierFilterParam filterParam; // 离群点滤波参数
|
||
VrLineSegParam lineSegParam; // 线段分割参数
|
||
VrTreeGrowParam growParam; // 树生长参数
|
||
VrPlaneCalibParam planeCalibParam; // 平面校准参数
|
||
VrWorkpieceHoleParam workpieceHoleParam; // 工件孔参数
|
||
|
||
// 显式赋值构造函数,确保正确的深拷贝
|
||
VrAlgorithmParams& operator=(const VrAlgorithmParams& other) {
|
||
if (this != &other) {
|
||
filterParam = other.filterParam;
|
||
lineSegParam = other.lineSegParam;
|
||
growParam = other.growParam;
|
||
planeCalibParam = other.planeCalibParam;
|
||
workpieceHoleParam = other.workpieceHoleParam;
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
// 显式复制构造函数
|
||
VrAlgorithmParams(const VrAlgorithmParams& other)
|
||
: filterParam(other.filterParam)
|
||
, lineSegParam(other.lineSegParam)
|
||
, growParam(other.growParam)
|
||
, planeCalibParam(other.planeCalibParam)
|
||
, workpieceHoleParam(other.workpieceHoleParam) {
|
||
}
|
||
|
||
// 默认构造函数
|
||
VrAlgorithmParams() = default;
|
||
};
|
||
|
||
/**
|
||
* @brief 配置加载结果
|
||
*/
|
||
struct ConfigResult
|
||
{
|
||
std::vector<DeviceInfo> cameraList;
|
||
std::vector<DeviceInfo> deviceList;
|
||
VrAlgorithmParams algorithmParams; // 算法参数
|
||
VrDebugParam debugParam; // 调试参数
|
||
SerialConfig serialConfig; // 串口配置
|
||
|
||
// 显式赋值构造函数,确保正确的深拷贝
|
||
ConfigResult& operator=(const ConfigResult& other) {
|
||
if (this != &other) {
|
||
cameraList = other.cameraList;
|
||
deviceList = other.deviceList;
|
||
algorithmParams = other.algorithmParams;
|
||
debugParam = other.debugParam;
|
||
serialConfig = other.serialConfig;
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
// 显式复制构造函数
|
||
ConfigResult(const ConfigResult& other)
|
||
: cameraList(other.cameraList)
|
||
, deviceList(other.deviceList)
|
||
, algorithmParams(other.algorithmParams)
|
||
, debugParam(other.debugParam)
|
||
, serialConfig(other.serialConfig) {
|
||
}
|
||
|
||
// 默认构造函数
|
||
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
|