238 lines
7.5 KiB
C++
238 lines
7.5 KiB
C++
#ifndef VRCOMMONCONFIG_H
|
||
#define VRCOMMONCONFIG_H
|
||
|
||
#include <string>
|
||
#include <vector>
|
||
#include <algorithm>
|
||
#include <cstring>
|
||
|
||
/**
|
||
* @brief 设备信息结构体(通用版本)
|
||
*
|
||
* 用于描述相机等设备的基本信息
|
||
*/
|
||
struct DeviceInfo
|
||
{
|
||
int index = 0; // 设备序号(1-based,可选)
|
||
std::string name; // 设备名称
|
||
std::string ip; // 设备IP地址
|
||
|
||
// 显式赋值构造函数
|
||
DeviceInfo& operator=(const DeviceInfo& other) {
|
||
if (this != &other) {
|
||
index = other.index;
|
||
name = other.name;
|
||
ip = other.ip;
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
// 显式复制构造函数
|
||
DeviceInfo(const DeviceInfo& other)
|
||
: index(other.index)
|
||
, name(other.name)
|
||
, ip(other.ip) {
|
||
}
|
||
|
||
// 默认构造函数
|
||
DeviceInfo() = default;
|
||
};
|
||
|
||
/**
|
||
* @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; // 是否启用串口通信
|
||
|
||
// 显式赋值构造函数
|
||
SerialConfig& operator=(const SerialConfig& other) {
|
||
if (this != &other) {
|
||
portName = other.portName;
|
||
baudRate = other.baudRate;
|
||
dataBits = other.dataBits;
|
||
stopBits = other.stopBits;
|
||
parity = other.parity;
|
||
flowControl = other.flowControl;
|
||
enabled = other.enabled;
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
// 显式复制构造函数
|
||
SerialConfig(const SerialConfig& other)
|
||
: portName(other.portName)
|
||
, baudRate(other.baudRate)
|
||
, dataBits(other.dataBits)
|
||
, stopBits(other.stopBits)
|
||
, parity(other.parity)
|
||
, flowControl(other.flowControl)
|
||
, enabled(other.enabled) {
|
||
}
|
||
|
||
// 默认构造函数
|
||
SerialConfig() = default;
|
||
};
|
||
|
||
/**
|
||
* @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; // 是否已经校准
|
||
|
||
// 显式赋值构造函数
|
||
VrCameraPlaneCalibParam& operator=(const VrCameraPlaneCalibParam& other) {
|
||
if (this != &other) {
|
||
cameraIndex = other.cameraIndex;
|
||
cameraName = other.cameraName;
|
||
memcpy(planeCalib, other.planeCalib, sizeof(planeCalib));
|
||
planeHeight = other.planeHeight;
|
||
memcpy(invRMatrix, other.invRMatrix, sizeof(invRMatrix));
|
||
isCalibrated = other.isCalibrated;
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
// 显式复制构造函数
|
||
VrCameraPlaneCalibParam(const VrCameraPlaneCalibParam& other)
|
||
: cameraIndex(other.cameraIndex)
|
||
, cameraName(other.cameraName)
|
||
, planeHeight(other.planeHeight)
|
||
, isCalibrated(other.isCalibrated) {
|
||
memcpy(planeCalib, other.planeCalib, sizeof(planeCalib));
|
||
memcpy(invRMatrix, other.invRMatrix, sizeof(invRMatrix));
|
||
}
|
||
|
||
// 默认构造函数
|
||
VrCameraPlaneCalibParam() = default;
|
||
};
|
||
|
||
/**
|
||
* @brief 平面校准参数(支持多相机)
|
||
*/
|
||
struct VrPlaneCalibParam
|
||
{
|
||
std::vector<VrCameraPlaneCalibParam> cameraCalibParams; // 各个相机的校准参数
|
||
|
||
// 获取指定相机的校准参数(C++11兼容方式,返回bool,通过引用参数传出结果)
|
||
// 返回true表示找到该相机的参数,false表示未找到
|
||
bool GetCameraCalibParam(int cameraIndex, VrCameraPlaneCalibParam& outParam) const {
|
||
for (const auto& param : cameraCalibParams) {
|
||
if (param.cameraIndex == cameraIndex) {
|
||
outParam = param; // 返回一个副本
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// 设置或更新指定相机的校准参数
|
||
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());
|
||
}
|
||
|
||
// 显式赋值构造函数
|
||
VrPlaneCalibParam& operator=(const VrPlaneCalibParam& other) {
|
||
if (this != &other) {
|
||
cameraCalibParams = other.cameraCalibParams;
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
// 显式复制构造函数
|
||
VrPlaneCalibParam(const VrPlaneCalibParam& other)
|
||
: cameraCalibParams(other.cameraCalibParams) {
|
||
}
|
||
|
||
// 默认构造函数
|
||
VrPlaneCalibParam() = default;
|
||
};
|
||
|
||
/**
|
||
* @brief 调试参数
|
||
*/
|
||
struct VrDebugParam
|
||
{
|
||
bool enableDebug = true; // 是否开启调试模式
|
||
bool savePointCloud = false; // 是否保存点云数据
|
||
bool saveDebugImage = false; // 是否保存调试图像
|
||
bool printDetailLog = true; // 是否打印详细日志
|
||
std::string debugOutputPath = ""; // 调试输出路径
|
||
|
||
// 显式赋值构造函数
|
||
VrDebugParam& operator=(const VrDebugParam& other) {
|
||
if (this != &other) {
|
||
enableDebug = other.enableDebug;
|
||
savePointCloud = other.savePointCloud;
|
||
saveDebugImage = other.saveDebugImage;
|
||
printDetailLog = other.printDetailLog;
|
||
debugOutputPath = other.debugOutputPath;
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
// 显式复制构造函数
|
||
VrDebugParam(const VrDebugParam& other)
|
||
: enableDebug(other.enableDebug)
|
||
, savePointCloud(other.savePointCloud)
|
||
, saveDebugImage(other.saveDebugImage)
|
||
, printDetailLog(other.printDetailLog)
|
||
, debugOutputPath(other.debugOutputPath) {
|
||
}
|
||
|
||
// 默认构造函数
|
||
VrDebugParam() = default;
|
||
};
|
||
|
||
/**
|
||
* @brief 配置改变通知接口(前向声明ConfigResult)
|
||
*/
|
||
struct ConfigResult;
|
||
|
||
class IVrConfigChangeNotify
|
||
{
|
||
public:
|
||
virtual ~IVrConfigChangeNotify() {}
|
||
|
||
/**
|
||
* @brief 配置数据改变通知
|
||
* @param configResult 新的配置数据
|
||
*/
|
||
virtual void OnConfigChanged(const ConfigResult& configResult) = 0;
|
||
};
|
||
|
||
#endif // VRCOMMONCONFIG_H
|