214 lines
5.8 KiB
C++
214 lines
5.8 KiB
C++
#ifndef IVRCONFIG_H
|
||
#define IVRCONFIG_H
|
||
|
||
#include <cstdint>
|
||
#include <iostream>
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
#include <QString>
|
||
|
||
#include "VrCommonConfig.h"
|
||
#include "VrHandEyeCalibConfig.h"
|
||
|
||
struct VrScrewParam
|
||
{
|
||
double rodDiameter = 10.0;
|
||
bool isHorizonScan = true;
|
||
};
|
||
|
||
struct VrCornerParam
|
||
{
|
||
double minEndingGap = 20.0;
|
||
double minEndingGap_z = 5.0;
|
||
double scale = 2.5;
|
||
double cornerTh = 30.0;
|
||
double jumpCornerTh_1 = 15.0;
|
||
double jumpCornerTh_2 = 60.0;
|
||
};
|
||
|
||
struct VrOutlierFilterParam
|
||
{
|
||
double continuityTh = 20.0;
|
||
double outlierTh = 5.0;
|
||
};
|
||
|
||
struct VrTreeGrowParam
|
||
{
|
||
double yDeviation_max = 5.0;
|
||
double zDeviation_max = 50.0;
|
||
int maxLineSkipNum = 10;
|
||
double maxSkipDistance = 30.0;
|
||
double minLTypeTreeLen = 50.0;
|
||
double minVTypeTreeLen = 50.0;
|
||
};
|
||
|
||
struct VrAlgorithmParams
|
||
{
|
||
VrScrewParam screwParam;
|
||
VrCornerParam cornerParam;
|
||
VrOutlierFilterParam filterParam;
|
||
VrTreeGrowParam growParam;
|
||
// 多相机平面校准:在 ScrewPosition 中作为「相机级」共享配置,
|
||
// 不随检测对象切换,因此不属于 VrDetectionConfigSet。
|
||
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;
|
||
};
|
||
|
||
struct ConfigResult
|
||
{
|
||
std::vector<DeviceInfo> cameraList;
|
||
VrDebugParam debugParam;
|
||
SerialConfig serialConfig;
|
||
uint16_t tcpPort = 7800;
|
||
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)
|
||
{
|
||
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;
|
||
};
|
||
|
||
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;
|
||
};
|
||
|
||
#endif // IVRCONFIG_H
|