GrabBag/VrConfig/Inc/IVrConfig.h

264 lines
7.4 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 <string>
#include <vector>
#include <utility>
#include <algorithm>
struct DeviceInfo
{
std::string name;
std::string ip;
};
/**
* @brief 串口配置信息
*/
struct SerialConfig
{
#ifdef _WIN32
std::string portName = "COM8"; // 串口名称
#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 VrBagParam
{
double bagL = 650.0; // 长
double bagW = 450.0; // 宽
double bagH = 160.0; // 高
};
/**
* @brief 垛参数
*/
struct VrPileParam
{
double pileL = 1300.0; // 垛长
double pileW = 900.0; // 垛宽
double pileH = 800.0; // 垛高
};
/**
* @brief 离群点滤波参数
*/
struct VrOutlierFilterParam
{
double continuityTh = 20.0; // 连续性阈值
int outlierTh = 5; // 离群点判断阈值
};
/**
* @brief 角点参数
*/
struct VrCornerParam
{
double minEndingGap = 20.0; // 最小结束间隙
double scale = 15.0; // 计算方向角的窗口比例因子
double cornerTh = 30.0; // 角点阈值
double jumpCornerTh_1 = 60.0; // 判断角点是否为跳跃的第一阈值
double jumpCornerTh_2 = 15.0; // 判断角点是否为跳跃的第二阈值
};
/**
* @brief 斜率参数
*/
struct VrSlopeParam
{
double LSlopeZWin = 10.0; // 计算L型Slope特征高度计算的窗口长度
double validSlopeH = 10.0; // 有效斜率高度
double minLJumpH = 20.0; // 最小L跳跃高度
double minEndingGap = 20.0; // 最小结束间隙
};
/**
* @brief V特征参数
*/
struct VrVFeatureParam
{
double valleyMinH = 10.0; // 山谷最小高度
double valleyMaxW = 80.0; // 山谷最大宽度
};
/**
* @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型树的最小长度
};
/**
* @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
{
bool enableDebug = false; // 是否开启调试模式
bool savePointCloud = false; // 是否保存点云数据
bool saveDebugImage = false; // 是否保存调试图像
bool printDetailLog = false; // 是否打印详细日志
std::string debugOutputPath = ""; // 调试输出路径
};
/**
* @brief 算法参数配置结构
*/
struct VrAlgorithmParams
{
VrBagParam bagParam; // 编织袋参数
VrPileParam pileParam; // 垛参数
VrOutlierFilterParam filterParam; // 滤波参数
VrCornerParam cornerParam; // 角点特征参数
VrSlopeParam slopeParam; // 斜率参数
VrVFeatureParam valleyParam; // 山谷参数
VrTreeGrowParam growParam; // 增长参数
VrPlaneCalibParam planeCalibParam; // 平面校准参数
};
/**
* @brief 配置加载结果
*/
struct ConfigResult
{
std::vector<DeviceInfo> cameraList;
std::vector<DeviceInfo> deviceList;
VrAlgorithmParams algorithmParams; // 算法参数
VrDebugParam debugParam; // 调试参数
SerialConfig serialConfig; // 串口配置
};
/**
* @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