2025-11-08 00:28:59 +08:00
|
|
|
|
#ifndef IVISIONAPPLICATIONSTATUS_H
|
|
|
|
|
|
#define IVISIONAPPLICATIONSTATUS_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <QImage>
|
|
|
|
|
|
#include <QMetaType>
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 工作状态枚举
|
|
|
|
|
|
*
|
|
|
|
|
|
* 定义视觉检测应用的通用工作状态
|
|
|
|
|
|
*/
|
|
|
|
|
|
enum class WorkStatus {
|
|
|
|
|
|
InitIng, // 初始化中
|
|
|
|
|
|
Ready, // 准备就绪
|
|
|
|
|
|
Working, // 正在工作
|
2025-11-26 22:44:38 +08:00
|
|
|
|
Detecting, // 正在检测
|
2025-11-08 00:28:59 +08:00
|
|
|
|
Completed, // 监测完成
|
|
|
|
|
|
Error // 设备异常
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 工作状态转换为字符串的工具函数
|
|
|
|
|
|
* @param status 工作状态
|
|
|
|
|
|
* @return 状态的中文描述
|
|
|
|
|
|
*/
|
|
|
|
|
|
inline std::string WorkStatusToString(WorkStatus status) {
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
|
case WorkStatus::InitIng: return "初始化中";
|
|
|
|
|
|
case WorkStatus::Ready: return "准备就绪";
|
|
|
|
|
|
case WorkStatus::Working: return "正在工作";
|
2025-11-26 22:44:38 +08:00
|
|
|
|
case WorkStatus::Detecting: return "正在检测";
|
2025-11-08 00:28:59 +08:00
|
|
|
|
case WorkStatus::Completed: return "检测完成";
|
|
|
|
|
|
case WorkStatus::Error: return "设备异常";
|
|
|
|
|
|
default: return "未知状态";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 通用坐标结构体模板
|
|
|
|
|
|
*
|
|
|
|
|
|
* @tparam T 坐标数据类型(通常为 double)
|
|
|
|
|
|
*
|
|
|
|
|
|
* 用法示例:
|
|
|
|
|
|
* @code
|
|
|
|
|
|
* using GrabBagPosition = PositionData<double>;
|
|
|
|
|
|
* using LapWeldPosition = PositionData<double>;
|
|
|
|
|
|
* @endcode
|
|
|
|
|
|
*/
|
|
|
|
|
|
template<typename T = double>
|
|
|
|
|
|
struct PositionData {
|
|
|
|
|
|
T x;
|
|
|
|
|
|
T y;
|
|
|
|
|
|
T z;
|
|
|
|
|
|
T roll;
|
|
|
|
|
|
T pitch;
|
|
|
|
|
|
T yaw;
|
|
|
|
|
|
|
|
|
|
|
|
// 默认构造函数
|
|
|
|
|
|
PositionData() : x(0), y(0), z(0), roll(0), pitch(0), yaw(0) {}
|
|
|
|
|
|
|
|
|
|
|
|
// 带参构造函数
|
|
|
|
|
|
PositionData(T _x, T _y, T _z, T _roll, T _pitch, T _yaw)
|
|
|
|
|
|
: x(_x), y(_y), z(_z), roll(_roll), pitch(_pitch), yaw(_yaw) {}
|
|
|
|
|
|
|
|
|
|
|
|
// 拷贝构造函数和赋值运算符
|
|
|
|
|
|
PositionData(const PositionData&) = default;
|
|
|
|
|
|
PositionData& operator=(const PositionData&) = default;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 常用的坐标类型别名
|
|
|
|
|
|
using VisionPosition = PositionData<double>;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 检测结果结构体模板
|
|
|
|
|
|
*
|
|
|
|
|
|
* @tparam PositionType 位置数据类型(如 GrabBagPosition, LapWeldPosition 等)
|
|
|
|
|
|
*
|
|
|
|
|
|
* 用法示例:
|
|
|
|
|
|
* @code
|
|
|
|
|
|
* using GrabBagDetectionResult = DetectionResultData<GrabBagPosition>;
|
|
|
|
|
|
* using LapWeldDetectionResult = DetectionResultData<LapWeldPosition>;
|
|
|
|
|
|
* @endcode
|
|
|
|
|
|
*/
|
|
|
|
|
|
template<typename PositionType>
|
|
|
|
|
|
struct DetectionResultData {
|
|
|
|
|
|
QImage image;
|
|
|
|
|
|
std::vector<PositionType> positions;
|
|
|
|
|
|
int cameraIndex = 1; // 相机索引,默认为1(第一个相机)
|
|
|
|
|
|
|
|
|
|
|
|
// 默认构造函数
|
|
|
|
|
|
DetectionResultData() = default;
|
|
|
|
|
|
|
|
|
|
|
|
// 拷贝构造函数和赋值运算符
|
|
|
|
|
|
DetectionResultData(const DetectionResultData&) = default;
|
|
|
|
|
|
DetectionResultData& operator=(const DetectionResultData&) = default;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 常用的检测结果类型别名
|
|
|
|
|
|
using VisionDetectionResult = DetectionResultData<VisionPosition>;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 视觉应用状态回调接口模板
|
|
|
|
|
|
*
|
|
|
|
|
|
* @tparam DetectionResultType 检测结果类型(如 DetectionResultData<GrabBagPosition>)
|
|
|
|
|
|
*
|
|
|
|
|
|
* 该接口定义了视觉检测应用的通用回调方法
|
|
|
|
|
|
* 各个具体应用应该继承此接口并实现这些方法
|
|
|
|
|
|
*
|
|
|
|
|
|
* 用法示例:
|
|
|
|
|
|
* @code
|
|
|
|
|
|
* class IYGrabBagStatus : public IVisionApplicationStatus<DetectionResultData<GrabBagPosition>> {
|
|
|
|
|
|
* public:
|
|
|
|
|
|
* // 实现所有虚函数...
|
|
|
|
|
|
* };
|
|
|
|
|
|
* @endcode
|
|
|
|
|
|
*/
|
|
|
|
|
|
template<typename DetectionResultType>
|
|
|
|
|
|
class IVisionApplicationStatus
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
virtual ~IVisionApplicationStatus() = default;
|
|
|
|
|
|
|
|
|
|
|
|
// 状态文字回调
|
|
|
|
|
|
virtual void OnStatusUpdate(const std::string& statusMessage) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// 算法监测结果回调
|
|
|
|
|
|
virtual void OnDetectionResult(const DetectionResultType& result) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// 相机状态回调
|
|
|
|
|
|
virtual void OnCamera1StatusChanged(bool isConnected) = 0;
|
|
|
|
|
|
virtual void OnCamera2StatusChanged(bool isConnected) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// 机械臂连接状态回调
|
|
|
|
|
|
virtual void OnRobotConnectionChanged(bool isConnected) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// 串口连接状态回调
|
|
|
|
|
|
virtual void OnSerialConnectionChanged(bool isConnected) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// 相机个数回调
|
|
|
|
|
|
virtual void OnCameraCountChanged(int cameraCount) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// 工作状态回调
|
|
|
|
|
|
virtual void OnWorkStatusChanged(WorkStatus status) = 0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 为常用类型注册Qt元类型(使其能够在信号槽中传递)
|
|
|
|
|
|
// 注意:各应用仍需在自己的代码中调用 qRegisterMetaType 注册自定义的Position类型
|
|
|
|
|
|
|
|
|
|
|
|
// 声明Qt元类型
|
|
|
|
|
|
Q_DECLARE_METATYPE(WorkStatus)
|
|
|
|
|
|
Q_DECLARE_METATYPE(VisionPosition)
|
|
|
|
|
|
Q_DECLARE_METATYPE(VisionDetectionResult)
|
|
|
|
|
|
|
|
|
|
|
|
#endif // IVISIONAPPLICATIONSTATUS_H
|