132 lines
3.3 KiB
C++
132 lines
3.3 KiB
C++
#ifndef HANDEYECALIBWIDGET_H
|
||
#define HANDEYECALIBWIDGET_H
|
||
|
||
#include <QWidget>
|
||
#include <QVector>
|
||
#include <QString>
|
||
#include <QComboBox>
|
||
#include <QLabel>
|
||
#include <QLineEdit>
|
||
#include <QPushButton>
|
||
|
||
/**
|
||
* @brief 手眼标定相机信息
|
||
*/
|
||
struct HandEyeCalibCameraInfo
|
||
{
|
||
int cameraIndex; // 相机索引(1-based)
|
||
QString displayName; // 显示名称
|
||
};
|
||
|
||
/**
|
||
* @brief 单个相机的标定数据缓存
|
||
*/
|
||
struct HandEyeCalibData
|
||
{
|
||
int cameraIndex = 0;
|
||
double matrix[16] = {
|
||
1.0, 0.0, 0.0, 0.0,
|
||
0.0, 1.0, 0.0, 0.0,
|
||
0.0, 0.0, 1.0, 0.0,
|
||
0.0, 0.0, 0.0, 1.0
|
||
};
|
||
bool isCalibrated = false;
|
||
};
|
||
|
||
/**
|
||
* @brief 手眼标定共享控件
|
||
*
|
||
* 纯 QWidget,代码构建 UI(无 .ui 文件),可嵌入任意 tab/layout。
|
||
* 配置无关:不依赖任何 App 的 IVrConfig,只操作原始数据。
|
||
* 自带 INI 解析:用 QSettings 读取 [CalibMatrixInfo_0] section。
|
||
*
|
||
* UI 布局:选择相机 ComboBox → 标定状态 Label → 4x4 矩阵 GridLayout → 加载/保存按钮
|
||
*/
|
||
class HandEyeCalibWidget : public QWidget
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
explicit HandEyeCalibWidget(QWidget *parent = nullptr);
|
||
~HandEyeCalibWidget();
|
||
|
||
/**
|
||
* @brief 设置相机列表
|
||
*/
|
||
void setCameraList(const QVector<HandEyeCalibCameraInfo>& cameras);
|
||
|
||
/**
|
||
* @brief 设置指定相机的标定数据
|
||
*/
|
||
void setCalibData(int cameraIndex, const double matrix[16], bool isCalibrated);
|
||
|
||
/**
|
||
* @brief 获取指定相机的标定数据
|
||
* @return 是否存在该相机的数据
|
||
*/
|
||
bool getCalibData(int cameraIndex, double outMatrix[16], bool& outIsCalibrated) const;
|
||
|
||
/**
|
||
* @brief 获取当前选中的相机索引
|
||
* @return 相机索引,未选择返回 -1
|
||
*/
|
||
int currentCameraIndex() const;
|
||
|
||
/**
|
||
* @brief 设置默认文件打开路径
|
||
*/
|
||
void setDefaultFilePath(const QString& path);
|
||
|
||
/**
|
||
* @brief 设置矩阵是否可编辑
|
||
*/
|
||
void setMatrixEditable(bool editable);
|
||
|
||
signals:
|
||
/**
|
||
* @brief 标定矩阵已从文件加载
|
||
* @param cameraIndex 相机索引
|
||
* @param matrix 16 个 double 的矩阵
|
||
*/
|
||
void calibMatrixLoaded(int cameraIndex, const double* matrix);
|
||
|
||
/**
|
||
* @brief 请求保存标定数据
|
||
* @param cameraIndex 相机索引
|
||
* @param matrix 16 个 double 的矩阵
|
||
*/
|
||
void saveCalibRequested(int cameraIndex, const double* matrix);
|
||
|
||
private slots:
|
||
void onCameraSelectionChanged(int index);
|
||
void onLoadCalibMatrixClicked();
|
||
void onSaveCalibMatrixClicked();
|
||
|
||
private:
|
||
void setupUI();
|
||
void displayMatrix(const double* matrix);
|
||
void clearMatrix();
|
||
void displayIdentityMatrix();
|
||
void updateCalibStatus(bool isCalibrated);
|
||
|
||
// 从矩阵编辑框读取当前矩阵值
|
||
bool readMatrixFromUI(double outMatrix[16]) const;
|
||
|
||
// 查找缓存中指定相机的数据
|
||
HandEyeCalibData* findCalibData(int cameraIndex);
|
||
const HandEyeCalibData* findCalibData(int cameraIndex) const;
|
||
|
||
private:
|
||
QComboBox* m_comboCamera;
|
||
QLabel* m_labelStatus;
|
||
QLineEdit* m_matrixEdits[4][4]; // 4x4 矩阵编辑框
|
||
QPushButton* m_btnLoad;
|
||
QPushButton* m_btnSave;
|
||
|
||
QVector<HandEyeCalibData> m_calibDataCache; // 按相机索引缓存
|
||
QString m_defaultFilePath;
|
||
bool m_matrixEditable;
|
||
};
|
||
|
||
#endif // HANDEYECALIBWIDGET_H
|