220 lines
6.1 KiB
C
Raw Permalink Normal View History

2025-09-10 00:31:27 +08:00
#ifndef IVRCONFIG_H
#define IVRCONFIG_H
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include "VrCommonConfig.h" // 使用公共配置结构体定义
2025-09-10 00:31:27 +08:00
/**
* @brief
*/
enum class ProjectType
{
2025-09-14 14:51:38 +08:00
LapWeld = 0, // 激光焊接
2025-09-10 00:31:27 +08:00
DirectBag = 1, // 带方向的编织袋
};
/**
* @brief
*/
inline std::string ProjectTypeToString(ProjectType type)
{
switch (type) {
2025-09-14 14:51:38 +08:00
case ProjectType::LapWeld:
return "LapWeld";
2025-09-10 00:31:27 +08:00
case ProjectType::DirectBag:
return "DirectBag";
default:
return "Unknown";
}
}
/**
* @brief
*/
inline ProjectType StringToProjectType(const std::string& str)
{
2025-09-14 14:51:38 +08:00
if (str == "LapWeld" || str == "0") {
return ProjectType::LapWeld;
2025-09-10 00:31:27 +08:00
} else if (str == "DirectBag" || str == "1") {
return ProjectType::DirectBag;
} else {
2025-09-14 14:51:38 +08:00
return ProjectType::LapWeld; // 默认返回激光焊接
2025-09-10 00:31:27 +08:00
}
}
// DeviceInfo, SerialConfig 已在 VrCommonConfig.h 中定义
2025-09-10 00:31:27 +08:00
/**
* @brief
*/
struct VrOutlierFilterParam
{
double continuityTh = 20.0; // 连续性阈值
int outlierTh = 5; // 离群点判断阈值
};
/**
* @brief
*/
struct VrSlopeParam
{
double LSlopeZWin = 10.0; // 斜坡计算的窗口长度
double validSlopeH = 5.0; // 有效斜坡高度
double minLJumpH = 3.0; // 最小L跳跃高度
double minEndingGap = 2.0; // 最小结束间隔
};
/**
* @brief
*/
struct VrCornerParam
{
2025-09-18 23:49:32 +08:00
double cornerTh = 25; // 拐角阈值
double scale = 4; // 计算方向角的窗口比例因子
2025-09-18 23:49:32 +08:00
double minEndingGap = 6; // Y方向最小结束间隔
double minEndingGap_z = 1.5; // Z方向最小结束间隔
double jumpCornerTh_1 = 10; // 跳跃拐角阈值1
2025-09-18 23:49:32 +08:00
double jumpCornerTh_2 = 25; // 跳跃拐角阈值2
};
2025-09-10 00:31:27 +08:00
/**
* @brief
*/
struct VrTreeGrowParam
{
int maxLineSkipNum = 5; // 生长时允许跳过的最大线条数
double yDeviation_max = 1.0; // 生长时允许的最大Y偏差
double maxSkipDistance = 5.0; // 最大跳跃距离
double zDeviation_max = 2; // 生长时允许的最大Z偏差
double minLTypeTreeLen = 30.0; // L型树的最小长度
double minVTypeTreeLen = 30.0; // V型树的最小长度
2025-09-10 00:31:27 +08:00
};
/**
* @brief
*/
enum class WeldScanMode
{
ScanMode_V = 0, // 垂直线垂直方向扫描
ScanMode_H = 1, // 水平线平行水平扫描
ScanMode_Both = 2 // 既有垂直扫描,也有水平扫描
};
/**
* @brief
*/
inline std::string WeldScanModeToString(WeldScanMode mode)
{
switch (mode) {
case WeldScanMode::ScanMode_V:
return "ScanMode_V";
case WeldScanMode::ScanMode_H:
return "ScanMode_H";
case WeldScanMode::ScanMode_Both:
return "ScanMode_Both";
default:
return "Unknown";
}
}
/**
* @brief
*/
inline WeldScanMode StringToWeldScanMode(const std::string& str)
{
if (str == "ScanMode_V" || str == "0") {
return WeldScanMode::ScanMode_V;
} else if (str == "ScanMode_H" || str == "1") {
return WeldScanMode::ScanMode_H;
} else if (str == "ScanMode_Both" || str == "2") {
return WeldScanMode::ScanMode_Both;
} else {
return WeldScanMode::ScanMode_V; // 默认返回垂直扫描
}
}
2025-09-10 00:31:27 +08:00
/**
2025-09-14 14:51:38 +08:00
* @brief
2025-09-10 00:31:27 +08:00
*/
2025-09-14 14:51:38 +08:00
struct VrLapWeldParam
2025-09-10 00:31:27 +08:00
{
double lapHeight = 2.0; // 搭接厚度
double weldMinLen = 2.0; // 最小焊缝长度,用于过滤可能的虚假焊缝
int weldRefPoints = 2; // 输出的直线焊缝的参考点默认是2个起点和终点
WeldScanMode scanMode = WeldScanMode::ScanMode_V; // 焊接扫描模式
2025-09-10 00:31:27 +08:00
};
// VrCameraPlaneCalibParam, VrPlaneCalibParam, VrDebugParam 已在 VrCommonConfig.h 中定义
2025-09-10 00:31:27 +08:00
/**
* @brief
*/
struct VrAlgorithmParams
{
VrOutlierFilterParam filterParam; // 滤波参数
VrSlopeParam slopeParam; // 斜坡参数
VrCornerParam cornerParam; // 拐角参数
2025-09-10 00:31:27 +08:00
VrTreeGrowParam growParam; // 增长参数
VrPlaneCalibParam planeCalibParam; // 平面校准参数
2025-09-14 14:51:38 +08:00
VrLapWeldParam lapWeldParam; // 激光焊接参数
2025-09-10 00:31:27 +08:00
};
/**
* @brief
*/
struct ConfigResult
{
std::vector<DeviceInfo> cameraList;
std::vector<DeviceInfo> deviceList;
VrAlgorithmParams algorithmParams; // 算法参数
VrDebugParam debugParam; // 调试参数
SerialConfig serialConfig; // 串口配置
ProjectType projectType; // 项目类型
};
// IVrConfigChangeNotify 已在 VrCommonConfig.h 中定义
2025-09-10 00:31:27 +08:00
/**
* @brief VrConfig接口类
*/
class IVrConfig
{
public:
/**
* @brief
*/
virtual ~IVrConfig() {}
/**
* @brief
* @return
*/
static bool CreateInstance(IVrConfig** ppVrConfig);
/**
* @brief
* @param filePath
* @return
*/
virtual ConfigResult LoadConfig(const std::string& filePath) = 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