268 lines
8.0 KiB
C
Raw Normal View History

#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; // 连续性阈值
double outlierTh = 5.0; // 离群点判断阈值
};
/**
* @brief
*/
struct VrCornerParam
{
double cornerTh = 60; // 拐角阈值
double scale = 50; // 计算方向角的窗口比例因子
double minEndingGap = 20; // Y方向最小结束间隔
double minEndingGap_z = 20; // Z方向最小结束间隔
double jumpCornerTh_1 = 10; // 跳跃拐角阈值1
double jumpCornerTh_2 = 60; // 跳跃拐角阈值2
};
/**
* @brief
*/
struct VrTreeGrowParam
{
int maxLineSkipNum = 10; // 生长时允许跳过的最大线条数
double yDeviation_max = 10.0; // 生长时允许的最大Y偏差
double maxSkipDistance = 10.0; // 最大跳跃距离
double zDeviation_max = 10; // 生长时允许的最大Z偏差
double minLTypeTreeLen = 100.0; // L型树的最小长度
double minVTypeTreeLen = 100.0; // V型树的最小长度
};
/**
* @brief
*/
struct VrWorkpieceParam
{
double lineLen = 180.0; // 工件角点提取:直线段长度阈值
double dirAngleScale = 25.0; // 计算方向角的尺度
double lineDeviation = 20.0; // 直线偏差
double minCutAngleTh = 15.0; // 最小截角阈值
};
/**
* @brief 4x4变换矩阵
*/
struct VrHandEyeCalibParam
{
int cameraIndex = 1; // 相机索引1-based
std::string cameraName = ""; // 相机名称
double transformMatrix[16] = { // 4x4变换矩阵默认单位矩阵
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
bool isCalibrated = false; // 是否已经校准
VrHandEyeCalibParam& operator=(const VrHandEyeCalibParam& other) {
if (this != &other) {
cameraIndex = other.cameraIndex;
cameraName = other.cameraName;
memcpy(transformMatrix, other.transformMatrix, sizeof(transformMatrix));
isCalibrated = other.isCalibrated;
}
return *this;
}
VrHandEyeCalibParam(const VrHandEyeCalibParam& other)
: cameraIndex(other.cameraIndex)
, cameraName(other.cameraName)
, isCalibrated(other.isCalibrated) {
memcpy(transformMatrix, other.transformMatrix, sizeof(transformMatrix));
}
VrHandEyeCalibParam() = default;
};
/**
* @brief
*/
struct VrHandEyeCalibParams
{
std::vector<VrHandEyeCalibParam> cameraHandEyeParams;
VrHandEyeCalibParam* GetCameraHandEyeParam(int cameraIndex) {
for (auto& param : cameraHandEyeParams) {
if (param.cameraIndex == cameraIndex) {
return &param;
}
}
return nullptr;
}
const VrHandEyeCalibParam* GetCameraHandEyeParam(int cameraIndex) const {
for (const auto& param : cameraHandEyeParams) {
if (param.cameraIndex == cameraIndex) {
return &param;
}
}
return nullptr;
}
void SetCameraHandEyeParam(const VrHandEyeCalibParam& param) {
for (auto& existingParam : cameraHandEyeParams) {
if (existingParam.cameraIndex == param.cameraIndex) {
existingParam = param;
return;
}
}
cameraHandEyeParams.push_back(param);
}
void RemoveCameraHandEyeParam(int cameraIndex) {
cameraHandEyeParams.erase(
std::remove_if(cameraHandEyeParams.begin(), cameraHandEyeParams.end(),
[cameraIndex](const VrHandEyeCalibParam& param) {
return param.cameraIndex == cameraIndex;
}),
cameraHandEyeParams.end());
}
};
/**
* @brief
*/
struct VrAlgorithmParams
{
VrOutlierFilterParam filterParam; // 离群点滤波参数
VrCornerParam cornerParam; // 拐角参数
VrTreeGrowParam growParam; // 树生长参数
VrPlaneCalibParam planeCalibParam; // 平面校准参数
VrWorkpieceParam workpieceParam; // 工件参数
VrHandEyeCalibParams handEyeCalibParam; // 手眼标定参数
// 显式赋值构造函数,确保正确的深拷贝
VrAlgorithmParams& operator=(const VrAlgorithmParams& other) {
if (this != &other) {
filterParam = other.filterParam;
cornerParam = other.cornerParam;
growParam = other.growParam;
planeCalibParam = other.planeCalibParam;
workpieceParam = other.workpieceParam;
handEyeCalibParam = other.handEyeCalibParam;
}
return *this;
}
// 显式复制构造函数
VrAlgorithmParams(const VrAlgorithmParams& other)
: filterParam(other.filterParam)
, cornerParam(other.cornerParam)
, growParam(other.growParam)
, planeCalibParam(other.planeCalibParam)
, workpieceParam(other.workpieceParam)
, handEyeCalibParam(other.handEyeCalibParam) {
}
// 默认构造函数
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