260 lines
7.4 KiB
C
Raw 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>
/**
* @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
}
}
struct DeviceInfo
{
std::string name;
std::string ip;
};
/**
* @brief
*/
struct SerialConfig
{
#ifdef _WIN32
std::string portName = "COM6"; // 串口名称
#else
std::string portName = "/dev/ttyS3"; // 串口名称
#endif
int baudRate = 115200; // 波特率
int dataBits = 8; // 数据位
int stopBits = 1; // 停止位
int parity = 0; // 校验位 (0-无校验, 1-奇校验, 2-偶校验)
int flowControl = 0; // 流控制 (0-无, 1-硬件, 2-软件)
bool enabled = true; // 是否启用串口通信
};
/**
* @brief
*/
struct VrOutlierFilterParam
{
double continuityTh = 20.0; // 连续性阈值
int outlierTh = 5; // 离群点判断阈值
};
/**
* @brief
*/
struct VrTreeGrowParam
{
double yDeviation_max = 20.0; // 生长时允许的最大Y偏差
double zDeviation_max = 80.0; // 生长时允许的最大Z偏差
int maxLineSkipNum = 5; // 生长时允许跳过的最大线条数
double maxSkipDistance = 20.0; // 最大跳跃距离
double minLTypeTreeLen = 50.0; // L型树的最小长度
double minVTypeTreeLen = 50.0; // V型树的最小长度
};
/**
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
{
2025-09-14 14:51:38 +08:00
double lapHeight = 2.0;//搭接厚度
double weldMinLen = 2.0; //最小焊缝长度,用于过滤可能的虚假焊缝
int weldRefPoints = 2; //输出的直线焊缝的参考点默认是2个起点和终点
2025-09-10 00:31:27 +08:00
};
/**
* @brief
*/
struct VrCameraPlaneCalibParam
{
int cameraIndex = 1; // 相机索引1-based
std::string cameraName = ""; // 相机名称
double planeCalib[9] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}; // 旋转矩阵,将数据调平(默认单位矩阵)
double planeHeight = -1.0; // 参考平面的高度,用于去除地面数据
double invRMatrix[9] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}; // 逆旋转矩阵,回到原坐标系(默认单位矩阵)
bool isCalibrated = false; // 是否已经校准
};
/**
* @brief
*/
struct VrPlaneCalibParam
{
std::vector<VrCameraPlaneCalibParam> cameraCalibParams; // 各个相机的校准参数
// 获取指定相机的校准参数
VrCameraPlaneCalibParam* GetCameraCalibParam(int cameraIndex) {
for (auto& param : cameraCalibParams) {
if (param.cameraIndex == cameraIndex) {
return &param;
}
}
return nullptr;
}
// 获取指定相机的校准参数const版本
const VrCameraPlaneCalibParam* GetCameraCalibParam(int cameraIndex) const {
for (const auto& param : cameraCalibParams) {
if (param.cameraIndex == cameraIndex) {
return &param;
}
}
return nullptr;
}
// 设置或更新指定相机的校准参数
void SetCameraCalibParam(const VrCameraPlaneCalibParam& param) {
for (auto& existingParam : cameraCalibParams) {
if (existingParam.cameraIndex == param.cameraIndex) {
existingParam = param;
return;
}
}
// 如果不存在,则添加新的
cameraCalibParams.push_back(param);
}
// 移除指定相机的校准参数
void RemoveCameraCalibParam(int cameraIndex) {
cameraCalibParams.erase(
std::remove_if(cameraCalibParams.begin(), cameraCalibParams.end(),
[cameraIndex](const VrCameraPlaneCalibParam& param) {
return param.cameraIndex == cameraIndex;
}),
cameraCalibParams.end());
}
};
/**
* @brief
*/
struct VrDebugParam
{
2025-09-14 14:51:38 +08:00
bool enableDebug = true; // 是否开启调试模式
2025-09-10 00:31:27 +08:00
bool savePointCloud = false; // 是否保存点云数据
bool saveDebugImage = false; // 是否保存调试图像
2025-09-14 14:51:38 +08:00
bool printDetailLog = true; // 是否打印详细日志
2025-09-10 00:31:27 +08:00
std::string debugOutputPath = ""; // 调试输出路径
};
/**
* @brief
*/
struct VrAlgorithmParams
{
VrOutlierFilterParam filterParam; // 滤波参数
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; // 项目类型
};
/**
* @brief
*/
class IVrConfigChangeNotify
{
public:
virtual ~IVrConfigChangeNotify() {}
/**
* @brief
* @param configResult
*/
virtual void OnConfigChanged(const ConfigResult& configResult) = 0;
};
/**
* @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