189 lines
5.1 KiB
C
Raw Normal View History

#ifndef IVRCONFIG_H
#define IVRCONFIG_H
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include <QString>
#include "VrCommonConfig.h"
#include "VrHandEyeCalibConfig.h"
// 角点检测参数(砂轮盘孔定位算法仅使用 cornerParam
struct VrCornerParam
{
double minEndingGap = 10.0;
double minEndingGap_z = 5.0;
double scale = 10.0;
double cornerTh = 60.0;
double jumpCornerTh_1 = 15.0;
double jumpCornerTh_2 = 60.0;
};
// DiscHolePose 算法参数:仅 cornerParam因为 sx_getDiscHolePose
// 和 sx_getDiscRackCenterPosition 都只接受 SSG_cornerParam
struct VrAlgorithmParams
{
VrCornerParam cornerParam;
// 多相机平面校准:相机级共享配置
VrPlaneCalibParam planeCalibParam;
};
// 检测对象类型:砂轮盘孔 / 砂轮盘架子
enum DetectionType {
DETECTION_TYPE_DISC_HOLE = 1,
DETECTION_TYPE_DISC_RACK = 2
};
/**
* @brief (, )
*
*
* x = 4 set
*/
struct VrDetectionConfigSet
{
int cameraIndex = 1;
DetectionType detectionType = DETECTION_TYPE_DISC_HOLE;
VrHandEyeCalibMatrix handEyeMatrix;
VrAlgorithmParams algorithmParams;
};
struct ConfigResult
{
std::vector<DeviceInfo> cameraList;
VrDebugParam debugParam;
SerialConfig serialConfig;
uint16_t tcpPort = 7800;
int poseOutputOrder = 0;
int byteOrder = 0;
// 共享算法参数:仅 planeCalibParam 字段在此结构中被使用
VrAlgorithmParams algorithmParams;
// 4 套 (相机, 对象) 配置
std::vector<VrDetectionConfigSet> detectionConfigList;
// —— 辅助查询 ——
const VrDetectionConfigSet* FindDetectionConfig(int cameraIndex, DetectionType type) const
{
for (const auto& item : detectionConfigList) {
if (item.cameraIndex == cameraIndex && item.detectionType == type) {
return &item;
}
}
return nullptr;
}
VrDetectionConfigSet* FindDetectionConfig(int cameraIndex, DetectionType type)
{
for (auto& item : detectionConfigList) {
if (item.cameraIndex == cameraIndex && item.detectionType == type) {
return &item;
}
}
return nullptr;
}
VrDetectionConfigSet& EnsureDetectionConfig(int cameraIndex, DetectionType type)
{
if (auto* p = FindDetectionConfig(cameraIndex, type)) {
return *p;
}
VrDetectionConfigSet item;
item.cameraIndex = cameraIndex;
item.detectionType = type;
item.handEyeMatrix.cameraIndex = cameraIndex;
detectionConfigList.push_back(item);
return detectionConfigList.back();
}
ConfigResult& operator=(const ConfigResult& other)
{
if (this != &other) {
cameraList = other.cameraList;
debugParam = other.debugParam;
serialConfig = other.serialConfig;
tcpPort = other.tcpPort;
poseOutputOrder = other.poseOutputOrder;
byteOrder = other.byteOrder;
algorithmParams = other.algorithmParams;
detectionConfigList = other.detectionConfigList;
}
return *this;
}
ConfigResult(const ConfigResult& other)
: cameraList(other.cameraList)
, debugParam(other.debugParam)
, serialConfig(other.serialConfig)
, tcpPort(other.tcpPort)
, poseOutputOrder(other.poseOutputOrder)
, byteOrder(other.byteOrder)
, algorithmParams(other.algorithmParams)
, detectionConfigList(other.detectionConfigList)
{
}
ConfigResult() = default;
};
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
};
class IVrConfig
{
public:
virtual ~IVrConfig() {}
static bool CreateInstance(IVrConfig** ppVrConfig);
virtual int LoadConfig(const std::string& filePath, ConfigResult& configResult) = 0;
virtual bool SaveConfig(const std::string& filePath, ConfigResult& configResult) = 0;
virtual void SetConfigChangeNotify(IVrConfigChangeNotify* notify) = 0;
};
// ---- 检测输出结构 ----
// 砂轮盘孔输出(来自 sx_getDiscHolePose 返回的 WD_HolePositionInfo
struct DiscHoleDetectOutput {
double x = 0.0;
double y = 0.0;
double z = 0.0;
double roll = 0.0;
double pitch = 0.0;
double yaw = 0.0;
};
// 砂轮盘架子输出(来自 sx_getDiscRackCenterPosition 返回的 SSG_pointPose
struct DiscRackDetectOutput {
double x = 0.0;
double y = 0.0;
double z = 0.0;
double roll = 0.0;
double pitch = 0.0;
double yaw = 0.0;
};
// 统一协议输出
struct ProtocolDetectionOutput {
DetectionType type = DETECTION_TYPE_DISC_HOLE;
bool success = true;
int errorCode = 0;
QString message;
int cameraIndex = 0;
qint64 timestamp = 0;
std::vector<DiscHoleDetectOutput> discHoleOutputs;
std::vector<DiscRackDetectOutput> discRackOutputs;
};
#endif // IVRCONFIG_H