23 Commits

Author SHA1 Message Date
8329c00165 add,计划采集11:
1、完善定时采集流程信息统计:时间;
2、添加状态:跳过;
2026-06-12 10:37:54 +08:00
f69edcf2c9 add,计划采集10:
解决偶发单反唤起失败问题;

任务文件要求:
1、高光谱必须在前面,没有顺序要求,因为在执行高光谱任务前会预热卤素灯,所有高光谱任务完成后才关闭卤素灯;
2、单反/深度必须在后面,没有顺序要求;
3、必须要有高光谱任务:单反存在唤醒程序和一定反应时间,所以必须依赖前一个任务进行唤醒;
 (1)当单反已经是唤醒状态时,重新上电(先下电后上电)后可马上重新唤醒单反:单反适配器剩余电量马上耗尽,所以才能马上重新唤醒单反;
 (2)当单反在上电的状态下,从唤醒状态自动进入休眠状态时,重新下电后需要等待2分15秒(135秒)后,再重新上电才能唤醒单反:等待135秒的目的是将适配器中电容的剩余电量耗尽;
2026-06-11 15:27:02 +08:00
509f4b0767 add,计划采集9:
基本计划采集功能:采集流程电源通断控制ok
2026-06-10 18:10:47 +08:00
4a62d9a007 add,计划采集8:
实现部分计划采集功能:电源通断控制
2026-06-09 11:08:02 +08:00
467bebe9dd add,计划采集7:
实现部分计划采集功能:定时任务可完整执行
2026-06-05 11:36:38 +08:00
41a1a938b9 add,计划采集6:
实现部分计划采集功能:定时任务可控制单反
2026-06-04 18:01:22 +08:00
3607913f13 add,计划采集5:
实现部分计划采集功能:
2026-06-04 16:41:51 +08:00
a8760652bd add,计划采集3:
实现部分计划采集功能
2026-06-03 15:04:03 +08:00
3521a7f225 add,计划采集2:
添加计划任务的数据结构,并实现读写数据结构
2026-06-02 18:00:01 +08:00
6111634eff add,计划采集1:
添加窗口
2026-06-02 14:38:56 +08:00
4d42314a84 修改:
分离TwoMotionCaptureCoordinator和ImagerOperationBase
2026-06-01 17:10:37 +08:00
6456232114 add,单反相机
1、分离功能:单反相机的实时视频流和拍照;
2、将视频流和拍照功能状态反馈到界面上,并做简单控制;
2026-05-28 13:51:15 +08:00
525b39851a 配置release 2026-05-28 10:49:15 +08:00
5f965f0d8e fix
兼容2种帧数显示逻辑:(1)采集时的实时帧数(2)打开影像时的帧数;
2026-05-28 09:27:25 +08:00
3568495aa9 add:
深度相机:改变数据保存路径;
2026-05-27 22:58:41 +08:00
410da482bc 采集过程中禁用图层树的选择功能 2026-05-27 22:37:54 +08:00
43acd5ba01 fix:
1、采集时,创建RasterImageLayer时,dataprovider延迟初始化;
2、采集时,不通过渲染器渲染;
2026-05-27 17:42:14 +08:00
5dc589aee0 add,单反相机2:
1、实现3s拍照;
2、设置照片保存路径;
3、轮播看板:显示单反实时视频流;
2026-05-27 16:03:16 +08:00
e8ae6aa3b9 add
单反相机:实现1s拍照,并将照片传回控制电脑
2026-05-26 14:54:50 +08:00
304a1aa28b add
添加场景:3D植物表型,只涉及了部分界面
2026-05-26 14:04:21 +08:00
b2ed6e9c73 add
1、修改渲染参数:拉伸最大值;
2、toc添加数据管理功能:同步渲染参数到右下角“图像控制”面板;
2026-05-25 13:48:31 +08:00
dcce0a6665 toc添加数据管理功能 2026-05-22 16:21:41 +08:00
eda0a01098 add
1、添加layerTree节点类型:image,然后修改LayerTreeLayer,继承LayerTreeGroup。
2026-05-11 11:13:21 +08:00
61 changed files with 4922 additions and 535 deletions

View File

@ -1,10 +1,13 @@
#include "AppSettings.h"
#include <QCoreApplication>
const QString AppSettings::kDefaultDataFolder = QStringLiteral("C:\\HPPA_image");
const QString AppSettings::kDefaultFileName = QStringLiteral("test_image");
const int AppSettings::kDefaultFrameRate = 20;
const int AppSettings::kDefaultIntegrationTime = 1;
const int AppSettings::kDefaultGain = 0;
const QString AppSettings::kDefaultSLRDataFolder = QString();
const QString AppSettings::kDefaultDepthCameraDataFolder = QString();
AppSettings::AppSettings()
: m_settings(QSettings::IniFormat, QSettings::UserScope,
@ -32,6 +35,7 @@ QString AppSettings::fileName() const
{
return m_settings.value("General/FileName", kDefaultFileName).toString();
}
void AppSettings::setFileName(const QString& path)
{
m_settings.setValue("General/FileName", path);
@ -41,6 +45,7 @@ int AppSettings::frameRate() const
{
return m_settings.value("CameraParams/FrameRate", kDefaultFrameRate).toInt();
}
void AppSettings::setFrameRate(int value)
{
m_settings.setValue("CameraParams/FrameRate", value);
@ -50,6 +55,7 @@ int AppSettings::integrationTime() const
{
return m_settings.value("CameraParams/IntegrationTime", kDefaultIntegrationTime).toInt();
}
void AppSettings::setIntegrationTime(int value)
{
m_settings.setValue("CameraParams/IntegrationTime", value);
@ -59,7 +65,38 @@ int AppSettings::gain() const
{
return m_settings.value("CameraParams/Gain", kDefaultGain).toInt();
}
void AppSettings::setGain(int value)
{
m_settings.setValue("CameraParams/Gain", value);
}
QString AppSettings::slrDataFolder() const
{
QString path = m_settings.value("General/SLRDataFolder").toString();
if (path.isEmpty())
{
return QCoreApplication::applicationDirPath() + "/CapturedImages/";
}
return path;
}
void AppSettings::setSlrDataFolder(const QString& path)
{
m_settings.setValue("General/SLRDataFolder", path);
}
QString AppSettings::depthCameraDataFolder() const
{
QString path = m_settings.value("General/DepthCameraDataFolder").toString();
if (path.isEmpty())
{
return QCoreApplication::applicationDirPath() + "/CapturedDepthImages/";
}
return path;
}
void AppSettings::setDepthCameraDataFolder(const QString& path)
{
m_settings.setValue("General/DepthCameraDataFolder", path);
}

View File

@ -26,6 +26,14 @@ public:
// 增益
int gain() const;
void setGain(int value);
// 单反相机数据保存路径
QString slrDataFolder() const;
void setSlrDataFolder(const QString& path);
// 深度相机数据保存路径
QString depthCameraDataFolder() const;
void setDepthCameraDataFolder(const QString& path);
// 在此处添加更多参数的 getter/setter ...
private:
@ -41,4 +49,6 @@ private:
static const int kDefaultFrameRate;
static const int kDefaultIntegrationTime;
static const int kDefaultGain;
static const QString kDefaultSLRDataFolder;
static const QString kDefaultDepthCameraDataFolder;
};

View File

@ -2,12 +2,11 @@
TwoMotionCaptureCoordinator::TwoMotionCaptureCoordinator(
IrisMultiMotorController* motorCtrl,
ImagerOperationBase* cameraCtrl,
QObject* parent)
: QObject(parent)
, m_motorCtrl(motorCtrl)
, m_cameraCtrl(cameraCtrl)
, m_isRunning(false)
, m_isValidCapturing(false)
{
//这些信号槽是按照逻辑顺序的
connect(this, SIGNAL(moveTo(int, double, double, int)),
@ -20,35 +19,6 @@ TwoMotionCaptureCoordinator::TwoMotionCaptureCoordinator(
this, &TwoMotionCaptureCoordinator::handlePositionReached);
//connect(m_motorCtrl, &IrisMultiMotorController::moveFailed,
// this, &TwoMotionCaptureCoordinator::handleError);
connect(this, &TwoMotionCaptureCoordinator::startRecordHSISignal,
m_cameraCtrl, &ImagerOperationBase::start_record);
connect(this, &TwoMotionCaptureCoordinator::stopRecordHSISignal,
m_cameraCtrl, &ImagerOperationBase::stop_record);
connect(m_cameraCtrl, &ImagerOperationBase::RecordFinishedSignal_WhenFrameNumberMeet,
this, &TwoMotionCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet);
//connect(m_cameraCtrl, &ImagerOperationBase::RecordFinishedSignal_WhenFrameNumberNotMeet,
// this, &TwoMotionCaptureCoordinator::handleCaptureCompleteWhenFrameNumberNotMeet);
//connect(m_cameraCtrl, &ImagerOperationBase::captureFailed,
// this, &TwoMotionCaptureCoordinator::handleError);
}
TwoMotionCaptureCoordinator::TwoMotionCaptureCoordinator(
IrisMultiMotorController* motorCtrl,
QObject* parent)
: QObject(parent)
, m_motorCtrl(motorCtrl)
, m_isRunning(false)
{
connect(this, SIGNAL(moveTo(int, double, double, int)),
m_motorCtrl, SLOT(moveTo(int, double, double, int)));
connect(this, SIGNAL(moveTo(const std::vector<double>, const std::vector<double>, int)),
m_motorCtrl, SLOT(moveTo(const std::vector<double>, const std::vector<double>, int)));
connect(m_motorCtrl, &IrisMultiMotorController::motorStopSignal,
this, &TwoMotionCaptureCoordinator::handlePositionReached);
//connect(m_motorCtrl, &IrisMultiMotorController::moveFailed,
// this, &TwoMotionCaptureCoordinator::handleError);
}
TwoMotionCaptureCoordinator::~TwoMotionCaptureCoordinator()
@ -98,11 +68,7 @@ void TwoMotionCaptureCoordinator::stop()
savePathLinesToCsv();
emit finishRecordLineNumSignal(m_numCurrentPathLine);
//emit stopRecordHSISignal(m_numCurrentPathLine);
if (m_cameraCtrl != nullptr)
{
m_cameraCtrl->stop_record();
}
emit stopRecordHSISignal(m_numCurrentPathLine);
move2LocBeforeStart();
@ -121,6 +87,7 @@ void TwoMotionCaptureCoordinator::getLocBeforeStart()
QMetaObject::Connection conn = QObject::connect(m_motorCtrl, &IrisMultiMotorController::locationSignal,
[&](std::vector<double> pos) {
m_locBeforeStart = pos;
std::cout << "start pos: "<< pos[0] <<", " << pos[1] << std::endl;
received = true;
loop.quit();
});
@ -148,7 +115,7 @@ void TwoMotionCaptureCoordinator::move2LocBeforeStart()
speed.push_back(tmp.speedTargetYPosition);
emit moveTo(m_locBeforeStart, speed, 1000);
m_isRunning = false;
m_isValidCapturing = false;
m_isMoving2XMin = false;
m_isMoving2XMax = false;
@ -230,12 +197,12 @@ void TwoMotionCaptureCoordinator::handlePositionReached(int motorID, double pos)
//QMutexLocker locker(&m_dataMutex);
PathLine &tmp = m_pathLines[m_numCurrentPathLine];
if (motorID == 1)//y马达
{
if (m_isMoving2YTargeLoc)
{
PathLine& tmp = m_pathLines[m_numCurrentPathLine];
double threshold = getThre(tmp.targetYPosition, pos);
if (threshold > 5)
@ -265,6 +232,7 @@ void TwoMotionCaptureCoordinator::handlePositionReached(int motorID, double pos)
if (m_isMoving2YStartLoc)
{
m_isMoving2YStartLoc = false;
isBack2Origin();
return;
}
@ -273,6 +241,8 @@ void TwoMotionCaptureCoordinator::handlePositionReached(int motorID, double pos)
{
if (m_isMoving2XMin)
{
PathLine& tmp = m_pathLines[m_numCurrentPathLine];
double threshold = getThre(tmp.targetXMinPosition, pos);
if (threshold > 5)
@ -301,6 +271,8 @@ void TwoMotionCaptureCoordinator::handlePositionReached(int motorID, double pos)
if (m_isMoving2XMax)
{
PathLine& tmp = m_pathLines[m_numCurrentPathLine];
double threshold = getThre(tmp.targetXMaxPosition, pos);
if (threshold > 5 && !m_isImagerFrameNumberMeet)//马达没到准确位置 && 【非】光谱仪因帧数限制主动停止采集
@ -324,11 +296,7 @@ void TwoMotionCaptureCoordinator::handlePositionReached(int motorID, double pos)
//停止采集高光谱数据
emit finishRecordLineNumSignal(m_numCurrentPathLine);
//emit stopRecordHSISignal(m_numCurrentPathLine);
if (m_cameraCtrl!=nullptr)
{
m_cameraCtrl->stop_record();
}
emit stopRecordHSISignal(m_numCurrentPathLine);
m_isMoving2XMax = false;
m_isImagerFrameNumberMeet = false;
@ -341,6 +309,7 @@ void TwoMotionCaptureCoordinator::handlePositionReached(int motorID, double pos)
if (m_isMoving2XStartLoc)
{
m_isMoving2XStartLoc = false;
isBack2Origin();
return;
}
@ -380,9 +349,25 @@ void TwoMotionCaptureCoordinator::startRecordHsi()
emit moveTo(0, tmp.targetXMaxPosition, tmp.speedTargetXMaxPosition, 1000);
emit startRecordHSISignal(m_numCurrentPathLine);
emit startRecordLineNumSignal(m_numCurrentPathLine);
}
}
void TwoMotionCaptureCoordinator::isBack2Origin()
{
if (!m_isRunning) return;
//QMutexLocker locker(&m_dataMutex);
if (!m_isMoving2XStartLoc && !m_isMoving2YStartLoc)
{
m_isRunning = false;
emit back2OriginSignal();
}
}
void TwoMotionCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet()
{
m_isImagerFrameNumberMeet = true;
@ -426,7 +411,8 @@ void TwoMotionCaptureCoordinator::processNextPathLine()
}
std::cout << "\nNew path line: " << m_numCurrentPathLine << std::endl;
emit startRecordLineNumSignal(m_numCurrentPathLine);
emit gotoRecordLineNumSignal(m_numCurrentPathLine);
m_isValidCapturing = true;
PathLine &tmp = m_pathLines[m_numCurrentPathLine];
tmp.timestamp1 = QDateTime::currentDateTime();

View File

@ -38,9 +38,6 @@ class TwoMotionCaptureCoordinator : public QObject
{
Q_OBJECT
public:
TwoMotionCaptureCoordinator(IrisMultiMotorController* motorCtrl,
ImagerOperationBase* cameraCtrl,
QObject* parent = nullptr);
TwoMotionCaptureCoordinator(IrisMultiMotorController* motorCtrl,
QObject* parent = nullptr);
~TwoMotionCaptureCoordinator();
@ -49,6 +46,8 @@ public:
signals:
void sequenceComplete(int);//0所有采集线正常运行完成1用户主动取消采集
void back2OriginSignal();
void gotoRecordLineNumSignal(int lineNum);
void startRecordLineNumSignal(int lineNum);
void finishRecordLineNumSignal(int lineNum);
@ -62,13 +61,15 @@ signals:
void recordState(bool state);
public slots:
void handleCaptureCompleteWhenFrameNumberMeet();
private slots:
void start(QVector<PathLine> pathLines);
void stop();
void getRecordState();
void handlePositionReached(int motorID, double pos);
void handleCaptureCompleteWhenFrameNumberMeet();
void handleError(const QString& error);
void move2LocBeforeStart();
@ -76,6 +77,7 @@ private slots:
private:
void processNextPathLine();
void startRecordHsi();
void isBack2Origin();
void getLocBeforeStart();
double getThre(double targetLoc, double actualLoc);
@ -88,6 +90,7 @@ private:
mutable QMutex m_dataMutex;
bool m_isRunning;
bool m_isValidCapturing;
bool m_isMoving2YTargeLoc;
bool m_isMoving2XMin;
bool m_isMoving2XMax;

View File

@ -0,0 +1,14 @@
#include "CommunicationInterfaceBase.h"
using namespace MotorParams;
CommunicationInterfaceBase::CommunicationInterfaceBase(QObject* parent)
:QObject(parent)
{
}
CommunicationInterfaceBase::~CommunicationInterfaceBase()
{
}

View File

@ -0,0 +1,36 @@
#pragma once
#include <QObject>
#include <QString>
#include "motorParams.h"
namespace MotorParams {
struct TCPConnectionParams
{
QString serverIP;
int port;
};
class CommunicationInterfaceBase :public QObject
{
Q_OBJECT
public:
CommunicationInterfaceBase(QObject* parent = nullptr);
~CommunicationInterfaceBase();
virtual bool connect2Motor() = 0;
//virtual void disconnect() = 0;
//virtual bool isConnected() const = 0;
virtual int sendCommand(const QString command) = 0;
//virtual void sendCommandAsync(const QString& command) = 0;
virtual int recvData(QByteArray& dataRecv) = 0;
signals:
void dataReceived(const QByteArray& data);
void connected(); // <20><><EFBFBD>ܴ<EFBFBD><DCB4>ڻ<EFBFBD><DABB><EFBFBD>TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B7A2><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
void disconnected();
void errorOccurred(QString msg);
};
} // namespace MotorParams

View File

@ -0,0 +1,95 @@
#include "CommunicationViaTCP.h"
using namespace MotorParams;
CommunicationViaTCP::CommunicationViaTCP(MotorParams::TCPConnectionParams connectionParams, QObject* parent)
:MotorParams::CommunicationInterfaceBase(parent)
{
m_bConnected = false;
m_tcpServer = new QTcpServer(this);
connect(m_tcpServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
m_tcpServer->listen(QHostAddress::Any, connectionParams.port);
}
CommunicationViaTCP::~CommunicationViaTCP()
{
m_tcpServer->close();
delete m_tcpServer;
//这两行代码要报错,为啥呢?????????????????
//m_tcpSocket->disconnectFromHost();
//delete m_tcpSocket;
}
bool CommunicationViaTCP::connect2Motor()
{
return true;
}
void CommunicationViaTCP::onNewConnection()
{
m_bConnected = true;
m_tcpSocket = m_tcpServer->nextPendingConnection();
connect(m_tcpSocket, SIGNAL(disconnected()), this, SLOT(onTcpSocketDisconnected()));
emit connected();
}
bool CommunicationViaTCP::isConnected() const
{
return m_bConnected;
}
//从拔掉客户端的电源客户端m_tcpSocket断开连接到这个函数被调用有延迟所以这个函数调用也有延迟导致拔掉电源后的一小段时间函数isConnected()还是返回true
void CommunicationViaTCP::onTcpSocketDisconnected()
{
int a = 1;
m_bConnected = false;
m_tcpSocket->deleteLater();
}
int CommunicationViaTCP::sendCommand(const QString cmd)
{
if (!isConnected()) {
QString error = "No client connected";
emit commandSendResult(-1, error);
qWarning() << error << "command:" << cmd;
return -1;
}
qint64 bytesWritten = m_tcpSocket->write(cmd.toUtf8().data());
m_tcpSocket->waitForBytesWritten(50);
return bytesWritten;
}
int CommunicationViaTCP::recvData(QByteArray& dataRecv)
{
if (!isConnected()) {
QString error = "No client connected";
return -1;
}
dataRecv.clear();
QByteArray temp;
temp = m_tcpSocket->readAll();
dataRecv.append(temp);
int counter = 0;
while (dataRecv.size() < 21)
{
counter++;
m_tcpSocket->waitForReadyRead(100);
temp = m_tcpSocket->readAll();
dataRecv.append(temp);
if (counter >= 5)
break;
}
//qDebug() << "Hex:" << dataRecv.toHex();
return dataRecv.size();
}

View File

@ -0,0 +1,45 @@
#pragma once
#include <QObject>
#include <QThread>
#include <QDebug>
#include <QTcpServer>
#include <QTcpSocket>
#include "CommunicationInterfaceBase.h"
namespace MotorParams {
class CommunicationViaTCP :
public CommunicationInterfaceBase
{
Q_OBJECT
public:
CommunicationViaTCP(TCPConnectionParams connectionParams, QObject* parent = nullptr);
~CommunicationViaTCP();
//继承基类
bool connect2Motor();
//void disconnect();
//bool isConnected() const;
int sendCommand(const QString cmd);
//void sendCommandAsync(const QString& command);
int recvData(QByteArray& dataRecv);
private:
QTcpServer* m_tcpServer;
QTcpSocket* m_tcpSocket;
int m_iCommunicationProtocol;
bool m_bConnected;
bool isConnected() const;
public Q_SLOTS:
void onNewConnection();
void onTcpSocketDisconnected();
signals:
void commandSendResult(int bytesWritten, const QString& error = QString());
};
}

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>416</width>
<height>219</height>
<width>857</width>
<height>477</height>
</rect>
</property>
<property name="sizePolicy">
@ -83,19 +83,6 @@ QPushButton:pressed
</property>
</spacer>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>135</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
@ -126,7 +113,20 @@ QPushButton:pressed
</item>
</layout>
</item>
<item row="1" column="2">
<item row="2" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>135</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -139,7 +139,52 @@ QPushButton:pressed
</property>
</spacer>
</item>
<item row="2" column="1">
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="styleSheet">
<string notr="true">QLabel {
color: rgb(255, 255, 255);
}</string>
</property>
<property name="text">
<string>数据路径</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="dataFolderLineEdit">
<property name="styleSheet">
<string notr="true">QLineEdit {
background-color: #142D7F;
color: #e6eeff;
border: 1px solid #2f6bff;
border-radius: 6px;
padding: 4px 8px;
min-width: 70px;
min-height: 20px;
font-size: 13px;
}</string>
</property>
<property name="text">
<string>./CapturedImages</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="dataFolderBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>

View File

@ -10,16 +10,21 @@ DepthCameraWindow::DepthCameraWindow(QWidget* parent)
m_DepthCameraOperation->moveToThread(m_DepthCameraThread);
m_DepthCameraThread->start();
connect(ui.openDepthCamera_btn, &QPushButton::clicked, this, &DepthCameraWindow::openDepthCamera);
connect(ui.closeDepthCamera_btn, &QPushButton::clicked, this, &DepthCameraWindow::closeDepthCamera);
connect(ui.openDepthCamera_btn, &QPushButton::clicked, this, &DepthCameraWindow::openDepthCamera);
connect(ui.closeDepthCamera_btn, &QPushButton::clicked, this, &DepthCameraWindow::closeDepthCamera);
connect(this, &DepthCameraWindow::openDepthCameraSignal, m_DepthCameraOperation, &DepthCameraOperation::OpenDepthCamera);
connect(this, &DepthCameraWindow::openDepthCameraSignal, m_DepthCameraOperation, &DepthCameraOperation::OpenDepthCamera);
connect(m_DepthCameraOperation, &DepthCameraOperation::CamOpenedSignal, this, &DepthCameraWindow::onCamOpened);
connect(m_DepthCameraOperation, &DepthCameraOperation::CamClosedSignal, this, &DepthCameraWindow::onCamClosed);
connect(m_DepthCameraOperation, &DepthCameraOperation::CamOpenedSignal, this, &DepthCameraWindow::onCamOpened);
connect(m_DepthCameraOperation, &DepthCameraOperation::CamClosedSignal, this, &DepthCameraWindow::onCamClosed);
connect(m_DepthCameraOperation, &DepthCameraOperation::PlotSignal, this, &DepthCameraWindow::PlotDepthImageSignal);
connect(m_DepthCameraOperation, &DepthCameraOperation::CamClosedSignal, this, &DepthCameraWindow::DepthCamClosedSignal);
connect(m_DepthCameraOperation, &DepthCameraOperation::PlotSignal, this, &DepthCameraWindow::PlotDepthImageSignal);
connect(m_DepthCameraOperation, &DepthCameraOperation::CamClosedSignal, this, &DepthCameraWindow::DepthCamClosedSignal);
connect(this->ui.dataFolderBtn, SIGNAL(clicked()), this, SLOT(onSelectDataFolder()));
// 初始化数据保存路径显示(从 AppSettings 恢复或使用默认)
ui.dataFolderLineEdit->setText(AppSettings::instance().depthCameraDataFolder());
}
DepthCameraWindow::~DepthCameraWindow()
@ -30,6 +35,29 @@ DepthCameraWindow::~DepthCameraWindow()
m_DepthCameraOperation = nullptr;
}
void DepthCameraWindow::onSelectDataFolder()
{
QString dir = QFileDialog::getExistingDirectory(this,
QString::fromLocal8Bit("选择数据保存路径"),
ui.dataFolderLineEdit->text());
setDataFolder(dir);
}
void DepthCameraWindow::setDataFolder(QString dir)
{
if (!dir.isEmpty())
{
ui.dataFolderLineEdit->setText(dir);
AppSettings::instance().setDepthCameraDataFolder(dir);
}
}
void DepthCameraWindow::setCaptureInterval(int captureIntervalSeconds)
{
m_DepthCameraOperation->setCaptureInterval(captureIntervalSeconds);
}
void DepthCameraWindow::openDepthCamera()
{
if (!m_DepthCameraOperation->getRecordStatus())
@ -65,6 +93,8 @@ DepthCameraOperation::DepthCameraOperation()
m_pipe = nullptr;
m_func = nullptr;
record = false;
m_captureIntervalMilliseconds = 3000;
}
DepthCameraOperation::~DepthCameraOperation()
@ -78,6 +108,11 @@ DepthCameraOperation::~DepthCameraOperation()
}
}
void DepthCameraOperation::setCaptureInterval(int captureIntervalSeconds)
{
m_captureIntervalMilliseconds = captureIntervalSeconds * 1000;
}
void DepthCameraOperation::OpenDepthCamera()
{
if (m_pipe)
@ -124,14 +159,14 @@ void DepthCameraOperation::OpenDepthCamera()
// Drop several frames
for (int i = 0; i < 15; ++i) {
auto lost = m_pipe->waitForFrameset(100);
auto lost = m_pipe->waitForFrameset(m_captureIntervalMilliseconds);
}
auto pointCloud = std::make_shared<ob::PointCloudFilter>();
int frameIndex = 0;
record = true;
QString fileNamePrefix = AppSettings::instance().dataFolder() + QDir::separator() + AppSettings::instance().fileName();
QString fileNamePrefix = AppSettings::instance().depthCameraDataFolder() + QDir::separator() + "Gemini336L";
QString imuFilePath = fileNamePrefix + "_IMU.txt";
std::ofstream imuFile(imuFilePath.toStdString(), std::ios::out | std::ios::trunc);
while (record)
@ -142,7 +177,7 @@ void DepthCameraOperation::OpenDepthCamera()
std::cout << "Start recording..." << std::endl;
}
auto frameSet = m_pipe->waitForFrameset(100);
auto frameSet = m_pipe->waitForFrameset(m_captureIntervalMilliseconds);
if (frameSet == nullptr)
{
std::cout << "No frames received in 100ms..." << std::endl;
@ -200,7 +235,7 @@ void DepthCameraOperation::OpenDepthCamera()
pointCloud->setCreatePointFormat(OB_FORMAT_RGB_POINT);
std::shared_ptr<ob::Frame> frame = pointCloud->process(frameSet);
QString plyPath = fileNamePrefix + "_"+ QString::number(frameIndex) + ".ply";
QString plyPath = fileNamePrefix + "_PointCloud_"+ QString::number(frameIndex) + ".ply";
ob::PointCloudHelper::savePointcloudToPly(plyPath.toStdString().c_str(), frame, false, false, 50);
//惯导数据

View File

@ -7,6 +7,8 @@
#include <QImage>
#include <Qthread>
#include <QDir>
//#include <QLabel>
#include <QFileDialog>
#include <iostream>
#include "ui_DepthCamera.h"
@ -31,6 +33,8 @@ public:
void setCallback(void(*func)());
bool getRecordStatus() const { return record; }
void setCaptureInterval(int captureIntervalSeconds);
private:
ob::Pipeline* m_pipe;
cv::Mat frame;
@ -44,6 +48,8 @@ private:
bool record;
int m_captureIntervalMilliseconds;
public slots:
void OpenDepthCamera();
void OpenDepthCamera_callback();//不使用信号而使用回调函数来通知界面刷新视频
@ -66,12 +72,17 @@ public:
DepthCameraOperation* m_DepthCameraOperation;
void setDataFolder(QString dir);
void setCaptureInterval(int captureIntervalSeconds);
public Q_SLOTS:
void openDepthCamera();
void onCamOpened();
void closeDepthCamera();
void onCamClosed();
void onSelectDataFolder();
signals:
void openDepthCameraSignal();
void PlotDepthImageSignal();

View File

@ -2,16 +2,22 @@
//#include <afx.h>
#include <exception>
#include <memory>
#include <vector>
#include <QMessageBox>
#include <QFileInfo> // 新增,用于解析路径
#include "HPPA.h"
#include "RasterLayer.h"
#include "RasterImageLayer.h"
#include "RasterRenderParams.h"
#include "LayerTreeLayerNode.h"
#include "MapTool.h"
#include "MapToolPan.h"
#include "MapToolSpectral.h"
#include "MapTools.h"
#include <algorithm>
#include <cmath>
HPPA* HPPA::s_instance = nullptr;
@ -111,6 +117,7 @@ HPPA::HPPA(QWidget* parent)
connect(this->ui.action_about, SIGNAL(triggered()), this, SLOT(onAbout()));
connect(this->ui.mActionOneMotorScenario, SIGNAL(triggered()), this, SLOT(createOneMotorScenario()));
connect(this->ui.mActionPlantPhenotypeScenario, SIGNAL(triggered()), this, SLOT(createPlantPhenotypeScenario()));
connect(this->ui.mAction3DPlantPhenotypeScenario, SIGNAL(triggered()), this, SLOT(create3DPlantPhenotypeScenario()));
connect(this->ui.mActionMicroscopicMotionControlScenario, SIGNAL(triggered()), this, SLOT(createMicroscopicMotionControlScenario()));
delete ui.centralWidget;
@ -378,6 +385,7 @@ HPPA::HPPA(QWidget* parent)
m_carousel = new MyCarousel();
m_carousel->setObjectName(QString::fromUtf8("carousel"));
//---------------------------------------------------------------------
QScrollArea* sa = new QScrollArea();
sa->setObjectName("sa");
sa->setStyleSheet(R"(
@ -423,6 +431,29 @@ HPPA::HPPA(QWidget* parent)
m_carousel->addWidget(sa_depthCamera);
m_carousel->setContentsMargins(0, 0, 0, 0);
//---------------------------------------------------------------------
QScrollArea* sa_SingleLensReflexCamera = new QScrollArea();
sa_SingleLensReflexCamera->setObjectName("sa_SingleLensReflexCamera");
sa_SingleLensReflexCamera->setStyleSheet(R"(
border: none;
background-color: #0D1233;
)");
QGridLayout* gridLayout_sa_SingleLensReflexCamera = new QGridLayout(sa_SingleLensReflexCamera);
gridLayout_sa_SingleLensReflexCamera->setSpacing(6);
gridLayout_sa_SingleLensReflexCamera->setObjectName(QString::fromUtf8("gridLayout_sa_SingleLensReflexCamera"));
gridLayout_sa_SingleLensReflexCamera->setVerticalSpacing(0);
gridLayout_sa_SingleLensReflexCamera->setContentsMargins(0, 0, 0, 0);
m_SingleLensReflexCamera_label = new QLabel();
m_SingleLensReflexCamera_label->setAlignment(Qt::AlignHCenter);
m_SingleLensReflexCamera_label->setStyleSheet(R"(
background-color: #0D1233;
)");
gridLayout_sa_SingleLensReflexCamera->addWidget(m_SingleLensReflexCamera_label);
m_carousel->addWidget(sa_SingleLensReflexCamera);
m_carousel->setContentsMargins(0, 0, 0, 0);
m_carousel->play();
gridLayout_carouselContainer->addWidget(m_carousel);
@ -544,6 +575,9 @@ HPPA::HPPA(QWidget* parent)
initMapTools();
//定时采集
initTimedDataCollection();
QString strPath = QCoreApplication::applicationDirPath() + "/UILayout.ini";
QFile file(strPath);
if (file.open(QIODevice::ReadOnly))
@ -557,6 +591,143 @@ HPPA::HPPA(QWidget* parent)
this->showMaximized();
}
void HPPA::initTimedDataCollection()
{
connect(this->ui.mActionTimedDataCollection, SIGNAL(triggered()), this, SLOT(onTimedDataCollection()));
mTimedDataCollectionWindow = new TimedDataCollection();
// 定时采集控制器 → 相机/马达
connect(mTimedDataCollectionWindow, &TimedDataCollection::hyperCamParm, this, &HPPA::setTimedDataCollectionHyperCamParm);
connect(mTimedDataCollectionWindow, &TimedDataCollection::camParm, this, &HPPA::setTimedDataCollectionCamParm);
connect(mTimedDataCollectionWindow, &TimedDataCollection::motorParm, this, &HPPA::setTimedDataCollectionMotorParm);
connect(mTimedDataCollectionWindow, &TimedDataCollection::startRecordSignal, this, &HPPA::onStartTimedDataCollection);
connect(mTimedDataCollectionWindow, &TimedDataCollection::switchHalogenLampSignal, m_pc3D, &PowerControl3D::switchHalogenLampPower);
connect(mTimedDataCollectionWindow, &TimedDataCollection::switchD65LampSignal, m_pc3D, &PowerControl3D::switchD65LampPower);
connect(mTimedDataCollectionWindow, &TimedDataCollection::switchSlrSignal, m_pc3D, &PowerControl3D::switchSlrPower);
// 相机/马达 → 定时采集控制器
connect(m_tmc, &TwoMotorControl::sequenceComplete, mTimedDataCollectionWindow, &TimedDataCollection::subTaskCompleted);
connect(m_tmc, &TwoMotorControl::back2OriginSignal_TimedDataCollection, mTimedDataCollectionWindow, &TimedDataCollection::onBack2Origin);
}
void HPPA::setTimedDataCollectionHyperCamParm(int camType, double f, double e, QString filePath, QString fileName)
{
switch (camType)
{
case 0:
{
disconnectImagerAndCleanup();
ui.mActionPica_L->setChecked(true);
AppSettings::instance().setFrameRate(f);
AppSettings::instance().setIntegrationTime(e);
AppSettings::instance().setDataFolder(filePath);
AppSettings::instance().setFileName(fileName);
this->frame_number->setText("100000");
onconnect();
break;
}
case 1:
{
disconnectImagerAndCleanup();
ui.mActionPica_NIR->setChecked(true);
AppSettings::instance().setFrameRate(f);
AppSettings::instance().setIntegrationTime(e);
AppSettings::instance().setDataFolder(filePath);
AppSettings::instance().setFileName(fileName);
this->frame_number->setText("100000");
onconnect();
break;
}
}
}
void HPPA::setTimedDataCollectionCamParm(int camType, int captureIntervalSeconds, QString folder)
{
switch (camType)
{
case 2:
{
//唤醒单反相机
m_pc3D->slrPowerDown();
m_pc3D->slrPowerOn();
m_singleLensReflexCameraWindow->setDataFolder(folder);
m_singleLensReflexCameraWindow->setCaptureInterval(captureIntervalSeconds);
break;
}
case 3:
{
m_pc3D->d65LampPowerOn();
m_depthCameraWindow->setDataFolder(folder);
m_depthCameraWindow->setCaptureInterval(captureIntervalSeconds);
break;
}
}
}
void HPPA::setTimedDataCollectionMotorParm(QString pathLineFilePath)
{
m_tmc->readRecordLineFile(pathLineFilePath);
//m_tmc->onConnectMotor();
//QThread::msleep(1000);
}
void HPPA::onStartTimedDataCollection(int camType)
{
switch (camType)
{
case 0:
{
onStartRecordStep1();
break;
}
case 1:
{
onStartRecordStep1();
break;
}
case 2:
{
m_tmc->run2(m_singleLensReflexCameraWindow);
break;
}
case 3:
{
m_tmc->run3(m_depthCameraWindow);
break;
}
}
}
void HPPA::onTimedDataCollection()
{
QAction* checkedScenario = m_ScenarioActionGroup->checkedAction();
QString checkedScenarioName = checkedScenario->objectName();
if (checkedScenarioName == "mAction3DPlantPhenotypeScenario")//计划采集
{
mTimedDataCollectionWindow->show();
//mTimedDataCollectionWindow->exec();
return;
}
else if (checkedScenarioName == "mActionPlantPhenotypeScenario")
{
}
}
void HPPA::initMenubarToolbar()
{
//自定义菜单栏和工具栏
@ -777,6 +948,9 @@ void HPPA::initControlTabwidget()
//单反相机
m_singleLensReflexCameraWindow = new SingleLensReflexCameraWindow();
connect(m_singleLensReflexCameraWindow, &SingleLensReflexCameraWindow::LiveViewImageReady, this, &HPPA::onLiveViewImageReady);
connect(m_singleLensReflexCameraWindow, &SingleLensReflexCameraWindow::LiveViewStopped, this, &HPPA::onLiveViewStopped);
ui.controlTabWidget->addTab(m_singleLensReflexCameraWindow, QString::fromLocal8Bit("单反相机"));
//rgb相机
@ -799,6 +973,11 @@ void HPPA::initControlTabwidget()
m_pc->setWindowFlags(Qt::Widget);
ui.controlTabWidget->addTab(m_pc, QString::fromLocal8Bit("电源控制"));
//电源控制3D
m_pc3D = new PowerControl3D();
m_pc3D->setWindowFlags(Qt::Widget);
ui.controlTabWidget->addTab(m_pc3D, QString::fromLocal8Bit("电源控制3D"));
//机械臂控制
m_rac = new RobotArmControl();
connect(m_rac->robotController, SIGNAL(hsiRecordSignal(int)), this, SLOT(recordFromRobotArm(int)));
@ -813,13 +992,13 @@ void HPPA::initControlTabwidget()
//2轴马达控制
m_tmc = new TwoMotorControl(this);
//connect(m_tmc, SIGNAL(startLineNumSignal(int)), this, SLOT(onCreateTab(int)));
connect(m_tmc, SIGNAL(sequenceComplete()), this, SLOT(onsequenceComplete()));
connect(m_tmc, &TwoMotorControl::back2OriginSignal, this, &HPPA::onsequenceComplete);
m_tmc->setWindowFlags(Qt::Widget);
ui.controlTabWidget->addTab(m_tmc, QString::fromLocal8Bit("2轴控制"));
// Connect ImageControl band change to re-render (m_ic created in initControlTabwidget)
connect(m_ic, SIGNAL(bandSelectionChanged(double,double,double)),
this, SLOT(onBandSelectionChanged(double,double,double)));
//connect(m_ic, SIGNAL(bandSelectionChanged(double, double, double)),
// this, SLOT(onBandSelectionChanged(double, double, double)));
}
void HPPA::recordFromRobotArm(int fileCounter)
@ -1009,37 +1188,110 @@ void HPPA::removeLayerByTreeIndex()
LayerTreeNode* node = static_cast<LayerTreeNode*>(currentIndexTmp.internalPointer());
if (!node || node->type() != LayerTreeNode::Type::Layer) return;
auto* layerNode = static_cast<LayerTreeLayer*>(node);
MapLayer* mapLayer = layerNode->mapLayer();
QWidget* layerWidget = nullptr;
removeLayerByNode(node);
}
if (mapLayer && m_MapLayerStore)
{
layerWidget = m_MapLayerStore->widgetForLayer(mapLayer);
m_MapLayerStore->removeLayer(mapLayer);
}
void HPPA::removeLayerByNode(LayerTreeNode* node)
{
if (!node || node->type() != LayerTreeNode::Type::Layer) return;
if (layerWidget && m_imageViewerTabWidget)
{
const int tabIndex = m_imageViewerTabWidget->indexOf(layerWidget);
if (tabIndex >= 0)
{
if (m_recordFrameCounter)
{
m_recordFrameCounter->removeCounter(layerWidget);
}
m_imageViewerTabWidget->removeTab(tabIndex);
}
layerWidget->deleteLater();
}
auto* layerNode = static_cast<LayerTreeLayer*>(node);
MapLayer* mapLayer = layerNode->mapLayer();
LayerTreeNode* parent = node->parentNode();
int row = node->rowInParent();
LayerTreeNode* removed = model->removeNode(parent, row);
if (removed)
{
delete removed;
}
if (!mapLayer || !m_MapLayerStore) return;
// 获取该 mapLayer 对应的所有 widget 并从 tab 中移除
std::vector<QWidget*> widgets = m_MapLayerStore->widgetsForMapLayer(mapLayer);
for (QWidget* widget : widgets)
{
if (widget && m_imageViewerTabWidget)
{
const int tabIndex = m_imageViewerTabWidget->indexOf(widget);
if (tabIndex >= 0)
{
m_imageViewerTabWidget->removeTab(tabIndex);
}
widget->deleteLater();
}
}
if (!mapLayer || mapLayer->layerType() == MapLayer::LayerType::Raster)
{
if (m_recordFrameCounter)
{
m_recordFrameCounter->removeCounter(static_cast<RasterLayer*>(mapLayer));
}
}
// 删除 MapLayerStore 中的 mapLayer
m_MapLayerStore->removeLayer(mapLayer);
// 删除树模型中的节点
LayerTreeNode* parent = node->parentNode();
int row = node->rowInParent();
LayerTreeNode* removed = m_LayerTreeModel->removeNode(parent, row);
if (removed)
{
delete removed;
}
}
void HPPA::showColorImageByTreeIndex()
{
QModelIndex currentIndexTmp = m_layerTreeView->currentIndex();
if (!currentIndexTmp.isValid()) return;
LayerTreeModel* model = const_cast<LayerTreeModel*>(static_cast<const LayerTreeModel*>(currentIndexTmp.model()));
if (!model) return;
LayerTreeNode* node = static_cast<LayerTreeNode*>(currentIndexTmp.internalPointer());
if (!node || node->type() != LayerTreeNode::Type::Layer) return;
auto* layerNode = static_cast<LayerTreeLayer*>(node);
RasterLayer* mapLayer = static_cast<RasterLayer*>(layerNode->mapLayer());
newImage(mapLayer, RasterImageLayer::RendererType::Multiband, node);
}
void HPPA::removeImageByTreeIndex()
{
QModelIndex currentIndexTmp = m_layerTreeView->currentIndex();
if (!currentIndexTmp.isValid()) return;
LayerTreeModel* model = const_cast<LayerTreeModel*>(static_cast<const LayerTreeModel*>(currentIndexTmp.model()));
if (!model) return;
LayerTreeNode* node = static_cast<LayerTreeNode*>(currentIndexTmp.internalPointer());
if (!node || node->type() != LayerTreeNode::Type::Image) return;
auto* layerNode = static_cast<LayerTreeImageNode*>(node);
RasterImageLayer* rasterImageLayer = layerNode->imageLayer();
QWidget* layerWidget = nullptr;
if (rasterImageLayer && m_MapLayerStore)
{
layerWidget = m_MapLayerStore->widgetForImageLayer(rasterImageLayer);
m_MapLayerStore->removeImageLayer(rasterImageLayer);
}
if (layerWidget && m_imageViewerTabWidget)
{
const int tabIndex = m_imageViewerTabWidget->indexOf(layerWidget);
if (tabIndex >= 0)
{
m_imageViewerTabWidget->removeTab(tabIndex);
}
layerWidget->deleteLater();
}
LayerTreeNode* parent = node->parentNode();
int row = node->rowInParent();
LayerTreeNode* removed = model->removeNode(parent, row);
if (removed)
{
delete removed;
}
}
void HPPA::removeAllLayersInRasterGroup()
@ -1058,46 +1310,7 @@ void HPPA::removeAllLayersInRasterGroup()
pending.pop_back();
if (!node) continue;
for (int i = 0; i < node->childCount(); ++i)
{
pending.push_back(node->childAt(i));
}
if (node->type() != LayerTreeNode::Type::Layer) continue;
auto* layerNode = static_cast<LayerTreeLayer*>(node);
MapLayer* mapLayer = layerNode->mapLayer();
QWidget* layerWidget = nullptr;
if (mapLayer && m_MapLayerStore)
{
layerWidget = m_MapLayerStore->widgetForLayer(mapLayer);
m_MapLayerStore->removeLayer(mapLayer);
}
if (layerWidget && m_imageViewerTabWidget)
{
const int tabIndex = m_imageViewerTabWidget->indexOf(layerWidget);
if (tabIndex >= 0)
{
if (m_recordFrameCounter)
{
m_recordFrameCounter->removeCounter(layerWidget);
}
m_imageViewerTabWidget->removeTab(tabIndex);
}
layerWidget->deleteLater();
}
}
while (m_RasterGroup->childCount() > 0)
{
const int row = m_RasterGroup->childCount() - 1;
LayerTreeNode* removed = m_LayerTreeModel->removeNode(m_RasterGroup, row);
if (removed)
{
delete removed;
}
removeLayerByNode(node);
}
}
@ -1193,6 +1406,7 @@ void HPPA::createScenarioActionGroup()
m_ScenarioActionGroup = new QActionGroup(this);
m_ScenarioActionGroup->addAction(ui.mActionOneMotorScenario);
m_ScenarioActionGroup->addAction(ui.mActionPlantPhenotypeScenario);
m_ScenarioActionGroup->addAction(ui.mAction3DPlantPhenotypeScenario);
m_ScenarioActionGroup->addAction(ui.mActionMicroscopicMotionControlScenario);
// 读取上次选择的结果
@ -1210,6 +1424,11 @@ void HPPA::createScenarioActionGroup()
ui.mActionPlantPhenotypeScenario->setChecked(true);
ui.mActionPlantPhenotypeScenario->trigger();
}
else if (lastSelectedAction == "mAction3DPlantPhenotypeScenario")
{
ui.mAction3DPlantPhenotypeScenario->setChecked(true);
ui.mAction3DPlantPhenotypeScenario->trigger();
}
else if (lastSelectedAction == "mActionMicroscopicMotionControlScenario")
{
ui.mActionMicroscopicMotionControlScenario->setChecked(true);
@ -1245,14 +1464,10 @@ void HPPA::createOneMotorScenario()
ui.mAction_1AxisMotor->setChecked(true);
//右下角控制tab
m_tabManager->hideTab(m_singleLensReflexCameraWindow);
m_tabManager->hideTab(m_depthCameraWindow);
m_tabManager->hideTab(m_rgbCameraControlWindow);
m_tabManager->hideTab(m_adt);
m_tabManager->hideTab(m_pc);
m_tabManager->hideTab(m_rac);
m_tabManager->hideTab(m_tmc);
m_tabManager->hideAllTabs();
m_tabManager->showTab(m_hic);
m_tabManager->showTab(m_ic);
m_tabManager->showTab(m_omc);
m_view3DModelManager->switchScenario(View3DModelManager::ScenarioType::OneMotor);
@ -1280,11 +1495,10 @@ void HPPA::createPlantPhenotypeScenario()
ui.mAction_2AxisMotor_new->setChecked(true);
//右下角控制tab
m_tabManager->hideTab(m_rac);
m_tabManager->hideTab(m_omc);
m_tabManager->hideAllTabs();
m_tabManager->showTab(m_depthCameraWindow);
m_tabManager->showTab(m_singleLensReflexCameraWindow);
m_tabManager->showTab(m_hic);
m_tabManager->showTab(m_ic);
m_tabManager->showTab(m_rgbCameraControlWindow);
m_tabManager->showTab(m_adt);
m_tabManager->showTab(m_pc);
@ -1296,6 +1510,33 @@ void HPPA::createPlantPhenotypeScenario()
}
void HPPA::create3DPlantPhenotypeScenario()
{
//if (ui.mAction3DPlantPhenotypeScenario->isChecked())
// return;
//在菜单中选择移动平台
ui.mAction_2AxisMotor_new->setChecked(true);
//右下角控制tab
m_tabManager->hideAllTabs();
m_tabManager->showTab(m_hic);
m_tabManager->showTab(m_ic);
m_tabManager->showTab(m_depthCameraWindow);
m_tabManager->showTab(m_singleLensReflexCameraWindow);
//m_tabManager->showTab(m_rgbCameraControlWindow);
m_tabManager->showTab(m_adt);
//m_tabManager->showTab(m_pc);
m_tabManager->showTab(m_pc3D);
m_tabManager->showTab(m_tmc);
m_view3DModelManager->switchScenario(View3DModelManager::ScenarioType::PlantPhenotype);
//右上角轮播
}
void HPPA::createMicroscopicMotionControlScenario()
{
//if (ui.mActionMicroscopicMotionControl->isChecked())
@ -1305,14 +1546,10 @@ void HPPA::createMicroscopicMotionControlScenario()
ui.mAction_2AxisMotor_new->setChecked(true);
//右下角控制tab
m_tabManager->hideTab(m_singleLensReflexCameraWindow);
m_tabManager->hideTab(m_depthCameraWindow);
m_tabManager->hideTab(m_rgbCameraControlWindow);
m_tabManager->hideTab(m_adt);
m_tabManager->hideTab(m_pc);
m_tabManager->hideTab(m_rac);
m_tabManager->hideTab(m_omc);
m_tabManager->hideAllTabs();
m_tabManager->showTab(m_hic);
m_tabManager->showTab(m_ic);
m_tabManager->showTab(m_tmc);
m_view3DModelManager->switchScenario(View3DModelManager::ScenarioType::MicroscopicMotionControl);
@ -1465,7 +1702,7 @@ void HPPA::onStartRecordStep1()
{
}
//判断光谱仪
if(!testImagerVality())
{
@ -1610,11 +1847,6 @@ QWidget* HPPA::onCreateTab(QString tabName)
m_imageViewerTabWidget->setCurrentIndex(m_imageViewerTabWidget->count() - 1);
if (m_recordFrameCounter)
{
m_recordFrameCounter->addCounter(tabTmp);
}
return tabTmp;
}
@ -1631,7 +1863,11 @@ void HPPA::onTabWidgetCurrentChanged(int index)//代码新建一个tab会调
if (m_recordFrameCounter)
{
QWidget* currentWidget = m_imageViewerTabWidget->widget(index);
m_recordFrameCounter->switchTo(currentWidget);
MapLayer* currentMapLayer = m_MapLayerStore->mapLayerForWidget(currentWidget);
if (currentMapLayer)
{
m_recordFrameCounter->switchTo(static_cast<RasterLayer*>(currentMapLayer));
}
}
//获取绘图控件
@ -1651,7 +1887,7 @@ void HPPA::onTabWidgetCurrentChanged(int index)//代码新建一个tab会调
// Sync layer tree view selection with the current tab
if (m_MapLayerStore && m_layerTreeView && m_LayerTreeModel && m_RasterGroup)
{
MapLayer* layer = m_MapLayerStore->layerForWidget(currentWidget);
MapLayer* layer = m_MapLayerStore->mapLayerForWidget(currentWidget);
if (layer)
{
// Find the LayerTreeLayer node in m_RasterGroup that matches this layer
@ -1671,10 +1907,9 @@ void HPPA::onTabWidgetCurrentChanged(int index)//代码新建一个tab会调
m_layerTreeView->selectionModel()->blockSignals(false);
// Manually update ImageControl since we blocked the signal
RasterLayer* rl = qobject_cast<RasterLayer*>(layer);
if (rl)
{
m_ic->setActiveLayer(rl);
QList<Mapcavas*> mapcavas = currentWidget->findChildren<Mapcavas*>();
if (!mapcavas.isEmpty()) {
m_ic->setActiveLayer(mapcavas[0]->imageLayer());
}
break;
}
@ -1829,6 +2064,22 @@ void HPPA::onClearLabel()
m_cam_label->setText("closed");
}
void HPPA::onLiveViewImageReady(const QImage& image)
{
if (m_SingleLensReflexCamera_label && !image.isNull())
{
// 缩放图像以适应标签大小
QPixmap pixmap = QPixmap::fromImage(image);
pixmap = pixmap.scaled(m_SingleLensReflexCamera_label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
m_SingleLensReflexCamera_label->setPixmap(pixmap);
}
}
void HPPA::onLiveViewStopped()
{
m_SingleLensReflexCamera_label->clear();
}
void HPPA::onPlotDepthImage()
{
QPixmap pixmap = QPixmap::fromImage(m_depthCameraWindow->m_DepthCameraOperation->m_depthImage);
@ -1922,6 +2173,14 @@ void HPPA::onOpenImg()
QString baseName = fi.completeBaseName();
addLayer(baseName, uri, true);
// 获取影像行数并更新帧数显示
MapLayer* mapLayer = m_MapLayerStore->getLayerByAbsolutePath(uri);
if (mapLayer && m_recordFrameCounter)
{
RasterLayer* rasterLayer = static_cast<RasterLayer*>(mapLayer);
m_recordFrameCounter->updateFrameCount(rasterLayer, rasterLayer->height());
}
}
void HPPA::disconnectImagerAndCleanup()
@ -2342,6 +2601,15 @@ void HPPA::onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QSt
return;
}
MapLayer* mapLayer = m_MapLayerStore->getLayerByAbsolutePath(filePath);
if (mapLayer && m_recordFrameCounter)
{
m_recordFrameCounter->updateFrameCount(static_cast<RasterLayer*>(mapLayer), m_Imager->getFrameCounter());
}
if (ui.mAction3DPlantPhenotypeScenario->isChecked())
return;
//return;
//获取绘图控件
QWidget* currentWidget = m_MapLayerStore->widgetForLayer(filePath);
@ -2350,11 +2618,6 @@ void HPPA::onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QSt
QList<Mapcavas*> currentImageViewer = currentWidget->findChildren<Mapcavas*>();
currentImageViewer[0]->DisplayFrameNumber(m_Imager->getFrameCounter());//界面中显示已经采集的帧数
if (m_recordFrameCounter)
{
m_recordFrameCounter->updateFrameCount(currentWidget, m_Imager->getFrameCounter());
}
//创建需要显示的图像--opencv版本
ImageProcessor imageProcessor;
//cv::Mat rgbImage(*m_Imager->getRgbImage()->m_matRgbImage, cv::Range(0, m_Imager->getFrameCounter()), cv::Range::all());//2022.3.18重构的
@ -2535,10 +2798,18 @@ void WorkerThread3::run()
void HPPA::onLayerCreatedFromFile(const QString& baseName, const QString& filePath, int fileIndex)
{
if (!m_LayerTreeModel || !m_RasterGroup) return;
addLayer(baseName, filePath, false);
if (ui.mAction3DPlantPhenotypeScenario->isChecked())
{
addLayer(baseName, filePath, false, false);
}
else
{
addLayer(baseName, filePath, false);
}
}
void HPPA::addLayer(const QString& baseName, const QString& filePath,bool refresh)
void HPPA::addLayer(const QString& baseName, const QString& filePath,bool refresh, bool isAddImage)
{
// Create MapLayer first and attach it to a LayerTreeLayerNode
RasterLayer* ml = new RasterLayer(baseName, filePath);
@ -2546,10 +2817,40 @@ void HPPA::addLayer(const QString& baseName, const QString& filePath,bool refres
auto* layerNode = new LayerTreeLayer(ml);
LayerTreeNode* node = m_LayerTreeModel->addLayer(m_RasterGroup, layerNode);
QWidget* mapcavasContainer = onCreateTab(baseName);
if (m_MapLayerStore) m_MapLayerStore->addLayer(ml, mapcavasContainer);
if (m_MapLayerStore) m_MapLayerStore->addLayer(ml);
if (m_recordFrameCounter)
{
m_recordFrameCounter->addCounter(ml);
}
if (isAddImage)
{
newImage(ml, RasterImageLayer::RendererType::Multiband, node, refresh);
}
}
void HPPA::newImage(RasterLayer* ml, RasterImageLayer::RendererType type, LayerTreeNode* parent, bool refresh)
{
QWidget* mapcavasContainer = onCreateTab(ml->name());
RasterImageLayer* rasterImageLayer = new RasterImageLayer(ml, type);
QList<Mapcavas*> mapcavas = mapcavasContainer->findChildren<Mapcavas*>();
mapcavas[0]->setLayers(ml);
mapcavas[0]->setImageLayer(rasterImageLayer);
QString title = ml->name();
if (type == RasterImageLayer::RendererType::Multiband)
{
title = title + "-RGB";
}
else if(type == RasterImageLayer::RendererType::Singleband)
{
title = title + "-GreyScale";
}
LayerTreeImageNode* imageNode = new LayerTreeImageNode(rasterImageLayer, title);
LayerTreeNode* node2 = m_LayerTreeModel->addLayer(parent, imageNode);
if (m_MapLayerStore) m_MapLayerStore->addImageLayer(ml, rasterImageLayer, mapcavasContainer);
if (refresh)
{
@ -2559,66 +2860,100 @@ void HPPA::addLayer(const QString& baseName, const QString& filePath,bool refres
void HPPA::onLayerTreeSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
//采集过程中禁用图层树的选择功能
if (m_RecordState % 2 == 1)
{
return;
}
Q_UNUSED(deselected);
if (selected.indexes().isEmpty()) {
if (selected.indexes().isEmpty())
{
m_ic->setActiveLayer(nullptr);
return;
}
QModelIndex idx = selected.indexes().first();
if (!idx.isValid()) {
if (!idx.isValid())
{
m_ic->setActiveLayer(nullptr);
return;
}
LayerTreeNode* node = static_cast<LayerTreeNode*>(idx.internalPointer());
if (!node || node->type() != LayerTreeNode::Type::Layer) {
LayerTreeNode* node = static_cast<LayerTreeNode*>(idx.internalPointer());
if (!node || node->type() == LayerTreeNode::Type::Group)
{
m_ic->setActiveLayer(nullptr);
return;
}
//后续工作:当选择图层树中的图层时,应该显示此图层的元数据
if (!node || node->type() == LayerTreeNode::Type::Layer)
{
m_ic->setActiveLayer(nullptr);
return;
}
auto* layerNode = static_cast<LayerTreeLayer*>(node);
MapLayer* mapLayer = layerNode->mapLayer();
if (!mapLayer || mapLayer->layerType() != MapLayer::LayerType::Raster) {
m_ic->setActiveLayer(nullptr);
return;
}
if (!node || node->type() == LayerTreeNode::Type::Image)
{
auto* imageNode = static_cast<LayerTreeImageNode*>(node);
RasterImageLayer* imageLayer = imageNode->imageLayer();
MapLayer* mapLayer = imageLayer->layer();
RasterLayer* rl = static_cast<RasterLayer*>(mapLayer);
m_ic->setActiveLayer(rl);
if (!mapLayer || mapLayer->layerType() != MapLayer::LayerType::Raster) {
m_ic->setActiveLayer(nullptr);
return;
}
// Also switch to the corresponding tab in the image viewer
if (m_MapLayerStore && m_imageViewerTabWidget) {
QWidget* widget = m_MapLayerStore->widgetForLayer(mapLayer);
if (widget) {
int tabIndex = m_imageViewerTabWidget->indexOf(widget);
if (tabIndex >= 0) {
m_imageViewerTabWidget->setCurrentIndex(tabIndex);
}
}
}
if (m_MapLayerStore && m_imageViewerTabWidget)
{
QWidget* widget = m_MapLayerStore->widgetForImageLayer(imageLayer);
if (widget)
{
int tabIndex = m_imageViewerTabWidget->indexOf(widget);
if (tabIndex >= 0)
{
m_imageViewerTabWidget->setCurrentIndex(tabIndex);
}
}
QList<Mapcavas*> mapcavas = widget->findChildren<Mapcavas*>();
if (!mapcavas.isEmpty())
{
m_ic->setActiveLayer(mapcavas[0]->imageLayer());
}
else
{
m_ic->setActiveLayer(nullptr);
}
}
else
{
m_ic->setActiveLayer(nullptr);
}
}
}
void HPPA::onBandSelectionChanged(double rWave, double gWave, double bWave)
{
RasterLayer* rl = m_ic->activeLayer();
if (!rl) return;
RasterImageLayer* imageLayer = m_ic->activeLayer();
if (!imageLayer) return;
auto params = imageLayer->multibandParams();
params.rWave = rWave;
params.gWave = gWave;
params.bWave = bWave;
imageLayer->setMultibandParams(params);
// Find the Mapcavas widget associated with this layer and re-render
if (!m_MapLayerStore) return;
QWidget* container = m_MapLayerStore->widgetForLayer(rl);
MapLayer* mapLayer = imageLayer->layer();
QWidget* container = m_MapLayerStore->widgetForImageLayer(imageLayer);
if (!container) return;
QList<Mapcavas*> mapcavas = container->findChildren<Mapcavas*>();
if (mapcavas.isEmpty()) return;
RasterLayer::RenderParams params = rl->currentRenderParams();
params.rWave = rWave;
params.gWave = gWave;
params.bWave = bWave;
rl->setCurrentRenderParams(params);
mapcavas[0]->freshmap(params);
mapcavas[0]->freshmap();
}

View File

@ -81,6 +81,12 @@
#include "DepthCameraWindow.h"
#include "SingleLensReflexCameraWindow.h"
#include "LayerTreeImageNode.h"
#include "TimedDataCollection.h"
#include "PowerControl3D.h"
#define PI 3.1415926
QT_CHARTS_USE_NAMESPACE//QChartView 使用 需要加宏, 否则无法使用
@ -272,6 +278,7 @@ private:
MyCarousel* m_carousel;
QLabel* m_cam_label;
QLabel* m_SingleLensReflexCamera_label;
QLabel* m_depthCamera_label;
QPushButton* m_open_rgb_camera_btn;
QPushButton* m_close_rgb_camera_btn;
@ -285,6 +292,7 @@ private:
SingleLensReflexCameraWindow* m_singleLensReflexCameraWindow;
adjustTable* m_adt;
PowerControl* m_pc;
PowerControl3D* m_pc3D;
RobotArmControl* m_rac;
OneMotorControl* m_omc;
TwoMotorControl* m_tmc;
@ -313,6 +321,9 @@ private:
bool showResultMessageBox(QString title, QString msg);
void disconnectImagerAndCleanup();
TimedDataCollection* mTimedDataCollectionWindow;
void initTimedDataCollection();
public Q_SLOTS:
void onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QString filePath);
void focusPlotSpectralImg(int state);
@ -356,6 +367,9 @@ public Q_SLOTS:
void onPlotRgbImage();
void onPlotDepthImage();
void onLiveViewImageReady(const QImage& image);
void HPPA::onLiveViewStopped();
void onClearLabel();
void onClearDepthLabel();
@ -367,14 +381,19 @@ public Q_SLOTS:
void createOneMotorScenario();
void createPlantPhenotypeScenario();
void create3DPlantPhenotypeScenario();
void onCreated3DModelPlantPhenotype();
void onCreated3DModelMicroscopicMotion();
void createMicroscopicMotionControlScenario();
void onCreated3DModelOneMotor();
void addLayer(const QString& baseName, const QString& filePath, bool refresh);
void addLayer(const QString& baseName, const QString& filePath, bool refresh, bool isAddImage = true);
void newImage(RasterLayer* ml, RasterImageLayer::RendererType, LayerTreeNode* parent, bool refresh=true);
void onLayerCreatedFromFile(const QString& baseName, const QString& filePath, int fileIndex);
void removeLayerByTreeIndex();
void removeLayerByNode(LayerTreeNode* node);
void showColorImageByTreeIndex();
void removeImageByTreeIndex();
void removeAllLayersInRasterGroup();
void onLayerTreeSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
@ -382,6 +401,12 @@ public Q_SLOTS:
void onMapToolPanTriggered();
void onMapToolSpectralTriggered();
void onTimedDataCollection();
void setTimedDataCollectionHyperCamParm(int camType, double f, double e, QString filePath, QString fileName);
void setTimedDataCollectionCamParm(int camType, int captureIntervalSeconds, QString folder);
void setTimedDataCollectionMotorParm(QString pathLineFilePath);
void onStartTimedDataCollection(int camType);
protected:
void closeEvent(QCloseEvent* event) override;

View File

@ -105,6 +105,7 @@ color:white;
<addaction name="action_start_recording"/>
<addaction name="separator"/>
<addaction name="actionOpenDirectory"/>
<addaction name="mActionTimedDataCollection"/>
</widget>
<widget class="QMenu" name="menuhelp">
<property name="title">
@ -134,6 +135,7 @@ color:white;
<addaction name="mActionOneMotorScenario"/>
<addaction name="mActionPlantPhenotypeScenario"/>
<addaction name="mActionMicroscopicMotionControlScenario"/>
<addaction name="mAction3DPlantPhenotypeScenario"/>
</widget>
<widget class="QMenu" name="menu_4">
<property name="title">
@ -734,6 +736,19 @@ QPushButton:pressed
<string>显微运动控制台</string>
</property>
</action>
<action name="mAction3DPlantPhenotypeScenario">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>3D植物表型</string>
</property>
</action>
<action name="mActionTimedDataCollection">
<property name="text">
<string>定时采集</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

View File

@ -55,18 +55,18 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<IncludePath>D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;D:\cpp_library\vincecontrol_vs2017;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\IrisMultiMotorController;D:\cpp_library\eigen-3.4-rc1;C:\Program Files\OrbbecSDK 2.7.6\include;$(IncludePath)</IncludePath>
<LibraryPath>D:\cpp_library\opencv3.4.11\opencv\build\x64\vc15\lib;D:\cpp_library\gdal2.2.3_vs2017\lib;C:\Program Files\ResononAPI\lib64;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\x64\Debug;D:\cpp_library\libconfig-1.7.3\build\x64;D:\cpp_project_vs2022\HPPA\x64\Debug;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\x64\Debug;C:\Program Files\OrbbecSDK 2.7.6\lib;$(LibraryPath)</LibraryPath>
<IncludePath>D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;D:\cpp_library\vincecontrol_vs2017;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\IrisMultiMotorController;D:\cpp_library\eigen-3.4-rc1;C:\Program Files\OrbbecSDK 2.7.6\include;D:\cpp_library\EDSDK132010CD(13.20.10)\Windows\EDSDK_64\Header;$(IncludePath)</IncludePath>
<LibraryPath>D:\cpp_library\opencv3.4.11\opencv\build\x64\vc15\lib;D:\cpp_library\gdal2.2.3_vs2017\lib;C:\Program Files\ResononAPI\lib64;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\x64\Debug;D:\cpp_library\libconfig-1.7.3\build\x64;D:\cpp_project_vs2022\HPPA\x64\Debug;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\x64\Debug;C:\Program Files\OrbbecSDK 2.7.6\lib;D:\cpp_library\EDSDK132010CD(13.20.10)\Windows\EDSDK_64\Library;$(LibraryPath)</LibraryPath>
<TargetName>Spectral Insight</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<IncludePath>D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\IrisMultiMotorController;D:\cpp_library\eigen-3.4-rc1;C:\Program Files\OrbbecSDK 2.7.6\include;$(IncludePath)</IncludePath>
<LibraryPath>D:\cpp_library\opencv3.4.11\opencv\build\x64\vc15\lib;D:\cpp_library\vincecontrol_vs2017_release;D:\cpp_library\gdal2.2.3_vs2017\lib;C:\Program Files\ResononAPI\lib64;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\x64\Release;D:\cpp_library\libconfig-1.7.3\build\x64;D:\cpp_project_vs2022\IrisMultiMotorController\x64\Release;C:\XIMEA\API\xiAPI;C:\Program Files\OrbbecSDK 2.7.6\lib;$(LibraryPath)</LibraryPath>
<IncludePath>D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\IrisMultiMotorController;D:\cpp_library\eigen-3.4-rc1;C:\Program Files\OrbbecSDK 2.7.6\include;D:\cpp_library\EDSDK132010CD(13.20.10)\Windows\EDSDK_64\Header;$(IncludePath)</IncludePath>
<LibraryPath>D:\cpp_library\opencv3.4.11\opencv\build\x64\vc15\lib;D:\cpp_library\vincecontrol_vs2017_release;D:\cpp_library\gdal2.2.3_vs2017\lib;C:\Program Files\ResononAPI\lib64;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\x64\Release;D:\cpp_library\libconfig-1.7.3\build\x64;D:\cpp_project_vs2022\IrisMultiMotorController\x64\Release;C:\XIMEA\API\xiAPI;C:\Program Files\OrbbecSDK 2.7.6\lib;D:\cpp_library\EDSDK132010CD(13.20.10)\Windows\EDSDK_64\Library;$(LibraryPath)</LibraryPath>
<TargetName>Spectral Insight</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Link>
<AdditionalDependencies>opencv_world3411.lib;opencv_world3411d.lib;gdal_i.lib;resonon-basler.lib;AutoFocus_InspireLinearMotor_DLL.lib;libconfig++d.lib;vincecontrol.lib;resonon-allied.lib;xiapi64.lib;IrisMultiMotorController.lib;OrbbecSDK.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>opencv_world3411.lib;opencv_world3411d.lib;gdal_i.lib;resonon-basler.lib;AutoFocus_InspireLinearMotor_DLL.lib;libconfig++d.lib;vincecontrol.lib;resonon-allied.lib;xiapi64.lib;IrisMultiMotorController.lib;OrbbecSDK.lib;EDSDK.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>D:\cpp_project_vs2022\HPPA\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<ClCompile>
@ -75,7 +75,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Link>
<AdditionalDependencies>opencv_world3411.lib;vincecontrol.lib;gdal_i.lib;resonon-basler.lib;resonon-allied.lib;AutoFocus_InspireLinearMotor_DLL.lib;libconfig++.lib;xiapi64.lib;IrisMultiMotorController.lib;OrbbecSDK.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>opencv_world3411.lib;vincecontrol.lib;gdal_i.lib;resonon-basler.lib;resonon-allied.lib;AutoFocus_InspireLinearMotor_DLL.lib;libconfig++.lib;xiapi64.lib;IrisMultiMotorController.lib;OrbbecSDK.lib;EDSDK.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>D:\cpp_project_vs2022\HPPA\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
@ -112,6 +112,8 @@
<ClCompile Include="AspectRatioLabel.cpp" />
<ClCompile Include="CaptureCoordinator.cpp" />
<ClCompile Include="Carousel.cpp" />
<ClCompile Include="CommunicationInterfaceBase.cpp" />
<ClCompile Include="CommunicationViaTCP.cpp" />
<ClCompile Include="Corning410Imager.cpp" />
<ClCompile Include="CustomDockWidgetBase.cpp" />
<ClCompile Include="DepthCameraWindow.cpp" />
@ -124,6 +126,7 @@
<ClCompile Include="irisximeaimager.cpp" />
<ClCompile Include="LayerTree.cpp" />
<ClCompile Include="LayerTreeGroupNode.cpp" />
<ClCompile Include="LayerTreeImageNode.cpp" />
<ClCompile Include="LayerTreeLayerNode.cpp" />
<ClCompile Include="LayerTreeModel.cpp" />
<ClCompile Include="LayerTreeNode.cpp" />
@ -139,11 +142,15 @@
<ClCompile Include="OneMotorControl.cpp" />
<ClCompile Include="path_tc.cpp" />
<ClCompile Include="PowerControl.cpp" />
<ClCompile Include="PowerControl3D.cpp" />
<ClCompile Include="QDoubleSlider.cpp" />
<ClCompile Include="QMotorDoubleSlider.cpp" />
<ClCompile Include="RasterDataProvider.cpp" />
<ClCompile Include="RasterLayer.cpp" />
<ClCompile Include="RasterRenderer.cpp" />
<ClCompile Include="MultibandRasterRenderer.cpp" />
<ClCompile Include="RasterRendererBase.cpp" />
<ClCompile Include="RasterImageLayer.cpp" />
<ClCompile Include="SinglebandRasterRenderer.cpp" />
<ClCompile Include="recordFrameCounter.cpp" />
<ClCompile Include="resononImager.cpp" />
<ClCompile Include="ResononNirImager.cpp" />
@ -157,6 +164,8 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TabManager.cpp" />
<ClCompile Include="TimedDataCollection.cpp" />
<ClCompile Include="TimedDataCollectionDataStructures.cpp" />
<ClCompile Include="TwoMotorControl.cpp" />
<ClCompile Include="utility_tc.cpp" />
<ClCompile Include="View3D.cpp" />
@ -183,12 +192,14 @@
<QtUic Include="oneMotorControl.ui" />
<QtUic Include="PathPlan.ui" />
<QtUic Include="PowerControl.ui" />
<QtUic Include="PowerControl3D.ui" />
<QtUic Include="RadianceConversion.ui" />
<QtUic Include="ReflectanceConversion.ui" />
<QtUic Include="rgbCamera.ui" />
<QtUic Include="RobotArmControl.ui" />
<QtUic Include="set.ui" />
<QtUic Include="SingleLensReflexCamera.ui" />
<QtUic Include="TimedDataCollection_ui.ui" />
<QtUic Include="twoMotorControl.ui" />
</ItemGroup>
<ItemGroup>
@ -216,6 +227,8 @@
<ClInclude Include="AppSettings.h" />
<QtMoc Include="FileNameLineEdit.h" />
<QtMoc Include="DepthCameraWindow.h" />
<QtMoc Include="CommunicationViaTCP.h" />
<QtMoc Include="CommunicationInterfaceBase.h" />
<ClInclude Include="imager_base.h" />
<ClInclude Include="irisximeaimager.h" />
<QtMoc Include="OneMotorControl.h" />
@ -229,6 +242,7 @@
<QtMoc Include="MapLayer.h" />
<QtMoc Include="RasterLayer.h" />
<QtMoc Include="MapLayerStore.h" />
<QtMoc Include="LayerTreeImageNode.h" />
<ClInclude Include="LayerTreeView.h" />
<QtMoc Include="LayerTreeViewMenuProvider.h" />
<QtMoc Include="MapTool.h" />
@ -236,12 +250,18 @@
<QtMoc Include="MapToolSpectral.h" />
<QtMoc Include="MapTools.h" />
<ClInclude Include="MotorWindowBase.h" />
<QtMoc Include="PowerControl3D.h" />
<ClInclude Include="RasterDataProvider.h" />
<ClInclude Include="RasterRenderer.h" />
<ClInclude Include="MultibandRasterRenderer.h" />
<ClInclude Include="RasterImageLayer.h" />
<ClInclude Include="RasterRendererBase.h" />
<ClInclude Include="SinglebandRasterRenderer.h" />
<QtMoc Include="recordFrameCounter.h" />
<QtMoc Include="setWindow.h" />
<QtMoc Include="rgbCameraWindow.h" />
<QtMoc Include="SingleLensReflexCameraWindow.h" />
<QtMoc Include="TimedDataCollection.h" />
<QtMoc Include="TimedDataCollectionDataStructures.h" />
<ClInclude Include="utility_tc.h" />
<QtMoc Include="aboutWindow.h" />
<ClInclude Include="hppaConfigFile.h" />

View File

@ -160,10 +160,16 @@
<ClCompile Include="RasterLayer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RasterImageLayer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RasterDataProvider.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RasterRenderer.cpp">
<ClCompile Include="MultibandRasterRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SinglebandRasterRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MapLayerStore.cpp">
@ -220,6 +226,27 @@
<ClCompile Include="SingleLensReflexCameraWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LayerTreeImageNode.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RasterRendererBase.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TimedDataCollection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TimedDataCollectionDataStructures.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CommunicationViaTCP.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CommunicationInterfaceBase.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PowerControl3D.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="fileOperation.h">
@ -360,6 +387,24 @@
<QtMoc Include="SingleLensReflexCameraWindow.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="LayerTreeImageNode.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="TimedDataCollection.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="TimedDataCollectionDataStructures.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="CommunicationViaTCP.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="CommunicationInterfaceBase.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="PowerControl3D.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<ClInclude Include="imageProcessor.h">
@ -395,7 +440,16 @@
<ClInclude Include="RasterDataProvider.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RasterRenderer.h">
<ClInclude Include="MultibandRasterRenderer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RasterImageLayer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RasterRendererBase.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SinglebandRasterRenderer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LayerTreeView.h">
@ -457,6 +511,12 @@
<QtUic Include="SingleLensReflexCamera.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="TimedDataCollection_ui.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="PowerControl3D.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />

View File

@ -6,7 +6,7 @@
#include <QPoint>
#include "ImageViewer.h"
#include "RasterLayer.h"
#include "RasterImageLayer.h"
#include "MapTool.h"
@ -264,35 +264,22 @@ qreal Mapcavas::zoomDelta() const
return m_zoomDelta;
}
// new: set associated raster layer
void Mapcavas::setLayers(RasterLayer* layer)
// set associated raster image layer
void Mapcavas::setImageLayer(RasterImageLayer* layer)
{
m_rasterLayer = layer;
m_imageLayer = layer;
}
RasterLayer* Mapcavas::rasterLayer() const
RasterImageLayer* Mapcavas::imageLayer() const
{
return m_rasterLayer;
return m_imageLayer;
}
// new: refresh the map by rendering using the RasterLayer's render method
void Mapcavas::freshmap()
{
if (!m_rasterLayer) return;
if (!m_imageLayer) return;
RasterLayer::RenderParams params = m_rasterLayer->currentRenderParams();
QImage img = m_rasterLayer->render(params);
if (img.isNull()) return;
QPixmap pm = QPixmap::fromImage(img);
SetImage(&pm);
}
void Mapcavas::freshmap(const RasterLayer::RenderParams& params)
{
if (!m_rasterLayer) return;
QImage img = m_rasterLayer->render(params);
QImage img = m_imageLayer->render();
if (img.isNull()) return;
QPixmap pm = QPixmap::fromImage(img);

View File

@ -4,7 +4,8 @@
#include "QGraphicsView"
#include "qlabel.h"
#include <QVector>
#include "RasterLayer.h"
class RasterImageLayer;
class MapTool;
@ -16,7 +17,7 @@ public:
Mapcavas(QWidget* pParent = NULL);
~Mapcavas();
void DisplayFrameNumber(int frameNumber);
@ -47,12 +48,11 @@ public:
void setZoomDelta(qreal delta);
qreal zoomDelta() const;
// new: set raster layer and refresh map
void setLayers(RasterLayer* layer);
// set raster image layer and refresh map
void setImageLayer(RasterImageLayer* layer);
void freshmap();
void freshmap(const RasterLayer::RenderParams& params);
RasterLayer* rasterLayer() const;
RasterImageLayer* imageLayer() const;
// MapTool management
void setMapTool(MapTool* tool);
@ -65,7 +65,7 @@ private:
QGraphicsPixmapItem *m_GraphicsPixmapItemHandle;
QLabel *m_framNumberLabel;//显示实时采集到的帧数
RasterLayer* m_rasterLayer = nullptr; // associated raster layer
RasterImageLayer* m_imageLayer = nullptr; // associated raster image layer
MapTool* m_mapTool = nullptr; // current active map tool
qreal m_translateSpeed; // 平移速度

View File

@ -0,0 +1,31 @@
#include "LayerTreeImageNode.h"
#include "RasterImageLayer.h"
LayerTreeImageNode::LayerTreeImageNode(RasterImageLayer* imageLayer,
const QString& name,
QWidget* widget,
QObject* parent)
: LayerTreeNode(name, parent)
, m_imageLayer(imageLayer)
, m_widget(widget)
{
}
LayerTreeImageNode::~LayerTreeImageNode()
{
}
LayerTreeNode::Type LayerTreeImageNode::type() const
{
return Type::Image;
}
QWidget* LayerTreeImageNode::widget() const
{
return m_widget;
}
void LayerTreeImageNode::setWidget(QWidget* widget)
{
m_widget = widget;
}

30
HPPA/LayerTreeImageNode.h Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include "LayerTreeNode.h"
#include <memory>
class QWidget;
class RasterImageLayer;
class LayerTreeImageNode : public LayerTreeNode
{
Q_OBJECT
public:
explicit LayerTreeImageNode(RasterImageLayer* imageLayer,
const QString& name,
QWidget* widget = nullptr,
QObject* parent = nullptr);
~LayerTreeImageNode();
Type type() const override;
RasterImageLayer* imageLayer() const { return m_imageLayer; }
QWidget* widget() const;
void setWidget(QWidget* widget);
private:
RasterImageLayer* m_imageLayer;
QWidget* m_widget = nullptr;
};

View File

@ -1,7 +1,7 @@
#include "LayerTreeLayerNode.h"
LayerTreeLayer::LayerTreeLayer(MapLayer* layer, QObject* parent)
: LayerTreeNode(layer ? layer->name() : QString(), parent), m_layer(layer)
: LayerTreeGroup(layer ? layer->name() : QString(), parent), m_layer(layer)
{
}

View File

@ -1,5 +1,5 @@
#pragma once
#include "LayerTreeNode.h"
#include "LayerTreeGroupNode.h"
#include "MapLayer.h"
/**
@ -7,13 +7,13 @@
* - 基类为 LayerTreeNode
* - 持有一个 MapLayer 指针(不拥有)
*/
class LayerTreeLayer : public LayerTreeNode
class LayerTreeLayer : public LayerTreeGroup
{
Q_OBJECT
public:
explicit LayerTreeLayer(MapLayer* layer, QObject* parent = nullptr);
Type type() const override;
Type type() const;
void setMapLayer(MapLayer* layer);
MapLayer* mapLayer() const;

View File

@ -133,7 +133,7 @@ LayerTreeNode* LayerTreeModel::addGroup(LayerTreeNode* parent, const QString& na
return g;
}
LayerTreeNode* LayerTreeModel::addLayer(LayerTreeNode* parent, LayerTreeLayer* layerNode, const QIcon& icon)
LayerTreeNode* LayerTreeModel::addLayer(LayerTreeNode* parent, LayerTreeNode* layerNode, const QIcon& icon)
{
if (!parent) parent = m_tree;
if (!layerNode) return nullptr;

View File

@ -34,7 +34,7 @@ public:
LayerTreeNode* root() const;
LayerTreeNode* addGroup(LayerTreeNode* parent, const QString& name, const QIcon& icon = QIcon());
LayerTreeNode* addLayer(LayerTreeNode* parent, LayerTreeLayer* layerNode, const QIcon& icon = QIcon());
LayerTreeNode* addLayer(LayerTreeNode* parent, LayerTreeNode* layerNode, const QIcon& icon = QIcon());
void setCascadeCheckEnabled(bool enabled);
bool cascadeCheckEnabled() const;

View File

@ -19,7 +19,7 @@ class LayerTreeNode : public QObject
{
Q_OBJECT
public:
enum class Type { Group, Layer };
enum class Type { Group, Layer, Image };
explicit LayerTreeNode(const QString& name,
QObject* parent = nullptr);

View File

@ -36,9 +36,20 @@ QMenu* LayerTreeViewMenuProvider::createContextMenu()
if (node->type() == LayerTreeNode::Type::Layer)
{
QAction* removeAction = new QAction(QStringLiteral("移除图层"), menu);
connect(removeAction, &QAction::triggered, HPPA::instance(), &HPPA::removeLayerByTreeIndex);
menu->addAction(removeAction);
QAction* removeLayerAction = new QAction(QStringLiteral("移除图层"), menu);
connect(removeLayerAction, &QAction::triggered, HPPA::instance(), &HPPA::removeLayerByTreeIndex);
QAction* showColorImageAction = new QAction(QStringLiteral("显示彩色图像"), menu);
connect(showColorImageAction, &QAction::triggered, HPPA::instance(), &HPPA::showColorImageByTreeIndex);
menu->addAction(removeLayerAction);
menu->addAction(showColorImageAction);
}
else if (node->type() == LayerTreeNode::Type::Image)
{
QAction* removeImageAction = new QAction(QStringLiteral("移除图像"), menu);
connect(removeImageAction, &QAction::triggered, HPPA::instance(), &HPPA::removeImageByTreeIndex);
menu->addAction(removeImageAction);
}
else if (node->type() == LayerTreeNode::Type::Group)
{

View File

@ -1,43 +1,93 @@
#include "MapLayerStore.h"
#include "MapLayer.h"
#include "RasterImageLayer.h"
#include <QFileInfo>
#include <QWidget>
MapLayerStore::MapLayerStore(QObject* parent)
: QObject(parent)
{
int a = 1;
}
void MapLayerStore::addLayer(MapLayer* layer, QWidget* widget)
void MapLayerStore::addLayer(MapLayer* layer)
{
if (!layer) return;
MapLayer* raw = layer;
m_layers.emplace_back(std::shared_ptr<MapLayer>(layer));
if (widget)
m_layerWidgets[raw] = widget;
emit layerAdded(raw);
int index = (int)m_layers.size();
LayerEntry entry;
entry.mapLayer.reset(layer);
m_layers.push_back(std::move(entry));
m_mapLayerIndex[layer] = index;
emit layerAdded(layer);
}
void MapLayerStore::addImageLayer(MapLayer* mapLayer, RasterImageLayer* imageLayer, QWidget* widget)
{
if (!mapLayer || !imageLayer) return;
LayerEntry* entry = findLayerEntry(mapLayer);
if (!entry) return;
entry->imageLayers.push_back({std::unique_ptr<RasterImageLayer>(imageLayer), widget});
emit imageLayerAdded(imageLayer);
}
void MapLayerStore::removeLayer(MapLayer* layer)
{
if (!layer) return;
for (auto it = m_layers.begin(); it != m_layers.end(); ++it) {
if (it->get() == layer) {
emit layerAboutToBeRemoved(layer);
m_layers.erase(it);
m_layerWidgets.erase(layer);
return;
auto it = m_mapLayerIndex.find(layer);
if (it == m_mapLayerIndex.end()) return;
int index = it->second;
if (index < 0 || index >= (int)m_layers.size()) return;
LayerEntry& entry = m_layers[index];
// Delete all associated widgets
for (auto& imgEntry : entry.imageLayers) {
if (imgEntry.widget) {
delete imgEntry.widget;
}
}
entry.imageLayers.clear();
emit layerAboutToBeRemoved(layer);
m_layers.erase(m_layers.begin() + index);//?????????????????????
m_mapLayerIndex.erase(it);
// Rebuild index for layers after removed one
for (int i = index; i < (int)m_layers.size(); ++i) {
m_mapLayerIndex[m_layers[i].mapLayer.get()] = i;
}
}
void MapLayerStore::removeImageLayer(RasterImageLayer* imageLayer)//可以优化RasterImageLayer包含一个指向所属MapLayer的指针这样就不需要遍历所有图层来找到它了
{
if (!imageLayer) return;
for (auto& entry : m_layers) {
for (auto it = entry.imageLayers.begin(); it != entry.imageLayers.end(); ++it) {
if (it->imageLayer.get() == imageLayer) {
emit imageLayerAboutToBeRemoved(imageLayer);
if (it->widget) {
//delete it->widget;//在调用此函数的地方已经删除了widget了这里不需要再删除一次了
}
entry.imageLayers.erase(it);
return;
}
}
}
}
void MapLayerStore::removeLayerByName(const QString& name)
{
for (auto it = m_layers.begin(); it != m_layers.end(); ++it) {
if ((*it)->name() == name) {
MapLayer* raw = it->get();
emit layerAboutToBeRemoved(raw);
m_layers.erase(it);
m_layerWidgets.erase(raw);
for (auto& entry : m_layers) {
if (entry.mapLayer->name() == name) {
removeLayer(entry.mapLayer.get());
return;
}
}
@ -48,12 +98,12 @@ bool MapLayerStore::containsLayer(const QString& url, bool isAbsolutePath) const
QFileInfo fi(url);
QString fileName = fi.completeBaseName();
if (!isAbsolutePath)
{
if (!isAbsolutePath) {
return getLayer(fileName) != nullptr;
}
for (const auto& l : m_layers) {
if (l->dataPath() == url)
for (const auto& entry : m_layers) {
if (entry.mapLayer->dataPath() == url)
return true;
}
return false;
@ -61,16 +111,27 @@ bool MapLayerStore::containsLayer(const QString& url, bool isAbsolutePath) const
MapLayer* MapLayerStore::getLayer(const QString& name) const
{
for (const auto& l : m_layers) {
if (l->name() == name) return l.get();
for (const auto& entry : m_layers) {
if (entry.mapLayer->name() == name)
return entry.mapLayer.get();
}
return nullptr;
}
MapLayer* MapLayerStore::getLayerAt(int index) const
{
if (index < 0 || index >= (int)m_layers.size()) return nullptr;
return m_layers[index].get();
if (index < 0 || index >= (int)m_layers.size())
return nullptr;
return m_layers[index].mapLayer.get();
}
MapLayer* MapLayerStore::getLayerByAbsolutePath(const QString& absolutePath) const
{
for (const auto& entry : m_layers) {
if (entry.mapLayer->dataPath() == absolutePath)
return entry.mapLayer.get();
}
return nullptr;
}
int MapLayerStore::layerCount() const
@ -78,31 +139,129 @@ int MapLayerStore::layerCount() const
return (int)m_layers.size();
}
QWidget* MapLayerStore::widgetForLayer(MapLayer* layer) const
RasterImageLayer* MapLayerStore::getImageLayer(MapLayer* mapLayer, int index) const
{
auto it = m_layerWidgets.find(layer);
if (it == m_layerWidgets.end()) return nullptr;
return it->second;
const LayerEntry* entry = findLayerEntry(mapLayer);
if (!entry) return nullptr;
if (index < 0 || index >= (int)entry->imageLayers.size())
return nullptr;
return entry->imageLayers[index].imageLayer.get();
}
int MapLayerStore::imageLayerCount(MapLayer* mapLayer) const
{
const LayerEntry* entry = findLayerEntry(mapLayer);
if (!entry) return 0;
return (int)entry->imageLayers.size();
}
std::vector<RasterImageLayer*> MapLayerStore::getAllImageLayers() const
{
std::vector<RasterImageLayer*> result;
for (const auto& entry : m_layers) {
for (const auto& imgEntry : entry.imageLayers) {
if (imgEntry.imageLayer)
result.push_back(imgEntry.imageLayer.get());
}
}
return result;
}
QWidget* MapLayerStore::widgetForImageLayer(RasterImageLayer* imageLayer) const
{
for (const auto& entry : m_layers) {
for (const auto& imgEntry : entry.imageLayers) {
if (imgEntry.imageLayer.get() == imageLayer)
return imgEntry.widget;
}
}
return nullptr;
}
QWidget* MapLayerStore::widgetForLayer(MapLayer* layer) const//需要修改??????????????????????????????????????????????
{
const LayerEntry* entry = findLayerEntry(layer);
if (!entry || entry->imageLayers.empty())
return nullptr;
return entry->imageLayers.front().widget;
}
QWidget* MapLayerStore::widgetForLayer(const QString& absolutePath) const
{
for (const auto& sp : m_layers) {
if (sp && sp->dataPath() == absolutePath) {
MapLayer* raw = sp.get();
auto it = m_layerWidgets.find(raw);
if (it != m_layerWidgets.end()) return it->second;
for (const auto& entry : m_layers) {
if (entry.mapLayer->dataPath() == absolutePath) {
if (!entry.imageLayers.empty())
return entry.imageLayers.front().widget;
return nullptr;
}
}
return nullptr;
}
MapLayer* MapLayerStore::layerForWidget(QWidget* widget) const
std::vector<QWidget*> MapLayerStore::widgetsForMapLayer(MapLayer* mapLayer) const
{
if (!widget) return nullptr;
for (const auto& kv : m_layerWidgets) {
if (kv.second == widget) return kv.first;
std::vector<QWidget*> result;
const LayerEntry* entry = findLayerEntry(mapLayer);
if (!entry) return result;
for (const auto& imgEntry : entry->imageLayers) {
if (imgEntry.widget)
result.push_back(imgEntry.widget);
}
return result;
}
MapLayer* MapLayerStore::mapLayerForImageLayer(RasterImageLayer* imageLayer) const
{
for (const auto& entry : m_layers) {
for (const auto& imgEntry : entry.imageLayers) {
if (imgEntry.imageLayer.get() == imageLayer)
return entry.mapLayer.get();
}
}
return nullptr;
}
MapLayer* MapLayerStore::mapLayerForWidget(QWidget* widget) const
{
if (!widget) return nullptr;
for (const auto& entry : m_layers) {
for (const auto& imgEntry : entry.imageLayers) {
if (imgEntry.widget == widget)
return entry.mapLayer.get();
}
}
return nullptr;
}
RasterImageLayer* MapLayerStore::imageLayerForWidget(QWidget* widget) const
{
if (!widget) return nullptr;
for (const auto& entry : m_layers) {
for (const auto& imgEntry : entry.imageLayers) {
if (imgEntry.widget == widget)
return imgEntry.imageLayer.get();
}
}
return nullptr;
}
MapLayerStore::LayerEntry* MapLayerStore::findLayerEntry(MapLayer* mapLayer)
{
auto it = m_mapLayerIndex.find(mapLayer);
if (it == m_mapLayerIndex.end()) return nullptr;
int index = it->second;
if (index < 0 || index >= (int)m_layers.size()) return nullptr;
return &m_layers[index];
}
const MapLayerStore::LayerEntry* MapLayerStore::findLayerEntry(MapLayer* mapLayer) const
{
auto it = m_mapLayerIndex.find(mapLayer);
if (it == m_mapLayerIndex.end()) return nullptr;
int index = it->second;
if (index < 0 || index >= (int)m_layers.size()) return nullptr;
return &m_layers[index];
}

View File

@ -2,53 +2,71 @@
#include <QObject>
#include <QString>
#include <QFileInfo>
#include <vector>
#include <memory>
#include <unordered_map>
class MapLayer;
class RasterImageLayer;
class QWidget;
class MapLayerStore : public QObject
{
Q_OBJECT
struct ImageLayerEntry {
std::unique_ptr<RasterImageLayer> imageLayer;
QWidget* widget;
};
struct LayerEntry {
std::unique_ptr<MapLayer> mapLayer;
std::vector<ImageLayerEntry> imageLayers;
};
public:
explicit MapLayerStore(QObject* parent = nullptr);
~MapLayerStore() override = default;
// Take ownership of the layer (store will own and manage its lifetime)
// Now also accept the associated QWidget so UI widget can be retrieved by layer pointer
void addLayer(MapLayer* layer, QWidget* widget = nullptr);
bool containsLayer(const QString& url, bool isAbsolutePath = true) const;
// Remove by pointer or by name. Destruction happens when removed from store.
public slots:
// Layer management
void addLayer(MapLayer* layer);
void removeLayer(MapLayer* layer);
void removeLayerByName(const QString& name);
bool containsLayer(const QString& url, bool isAbsolutePath = true) const;
// Queries
MapLayer* getLayer(const QString& name) const;
MapLayer* getLayerByAbsolutePath(const QString& absolutePath) const;
MapLayer* getLayerAt(int index) const;
int layerCount() const;
// Get associated widget for a layer (or nullptr if none)
QWidget* widgetForLayer(MapLayer* layer) const;
// Get associated widget by layer absolute data path
QWidget* widgetForLayer(const QString& absolutePath) const;
// ImageLayer management
void addImageLayer(MapLayer* mapLayer, RasterImageLayer* imageLayer, QWidget* widget);
void removeImageLayer(RasterImageLayer* imageLayer);
RasterImageLayer* getImageLayer(MapLayer* mapLayer, int index) const;
int imageLayerCount(MapLayer* mapLayer) const;
std::vector<RasterImageLayer*> getAllImageLayers() const;
// Reverse lookup: find the MapLayer associated with a given widget (or nullptr)
MapLayer* layerForWidget(QWidget* widget) const;
// Widget queries
QWidget* widgetForImageLayer(RasterImageLayer* imageLayer) const;
QWidget* widgetForLayer(MapLayer* layer) const;
QWidget* widgetForLayer(const QString& absolutePath) const;
std::vector<QWidget*> widgetsForMapLayer(MapLayer* mapLayer) const;
// Reverse lookups
MapLayer* mapLayerForImageLayer(RasterImageLayer* imageLayer) const;
MapLayer* mapLayerForWidget(QWidget* widget) const;
RasterImageLayer* imageLayerForWidget(QWidget* widget) const;
signals:
void layerAdded(MapLayer* layer);
// Emitted just before the layer is destroyed/removed from store
void layerAboutToBeRemoved(MapLayer* layer);
void imageLayerAdded(RasterImageLayer* imageLayer);
void imageLayerAboutToBeRemoved(RasterImageLayer* imageLayer);
private:
// store shared ownership so other parts can keep raw pointers safely (or use QPointer)
std::vector<std::shared_ptr<MapLayer>> m_layers;
// mapping from raw MapLayer pointer to associated QWidget*
std::unordered_map<MapLayer*, QWidget*> m_layerWidgets;
LayerEntry* findLayerEntry(MapLayer* mapLayer);
const LayerEntry* findLayerEntry(MapLayer* mapLayer) const;
std::vector<LayerEntry> m_layers;
std::unordered_map<MapLayer*, int> m_mapLayerIndex;
};

View File

@ -41,10 +41,10 @@ void MapToolSpectral::canvasMousePressEvent(QMouseEvent* e)
const int x = static_cast<int>(std::floor(scenePt.x()));
const int y = static_cast<int>(std::floor(scenePt.y()));
RasterLayer* rl = canvas()->rasterLayer();
auto* imageLayer = canvas()->imageLayer();
RasterLayer* rl = imageLayer ? imageLayer->layer() : nullptr;
if (rl && rl->isValidPixel(x, y))
{
// Place crosshair at pixel center
canvas()->updateCrosshair(x + 0.5, y + 0.5);
QVector<double> wavelengths;

View File

@ -4,6 +4,8 @@
#include "MapTool.h"
#include <QVector>
#include "RasterImageLayer.h"
class QGraphicsLineItem;
class MapToolSpectral : public MapTool

View File

@ -1,30 +1,32 @@
#include "RasterRenderer.h"
#include "MultibandRasterRenderer.h"
#include "RasterDataProvider.h"
#include <QDebug>
#include <algorithm>
RasterRenderer::RasterRenderer(RasterDataProvider* provider)
: m_provider(provider)
MultibandRasterRenderer::MultibandRasterRenderer(RasterDataProvider* provider)
: RasterRendererBase(provider)
{
}
void RasterRenderer::stretchTo8bit(const std::vector<float>& in, std::vector<unsigned char>& out, float minVal, float maxVal)
void MultibandRasterRenderer::stretchTo8bit(const std::vector<float>& in, std::vector<unsigned char>& out, float minVal, float maxVal)
{
size_t n = in.size();
out.resize(n);
if (maxVal <= minVal) {
if (maxVal <= minVal)
{
std::fill(out.begin(), out.end(), 0);
return;
}
float denom = 1.0f / (maxVal - minVal);
for (size_t i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i)
{
float v = (in[i] - minVal) * denom;
v = std::min(std::max(v, 0.0f), 1.0f);
out[i] = static_cast<unsigned char>(v * 255.0f);
}
}
QImage RasterRenderer::render(const Params& params)
QImage MultibandRasterRenderer::render()
{
if (!m_provider) return QImage();
int bands = m_provider->bandCount();
@ -38,7 +40,7 @@ QImage RasterRenderer::render(const Params& params)
auto chooseBandIndexForWave = [&](double wave)->int {
if (wavelengths.empty()) {
// fallback: select R,G,B as first three bands
if (bands >= 3) return (wave==params.rWave?0:(wave==params.gWave?1:2));
if (bands >= 3) return (wave==m_params.rWave?0:(wave==m_params.gWave?1:2));
if (bands >= 1) return 0;
return -1;
}
@ -53,9 +55,9 @@ QImage RasterRenderer::render(const Params& params)
return std::min(2, bands-1);
};
int rIdx = chooseBandIndexForWave(params.rWave);
int gIdx = chooseBandIndexForWave(params.gWave);
int bIdx = chooseBandIndexForWave(params.bWave);
int rIdx = chooseBandIndexForWave(m_params.rWave);
int gIdx = chooseBandIndexForWave(m_params.gWave);
int bIdx = chooseBandIndexForWave(m_params.bWave);
std::vector<float> rbuf, gbuf, bbuf;
if (rIdx >= 0) m_provider->readBandAsFloat(rIdx, rbuf);
@ -63,8 +65,8 @@ QImage RasterRenderer::render(const Params& params)
if (bIdx >= 0) m_provider->readBandAsFloat(bIdx, bbuf);
std::vector<unsigned char> r8, g8, b8;
float minV = static_cast<float>(params.minValue);
float maxV = static_cast<float>(params.maxValue);
float minV = static_cast<float>(m_params.minValue);
float maxV = static_cast<float>(m_params.maxValue);
if (!rbuf.empty()) stretchTo8bit(rbuf, r8, minV, maxV);
if (!gbuf.empty()) stretchTo8bit(gbuf, g8, minV, maxV);
if (!bbuf.empty()) stretchTo8bit(bbuf, b8, minV, maxV);

View File

@ -0,0 +1,26 @@
#pragma once
#include "RasterRendererBase.h"
#include "RasterRenderParams.h"
#include <vector>
#include <memory>
class RasterDataProvider;
class MultibandRasterRenderer : public RasterRendererBase
{
public:
explicit MultibandRasterRenderer(RasterDataProvider* provider);
QImage render() override;
// Parameter access
MultibandRenderParams params() const { return m_params; }
void setParams(const MultibandRenderParams& params) { m_params = params; }
private:
MultibandRenderParams m_params;
// Helper to map float buffer to 8-bit with min/max stretch
static void stretchTo8bit(const std::vector<float>& in, std::vector<unsigned char>& out, float minVal, float maxVal);
};

100
HPPA/PowerControl3D.cpp Normal file
View File

@ -0,0 +1,100 @@
#include "PowerControl3D.h"
using namespace MotorParams;
PowerControl3D::PowerControl3D(QWidget* parent)
: QDialog(parent)
{
ui.setupUi(this);
connect(ui.halogenLampPowerOn_btn, &QPushButton::clicked, this, &PowerControl3D::halogenLampPowerOn);
connect(ui.halogenLampPowerDown_btn, &QPushButton::clicked, this, &PowerControl3D::halogenLampPowerDown);
connect(ui.d65LampPowerOn_btn, &QPushButton::clicked, this, &PowerControl3D::d65LampPowerOn);
connect(ui.d65LampPowerDown_btn, &QPushButton::clicked, this, &PowerControl3D::d65LampPowerDown);
connect(ui.slrPowerOn_btn, &QPushButton::clicked, this, &PowerControl3D::slrPowerOn);
connect(ui.slrPowerDown_btn, &QPushButton::clicked, this, &PowerControl3D::slrPowerDown);
MotorParams::TCPConnectionParams tcpConnectionParams6003;
tcpConnectionParams6003.port = 6003;
tcpConnectionParams6003.serverIP = "192.168.1.2";
tcpServer6003 = new CommunicationViaTCP(tcpConnectionParams6003, this);
MotorParams::TCPConnectionParams tcpConnectionParams6004;
tcpConnectionParams6004.port = 6004;
tcpConnectionParams6004.serverIP = "192.168.1.2";
tcpServer6004 = new CommunicationViaTCP(tcpConnectionParams6004, this);
}
PowerControl3D::~PowerControl3D()
{
delete tcpServer6003;
delete tcpServer6004;
}
void PowerControl3D::halogenLampPowerOn()
{
tcpServer6003->sendCommand(R"({"key1":1,"type":"event"})");
}
void PowerControl3D::halogenLampPowerDown()
{
tcpServer6003->sendCommand(R"({"key1":0,"type":"event"})");
}
void PowerControl3D::switchHalogenLampPower(int state)
{
if (state==0)
{
halogenLampPowerDown();
}
else if(state == 1)
{
halogenLampPowerOn();
}
}
void PowerControl3D::d65LampPowerOn()
{
tcpServer6004->sendCommand(R"({"key1":1,"type":"event"})");
}
void PowerControl3D::d65LampPowerDown()
{
tcpServer6004->sendCommand(R"({"key1":0,"type":"event"})");
}
void PowerControl3D::switchD65LampPower(int state)
{
if (state == 0)
{
d65LampPowerDown();
}
else if (state == 1)
{
d65LampPowerOn();
}
}
void PowerControl3D::slrPowerOn()
{
tcpServer6003->sendCommand(R"({"key2":1,"type":"event"})");
}
void PowerControl3D::slrPowerDown()
{
tcpServer6003->sendCommand(R"({"key2":0,"type":"event"})");
}
void PowerControl3D::switchSlrPower(int state)
{
if (state == 0)
{
slrPowerDown();
}
else if (state == 1)
{
slrPowerOn();
}
}

42
HPPA/PowerControl3D.h Normal file
View File

@ -0,0 +1,42 @@
#pragma once
#include <QDialog>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include "ui_PowerControl3D.h"
#include "CommunicationViaTCP.h"
//using namespace MotorParams;
class PowerControl3D : public QDialog
{
Q_OBJECT
public:
PowerControl3D(QWidget* parent = nullptr);
~PowerControl3D();
public Q_SLOTS:
void halogenLampPowerOn();
void halogenLampPowerDown();
void switchHalogenLampPower(int state);
void d65LampPowerOn();
void d65LampPowerDown();
void switchD65LampPower(int state);
void slrPowerOn();
void slrPowerDown();
void switchSlrPower(int state);
signals:
//void powerOpened();
private:
Ui::PowerControl3D_UI ui;
MotorParams::CommunicationViaTCP* tcpServer6003;
MotorParams::CommunicationViaTCP* tcpServer6004;
};

350
HPPA/PowerControl3D.ui Normal file
View File

@ -0,0 +1,350 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PowerControl3D_UI</class>
<widget class="QDialog" name="PowerControl3D_UI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>493</width>
<height>369</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>PowerControl3D</string>
</property>
<property name="styleSheet">
<string notr="true">QGroupBox
{
border: 12px solid transparent;
/*border-top: 12px solid transparent;
border-right: 0px solid transparent;
border-bottom: 0px solid transparent;
border-left: 0px solid transparent;*/
color: #ACCDFF;
}
QPushButton
{
/*width: 172px;
height: 56px;*/
font: 19pt &quot;新宋体&quot;;
background-color: qlineargradient(
spread:pad,
x1:0.5, y1:0, x2:0.5, y2:1,
stop:0 #283D86,
stop:1 #0F1A40
);
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
}
QPushButton:hover
{
background-color: qlineargradient(
spread:pad,
x1:0, y1:0, x2:1, y2:0,
stop:0 #3A4875,
stop:1 #5F6B91
);
}
/* 按下时的效果 */
QPushButton:pressed
{
background-color: qlineargradient(
spread:pad,
x1:0, y1:0, x2:1, y2:0,
stop:0 #1A254F,
stop:1 #3A466B
);
/* 可选:添加下压效果 */
padding-top: 9px;
padding-bottom: 7px;
}</string>
</property>
<layout class="QGridLayout" name="gridLayout_4" rowstretch="1,2,2,2,1" columnstretch="1,10,1">
<item row="0" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>66</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>63</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="groupBox_8">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>卤素灯</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>18</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="halogenLampPowerOn_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>打 开</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="halogenLampPowerDown_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>关 闭</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>63</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>63</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QGroupBox" name="groupBox_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>D65灯</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>18</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="d65LampPowerOn_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>打 开</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="d65LampPowerDown_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>关 闭</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="2">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>63</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>63</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QGroupBox" name="groupBox_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>单反</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>18</number>
</property>
<item row="0" column="1">
<widget class="QPushButton" name="slrPowerDown_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>下 电</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="slrPowerOn_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>上 电</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>63</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>65</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

81
HPPA/RasterImageLayer.cpp Normal file
View File

@ -0,0 +1,81 @@
#include "RasterImageLayer.h"
#include "RasterLayer.h"
#include "RasterDataProvider.h"
#include "RasterRendererBase.h"
#include "MultibandRasterRenderer.h"
#include "SinglebandRasterRenderer.h"
RasterImageLayer::RasterImageLayer(RasterLayer* layer, RendererType type)
: m_layer(layer)
, m_rendererType(type)
, m_rendererInitialized(false)
{
}
void RasterImageLayer::ensureRenderer()
{
if (m_rendererInitialized) return;
if (!m_layer) return;
RasterDataProvider* provider = nullptr;
if (m_layer->dataProvider())
{
provider = m_layer->dataProvider();
}
else if (m_layer->openDataProvider())
{
provider = m_layer->dataProvider();
}
if (!provider) return;
switch (m_rendererType)
{
case RendererType::Multiband:
{
auto* multiRenderer = new MultibandRasterRenderer(provider);
m_renderer.reset(multiRenderer);
multiRenderer->setParams(m_multibandParams);
break;
}
case RendererType::Singleband:
{
auto* singleRenderer = new SinglebandRasterRenderer(provider);
m_renderer.reset(singleRenderer);
singleRenderer->setParams(m_singlebandParams);
break;
}
}
m_rendererInitialized = true;
}
RasterImageLayer::~RasterImageLayer()
{
m_renderer.reset();
}
QImage RasterImageLayer::render()
{
ensureRenderer();
if (!m_renderer) return QImage();
return m_renderer->render();
}
void RasterImageLayer::setMultibandParams(const MultibandRenderParams& params)
{
m_multibandParams = params;
if (m_rendererInitialized && m_rendererType == RendererType::Multiband) {
auto* r = static_cast<MultibandRasterRenderer*>(m_renderer.get());
r->setParams(params);
}
}
void RasterImageLayer::setSinglebandParams(const SinglebandRenderParams& params)
{
m_singlebandParams = params;
if (m_rendererInitialized && m_rendererType == RendererType::Singleband) {
auto* r = static_cast<SinglebandRasterRenderer*>(m_renderer.get());
r->setParams(params);
}
}

46
HPPA/RasterImageLayer.h Normal file
View File

@ -0,0 +1,46 @@
#pragma once
#include <memory>
#include <QImage>
#include "RasterRendererBase.h"
#include "RasterRenderParams.h"
class RasterLayer;
class RasterRendererBase;
class MultibandRasterRenderer;
class SinglebandRasterRenderer;
class RasterImageLayer
{
public:
enum class RendererType {
Multiband,
Singleband
};
RasterImageLayer(RasterLayer* layer, RendererType type);
~RasterImageLayer();
void ensureRenderer();
QImage render();
RasterLayer* layer() const { return m_layer; }
RasterRendererBase* renderer() const { return m_renderer.get(); }
RendererType rendererType() const { return m_rendererType; }
// Type-safe params access
MultibandRenderParams multibandParams() const { return m_multibandParams; }
SinglebandRenderParams singlebandParams() const { return m_singlebandParams; }
void setMultibandParams(const MultibandRenderParams& params);
void setSinglebandParams(const SinglebandRenderParams& params);
private:
RasterLayer* m_layer;
RendererType m_rendererType;
std::unique_ptr<RasterRendererBase> m_renderer;
MultibandRenderParams m_multibandParams;
SinglebandRenderParams m_singlebandParams;
bool m_rendererInitialized = false;
};

View File

@ -1,21 +1,18 @@
#include "RasterLayer.h"
#include "RasterDataProvider.h"
#include "RasterRenderer.h"
#include <algorithm>
RasterLayer::RasterLayer(const QString& name, const QString& uri)
: MapLayer(name, uri)
{
// lazy creation
}
RasterLayer::~RasterLayer()
{
}
MapLayer::LayerType RasterLayer::layerType() const
{
return MapLayer::LayerType::Raster;
MapLayer::LayerType RasterLayer::layerType() const
{
return MapLayer::LayerType::Raster;
}
RasterDataProvider* RasterLayer::dataProvider() const
@ -23,18 +20,11 @@ RasterDataProvider* RasterLayer::dataProvider() const
return m_provider ? m_provider.get() : nullptr;
}
RasterRenderer* RasterLayer::renderer() const
{
return m_renderer ? m_renderer.get() : nullptr;
}
bool RasterLayer::openDataProvider()
{
if (!m_provider) m_provider = std::make_unique<RasterDataProvider>(dataPath());
if (!m_provider) return false;
bool ok = m_provider->open();
if (ok && !m_renderer) m_renderer = std::make_unique<RasterRenderer>(m_provider.get());
return ok;
return m_provider->open();
}
bool RasterLayer::isValidPixel(int x, int y)
@ -71,31 +61,6 @@ bool RasterLayer::readPixelSpectrum(int x, int y, QVector<double>& wavelengths,
return true;
}
QImage RasterLayer::render(const RenderParams& params)
{
if (!m_provider) {
if (!openDataProvider()) return QImage();
}
if (!m_renderer) m_renderer = std::make_unique<RasterRenderer>(m_provider.get());
RasterRenderer::Params p;
p.rWave = params.rWave;
p.gWave = params.gWave;
p.bWave = params.bWave;
p.minValue = params.minValue;
p.maxValue = params.maxValue;
return m_renderer->render(p);
}
RasterLayer::RenderParams RasterLayer::currentRenderParams() const
{
return m_currentParams;
}
void RasterLayer::setCurrentRenderParams(const RenderParams& params)
{
m_currentParams = params;
}
bool RasterLayer::wavelengthRange(double& minWave, double& maxWave) const
{
auto wl = bandWavelengths();
@ -108,9 +73,26 @@ bool RasterLayer::wavelengthRange(double& minWave, double& maxWave) const
std::vector<double> RasterLayer::bandWavelengths() const
{
if (!m_provider) {
// need to open provider to read wavelengths - cast away const for lazy init
auto* self = const_cast<RasterLayer*>(this);
if (!self->openDataProvider()) return {};
}
return m_provider->bandWavelengths();
}
int RasterLayer::width() const
{
if (!m_provider) {
auto* self = const_cast<RasterLayer*>(this);
if (!self->openDataProvider()) return 0;
}
return m_provider->width();
}
int RasterLayer::height() const
{
if (!m_provider) {
auto* self = const_cast<RasterLayer*>(this);
if (!self->openDataProvider()) return 0;
}
return m_provider->height();
}

View File

@ -2,11 +2,10 @@
#include "MapLayer.h"
#include <memory>
#include <QImage>
#include <QVector>
#include <vector>
class RasterDataProvider;
class RasterRenderer;
class RasterLayer : public MapLayer
{
@ -17,9 +16,8 @@ public:
LayerType layerType() const override;
// Access provider/renderer
// Access provider
RasterDataProvider* dataProvider() const;
RasterRenderer* renderer() const;
// Create or open provider based on this layer's uri
bool openDataProvider();
@ -27,29 +25,16 @@ public:
bool isValidPixel(int x, int y);
bool readPixelSpectrum(int x, int y, QVector<double>& wavelengths, QVector<double>& spectrum);
struct RenderParams {
double rWave = 665.0; // default wavelengths (nm)
double gWave = 560.0;
double bWave = 490.0;
double minValue = 0.0; // optional stretch
double maxValue = 4095.0;
};
// Render the raster using current provider and renderer. Returns an empty QImage on failure.
QImage render(const RenderParams& params);
// Current render params stored per layer
RenderParams currentRenderParams() const;
void setCurrentRenderParams(const RenderParams& params);
// Get wavelength range from data provider (min, max). Returns false if unavailable.
bool wavelengthRange(double& minWave, double& maxWave) const;
// Get all band wavelengths
std::vector<double> bandWavelengths() const;
private:
// Get dimensions
int width() const;
int height() const;
protected:
std::unique_ptr<RasterDataProvider> m_provider;
std::unique_ptr<RasterRenderer> m_renderer;
RenderParams m_currentParams;
};

19
HPPA/RasterRenderParams.h Normal file
View File

@ -0,0 +1,19 @@
#pragma once
// Common base struct for all render parameters
struct RasterRenderParamsBase {
double minValue = 0.0;
double maxValue = 4095.0;
};
// Parameters for multiband rendering (RGB with wavelengths)
struct MultibandRenderParams : RasterRenderParamsBase {
double rWave = 665.0;
double gWave = 560.0;
double bWave = 490.0;
};
// Parameters for singleband rendering (wavelength)
struct SinglebandRenderParams : RasterRenderParamsBase {
double wavelength = 550.0;
};

View File

@ -1,29 +0,0 @@
#pragma once
#include <QImage>
#include <vector>
class RasterDataProvider;
class RasterRenderer
{
public:
struct Params {
double rWave = 665.0;
double gWave = 560.0;
double bWave = 490.0;
double minValue = 0.0;
double maxValue = 255.0;
};
explicit RasterRenderer(RasterDataProvider* provider);
// Render to an 8-bit RGB image. Returns empty image on failure.
QImage render(const Params& params);
private:
RasterDataProvider* m_provider;
// helper to map float buffer to 8-bit with min/max stretch
static void stretchTo8bit(const std::vector<float>& in, std::vector<unsigned char>& out, float minVal, float maxVal);
};

View File

@ -0,0 +1,6 @@
#include "RasterRendererBase.h"
RasterRendererBase::RasterRendererBase(RasterDataProvider* provider)
: m_provider(provider)
{
}

25
HPPA/RasterRendererBase.h Normal file
View File

@ -0,0 +1,25 @@
#pragma once
#include <QImage>
#include <memory>
class RasterDataProvider;
class RasterRendererBase
{
public:
//struct Params {
// virtual ~Params() = default;
//};
virtual ~RasterRendererBase() = default;
virtual QImage render() = 0;
RasterDataProvider* dataProvider() const { return m_provider; }
protected:
explicit RasterRendererBase(RasterDataProvider* provider);
RasterDataProvider* m_provider = nullptr;
};

View File

@ -69,7 +69,7 @@ QPushButton:pressed
padding-bottom: 7px;
}</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
@ -97,21 +97,8 @@ QPushButton:pressed
</spacer>
</item>
<item row="1" column="1">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QPushButton" name="closeSLRCamera_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>关 闭</string>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="openSLRCamera_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -124,9 +111,22 @@ QPushButton:pressed
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeSLRCamera_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>关 闭</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="2">
<item row="2" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -139,7 +139,52 @@ QPushButton:pressed
</property>
</spacer>
</item>
<item row="2" column="1">
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="styleSheet">
<string notr="true">QLabel {
color: rgb(255, 255, 255);
}</string>
</property>
<property name="text">
<string>数据路径</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="dataFolderLineEdit">
<property name="styleSheet">
<string notr="true">QLineEdit {
background-color: #142D7F;
color: #e6eeff;
border: 1px solid #2f6bff;
border-radius: 6px;
padding: 4px 8px;
min-width: 70px;
min-height: 20px;
font-size: 13px;
}</string>
</property>
<property name="text">
<string>./CapturedImages</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="dataFolderBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -152,7 +197,42 @@ QPushButton:pressed
</property>
</spacer>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="takePhoto_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>拍 摄</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stopTakePhoto_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>停 拍</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<zorder>dataFolderLineEdit</zorder>
<zorder>dataFolderBtn</zorder>
<zorder>label</zorder>
<zorder>openSLRCamera_btn</zorder>
<zorder>layoutWidget</zorder>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,13 @@
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include <QImage>
#include <Qthread>
#include <QThread>
#include <QDir>
#include <QTimer>
#include <QMutex>
#include <QDateTime>
#include <QLabel>
#include <QFileDialog>
#include <iostream>
#include "ui_SingleLensReflexCamera.h"
@ -14,63 +19,171 @@
#include <fstream>
#include <opencv2/opencv.hpp>
// 包含Canon EDSDK头文件
#include "EDSDK.h"
#include "EDSDKTypes.h"
#include "EDSDKErrors.h"
typedef void(*func)();
class SingleLensReflexCameraOperation :public QObject
class SingleLensReflexCameraOperation : public QObject
{
Q_OBJECT
Q_OBJECT
public:
SingleLensReflexCameraOperation();
~SingleLensReflexCameraOperation();
SingleLensReflexCameraOperation();
~SingleLensReflexCameraOperation();
QImage m_colorImage;
QImage m_depthImage;
void setCallback(void(*func)());
bool getRecordStatus() const { return record; }
QImage m_colorImage;
QImage m_depthImage;
void setCallback(void(*func)());
bool getRecordStatus() const { return m_isRecord; }
// 设置保存路径
void setSavePath(const QString& path);
// 获取当前实时取景图像
QImage getCurrentLiveViewImage();
void setCaptureInterval(int captureIntervalSeconds);
private:
cv::Mat frame;
func m_func;
bool record;
cv::Mat frame;
func m_func;
bool m_isRecord;
// Canon EDSDK相关成员
EdsCameraRef m_camera;
bool m_isSDKInitialized;
bool m_isSessionOpen;
bool m_isLiveViewActive;
QTimer* m_captureTimer; // 拍照定时器
QTimer* m_liveViewTimer; // 实时取景定时器
QString m_savePath;
int m_imageCounter;
int m_captureIntervalMilliseconds;
QMutex m_mutex;
QMutex m_liveViewMutex;
QImage m_liveViewImage; // 当前实时取景图像
// EDSDK辅助函数
EdsError initializeSDK();
EdsError terminateSDK();
EdsError openCamera();
EdsError closeCamera();
EdsError takePicture();
EdsError setupSaveToHost();
// 实时取景相关函数
EdsError startLiveView();
EdsError stopLiveView();
EdsError downloadEvfImage();
// 静态回调函数
static EdsError EDSCALLBACK handleObjectEvent(EdsObjectEvent event, EdsBaseRef object, EdsVoid* context);
static EdsError EDSCALLBACK handlePropertyEvent(EdsPropertyEvent event, EdsPropertyID property, EdsUInt32 param, EdsVoid* context);
static EdsError EDSCALLBACK handleStateEvent(EdsStateEvent event, EdsUInt32 parameter, EdsVoid* context);
// 下载图像
EdsError downloadImage(EdsDirectoryItemRef directoryItem);
public slots:
void OpenSLRCamera();
void OpenSLRCamera_callback();//不使用信号而使用回调函数来通知界面刷新视频
void CloseSLRCamera();
void OpenSLRCamera();
void takePhoto();
void OpenAndTakePhotoSLRCamera();
void stopTakePhoto();
void OpenSLRCamera_callback();
void CloseSLRCamera();
void onCaptureTimer();
void onLiveViewTimer();
// 控制拍照
void startCapture(); // 开始定时拍照
void stopCapture(); // 停止定时拍照
void captureOnce(); // 拍一张照片
signals:
void PlotSignal();
void PlotSignal();
void CamOpenedSignal();
void CamClosedSignal();
void ImageCapturedSignal(const QString& filePath);
void ErrorSignal(const QString& errorMsg);
// 实时取景信号
void LiveViewImageReady(const QImage& image);
void LiveViewStarted();
void LiveViewStopped();
void CamOpenedSignal();
void CamClosedSignal();
void CaptureStartedSignal();
void CaptureStoppedSignal();
};
class SingleLensReflexCameraWindow : public QDialog
{
Q_OBJECT
Q_OBJECT
public:
SingleLensReflexCameraWindow(QWidget* parent = nullptr);
~SingleLensReflexCameraWindow();
SingleLensReflexCameraWindow(QWidget* parent = nullptr);
~SingleLensReflexCameraWindow();
SingleLensReflexCameraOperation* m_SingleLensReflexCameraOperation;
SingleLensReflexCameraOperation* m_SingleLensReflexCameraOperation;
void setDataFolder(QString dir);
void setCaptureInterval(int captureIntervalSeconds);
public Q_SLOTS:
void openSLRCamera();
void onCamOpened();
void closeSLRCamera();
void onCamClosed();
void onSelectDataFolder();
void openSLRCamera();
void takePhoto();
void OpenAndTakePhotoSLRCamera();
void stopTakePhoto();
void onCamOpened();
void closeSLRCamera();
void onCamClosed();
void onImageCaptured(const QString& filePath);
void onError(const QString& errorMsg);
// 拍照控制
void onStartCapture();
void onStopCapture();
void onCaptureOnce();
void onCaptureStarted();
void onCaptureStopped();
void onStartTimedDataCollection(int lineNum);
void onStopTimedDataCollection();
signals:
void openSLRCameraSignal();
void PlotSLRImageSignal();
void SLRCamClosedSignal();
void openSLRCameraSignal();
void takePhotoSignal();
void OpenAndTakePhotoSLRCameraSignal();
void stopTakePhotoSignal();
void closeSLRCameraSignal();
void PlotSLRImageSignal();
void SLRCamClosedSignal();
// 控制信号
void startCaptureSignal();
void stopCaptureSignal();
void captureOnceSignal();
// 实时取景信号
void LiveViewImageReady(const QImage& image);
void LiveViewStarted();
void LiveViewStopped();
private:
Ui::SingleLensReflexCameraClass ui;
QThread* m_SLRCameraThread;
Ui::SingleLensReflexCameraClass ui;
QThread* m_SLRCameraThread;
// 用于显示实时取景的标签如果UI中没有可以动态创建
QLabel* m_liveViewLabel;
QString m_btnOldText; // 存储拍照按钮的原始文本
bool m_isCapturing; // 是否正在定时拍照
};

View File

@ -0,0 +1,85 @@
#include "SinglebandRasterRenderer.h"
#include "RasterDataProvider.h"
#include <algorithm>
SinglebandRasterRenderer::SinglebandRasterRenderer(RasterDataProvider* provider)
: RasterRendererBase(provider)
{
}
void SinglebandRasterRenderer::stretchTo8bit(const std::vector<float>& in, std::vector<unsigned char>& out, float minVal, float maxVal)
{
size_t n = in.size();
out.resize(n);
if (maxVal <= minVal) {
std::fill(out.begin(), out.end(), 0);
return;
}
float denom = 1.0f / (maxVal - minVal);
for (size_t i = 0; i < n; ++i) {
float v = (in[i] - minVal) * denom;
v = std::min(std::max(v, 0.0f), 1.0f);
out[i] = static_cast<unsigned char>(v * 255.0f);
}
}
int SinglebandRasterRenderer::nearestBandIndex(double wave) const
{
if (!m_provider) return -1;
int bands = m_provider->bandCount();
if (bands <= 0) return -1;
std::vector<double> wavelengths = m_provider->bandWavelengths();
if (wavelengths.empty()) {
// No wavelengths available, fallback to first band
return 0;
}
int best = -1;
double bestDiff = 1e12;
for (int i = 0; i < (int)wavelengths.size(); ++i) {
if (wavelengths[i] < 0) continue;
double d = std::abs(wavelengths[i] - wave);
if (d < bestDiff) {
bestDiff = d;
best = i;
}
}
return (best >= 0) ? best : 0;
}
QImage SinglebandRasterRenderer::render()
{
if (!m_provider) return QImage();
int w = m_provider->width();
int h = m_provider->height();
if (w <= 0 || h <= 0) return QImage();
int bandIdx = nearestBandIndex(m_params.wavelength);
if (bandIdx < 0 || bandIdx >= m_provider->bandCount()) {
bandIdx = 0;
}
std::vector<float> buf;
m_provider->readBandAsFloat(bandIdx, buf);
std::vector<unsigned char> gray8;
float minV = static_cast<float>(m_params.minValue);
float maxV = static_cast<float>(m_params.maxValue);
if (!buf.empty()) {
stretchTo8bit(buf, gray8, minV, maxV);
}
QImage out(w, h, QImage::Format_Grayscale8);
for (int y = 0; y < h; ++y) {
unsigned char* scan = out.scanLine(y);
for (int x = 0; x < w; ++x) {
int idx = y * w + x;
scan[x] = (gray8.size() > (size_t)idx) ? gray8[idx] : 0;
}
}
return out;
}

View File

@ -0,0 +1,27 @@
#pragma once
#include "RasterRendererBase.h"
#include "RasterRenderParams.h"
#include <vector>
class RasterDataProvider;
class SinglebandRasterRenderer : public RasterRendererBase
{
public:
explicit SinglebandRasterRenderer(RasterDataProvider* provider);
QImage render() override;
// Parameter access
SinglebandRenderParams params() const { return m_params; }
void setParams(const SinglebandRenderParams& params) { m_params = params; }
private:
SinglebandRenderParams m_params;
int nearestBandIndex(double wave) const;
// Helper to map float buffer to 8-bit with min/max stretch
static void stretchTo8bit(const std::vector<float>& in, std::vector<unsigned char>& out, float minVal, float maxVal);
};

View File

@ -7,6 +7,24 @@ TabManager::TabManager(QTabWidget* tabWidget, QObject* parent)
Q_ASSERT(m_tabWidget);
}
void TabManager::hideAllTabs()
{
int tabNumber = m_tabWidget->count();
for (size_t i = 0; i < tabNumber; i++)
{
int idx = 0;
TabInfo info;
info.index = idx;
info.text = m_tabWidget->tabText(idx);
info.icon = m_tabWidget->tabIcon(idx);
info.toolTip = m_tabWidget->tabToolTip(idx);
m_hiddenTabs.insert(m_tabWidget->widget(idx), info);
m_tabWidget->removeTab(idx);
}
}
void TabManager::hideTab(QWidget* page)
{
if (!page || !m_tabWidget)

View File

@ -10,6 +10,7 @@ class TabManager : public QObject
public:
explicit TabManager(QTabWidget* tabWidget, QObject* parent = nullptr);
void hideAllTabs();
void hideTab(QWidget* page);
void showTab(QWidget* page);
bool isHidden(QWidget* page) const;

View File

@ -0,0 +1,169 @@
#include "TimedDataCollection.h"
#include <QDateTime>
#include <QDebug>
TimedDataCollection::TimedDataCollection(QWidget* parent)
: QDialog(parent)
, m_scheduler(nullptr)
{
ui.setupUi(this);
ui.treeWidget->setDragEnabled(true); // 启用拖拽
ui.treeWidget->setAcceptDrops(true); // 接受拖放
ui.treeWidget->setDropIndicatorShown(true); // 显示插入位置指示线
ui.treeWidget->setDragDropMode(QAbstractItemView::InternalMove); // 内部移动
// 初始化调度器
m_scheduler = new TaskScheduler(this);
// 连接调度器信号
connect(m_scheduler, &TaskScheduler::taskStarted, this, &TimedDataCollection::taskStarted);
connect(m_scheduler, &TaskScheduler::taskFinished, this, &TimedDataCollection::taskFinished);
connect(m_scheduler, &TaskScheduler::subTaskStarted, this, &TimedDataCollection::subTaskStarted);
connect(m_scheduler, &TaskScheduler::subTaskFinished, this, &TimedDataCollection::subTaskFinished);
connect(m_scheduler, &TaskScheduler::errorOccurred, this, &TimedDataCollection::errorOccurred);
// 采集相关信号透传
connect(m_scheduler, &TaskScheduler::hyperCamParm, this, &TimedDataCollection::hyperCamParm);
connect(m_scheduler, &TaskScheduler::camParm, this, &TimedDataCollection::camParm);
connect(m_scheduler, &TaskScheduler::motorParm, this, &TimedDataCollection::motorParm);
connect(m_scheduler, &TaskScheduler::startRecordSignal, this, &TimedDataCollection::startRecordSignal);
connect(m_scheduler, &TaskScheduler::switchHalogenLampSignal, this, &TimedDataCollection::switchHalogenLampSignal);
connect(m_scheduler, &TaskScheduler::switchD65LampSignal, this, &TimedDataCollection::switchD65LampSignal);
connect(m_scheduler, &TaskScheduler::switchSlrSignal, this, &TimedDataCollection::switchSlrSignal);
connect(this, &TimedDataCollection::sequenceCompleteSignal, m_scheduler, &TaskScheduler::sequenceCompleteSignal);
connect(this, &TimedDataCollection::Back2OriginSignal, m_scheduler, &TaskScheduler::Back2OriginSignal);
//writeRead();
readTimedTaskFromFile("D:/0tmp/3Dtest/task.json");
// 加载任务到调度器
m_scheduler->loadTasks(m_loadedTasks);
connect(ui.run_btn, &QPushButton::clicked, this, &TimedDataCollection::startScheduler);
startScheduler();
}
TimedDataCollection::~TimedDataCollection()
{
if (m_scheduler) {
m_scheduler->stop();
}
}
void TimedDataCollection::subTaskCompleted(int status)
{
emit sequenceCompleteSignal(status);
}
void TimedDataCollection::onBack2Origin()
{
emit Back2OriginSignal();
}
void TimedDataCollection::startScheduler()
{
if (m_scheduler) {
m_scheduler->start();
}
}
void TimedDataCollection::stopScheduler()
{
if (m_scheduler) {
m_scheduler->stop();
}
}
void TimedDataCollection::readTimedTaskFromFile(const QString& filePath)
{
// 从文件读取
if (TimedDataCollectionDataStructuresReaderWriter::loadTasksFromFile(filePath, m_loadedTasks)) {
qDebug() << "Tasks loaded successfully, count:" << m_loadedTasks.size();
for (const auto& t : m_loadedTasks) {
qDebug() << " Task ID:" << t.id << "SubTasks:" << t.subTasks.size();
}
}
else {
qDebug() << "Failed to load tasks from:" << filePath;
}
int a = 1;
}
void TimedDataCollection::writeRead()
{
// 创建2个定时任务测试
QVector<TimedTask> tasks;
for (int i = 0; i < 2; ++i) {
TimedTask task;
task.id = i + 1;
task.scheduledTime = QDateTime::currentDateTime().addDays(i + 1);
task.savePath = QString("D:/0tmp/data");
task.status = TaskStatus::Waiting;
// 创建4种子任务
QVector<SubTaskType> types = {
SubTaskType::HyperSpectual400_1000nm,
SubTaskType::HyperSpectual1000_1700nm,
SubTaskType::SingleLensReflex,
SubTaskType::DepthCamera
};
for (int j = 0; j < types.size(); ++j) {
SubTask subTask;
subTask.type = types[j];
subTask.startTime = task.scheduledTime.addSecs(j * 3600);
subTask.endTime = subTask.startTime.addSecs(1800);
subTask.durationMinutes = 1800;
subTask.estimatedDurationMinutes = 1800;
subTask.pathLineFilePath = QString("D:/0tmp/3Dtest/pathLine/%1.RecordLine3").arg(j);
subTask.status = TaskStatus::Waiting;
// 根据类型设置特有属性
if (subTask.type == SubTaskType::HyperSpectual400_1000nm ||
subTask.type == SubTaskType::HyperSpectual1000_1700nm) {
subTask.frameRate = 30.0;
subTask.exposureTime = 1;
}
if (subTask.type == SubTaskType::HyperSpectual1000_1700nm) {
subTask.defaultRenderBand = 1200;
}
if (subTask.type == SubTaskType::SingleLensReflex ||
subTask.type == SubTaskType::DepthCamera) {
subTask.captureIntervalSeconds = 5;
}
task.subTasks.append(subTask);
}
tasks.append(task);
}
// 保存到文件
QString filePath = "D:/0tmp/3Dtest/task.json";
if (TimedDataCollectionDataStructuresReaderWriter::saveTasksToFile(filePath, tasks)) {
qDebug() << "Tasks saved to:" << filePath;
}
else {
qDebug() << "Failed to save tasks to:" << filePath;
}
// 从文件读取
QVector<TimedTask> loadedTasks;
if (TimedDataCollectionDataStructuresReaderWriter::loadTasksFromFile(filePath, loadedTasks)) {
qDebug() << "Tasks loaded successfully, count:" << loadedTasks.size();
for (const auto& t : loadedTasks) {
qDebug() << " Task ID:" << t.id << "SubTasks:" << t.subTasks.size();
}
}
else {
qDebug() << "Failed to load tasks from:" << filePath;
}
int a = 1;
}

View File

@ -0,0 +1,56 @@
#pragma once
#include <QDialog>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include "ui_TimedDataCollection_ui.h"
#include "TimedDataCollectionDataStructures.h"
class TimedDataCollection : public QDialog
{
Q_OBJECT
public:
TimedDataCollection(QWidget* parent = nullptr);
~TimedDataCollection();
void readTimedTaskFromFile(const QString& filePath);
public Q_SLOTS:
void startScheduler();
void stopScheduler();
void subTaskCompleted(int status);
void onBack2Origin();
Q_SIGNALS:
void taskStarted(int taskId);
void taskFinished(int taskId, bool success);
void subTaskStarted(int taskId, int subTaskIndex);
void subTaskFinished(int taskId, int subTaskIndex);
void errorOccurred(const QString& error);
// 采集相关信号 (透传 TaskScheduler)
void hyperCamParm(int camType, double f, double e, QString filePath, QString fileName);
void camParm(int camType, int captureIntervalSeconds, QString folder);
void motorParm(QString pathLineFilePath);
void startRecordSignal(int camType);
void switchHalogenLampSignal(int state);
void switchD65LampSignal(int state);
void switchSlrSignal(int state);
// 马达反馈的信号
void sequenceCompleteSignal(int status);
void Back2OriginSignal();
private:
Ui::TimedDataCollection_ui ui;
void writeRead();
QVector<TimedTask> m_loadedTasks;
TaskScheduler* m_scheduler;
};

View File

@ -0,0 +1,615 @@
#include "TimedDataCollectionDataStructures.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QFile>
#include <QTextStream>
#include <QDebug>
// ==================== 公共接口实现 ====================
bool TimedDataCollectionDataStructuresReaderWriter::saveTasksToFile(const QString& filePath, const QVector<TimedTask>& tasks)
{
QJsonObject root;
root["version"] = "1.0";
root["taskCount"] = tasks.size();
QJsonArray tasksArray;
for (const auto& task : tasks) {
tasksArray.append(timedTaskToJson(task));
}
root["tasks"] = tasksArray;
QJsonDocument doc(root);
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning() << "Failed to open file for writing:" << filePath;
return false;
}
QTextStream out(&file);
//out.setEncoding(QStringConverter::Utf8);
out << doc.toJson(QJsonDocument::Indented);
file.close();
return true;
}
bool TimedDataCollectionDataStructuresReaderWriter::loadTasksFromFile(const QString& filePath, QVector<TimedTask>& tasks)
{
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Failed to open file for reading:" << filePath;
return false;
}
QByteArray jsonData = file.readAll();
file.close();
QJsonParseError parseError;
QJsonDocument doc = QJsonDocument::fromJson(jsonData, &parseError);
if (parseError.error != QJsonParseError::NoError) {
qWarning() << "JSON parse error:" << parseError.errorString();
return false;
}
if (!doc.isObject()) {
qWarning() << "Invalid JSON root object";
return false;
}
QJsonObject root = doc.object();
QJsonArray tasksArray = root["tasks"].toArray();
tasks.clear();
tasks.reserve(tasksArray.size());
for (const auto& taskValue : tasksArray) {
if (!taskValue.isObject()) continue;
TimedTask task;
if (jsonToTimedTask(taskValue.toObject(), task)) {
tasks.append(task);
}
}
return true;
}
// ==================== 枚举转换函数 ====================
QString TimedDataCollectionDataStructuresReaderWriter::taskStatusToString(TaskStatus status)
{
switch (status) {
case TaskStatus::Waiting: return "Waiting";
case TaskStatus::Running: return "Running";
case TaskStatus::Finished: return "Finished";
default: return "Waiting";
}
}
TaskStatus TimedDataCollectionDataStructuresReaderWriter::stringToTaskStatus(const QString& str)
{
if (str == "Running") return TaskStatus::Running;
if (str == "Finished") return TaskStatus::Finished;
return TaskStatus::Waiting;
}
QString TimedDataCollectionDataStructuresReaderWriter::subTaskTypeToString(SubTaskType type)
{
switch (type) {
case SubTaskType::HyperSpectual400_1000nm: return "HyperSpectual400_1000nm";
case SubTaskType::HyperSpectual1000_1700nm: return "HyperSpectual1000_1700nm";
case SubTaskType::SingleLensReflex: return "SingleLensReflex";
case SubTaskType::DepthCamera: return "DepthCamera";
default: return "Unknown";
}
}
SubTaskType TimedDataCollectionDataStructuresReaderWriter::stringToSubTaskType(const QString& str)
{
if (str == "HyperSpectual400_1000nm") return SubTaskType::HyperSpectual400_1000nm;
if (str == "HyperSpectual1000_1700nm") return SubTaskType::HyperSpectual1000_1700nm;
if (str == "SingleLensReflex") return SubTaskType::SingleLensReflex;
if (str == "DepthCamera") return SubTaskType::DepthCamera;
return SubTaskType::SingleLensReflex;
}
// ==================== SubTask序列化 ====================
QJsonObject TimedDataCollectionDataStructuresReaderWriter::subTaskToJson(const SubTask& subTask)
{
QJsonObject obj;
obj["type"] = subTaskTypeToString(subTask.type);
obj["startTime"] = subTask.startTime.toString(Qt::ISODate);
obj["endTime"] = subTask.endTime.toString(Qt::ISODate);
obj["durationMinutes"] = subTask.durationMinutes;
obj["estimatedDurationMinutes"] = subTask.estimatedDurationMinutes;
obj["pathLineFilePath"] = subTask.pathLineFilePath;
obj["status"] = taskStatusToString(subTask.status);
obj["frameRate"] = subTask.frameRate;
obj["exposureTime"] = subTask.exposureTime;
obj["defaultRenderBand"] = subTask.defaultRenderBand;
obj["captureIntervalSeconds"] = subTask.captureIntervalSeconds;
return obj;
}
bool TimedDataCollectionDataStructuresReaderWriter::jsonToSubTask(const QJsonObject& json, SubTask& subTask)
{
subTask.type = stringToSubTaskType(json["type"].toString());
subTask.startTime = QDateTime::fromString(json["startTime"].toString(), Qt::ISODate);
subTask.endTime = QDateTime::fromString(json["endTime"].toString(), Qt::ISODate);
subTask.durationMinutes = json["durationMinutes"].toDouble();
subTask.estimatedDurationMinutes = json["estimatedDurationMinutes"].toDouble();
subTask.pathLineFilePath = json["pathLineFilePath"].toString();
subTask.status = stringToTaskStatus(json["status"].toString());
subTask.frameRate = json["frameRate"].toDouble();
subTask.exposureTime = json["exposureTime"].toDouble();
subTask.defaultRenderBand = json["defaultRenderBand"].toInt();
subTask.captureIntervalSeconds = json["captureIntervalSeconds"].toDouble();
return true;
}
// ==================== TimedTask序列化 ====================
QJsonObject TimedDataCollectionDataStructuresReaderWriter::timedTaskToJson(const TimedTask& task)
{
QJsonObject obj;
obj["id"] = task.id;
obj["scheduledTime"] = task.scheduledTime.toString(Qt::ISODate);
obj["startTime"] = task.startTime.toString(Qt::ISODate);
obj["endTime"] = task.endTime.toString(Qt::ISODate);
obj["durationMinutes"] = task.durationMinutes;
obj["savePath"] = task.savePath;
obj["status"] = taskStatusToString(task.status);
obj["HalogenLampPreheatingTime_Minute"] = task.HalogenLampPreheatingTime_Minute;
QJsonArray subTasksArray;
for (const auto& subTask : task.subTasks) {
subTasksArray.append(subTaskToJson(subTask));
}
obj["subTasks"] = subTasksArray;
return obj;
}
bool TimedDataCollectionDataStructuresReaderWriter::jsonToTimedTask(const QJsonObject& json, TimedTask& task)
{
task.id = json["id"].toInt();
task.scheduledTime = QDateTime::fromString(json["scheduledTime"].toString(), Qt::ISODate);
task.startTime = QDateTime::fromString(json["startTime"].toString(), Qt::ISODate);
task.endTime = QDateTime::fromString(json["endTime"].toString(), Qt::ISODate);
task.durationMinutes = json["durationMinutes"].toDouble();
task.savePath = json["savePath"].toString();
task.status = stringToTaskStatus(json["status"].toString());
task.HalogenLampPreheatingTime_Minute = json["HalogenLampPreheatingTime_Minute"].toDouble();
QJsonArray subTasksArray = json["subTasks"].toArray();
task.subTasks.clear();
task.subTasks.reserve(subTasksArray.size());
for (const auto& subTaskValue : subTasksArray) {
if (!subTaskValue.isObject()) continue;
SubTask subTask;
if (jsonToSubTask(subTaskValue.toObject(), subTask)) {
task.subTasks.append(subTask);
}
}
return true;
}
// ==================== TaskExecutor 实现 ====================
TaskExecutor::TaskExecutor(QObject* parent)
: QObject(parent)
, m_currentSubTaskIndex(0)
, m_isRunning(false)
{
}
TaskExecutor::~TaskExecutor()
{
stop();
}
void TaskExecutor::execute(const TimedTask& task)
{
if (m_isRunning) {
qWarning() << "TaskExecutor: Already running, ignoring execute request";
return;
}
m_task = task;
m_task.startTime = QDateTime::currentDateTime();
m_currentSubTaskIndex = 0;
m_isRunning = true;
qDebug() << "TaskExecutor: Starting task" << task.id;
// 打开卤素灯预热
emit switchHalogenLampSignal(1);
printMsgAndTime("open HalogenLamp");
makeFolder(m_task.savePath);
// 开始执行第一个子任务
double sleepTimeSecond = m_task.HalogenLampPreheatingTime_Minute * 60;
QTimer::singleShot(sleepTimeSecond *1000, this, &TaskExecutor::executeNextSubTask);
}
void TaskExecutor::printMsgAndTime(QString msg)
{
QDateTime now = QDateTime::currentDateTime();
QString timeString = now.toString("yyyy-MM-dd hh:mm:ss.zzz");
qDebug() << msg + " time:" << timeString;
}
void TaskExecutor::stop()
{
if (!m_isRunning) return;
qDebug() << "TaskExecutor: Stopping task" << m_task.id;
m_isRunning = false;
emit finished(false);
}
void TaskExecutor::makeFolder(QString savePath)
{
QDir dir(savePath);
if (!dir.exists()) {
if (dir.mkpath(".")) {
qDebug() << "TaskExecutor: Created data folder:" << savePath;
} else {
qWarning() << "TaskExecutor: Failed to create data folder:" << savePath;
}
} else {
qDebug() << "TaskExecutor: Data folder already exists:" << savePath;
}
}
QString TaskExecutor::makeSubTaskDataFolder(QString suffix)
{
QString dateStr = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss");
QString folderPath = m_task.savePath + QDir::separator() + dateStr + "_" + suffix;
makeFolder(folderPath);
return folderPath;
}
void TaskExecutor::onSequenceComplete(int status)
{
if (!m_isRunning) return;
qDebug() << "TaskExecutor: Sequence complete, status:" << status;
// 更新当前子任务状态
if (m_currentSubTaskIndex < m_task.subTasks.size()) {
SubTask& subTask = m_task.subTasks[m_currentSubTaskIndex];
subTask.status = (status == 0) ? TaskStatus::Finished : TaskStatus::Waiting;
subTask.endTime = QDateTime::currentDateTime();
subTask.durationMinutes = (double)subTask.startTime.secsTo(subTask.endTime) / 60;
qDebug() << "TaskExecutor: subtask "<< m_currentSubTaskIndex<< " time consuming(Minutes): "<< subTask.durationMinutes;
emit subTaskFinished(m_currentSubTaskIndex, subTask.type, (status == 0));
}
//
switch (m_task.subTasks[m_currentSubTaskIndex].type)
{
case SubTaskType::SingleLensReflex:
{
emit switchD65LampSignal(0);
emit switchSlrSignal(0);
break;
}
case SubTaskType::DepthCamera:
{
emit switchD65LampSignal(0);
break;
}
}
// 判断下一次的任务是否为高光谱任务,如果不是关闭卤素灯
int nestSubTaskIndex = m_currentSubTaskIndex + 1;
if (nestSubTaskIndex >= m_task.subTasks.size())
{
emit switchHalogenLampSignal(0);
return;
}
switch (m_task.subTasks[nestSubTaskIndex].type)
{
case SubTaskType::SingleLensReflex:
{
emit switchHalogenLampSignal(0);
break;
}
case SubTaskType::DepthCamera:
{
emit switchHalogenLampSignal(0);
break;
}
}
}
void TaskExecutor::onBack2Origin()
{
// 检查是否还有更多子任务
m_currentSubTaskIndex++;
if (m_currentSubTaskIndex < m_task.subTasks.size()) {
// 执行下一个子任务
if(m_task.subTasks[m_currentSubTaskIndex].type== SubTaskType::SingleLensReflex)
{
printMsgAndTime("Slr taskfor weak upplease wait 135 seconds!");
emit switchSlrSignal(0);
QTimer::singleShot(135*1000, this, &TaskExecutor::executeNextSubTask);
}
else
{
QTimer::singleShot(1000, this, &TaskExecutor::executeNextSubTask);
}
}
else {
// 所有子任务完成
m_task.endTime = QDateTime::currentDateTime();
m_task.durationMinutes = (double)m_task.startTime.secsTo(m_task.endTime) / 60;
qDebug() << "TaskExecutor: task time consuming(Minutes): " << m_task.durationMinutes;
m_isRunning = false;
qDebug() << "TaskExecutor: All subtasks completed";
emit finished(true);
}
}
void TaskExecutor::onError(const QString& error)
{
if (!m_isRunning) return;
qWarning() << "TaskExecutor: Error occurred:" << error;
m_isRunning = false;
emit errorOccurred(error);
emit finished(false);
}
void TaskExecutor::executeNextSubTask()
{
if (!m_isRunning || m_currentSubTaskIndex >= m_task.subTasks.size()) {
return;
}
SubTask& subTask = m_task.subTasks[m_currentSubTaskIndex];
subTask.status = TaskStatus::Running;
subTask.startTime = QDateTime::currentDateTime();
QString tmp = "TaskExecutor: Starting subtask" + QString::number(m_currentSubTaskIndex) + "type:" + static_cast<int>(subTask.type);
printMsgAndTime(tmp);
//printMsgAndTime("excute " + QString::number(m_currentSubTaskIndex) + " subTask: ");
//qDebug() << "TaskExecutor: Starting subtask" << m_currentSubTaskIndex
// << "type:" << static_cast<int>(subTask.type);
emit subTaskStarted(m_currentSubTaskIndex, subTask.type);
emit motorParm(subTask.pathLineFilePath);
int camType;
switch (subTask.type)
{
case SubTaskType::HyperSpectual400_1000nm:
{
camType = 0;
emit hyperCamParm(camType, subTask.frameRate, subTask.exposureTime, makeSubTaskDataFolder("L"), "test");
break;
}
case SubTaskType::HyperSpectual1000_1700nm:
{
camType = 1;
emit hyperCamParm(camType, subTask.frameRate, subTask.exposureTime, makeSubTaskDataFolder("NIR"), "test");
break;
}
case SubTaskType::SingleLensReflex:
{
camType = 2;
emit camParm(camType, 3, makeSubTaskDataFolder("SLR"));
emit switchD65LampSignal(1);
emit switchSlrSignal(1);
break;
}
case SubTaskType::DepthCamera:
{
camType = 3;
emit camParm(camType, 3, makeSubTaskDataFolder("DepthCamera"));
emit switchD65LampSignal(1);
break;
}
}
emit startRecordSignal(camType);
}
// ==================== TaskScheduler 实现 ====================
TaskScheduler::TaskScheduler(QObject* parent)
: QObject(parent)
, m_timer(nullptr)
, m_currentExecutor(nullptr)
, m_currentTaskId(-1)
{
}
TaskScheduler::~TaskScheduler()
{
stop();
}
void TaskScheduler::loadTasks(const QVector<TimedTask>& tasks)
{
m_tasks = tasks;
qDebug() << "TaskScheduler: Loaded" << tasks.size() << "tasks";
}
void TaskScheduler::start()
{
if (m_timer) {
qDebug() << "TaskScheduler: Already running";
return;
}
qDebug() << "TaskScheduler: Starting";
m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, &TaskScheduler::checkTasks);
m_timer->start(1000); // 每秒检查一次
emit schedulerStateChanged(true);
}
void TaskScheduler::stop()
{
if (m_timer) {
m_timer->stop();
delete m_timer;
m_timer = nullptr;
}
if (m_currentExecutor) {
m_currentExecutor->stop();
m_currentExecutor->deleteLater();
m_currentExecutor = nullptr;
}
qDebug() << "TaskScheduler: Stopped";
emit schedulerStateChanged(false);
}
void TaskScheduler::checkTasks()
{
QDateTime now = QDateTime::currentDateTime();
for (auto& task : m_tasks) {
if (task.status != TaskStatus::Waiting) continue;
// 超过计划时间1分钟以上认为任务已过时跳过
if (task.scheduledTime.addSecs(60) < now) {
std::cerr << "TaskScheduler::checkTasks任务已过时跳过:" << task.id << std::endl;
task.status = TaskStatus::Finished;
continue;
}
if (task.scheduledTime > now) continue;
// 到达计划时间,启动任务
std::cerr << "TaskScheduler::checkTasks到达计划时间启动任务" << std::endl;
executeTask(task);
break; // 一次只执行一个任务
}
}
void TaskScheduler::onTaskFinished(bool success)
{
if (m_currentTaskId > 0) {
TaskStatus status = success ? TaskStatus::Finished : TaskStatus::Waiting;
updateTaskStatus(m_currentTaskId, status);
emit taskFinished(m_currentTaskId, success);
}
// 清理执行器
if (m_currentExecutor) {
m_currentExecutor->deleteLater();
m_currentExecutor = nullptr;
}
m_currentTaskId = -1;
}
void TaskScheduler::onSubTaskStarted(int subTaskIndex, SubTaskType type)
{
if (m_currentTaskId > 0) {
emit subTaskStarted(m_currentTaskId, subTaskIndex);
}
}
void TaskScheduler::onSubTaskFinished(int subTaskIndex, SubTaskType type, bool success)
{
if (m_currentTaskId > 0) {
emit subTaskFinished(m_currentTaskId, subTaskIndex);
}
}
void TaskScheduler::onExecutorError(const QString& error)
{
emitError(error);
}
void TaskScheduler::executeTask(TimedTask& task)
{
qDebug() << "TaskScheduler: Executing task" << task.id;
updateTaskStatus(task.id, TaskStatus::Running);
m_currentTaskId = task.id;
emit taskStarted(task.id);
// 创建任务执行器
m_currentExecutor = new TaskExecutor(this);
// 连接信号
connect(m_currentExecutor, &TaskExecutor::finished,
this, &TaskScheduler::onTaskFinished);
connect(m_currentExecutor, &TaskExecutor::subTaskStarted,
this, &TaskScheduler::onSubTaskStarted);
connect(m_currentExecutor, &TaskExecutor::subTaskFinished,
this, &TaskScheduler::onSubTaskFinished);
connect(m_currentExecutor, &TaskExecutor::errorOccurred,
this, &TaskScheduler::onExecutorError);
// 采集相关信号透传
connect(m_currentExecutor, &TaskExecutor::hyperCamParm,
this, &TaskScheduler::hyperCamParm);
connect(m_currentExecutor, &TaskExecutor::camParm,
this, &TaskScheduler::camParm);
connect(m_currentExecutor, &TaskExecutor::motorParm,
this, &TaskScheduler::motorParm);
connect(m_currentExecutor, &TaskExecutor::startRecordSignal,
this, &TaskScheduler::startRecordSignal);
connect(m_currentExecutor, &TaskExecutor::switchHalogenLampSignal, this, &TaskScheduler::switchHalogenLampSignal);
connect(m_currentExecutor, &TaskExecutor::switchD65LampSignal, this, &TaskScheduler::switchD65LampSignal);
connect(m_currentExecutor, &TaskExecutor::switchSlrSignal, this, &TaskScheduler::switchSlrSignal);
connect(this, &TaskScheduler::sequenceCompleteSignal, m_currentExecutor, &TaskExecutor::onSequenceComplete);
connect(this, &TaskScheduler::Back2OriginSignal, m_currentExecutor, &TaskExecutor::onBack2Origin);
// 开始执行
m_currentExecutor->execute(task);
}
void TaskScheduler::updateTaskStatus(int taskId, TaskStatus status)
{
for (auto& task : m_tasks) {
if (task.id == taskId) {
task.status = status;
if (status == TaskStatus::Running) {
task.startTime = QDateTime::currentDateTime();
} else if (status == TaskStatus::Finished) {
task.endTime = QDateTime::currentDateTime();
}
break;
}
}
}
void TaskScheduler::emitError(const QString& error)
{
qWarning() << "TaskScheduler: Error:" << error;
emit errorOccurred(error);
}

View File

@ -0,0 +1,235 @@
#pragma once
#include <QDateTime>
#include <QString>
#include <QVector>
#include <QMetaType>
#include <QTimer>
#include "CaptureCoordinator.h"
// ==================== 枚举定义 ====================
// 任务状态
enum class TaskStatus {
Waiting, // 等待
Running, // 运行中
Finished, // 结束
Skiped //跳过
};
// 子任务类型
enum class SubTaskType {
HyperSpectual400_1000nm, // 400nm-1000nm高光谱相机
HyperSpectual1000_1700nm, // 1000nm-1700nm高光谱相机
SingleLensReflex, // 单反相机
DepthCamera // 深度相机
};
// ==================== 统一子任务封装 ====================
struct SubTask {
SubTaskType type; // 子任务类型
// 共享属性
QDateTime startTime;
QDateTime endTime;
double durationMinutes = 0;
double estimatedDurationMinutes = 0;
QString pathLineFilePath;
TaskStatus status = TaskStatus::Waiting;
// 类型特有属性根据type选择使用
double frameRate = 0.0; // 高光谱相机用
double exposureTime = 0.0; // 高光谱相机用
int defaultRenderBand = 550; // 1000-1700nm高光谱用
int captureIntervalSeconds = 5; // 单反/深度相机用
};
// ==================== 定时任务 ====================
struct TimedTask {
int id = 0; // 任务ID
QDateTime scheduledTime; // 计划时间
QDateTime startTime; // 开始时间
QDateTime endTime; // 结束时间
double durationMinutes = 0; // 耗时(秒)
QString savePath; // 数据保存路径
QVector<SubTask> subTasks; // 子任务列表
TaskStatus status = TaskStatus::Waiting; // 状态
double HalogenLampPreheatingTime_Minute;
// 计算所有子任务的预计总时间
int totalEstimatedDuration() const {
int total = 0;
for (const auto& subTask : subTasks) {
total += subTask.estimatedDurationMinutes;
}
return total;
}
// 获取子任务数量
int subTaskCount() const {
return subTasks.size();
}
};
// ==================== Qt元类型声明 ====================
Q_DECLARE_METATYPE(TaskStatus)
Q_DECLARE_METATYPE(SubTaskType)
Q_DECLARE_METATYPE(SubTask)
Q_DECLARE_METATYPE(TimedTask)
// ==================== 任务文件读写类 ====================
class TimedDataCollectionDataStructuresReaderWriter
{
public:
// 保存任务到文件
static bool saveTasksToFile(const QString& filePath, const QVector<TimedTask>& tasks);
// 从文件读取任务
static bool loadTasksFromFile(const QString& filePath, QVector<TimedTask>& tasks);
private:
// SubTask序列化
static QJsonObject subTaskToJson(const SubTask& subTask);
static bool jsonToSubTask(const QJsonObject& json, SubTask& subTask);
// TimedTask序列化
static QJsonObject timedTaskToJson(const TimedTask& task);
static bool jsonToTimedTask(const QJsonObject& json, TimedTask& task);
// 枚举转换
static QString taskStatusToString(TaskStatus status);
static TaskStatus stringToTaskStatus(const QString& str);
static QString subTaskTypeToString(SubTaskType type);
static SubTaskType stringToSubTaskType(const QString& str);
};
// ==================== 任务执行器 ====================
class TaskExecutor : public QObject
{
Q_OBJECT
public:
explicit TaskExecutor(QObject* parent = nullptr);
~TaskExecutor();
// 执行任务
void execute(const TimedTask& task);
void makeFolder(QString savePath);
QString makeSubTaskDataFolder(QString suffix);
// 获取当前执行的子任务索引
int currentSubTaskIndex() const { return m_currentSubTaskIndex; }
// 获取正在执行的任务
const TimedTask& currentTask() const { return m_task; }
// 是否正在执行
bool isRunning() const { return m_isRunning; }
// 停止执行
void stop();
signals:
void finished(bool success); // 任务完成
void subTaskStarted(int subTaskIndex, SubTaskType type); // 子任务开始
void subTaskFinished(int subTaskIndex, SubTaskType type, bool success); // 子任务完成
void errorOccurred(const QString& error); // 错误发生
// 采集相关信号
void hyperCamParm(int camType, double f, double e, QString filePath, QString fileName);
void camParm(int camType, int captureIntervalSeconds, QString folder);
void motorParm(QString pathLineFilePath);
void startRecordSignal(int camType);
void switchHalogenLampSignal(int state);
void switchD65LampSignal(int state);
void switchSlrSignal(int state);
public slots:
void onSequenceComplete(int status);
void onBack2Origin();
void onError(const QString& error);
private:
void executeNextSubTask();
void printMsgAndTime(QString msg);
TimedTask m_task;
int m_currentSubTaskIndex;
bool m_isRunning;
};
// ==================== 任务调度器 ====================
class TaskScheduler : public QObject
{
Q_OBJECT
public:
explicit TaskScheduler(QObject* parent = nullptr);
~TaskScheduler();
// 加载任务列表
void loadTasks(const QVector<TimedTask>& tasks);
// 获取任务列表
QVector<TimedTask> tasks() const { return m_tasks; }
// 开始调度
void start();
// 停止调度
void stop();
// 是否正在运行
bool isRunning() const { return m_timer != nullptr && m_timer->isActive(); }
signals:
void taskStarted(int taskId); // 任务开始
void taskFinished(int taskId, bool success); // 任务完成
void schedulerStateChanged(bool running); // 调度器状态变化
// 子任务的信号
void subTaskStarted(int taskId, int subTaskIndex); // 子任务开始
void subTaskFinished(int taskId, int subTaskIndex); // 子任务完成
void errorOccurred(const QString& error); // 错误发生
// 采集相关信号 (透传 TaskExecutor)
void hyperCamParm(int camType, double f, double e, QString filePath, QString fileName);
void camParm(int camType, int captureIntervalSeconds, QString folder);
void motorParm(QString pathLineFilePath);
void startRecordSignal(int camType);
void switchHalogenLampSignal(int state);
void switchD65LampSignal(int state);
void switchSlrSignal(int state);
// 马达反馈的信号
void sequenceCompleteSignal(int status);
void Back2OriginSignal();
private slots:
void checkTasks(); // 检查任务是否该启动
void onTaskFinished(bool success);
void onSubTaskStarted(int subTaskIndex, SubTaskType type);
void onSubTaskFinished(int subTaskIndex, SubTaskType type, bool success);
void onExecutorError(const QString& error);
private:
void executeTask(TimedTask& task);
void updateTaskStatus(int taskId, TaskStatus status);
void emitError(const QString& error);
QTimer* m_timer;
QVector<TimedTask> m_tasks;
TaskExecutor* m_currentExecutor;
int m_currentTaskId;
};

View File

@ -0,0 +1,279 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TimedDataCollection_ui</class>
<widget class="QDialog" name="TimedDataCollection_ui">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1160</width>
<height>576</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="3">
<widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTreeWidget" name="treeWidget">
<property name="allColumnsShowFocus">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>任务</string>
</property>
</column>
<column>
<property name="text">
<string>计划时间</string>
</property>
</column>
<column>
<property name="text">
<string>开始时间</string>
</property>
</column>
<column>
<property name="text">
<string>结束时间</string>
</property>
</column>
<column>
<property name="text">
<string>耗时</string>
</property>
</column>
<column>
<property name="text">
<string>状态</string>
</property>
</column>
<item>
<property name="text">
<string>1</string>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<item>
<property name="text">
<string>a</string>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
</item>
<item>
<property name="text">
<string>b</string>
</property>
</item>
</item>
<item>
<property name="text">
<string>2</string>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<item>
<property name="text">
<string>a</string>
</property>
</item>
<item>
<property name="text">
<string>b</string>
</property>
</item>
</item>
<item>
<property name="text">
<string>3</string>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<item>
<property name="text">
<string>a</string>
</property>
</item>
<item>
<property name="text">
<string>b</string>
</property>
</item>
</item>
<item>
<property name="text">
<string>4</string>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<item>
<property name="text">
<string>a</string>
</property>
</item>
<item>
<property name="text">
<string>b</string>
</property>
</item>
</item>
<item>
<property name="text">
<string>5</string>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="text">
<string/>
</property>
<item>
<property name="text">
<string>a</string>
</property>
</item>
<item>
<property name="text">
<string>b</string>
</property>
</item>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="page_2"/>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="addToptask_btn">
<property name="text">
<string>添加总计划任务</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="delToptask_btn">
<property name="text">
<string>删除总计划任务</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="addSubtask_btn">
<property name="text">
<string>添加子任务</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboBox"/>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="delSubtask_btn">
<property name="text">
<string>删除子任务</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QPushButton" name="run_btn">
<property name="text">
<string>运行</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -103,6 +103,113 @@ void TwoMotorControl::record_white()
m_whiteCaptureCoordinator->startStepMotion(s);
}
void TwoMotorControl::run2(SingleLensReflexCameraWindow* window)
{
int rowCount = ui.recordLine_tableWidget->rowCount();
if (rowCount == 0)
{
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请至少添加一行采集线!"));
emit sequenceComplete(0);
return;
}
m_coordinator_TimedDataCollection = new TwoMotionCaptureCoordinator(m_multiAxisController);
connect(this, SIGNAL(start(QVector<PathLine>)), m_coordinator_TimedDataCollection, SLOT(start(QVector<PathLine>)));
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::startRecordLineNumSignal, this, &TwoMotorControl::receiveStartRecordLineNum);
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::finishRecordLineNumSignal, this, &TwoMotorControl::receiveFinishRecordLineNum);
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::startRecordLineNumSignal, window, &SingleLensReflexCameraWindow::onStartTimedDataCollection);
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::sequenceComplete, window, &SingleLensReflexCameraWindow::onStopTimedDataCollection);
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::sequenceComplete, this, &TwoMotorControl::sequenceComplete);
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::back2OriginSignal, this, &TwoMotorControl::onBack2Origin2);
QVector<PathLine> pathLines;
//int columnCount = ui.recordLine_tableWidget->columnCount();
for (size_t i = 0; i < rowCount; i++)
{
PathLine tmp;
tmp.targetYPosition = ui.recordLine_tableWidget->item(i, 0)->text().toDouble();
tmp.speedTargetYPosition = ui.recordLine_tableWidget->item(i, 1)->text().toDouble();
tmp.targetXMinPosition = ui.recordLine_tableWidget->item(i, 2)->text().toDouble();
tmp.speedTargetXMinPosition = ui.recordLine_tableWidget->item(i, 3)->text().toDouble();
tmp.targetXMaxPosition = ui.recordLine_tableWidget->item(i, 4)->text().toDouble();
tmp.speedTargetXMaxPosition = ui.recordLine_tableWidget->item(i, 5)->text().toDouble();
pathLines.append(tmp);
}
for (size_t i = 0; i < ui.recordLine_tableWidget->rowCount(); i++)
{
for (size_t j = 0; j < ui.recordLine_tableWidget->columnCount(); j++)
{
ui.recordLine_tableWidget->item(i, j)->setBackgroundColor(QColor("#0E1C4C"));
}
}
emit start(pathLines);
}
void TwoMotorControl::run3(DepthCameraWindow* window)
{
int rowCount = ui.recordLine_tableWidget->rowCount();
if (rowCount == 0)
{
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请至少添加一行采集线!"));
emit sequenceComplete(0);
return;
}
m_coordinator_TimedDataCollection = new TwoMotionCaptureCoordinator(m_multiAxisController);
connect(this, SIGNAL(start(QVector<PathLine>)), m_coordinator_TimedDataCollection, SLOT(start(QVector<PathLine>)));
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::startRecordLineNumSignal, this, &TwoMotorControl::receiveStartRecordLineNum);
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::finishRecordLineNumSignal, this, &TwoMotorControl::receiveFinishRecordLineNum);
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::startRecordLineNumSignal, window, &DepthCameraWindow::openDepthCamera);
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::sequenceComplete, window, &DepthCameraWindow::closeDepthCamera);
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::sequenceComplete, this, &TwoMotorControl::sequenceComplete);
connect(m_coordinator_TimedDataCollection, &TwoMotionCaptureCoordinator::back2OriginSignal, this, &TwoMotorControl::onBack2Origin2);
QVector<PathLine> pathLines;
//int columnCount = ui.recordLine_tableWidget->columnCount();
for (size_t i = 0; i < rowCount; i++)
{
PathLine tmp;
tmp.targetYPosition = ui.recordLine_tableWidget->item(i, 0)->text().toDouble();
tmp.speedTargetYPosition = ui.recordLine_tableWidget->item(i, 1)->text().toDouble();
tmp.targetXMinPosition = ui.recordLine_tableWidget->item(i, 2)->text().toDouble();
tmp.speedTargetXMinPosition = ui.recordLine_tableWidget->item(i, 3)->text().toDouble();
tmp.targetXMaxPosition = ui.recordLine_tableWidget->item(i, 4)->text().toDouble();
tmp.speedTargetXMaxPosition = ui.recordLine_tableWidget->item(i, 5)->text().toDouble();
pathLines.append(tmp);
}
for (size_t i = 0; i < ui.recordLine_tableWidget->rowCount(); i++)
{
for (size_t j = 0; j < ui.recordLine_tableWidget->columnCount(); j++)
{
ui.recordLine_tableWidget->item(i, j)->setBackgroundColor(QColor("#0E1C4C"));
}
}
emit start(pathLines);
}
void TwoMotorControl::onBack2Origin2()
{
m_coordinator_TimedDataCollection->deleteLater();
m_coordinator_TimedDataCollection = nullptr;
emit back2OriginSignal_TimedDataCollection();
}
void TwoMotorControl::run()
{
if (getState())
@ -116,19 +223,26 @@ void TwoMotorControl::run()
{
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请至少添加一行采集线!"));
emit sequenceComplete();
emit sequenceComplete(0);
return;
}
qRegisterMetaType<QVector<PathLine>>("QVector<PathLine>");
m_coordinator = new TwoMotionCaptureCoordinator(m_multiAxisController, m_Imager);
m_coordinator = new TwoMotionCaptureCoordinator(m_multiAxisController);
m_coordinator->moveToThread(&m_coordinatorThread);
connect(&m_coordinatorThread, SIGNAL(finished()), m_coordinator, SLOT(deleteLater()));
connect(this, SIGNAL(start(QVector<PathLine>)), m_coordinator, SLOT(start(QVector<PathLine>)));
connect(this, SIGNAL(stopSignal()), m_coordinator, SLOT(stop()));
connect(m_coordinator, SIGNAL(startRecordLineNumSignal(int)), this, SLOT(receiveStartRecordLineNum(int)));
connect(m_coordinator, SIGNAL(finishRecordLineNumSignal(int)), this, SLOT(receiveFinishRecordLineNum(int)));
connect(m_coordinator, SIGNAL(sequenceComplete(int)), this, SLOT(onSequenceComplete()));
connect(m_coordinator, SIGNAL(sequenceComplete(int)), this, SLOT(onSequenceComplete(int)));
connect(m_coordinator, &TwoMotionCaptureCoordinator::back2OriginSignal, this, &TwoMotorControl::onBack2Origin);
connect(m_coordinator, &TwoMotionCaptureCoordinator::startRecordHSISignal, m_Imager, &ImagerOperationBase::start_record);
connect(m_coordinator, &TwoMotionCaptureCoordinator::stopRecordHSISignal, this, &TwoMotorControl::stop_record);
connect(m_Imager, &ImagerOperationBase::RecordFinishedSignal_WhenFrameNumberMeet, m_coordinator, &TwoMotionCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet);
m_coordinatorThread.start();
QVector<PathLine> pathLines;
@ -158,6 +272,11 @@ void TwoMotorControl::run()
emit start(pathLines);
}
void TwoMotorControl::stop_record()
{
m_Imager->stop_record();
}
void TwoMotorControl::stop()
{
emit stopSignal();
@ -252,16 +371,22 @@ void TwoMotorControl::receiveFinishRecordLineNum(int lineNum)
}
}
void TwoMotorControl::onSequenceComplete()
void TwoMotorControl::onSequenceComplete(int status)
{
isWritePosFile = false;
fclose(m_posFileHandle);
emit sequenceComplete(status);
}
void TwoMotorControl::onBack2Origin()
{
m_coordinatorThread.quit();
m_coordinatorThread.wait();
m_coordinator = nullptr;
emit sequenceComplete();
emit back2OriginSignal();
emit back2OriginSignal_TimedDataCollection();
}
bool TwoMotorControl::getMotorsConnectionStatus()
@ -540,7 +665,10 @@ void TwoMotorControl::onReadRecordLineFile_btn()
{
return;
}
readRecordLineFile(RecordLineFilePath);
}
void TwoMotorControl::readRecordLineFile(QString RecordLineFilePath)
{
FILE* RecordLineFileHandle = fopen(RecordLineFilePath.toStdString().c_str(), "rb");
double number;

View File

@ -10,6 +10,9 @@
#include "CaptureCoordinator.h"
#include "MotorWindowBase.h"
#include "SingleLensReflexCameraWindow.h"
#include "DepthCameraWindow.h"
#define PI 3.1415926
class TwoMotorControl : public QDialog, public MotorWindowBase
@ -27,6 +30,8 @@ public:
void record_white();
bool getMotorsConnectionStatus();
void readRecordLineFile(QString RecordLineFilePath);
private:
ImagerOperationBase* m_Imager;
@ -68,7 +73,14 @@ public Q_SLOTS:
void stop();
void receiveStartRecordLineNum(int lineNum);
void receiveFinishRecordLineNum(int lineNum);
void onSequenceComplete();
void onSequenceComplete(int status);
void onBack2Origin();
void run2(SingleLensReflexCameraWindow* w);
void run3(DepthCameraWindow* window);
void onBack2Origin2();
void stop_record();
signals:
void moveSignal(int, bool, double, int);
@ -84,7 +96,9 @@ signals:
void stopSignal();
void startLineNumSignal(int lineNum);
void sequenceComplete();//所有采集线正常运行完成
void sequenceComplete(int status);//所有采集线正常运行完成
void back2OriginSignal();
void back2OriginSignal_TimedDataCollection();
void broadcastLocationSignal(std::vector<double>);
@ -92,6 +106,7 @@ private:
Ui::twoMotorControl_UI ui;
QThread m_coordinatorThread;
TwoMotionCaptureCoordinator* m_coordinator = nullptr;
TwoMotionCaptureCoordinator* m_coordinator_TimedDataCollection = nullptr;
DarkAndWhiteCaptureCoordinator* m_darkCaptureCoordinator = nullptr;
DarkAndWhiteCaptureCoordinator* m_whiteCaptureCoordinator = nullptr;

View File

@ -1,5 +1,5 @@
#include "imageControl.h"
#include "RasterLayer.h"
#include "RasterImageLayer.h"
#include <algorithm>
#include <cmath>
@ -99,7 +99,7 @@ ImageControl::~ImageControl()
{
}
void ImageControl::setActiveLayer(RasterLayer* layer)
void ImageControl::setActiveLayer(RasterImageLayer* layer)
{
m_activeLayer = layer;
@ -110,8 +110,8 @@ void ImageControl::setActiveLayer(RasterLayer* layer)
}
setEnabled(true);
// Get band wavelengths from the layer's header
m_wavelengths = layer->bandWavelengths();
// Get band wavelengths from the underlying RasterLayer's header
m_wavelengths = layer->layer()->bandWavelengths();
std::sort(m_wavelengths.begin(), m_wavelengths.end());
if (m_wavelengths.empty()) {
@ -150,8 +150,8 @@ void ImageControl::setActiveLayer(RasterLayer* layer)
ui.sliderBlue->setMinimum(0);
ui.sliderBlue->setMaximum(maxIdx);
// Set current values from layer's render params
auto params = layer->currentRenderParams();
// Set current values from layer's render params (multiband)
auto params = layer->multibandParams();
int rIdx = nearestBandIndex(params.rWave);
int gIdx = nearestBandIndex(params.gWave);
@ -168,7 +168,7 @@ void ImageControl::setActiveLayer(RasterLayer* layer)
blockAllSignals(false);
}
RasterLayer* ImageControl::activeLayer() const
RasterImageLayer* ImageControl::activeLayer() const
{
return m_activeLayer;
}
@ -326,13 +326,13 @@ void ImageControl::emitBandChange()
double g = ui.spinGreen->value();
double b = ui.spinBlue->value();
// Update active layer's stored render params
// Update active layer's stored render params (multiband)
if (m_activeLayer) {
auto params = m_activeLayer->currentRenderParams();
auto params = m_activeLayer->multibandParams();
params.rWave = r;
params.gWave = g;
params.bWave = b;
m_activeLayer->setCurrentRenderParams(params);
m_activeLayer->setMultibandParams(params);
}
emit bandSelectionChanged(r, g, b);

View File

@ -6,9 +6,10 @@
#include <QNetworkAccessManager>
#include <vector>
#include "RasterLayer.h"
#include "ui_imgControl.h"
class RasterLayer;
class RasterImageLayer;
class ImageControl : public QDialog
{
@ -18,9 +19,9 @@ public:
ImageControl(QWidget* parent = nullptr);
~ImageControl();
// Populate controls from a RasterLayer's wavelength info and current render params
void setActiveLayer(RasterLayer* layer);
RasterLayer* activeLayer() const;
// Populate controls from a RasterImageLayer's wavelength info and current render params
void setActiveLayer(RasterImageLayer* layer);
RasterImageLayer* activeLayer() const;
public Q_SLOTS:
@ -62,7 +63,7 @@ private:
void setControlsToBandIndex(QDoubleSpinBox* spin, QSlider* slider, int idx);
Ui::ImageControl ui;
RasterLayer* m_activeLayer = nullptr;
RasterImageLayer* m_activeLayer = nullptr;
double m_minWave = 374.5;
double m_maxWave = 948.1;
std::vector<double> m_wavelengths; // band wavelengths from header

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "recordFrameCounter.h"
#include "RasterLayer.h"
recordFrameCounter::recordFrameCounter(QWidget* parent)
: QWidget(parent)
@ -16,19 +17,19 @@ recordFrameCounter::recordFrameCounter(QWidget* parent)
layout->addWidget(m_stackedWidget);
}
void recordFrameCounter::addCounter(QWidget* tabWidget)
void recordFrameCounter::addCounter(RasterLayer* mapLayer)
{
QLabel* label = new QLabel("0");
label->setStyleSheet("color: white;");
label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
m_labelMap.insert(tabWidget, label);
m_labelMap.insert(mapLayer, label);
m_stackedWidget->addWidget(label);
m_stackedWidget->setCurrentWidget(label);
}
void recordFrameCounter::removeCounter(QWidget* tabWidget)
void recordFrameCounter::removeCounter(RasterLayer* mapLayer)
{
auto it = m_labelMap.find(tabWidget);
auto it = m_labelMap.find(mapLayer);
if (it != m_labelMap.end())
{
QLabel* label = it.value();
@ -38,18 +39,18 @@ void recordFrameCounter::removeCounter(QWidget* tabWidget)
}
}
void recordFrameCounter::switchTo(QWidget* tabWidget)
void recordFrameCounter::switchTo(RasterLayer* mapLayer)
{
auto it = m_labelMap.find(tabWidget);
auto it = m_labelMap.find(mapLayer);
if (it != m_labelMap.end())
{
m_stackedWidget->setCurrentWidget(it.value());
}
}
void recordFrameCounter::updateFrameCount(QWidget* tabWidget, int frameCount)
void recordFrameCounter::updateFrameCount(RasterLayer* mapLayer, int frameCount)
{
auto it = m_labelMap.find(tabWidget);
auto it = m_labelMap.find(mapLayer);
if (it != m_labelMap.end())
{
it.value()->setText(QString::number(frameCount));

View File

@ -6,19 +6,20 @@
#include <QHBoxLayout>
#include <QMap>
class RasterLayer;
class recordFrameCounter : public QWidget
{
Q_OBJECT
public:
explicit recordFrameCounter(QWidget* parent = nullptr);
void addCounter(QWidget* tabWidget);
void removeCounter(QWidget* tabWidget);
void switchTo(QWidget* tabWidget);
void updateFrameCount(QWidget* tabWidget, int frameCount);
void addCounter(RasterLayer* mapLayer);
void removeCounter(RasterLayer* mapLayer);
void switchTo(RasterLayer* mapLayer);
void updateFrameCount(RasterLayer* mapLayer, int frameCount);
private:
QStackedWidget* m_stackedWidget = nullptr;
QMap<QWidget*, QLabel*> m_labelMap;
QMap<RasterLayer*, QLabel*> m_labelMap;
};