214 lines
5.8 KiB
C
Raw Normal View History

2026-03-28 10:49:55 +08:00
#ifndef IVRCONFIG_H
#define IVRCONFIG_H
#include <cstdint>
2026-03-28 10:49:55 +08:00
#include <iostream>
#include <string>
#include <vector>
#include <QString>
2026-03-28 10:49:55 +08:00
#include "VrCommonConfig.h"
#include "VrHandEyeCalibConfig.h"
2026-03-28 10:49:55 +08:00
struct VrScrewParam
{
double rodDiameter = 10.0;
bool isHorizonScan = true;
2026-03-28 10:49:55 +08:00
};
struct VrCornerParam
{
double minEndingGap = 20.0;
double minEndingGap_z = 5.0;
double scale = 2.5;
2026-05-17 00:38:31 +08:00
double cornerTh = 30.0;
2026-03-28 10:49:55 +08:00
double jumpCornerTh_1 = 15.0;
double jumpCornerTh_2 = 60.0;
};
struct VrOutlierFilterParam
{
double continuityTh = 20.0;
double outlierTh = 5.0;
2026-03-28 10:49:55 +08:00
};
struct VrTreeGrowParam
{
2026-05-17 00:38:31 +08:00
double yDeviation_max = 5.0;
2026-03-28 10:49:55 +08:00
double zDeviation_max = 50.0;
int maxLineSkipNum = 10;
2026-05-17 00:38:31 +08:00
double maxSkipDistance = 30.0;
double minLTypeTreeLen = 50.0;
double minVTypeTreeLen = 50.0;
2026-03-28 10:49:55 +08:00
};
struct VrAlgorithmParams
{
VrScrewParam screwParam;
VrCornerParam cornerParam;
VrOutlierFilterParam filterParam;
VrTreeGrowParam growParam;
// 多相机平面校准:在 ScrewPosition 中作为「相机级」共享配置,
// 不随检测对象切换,因此不属于 VrDetectionConfigSet。
2026-03-28 10:49:55 +08:00
VrPlaneCalibParam planeCalibParam;
};
// 检测对象类型:螺杆 / 工具盘
enum DetectionType {
DETECTION_TYPE_SCREW = 1,
DETECTION_TYPE_TOOL_DISK = 2
};
/**
* @brief (, )
*
*
* × = 4 set
*
* handEyeMatrix.cameraIndex cameraIndex
* algorithmParams.planeCalibParam 使
* ConfigResult::algorithmParams.planeCalibParam
*/
struct VrDetectionConfigSet
{
int cameraIndex = 1;
DetectionType detectionType = DETECTION_TYPE_SCREW;
VrHandEyeCalibMatrix handEyeMatrix;
VrAlgorithmParams algorithmParams;
};
2026-03-28 10:49:55 +08:00
struct ConfigResult
{
std::vector<DeviceInfo> cameraList;
VrDebugParam debugParam;
SerialConfig serialConfig;
uint16_t tcpPort = 7800;
2026-04-17 10:18:03 +08:00
int poseOutputOrder = 0;
int byteOrder = 0;
// 共享算法参数:仅 planeCalibParam 字段在此结构中被使用,
// 其余 (screw/corner/filter/grow) 字段保留以兼容 BaseConfigManager 头文件中的
// GetAlgorithmParams()/UpdateAlgorithmParams() 接口,对 ScrewPosition 实际无效。
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;
}
// 确保存在某 (camera, type) 槽位,不存在则插入默认值
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)
{
2026-03-28 10:49:55 +08:00
if (this != &other) {
cameraList = other.cameraList;
debugParam = other.debugParam;
serialConfig = other.serialConfig;
tcpPort = other.tcpPort;
2026-04-17 10:18:03 +08:00
poseOutputOrder = other.poseOutputOrder;
byteOrder = other.byteOrder;
2026-03-28 10:49:55 +08:00
algorithmParams = other.algorithmParams;
detectionConfigList = other.detectionConfigList;
2026-03-28 10:49:55 +08:00
}
return *this;
}
ConfigResult(const ConfigResult& other)
: cameraList(other.cameraList)
, debugParam(other.debugParam)
, serialConfig(other.serialConfig)
, tcpPort(other.tcpPort)
2026-04-17 10:18:03 +08:00
, poseOutputOrder(other.poseOutputOrder)
, byteOrder(other.byteOrder)
, algorithmParams(other.algorithmParams)
, detectionConfigList(other.detectionConfigList)
{
2026-03-28 10:49:55 +08:00
}
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
2026-03-28 10:49:55 +08:00
};
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;
};
struct ScrewDetectOutput {
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 ToolDiskDetectOutput {
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_SCREW;
bool success = true;
int errorCode = 0;
QString message;
int cameraIndex = 0;
qint64 timestamp = 0;
std::vector<ScrewDetectOutput> screwOutputs;
std::vector<ToolDiskDetectOutput> toolDiskOutputs;
};
2026-03-28 10:49:55 +08:00
#endif // IVRCONFIG_H