Compare commits
42 Commits
1.8.7
...
1c7780eb14
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c7780eb14 | |||
| 741e0e6734 | |||
| 5d5b440ba2 | |||
| 0b2744656b | |||
| ece7a34bfb | |||
| 452f7c8e5f | |||
| 0ac03f0eb5 | |||
| edfb72eaef | |||
| 7987abf711 | |||
| 09095592af | |||
| 4ad5c8b91e | |||
| 7f94513a16 | |||
| 8d2fe91043 | |||
| bdf956ed99 | |||
| e3b2d136d3 | |||
| 631216dc66 | |||
| 7d123ca11c | |||
| 8595f7cad7 | |||
| 30e63899a8 | |||
| 30306e9396 | |||
| f0f41f9a17 | |||
| f999d87da6 | |||
| 36ad438608 | |||
| bb1a01f402 | |||
| 797ff77f5f | |||
| 83ef26a1e2 | |||
| e7a73430d0 | |||
| fd5571712a | |||
| e14c5da80a | |||
| c2a3c28cdd | |||
| 52516d2f54 | |||
| af88a6a67e | |||
| 1e0cf1aa12 | |||
| 496f61c0e1 | |||
| ac241f45cc | |||
| 1867291c9b | |||
| 48be580226 | |||
| a629115e91 | |||
| c1e4144ed6 | |||
| c2b3f131ee | |||
| 20848bef1a | |||
| f6138dd2ed |
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,5 +1,12 @@
|
||||
# tc
|
||||
GeneratedFiles/
|
||||
ResononAPISetup-3.12-64bit.exe
|
||||
gdal202.dll
|
||||
*.rej
|
||||
HPPA类图.drawio
|
||||
HPPA - 副本.ui
|
||||
icon
|
||||
ignore_*
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
10
HPPA.sln
10
HPPA.sln
@ -10,6 +10,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HPPA", "HPPA\HPPA.vcxproj",
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vincecontrol", "vincecontrol\vincecontrol.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IrisMultiMotorController", "IrisMultiMotorController\IrisMultiMotorController\IrisMultiMotorController.vcxproj", "{2E792AA6-1BCB-4CDA-BE01-4D455EC5C473}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@ -34,6 +36,14 @@ Global
|
||||
{B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.Build.0 = Release|x64
|
||||
{B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x86.ActiveCfg = Release|Win32
|
||||
{B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x86.Build.0 = Release|Win32
|
||||
{2E792AA6-1BCB-4CDA-BE01-4D455EC5C473}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{2E792AA6-1BCB-4CDA-BE01-4D455EC5C473}.Debug|x64.Build.0 = Debug|x64
|
||||
{2E792AA6-1BCB-4CDA-BE01-4D455EC5C473}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{2E792AA6-1BCB-4CDA-BE01-4D455EC5C473}.Debug|x86.Build.0 = Debug|x64
|
||||
{2E792AA6-1BCB-4CDA-BE01-4D455EC5C473}.Release|x64.ActiveCfg = Release|x64
|
||||
{2E792AA6-1BCB-4CDA-BE01-4D455EC5C473}.Release|x64.Build.0 = Release|x64
|
||||
{2E792AA6-1BCB-4CDA-BE01-4D455EC5C473}.Release|x86.ActiveCfg = Release|x64
|
||||
{2E792AA6-1BCB-4CDA-BE01-4D455EC5C473}.Release|x86.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
716
HPPA/CaptureCoordinator.cpp
Normal file
716
HPPA/CaptureCoordinator.cpp
Normal file
@ -0,0 +1,716 @@
|
||||
#include "CaptureCoordinator.h"
|
||||
|
||||
TwoMotionCaptureCoordinator::TwoMotionCaptureCoordinator(
|
||||
IrisMultiMotorController* motorCtrl,
|
||||
ImagerOperationBase* cameraCtrl,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_motorCtrl(motorCtrl)
|
||||
, m_cameraCtrl(cameraCtrl)
|
||||
, 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(this, &TwoMotionCaptureCoordinator::stopMotorSignal, m_motorCtrl, &IrisMultiMotorController::stop);
|
||||
|
||||
connect(m_motorCtrl, &IrisMultiMotorController::motorStopSignal,
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TwoMotionCaptureCoordinator::start(QVector<PathLine> pathLines)
|
||||
{
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
if (m_isRunning)
|
||||
{
|
||||
emit errorOccurred("Sequence already running");
|
||||
std::cout << "already running" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
getLocBeforeStart();
|
||||
|
||||
m_pathLines = pathLines;
|
||||
|
||||
m_isMoving2XMin = false;
|
||||
m_isMoving2XMax = false;
|
||||
m_isMoving2XStartLoc = false;
|
||||
|
||||
m_isMoving2YTargeLoc = false;
|
||||
m_isMoving2YStartLoc = false;
|
||||
m_isImagerFrameNumberMeet = false;
|
||||
|
||||
m_retryTimesMoving2XMin = 0;
|
||||
m_retryTimesMoving2XMax = 0;
|
||||
m_retryTimesMoving2YTargeLoc = 0;
|
||||
|
||||
m_isRunning = true;
|
||||
m_numCurrentPathLine = 0;
|
||||
processNextPathLine();
|
||||
}
|
||||
|
||||
void TwoMotionCaptureCoordinator::stop()
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
std::cout << "The user manually stops the collection! " << std::endl;
|
||||
savePathLinesToCsv();
|
||||
|
||||
emit sequenceComplete(1);
|
||||
emit finishRecordLineNumSignal(m_numCurrentPathLine);
|
||||
//emit stopRecordHSISignal(m_numCurrentPathLine);
|
||||
if (m_cameraCtrl != nullptr)
|
||||
{
|
||||
m_cameraCtrl->stop_record();
|
||||
}
|
||||
|
||||
move2LocBeforeStart();
|
||||
}
|
||||
|
||||
void TwoMotionCaptureCoordinator::getLocBeforeStart()
|
||||
{
|
||||
QEventLoop loop;
|
||||
bool received = false;
|
||||
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
|
||||
QMetaObject::Connection conn = QObject::connect(m_motorCtrl, &IrisMultiMotorController::locationSignal,
|
||||
[&](std::vector<double> pos) {
|
||||
m_locBeforeStart = pos;
|
||||
received = true;
|
||||
loop.quit();
|
||||
});
|
||||
|
||||
QMetaObject::invokeMethod(m_motorCtrl, "getLoc", Qt::QueuedConnection);
|
||||
timer.start(3000);
|
||||
|
||||
loop.exec();
|
||||
|
||||
disconnect(conn);
|
||||
}
|
||||
|
||||
void TwoMotionCaptureCoordinator::getRecordState()
|
||||
{
|
||||
emit recordState(m_isRunning);
|
||||
}
|
||||
|
||||
void TwoMotionCaptureCoordinator::move2LocBeforeStart()
|
||||
{
|
||||
std::cout << "\nmove2LocBeforeStart." << std::endl;
|
||||
|
||||
PathLine& tmp = m_pathLines[0];
|
||||
std::vector<double> speed;
|
||||
speed.push_back(tmp.speedTargetXMinPosition);
|
||||
speed.push_back(tmp.speedTargetYPosition);
|
||||
emit moveTo(m_locBeforeStart, speed, 1000);
|
||||
|
||||
m_isRunning = false;
|
||||
|
||||
m_isMoving2XMin = false;
|
||||
m_isMoving2XMax = false;
|
||||
m_isMoving2YTargeLoc = false;
|
||||
|
||||
m_isMoving2XStartLoc = true;
|
||||
m_isMoving2YStartLoc = true;
|
||||
}
|
||||
|
||||
QVector<PathLine> TwoMotionCaptureCoordinator::pathLines() const
|
||||
{
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
return m_pathLines;
|
||||
}
|
||||
|
||||
double TwoMotionCaptureCoordinator::getTimeDiffMinutes(QDateTime startTime, QDateTime endTime)
|
||||
{
|
||||
qint64 diffMillis = startTime.msecsTo(endTime);
|
||||
double diffMinutes = (double)diffMillis / 60000;//min
|
||||
|
||||
return diffMinutes;
|
||||
}
|
||||
|
||||
bool TwoMotionCaptureCoordinator::savePathLinesToCsv(QString filename)
|
||||
{
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
if (filename.isEmpty())
|
||||
{
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QString format1 = "yyyyMMdd_HHmmss";
|
||||
QString fileNameTmp = now.toString("yyyyMMdd_HHmmss");
|
||||
|
||||
filename = QDir::cleanPath(QString::fromStdString(directory) + QDir::separator() + "pathLines" + QDir::separator() + fileNameTmp + "_pathLines.csv");
|
||||
}
|
||||
|
||||
QDir dir = QFileInfo(filename).absoluteDir();
|
||||
|
||||
// 如果目录不存在,则递归创建
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkpath(".")) {
|
||||
qWarning() << "Failed to create directory:" << dir.path();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out << "timestamp1,timestamp2,timestamp3,time consuming(min),targetYPosition,actualYPosition,targetXMinPosition,actualXMinPosition,targetXMaxPosition,actualXMaxPosition\n";
|
||||
|
||||
for (const auto& data : m_pathLines)
|
||||
{
|
||||
out << data.timestamp1.toString("yyyy-MM-dd HH:mm:ss.zzz") << ","
|
||||
<< data.timestamp2.toString("yyyy-MM-dd HH:mm:ss.zzz") << ","
|
||||
<< data.timestamp3.toString("yyyy-MM-dd HH:mm:ss.zzz") << ","
|
||||
<< QString::number(getTimeDiffMinutes(data.timestamp2, data.timestamp3), 'f', 4) << ","
|
||||
<< QString::number(data.targetYPosition, 'f', 4) << ","
|
||||
<< QString::number(data.actualYPosition, 'f', 4) << ","
|
||||
<< QString::number(data.targetXMinPosition, 'f', 4) << ","
|
||||
<< QString::number(data.actualXMinPosition, 'f', 4) << ","
|
||||
<< QString::number(data.targetXMaxPosition, 'f', 4) << ","
|
||||
<< QString::number(data.actualXMaxPosition, 'f', 4)
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void TwoMotionCaptureCoordinator::handlePositionReached(int motorID, double pos)
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
PathLine &tmp = m_pathLines[m_numCurrentPathLine];
|
||||
|
||||
if (motorID == 1)//y马达
|
||||
{
|
||||
if (m_isMoving2YTargeLoc)
|
||||
{
|
||||
double threshold = getThre(tmp.targetYPosition, pos);
|
||||
|
||||
if (threshold > 5)
|
||||
{
|
||||
//没到准确位置,再次给马达发送命令
|
||||
if (m_retryTimesMoving2YTargeLoc < m_retryLimit)
|
||||
{
|
||||
m_retryTimesMoving2YTargeLoc++;
|
||||
|
||||
std::cout << "Y motor Moving2YTargeLoc error. Retry..." << std::endl;
|
||||
emit moveTo(1, tmp.targetYPosition, tmp.speedTargetYPosition, 1000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_retryTimesMoving2YTargeLoc = 0;
|
||||
|
||||
tmp.actualYPosition = pos;
|
||||
|
||||
m_isMoving2YTargeLoc = false;
|
||||
|
||||
std::cout << "y motor is reached!!!! " << std::endl;
|
||||
startRecordHsi();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_isMoving2YStartLoc)
|
||||
{
|
||||
m_isMoving2YStartLoc = false;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (motorID == 0)//x马达
|
||||
{
|
||||
if (m_isMoving2XMin)
|
||||
{
|
||||
double threshold = getThre(tmp.targetXMinPosition, pos);
|
||||
|
||||
if (threshold > 5)
|
||||
{
|
||||
//没到准确位置,再次给马达发送命令
|
||||
if (m_retryTimesMoving2XMin < m_retryLimit)
|
||||
{
|
||||
m_retryTimesMoving2XMin++;
|
||||
|
||||
std::cout << "X motor Moving2XMin error. Retry..." << std::endl;
|
||||
emit moveTo(0, tmp.targetXMinPosition, tmp.speedTargetXMinPosition, 1000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_retryTimesMoving2XMin = 0;
|
||||
|
||||
tmp.actualXMinPosition = pos;
|
||||
|
||||
m_isMoving2XMin = false;
|
||||
|
||||
std::cout << "x motor is reached!!!! " << std::endl;
|
||||
startRecordHsi();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_isMoving2XMax)
|
||||
{
|
||||
double threshold = getThre(tmp.targetXMaxPosition, pos);
|
||||
|
||||
if (threshold > 5 && !m_isImagerFrameNumberMeet)//马达没到准确位置 && 【非】光谱仪因帧数限制主动停止采集
|
||||
{
|
||||
//没到准确位置,再次给马达发送命令
|
||||
if (m_retryTimesMoving2XMax < m_retryLimit)
|
||||
{
|
||||
m_retryTimesMoving2XMax++;
|
||||
|
||||
std::cout << "X motor Moving2XMax error. Retry..." << std::endl;
|
||||
emit moveTo(0, tmp.targetXMaxPosition, tmp.speedTargetXMaxPosition, 1000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_retryTimesMoving2XMax = 0;
|
||||
|
||||
tmp.actualXMaxPosition = pos;
|
||||
tmp.timestamp3 = QDateTime::currentDateTime();
|
||||
|
||||
std::cout << "Line " << m_numCurrentPathLine << " time span(min):" << getTimeDiffMinutes(tmp.timestamp2, tmp.timestamp3) << std::endl;
|
||||
|
||||
//停止采集高光谱数据
|
||||
emit finishRecordLineNumSignal(m_numCurrentPathLine);
|
||||
//emit stopRecordHSISignal(m_numCurrentPathLine);
|
||||
if (m_cameraCtrl!=nullptr)
|
||||
{
|
||||
m_cameraCtrl->stop_record();
|
||||
}
|
||||
|
||||
m_isMoving2XMax = false;
|
||||
m_isImagerFrameNumberMeet = false;
|
||||
m_numCurrentPathLine++;
|
||||
processNextPathLine();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_isMoving2XStartLoc)
|
||||
{
|
||||
m_isMoving2XStartLoc = false;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double TwoMotionCaptureCoordinator::getThre(double targetLoc,double actualLoc)
|
||||
{
|
||||
double targetLocTmp;
|
||||
if (targetLoc == 0)
|
||||
{
|
||||
targetLocTmp = 0.001;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetLocTmp = targetLoc;
|
||||
}
|
||||
double thre = abs(targetLoc - actualLoc) / targetLocTmp * 100;
|
||||
|
||||
return thre;
|
||||
}
|
||||
|
||||
void TwoMotionCaptureCoordinator::startRecordHsi()
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
if (!m_isMoving2XMin && !m_isMoving2YTargeLoc)
|
||||
{
|
||||
//开始采集高光谱数据
|
||||
PathLine &tmp = m_pathLines[m_numCurrentPathLine];
|
||||
tmp.timestamp2 = QDateTime::currentDateTime();
|
||||
std::cout << "start recording hsi, moving to " << tmp.targetXMaxPosition << std::endl;
|
||||
|
||||
m_isMoving2XMax = true;
|
||||
emit moveTo(0, tmp.targetXMaxPosition, tmp.speedTargetXMaxPosition, 1000);
|
||||
|
||||
emit startRecordHSISignal(m_numCurrentPathLine);
|
||||
}
|
||||
}
|
||||
|
||||
void TwoMotionCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet()
|
||||
{
|
||||
m_isImagerFrameNumberMeet = true;
|
||||
emit stopMotorSignal(0);
|
||||
}
|
||||
|
||||
void TwoMotionCaptureCoordinator::handleError(const QString& error)
|
||||
{
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
m_isRunning = false;
|
||||
emit errorOccurred(error);
|
||||
}
|
||||
|
||||
void TwoMotionCaptureCoordinator::processNextPathLine()
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
int numPathLines = m_pathLines.size();
|
||||
|
||||
if (numPathLines == 0)
|
||||
{
|
||||
move2LocBeforeStart();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_isMoving2YTargeLoc || m_isMoving2XMin)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_numCurrentPathLine > numPathLines - 1)
|
||||
{
|
||||
std::cout << "\nAll path lines is finished! " << std::endl;
|
||||
|
||||
move2LocBeforeStart();
|
||||
savePathLinesToCsv();
|
||||
|
||||
emit sequenceComplete(0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "\nNew path line: " << m_numCurrentPathLine << std::endl;
|
||||
emit startRecordLineNumSignal(m_numCurrentPathLine);
|
||||
|
||||
PathLine &tmp = m_pathLines[m_numCurrentPathLine];
|
||||
tmp.timestamp1 = QDateTime::currentDateTime();
|
||||
|
||||
std::vector<double> loc;
|
||||
loc.push_back(tmp.targetXMinPosition);
|
||||
loc.push_back(tmp.targetYPosition);
|
||||
std::vector<double> speed;
|
||||
speed.push_back(tmp.speedTargetXMinPosition);
|
||||
speed.push_back(tmp.speedTargetYPosition);
|
||||
|
||||
m_isMoving2YTargeLoc = true;
|
||||
m_isMoving2XMin = true;
|
||||
emit moveTo(loc, speed, 1000);
|
||||
}
|
||||
|
||||
OneMotionCaptureCoordinator::OneMotionCaptureCoordinator(
|
||||
IrisMultiMotorController* motorCtrl,
|
||||
ImagerOperationBase* cameraCtrl,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_motorCtrl(motorCtrl)
|
||||
, m_cameraCtrl(cameraCtrl)
|
||||
, m_isRunning(false)
|
||||
{
|
||||
connect(this, SIGNAL(moveTo(int, double, double, int)),
|
||||
m_motorCtrl, SLOT(moveTo(int, double, double, int)));
|
||||
connect(this, SIGNAL(moveSignal(int, bool, double, int)), m_motorCtrl, SLOT(move(int, bool, double, int)));
|
||||
connect(this, &OneMotionCaptureCoordinator::stopMotorSignal, m_motorCtrl, &IrisMultiMotorController::stop);
|
||||
|
||||
connect(m_motorCtrl, &IrisMultiMotorController::motorStopSignal,
|
||||
this, &OneMotionCaptureCoordinator::handleMotorStoped);
|
||||
//connect(m_motorCtrl, &IrisMultiMotorController::moveFailed,
|
||||
// this, &OneMotionCaptureCoordinator::handleError);
|
||||
|
||||
connect(this, &OneMotionCaptureCoordinator::startRecordHSISignal,
|
||||
m_cameraCtrl, &ImagerOperationBase::start_record);
|
||||
connect(this, &OneMotionCaptureCoordinator::stopRecordHSISignal,
|
||||
m_cameraCtrl, &ImagerOperationBase::stop_record);
|
||||
connect(m_cameraCtrl, &ImagerOperationBase::RecordFinishedSignal_WhenFrameNumberMeet,
|
||||
this, &OneMotionCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet);
|
||||
}
|
||||
|
||||
OneMotionCaptureCoordinator::~OneMotionCaptureCoordinator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::startStepMotion(OneMotionCapturePathLine pathLine)
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
if (m_isRunning)
|
||||
{
|
||||
emit errorOccurred("Sequence already running");
|
||||
return;
|
||||
}
|
||||
|
||||
m_isRunning = true;
|
||||
m_pathLine = pathLine;
|
||||
|
||||
getLocBeforeStart();
|
||||
m_pathLine.startPosition = m_locBeforeStart[0];
|
||||
m_pathLine.timestamp1 = QDateTime::currentDateTime();
|
||||
|
||||
//移动马达并开始采集高光谱
|
||||
emit moveSignal(0, false, m_pathLine.speedRecord, 1000);
|
||||
emit startRecordHSISignal();
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::stopStepMotion()
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
if (m_cameraCtrl != nullptr)
|
||||
{
|
||||
m_cameraCtrl->stop_record();
|
||||
}
|
||||
|
||||
emit stopMotorSignal(0);
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet()
|
||||
{
|
||||
emit stopMotorSignal(0);
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::getLocBeforeStart()
|
||||
{
|
||||
QEventLoop loop;
|
||||
bool received = false;
|
||||
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
|
||||
QMetaObject::Connection conn = QObject::connect(m_motorCtrl, &IrisMultiMotorController::locationSignal,
|
||||
[&](std::vector<double> pos) {
|
||||
m_locBeforeStart = pos;
|
||||
received = true;
|
||||
loop.quit();
|
||||
});
|
||||
|
||||
QMetaObject::invokeMethod(m_motorCtrl, "getLoc", Qt::QueuedConnection);
|
||||
timer.start(3000);
|
||||
|
||||
loop.exec();
|
||||
|
||||
disconnect(conn);
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::move2LocBeforeStart()
|
||||
{
|
||||
std::cout << "\nmove2LocBeforeStart." << std::endl;
|
||||
|
||||
emit moveTo(0, m_locBeforeStart[0], m_pathLine.speedBack, 1000);
|
||||
|
||||
m_isRunning = false;
|
||||
}
|
||||
|
||||
bool OneMotionCaptureCoordinator::saveToCsv(const QString& filename)
|
||||
{
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out << "startTime,stopTime,startPosition,stopPosition\n";
|
||||
|
||||
out << m_pathLine.timestamp1.toString("yyyy-MM-dd HH:mm:ss.zzz") << ","
|
||||
<< m_pathLine.timestamp2.toString("yyyy-MM-dd HH:mm:ss.zzz") << ","
|
||||
<< QString::number(m_pathLine.startPosition, 'f', 4) << ","
|
||||
<< QString::number(m_pathLine.stopPosition, 'f', 4) << "\n";
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::handleMotorStoped(int motorID, double pos)
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
// 记录位置信息
|
||||
m_pathLine.stopPosition = pos;
|
||||
m_pathLine.timestamp2 = QDateTime::currentDateTime();
|
||||
|
||||
//光谱仪停止采集,马达回到初始位置
|
||||
emit stopRecordHSISignal();
|
||||
if (m_cameraCtrl != nullptr)
|
||||
{
|
||||
m_cameraCtrl->stop_record();
|
||||
}
|
||||
move2LocBeforeStart();
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::handleCaptureComplete(double index)
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
}
|
||||
|
||||
void OneMotionCaptureCoordinator::handleError(const QString& error)
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
m_isRunning = false;
|
||||
emit errorOccurred(error);
|
||||
}
|
||||
|
||||
DarkAndWhiteCaptureCoordinator::DarkAndWhiteCaptureCoordinator(
|
||||
int model,
|
||||
IrisMultiMotorController* motorCtrl,
|
||||
ImagerOperationBase* cameraCtrl,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_model(model)
|
||||
, m_motorCtrl(motorCtrl)
|
||||
, m_cameraCtrl(cameraCtrl)
|
||||
, m_isRunning(false)
|
||||
{
|
||||
connect(this, SIGNAL(moveTo(int, double, double, int)),
|
||||
m_motorCtrl, SLOT(moveTo(int, double, double, int)));
|
||||
connect(this, SIGNAL(moveSignal(int, bool, double, int)), m_motorCtrl, SLOT(move(int, bool, double, int)));
|
||||
connect(this, &DarkAndWhiteCaptureCoordinator::stopMotorSignal, m_motorCtrl, &IrisMultiMotorController::stop);
|
||||
|
||||
connect(m_motorCtrl, &IrisMultiMotorController::motorStopSignal,
|
||||
this, &DarkAndWhiteCaptureCoordinator::handleMotorStoped);
|
||||
|
||||
if (m_model == 0)//dark
|
||||
{
|
||||
connect(this, &DarkAndWhiteCaptureCoordinator::startRecordHSISignal,
|
||||
m_cameraCtrl, &ImagerOperationBase::record_dark);
|
||||
connect(m_cameraCtrl, &ImagerOperationBase::RecordDarlFinishSignal,
|
||||
this, &DarkAndWhiteCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet);
|
||||
}
|
||||
else if(m_model == 1)//white
|
||||
{
|
||||
connect(this, &DarkAndWhiteCaptureCoordinator::startRecordHSISignal,
|
||||
m_cameraCtrl, &ImagerOperationBase::record_white);
|
||||
connect(m_cameraCtrl, &ImagerOperationBase::RecordWhiteFinishSignal,
|
||||
this, &DarkAndWhiteCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DarkAndWhiteCaptureCoordinator::~DarkAndWhiteCaptureCoordinator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DarkAndWhiteCaptureCoordinator::startStepMotion(double speed)
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
if (m_isRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_isRunning = true;
|
||||
|
||||
m_speed = speed;
|
||||
|
||||
getLocBeforeStart();
|
||||
|
||||
//移动马达并开始采集高光谱
|
||||
emit moveSignal(0, false, m_speed, 1000);
|
||||
emit startRecordHSISignal();
|
||||
}
|
||||
|
||||
void DarkAndWhiteCaptureCoordinator::handleCaptureCompleteWhenFrameNumberMeet()
|
||||
{
|
||||
emit stopMotorSignal(0);
|
||||
}
|
||||
|
||||
void DarkAndWhiteCaptureCoordinator::getLocBeforeStart()
|
||||
{
|
||||
QEventLoop loop;
|
||||
bool received = false;
|
||||
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
|
||||
QMetaObject::Connection conn = QObject::connect(m_motorCtrl, &IrisMultiMotorController::locationSignal,
|
||||
[&](std::vector<double> pos) {
|
||||
m_locBeforeStart = pos;
|
||||
received = true;
|
||||
loop.quit();
|
||||
});
|
||||
|
||||
QMetaObject::invokeMethod(m_motorCtrl, "getLoc", Qt::QueuedConnection);
|
||||
timer.start(3000);
|
||||
|
||||
loop.exec();
|
||||
|
||||
disconnect(conn);
|
||||
}
|
||||
|
||||
void DarkAndWhiteCaptureCoordinator::move2LocBeforeStart()
|
||||
{
|
||||
std::cout << "\nmove2LocBeforeStart." << std::endl;
|
||||
|
||||
emit moveTo(0, m_locBeforeStart[0], m_speed, 1000);
|
||||
|
||||
m_isRunning = false;
|
||||
}
|
||||
|
||||
void DarkAndWhiteCaptureCoordinator::handleMotorStoped(int motorID, double pos)
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
if (!m_isRunning) return;
|
||||
|
||||
move2LocBeforeStart();
|
||||
}
|
||||
|
||||
void DarkAndWhiteCaptureCoordinator::handleCaptureComplete(double index)
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
}
|
||||
210
HPPA/CaptureCoordinator.h
Normal file
210
HPPA/CaptureCoordinator.h
Normal file
@ -0,0 +1,210 @@
|
||||
#pragma once
|
||||
#include <QDateTime>
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QMetaType>
|
||||
|
||||
#include "ImagerOperationBase.h"
|
||||
#include "IrisMultiMotorController.h"
|
||||
|
||||
struct PathLine
|
||||
{
|
||||
double targetYPosition;
|
||||
double actualYPosition;
|
||||
double speedTargetYPosition;
|
||||
|
||||
double targetXMinPosition;
|
||||
double actualXMinPosition;
|
||||
double speedTargetXMinPosition;
|
||||
|
||||
double targetXMaxPosition;
|
||||
double actualXMaxPosition;
|
||||
double speedTargetXMaxPosition;
|
||||
|
||||
QDateTime timestamp1;//开始航线
|
||||
QDateTime timestamp2;//开始采集高光谱
|
||||
QDateTime timestamp3;//结束采集高光谱
|
||||
|
||||
PathLine(double targetYPosition_=0, double targetXMinPosition_ = 0, double targetXMaxPosition_ = 0)
|
||||
: targetYPosition(targetYPosition_), actualYPosition(0), speedTargetYPosition(0),
|
||||
targetXMinPosition(targetXMinPosition_), actualXMinPosition(0), speedTargetXMinPosition(0),
|
||||
targetXMaxPosition(targetXMaxPosition_), actualXMaxPosition(0), speedTargetXMaxPosition(0),
|
||||
timestamp1(QDateTime::currentDateTime()), timestamp2(QDateTime::currentDateTime()), timestamp3(QDateTime::currentDateTime()) {}
|
||||
};
|
||||
Q_DECLARE_METATYPE(PathLine);
|
||||
//Q_DECLARE_METATYPE(QVector<PathLine>);
|
||||
|
||||
class TwoMotionCaptureCoordinator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TwoMotionCaptureCoordinator(IrisMultiMotorController* motorCtrl,
|
||||
ImagerOperationBase* cameraCtrl,
|
||||
QObject* parent = nullptr);
|
||||
TwoMotionCaptureCoordinator(IrisMultiMotorController* motorCtrl,
|
||||
QObject* parent = nullptr);
|
||||
~TwoMotionCaptureCoordinator();
|
||||
|
||||
QVector<PathLine> pathLines() const;
|
||||
|
||||
signals:
|
||||
void sequenceComplete(int);//0:所有采集线正常运行完成,1:用户主动取消采集
|
||||
void startRecordLineNumSignal(int lineNum);
|
||||
void finishRecordLineNumSignal(int lineNum);
|
||||
|
||||
void startRecordHSISignal(int lineNum);
|
||||
void stopRecordHSISignal(int lineNum);
|
||||
|
||||
void errorOccurred(const QString& error);
|
||||
void moveTo(int, double, double, int);
|
||||
void moveTo(const std::vector<double>, const std::vector<double>, int);
|
||||
void stopMotorSignal(int axis);
|
||||
|
||||
void recordState(bool state);
|
||||
|
||||
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();
|
||||
|
||||
private:
|
||||
void processNextPathLine();
|
||||
void startRecordHsi();
|
||||
void getLocBeforeStart();
|
||||
double getThre(double targetLoc, double actualLoc);
|
||||
|
||||
double getTimeDiffMinutes(QDateTime startTime, QDateTime endTime);
|
||||
bool savePathLinesToCsv(QString filename= QString());
|
||||
|
||||
IrisMultiMotorController* m_motorCtrl;
|
||||
ImagerOperationBase* m_cameraCtrl=nullptr;
|
||||
QVector<PathLine> m_pathLines;
|
||||
mutable QMutex m_dataMutex;
|
||||
|
||||
bool m_isRunning;
|
||||
bool m_isMoving2YTargeLoc;
|
||||
bool m_isMoving2XMin;
|
||||
bool m_isMoving2XMax;
|
||||
|
||||
int m_retryLimit = 3;
|
||||
int m_retryTimesMoving2YTargeLoc;
|
||||
int m_retryTimesMoving2XMin;
|
||||
int m_retryTimesMoving2XMax;
|
||||
|
||||
bool m_isImagerFrameNumberMeet;//光谱仪帧数限制到了,主动停止采集
|
||||
std::vector<double> m_locBeforeStart;
|
||||
|
||||
bool m_isMoving2XStartLoc;
|
||||
bool m_isMoving2YStartLoc;
|
||||
|
||||
int m_numCurrentPathLine;
|
||||
};
|
||||
|
||||
|
||||
struct OneMotionCapturePathLine
|
||||
{
|
||||
double startPosition;
|
||||
double stopPosition;
|
||||
double speedRecord;
|
||||
double speedBack;
|
||||
|
||||
QDateTime timestamp1;//开始
|
||||
QDateTime timestamp2;//结束
|
||||
|
||||
OneMotionCapturePathLine()
|
||||
: startPosition(0), stopPosition(0), speedRecord(0), speedBack(0),
|
||||
timestamp1(QDateTime::currentDateTime()), timestamp2(QDateTime::currentDateTime()) {}
|
||||
};
|
||||
Q_DECLARE_METATYPE(OneMotionCapturePathLine);
|
||||
|
||||
class OneMotionCaptureCoordinator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
OneMotionCaptureCoordinator(IrisMultiMotorController* motorCtrl,
|
||||
ImagerOperationBase* cameraCtrl,
|
||||
QObject* parent = nullptr);
|
||||
~OneMotionCaptureCoordinator();
|
||||
|
||||
bool saveToCsv(const QString& filename);
|
||||
|
||||
public slots:
|
||||
void startStepMotion(OneMotionCapturePathLine pathLine);
|
||||
void stopStepMotion();
|
||||
|
||||
void handleCaptureCompleteWhenFrameNumberMeet();
|
||||
|
||||
signals:
|
||||
void sequenceComplete(int);
|
||||
void errorOccurred(const QString& error);
|
||||
void moveTo(int, double, double, int);
|
||||
void moveSignal(int, bool, double, int);
|
||||
void stopMotorSignal(int axis);
|
||||
|
||||
void startRecordHSISignal();
|
||||
void stopRecordHSISignal();
|
||||
|
||||
private slots:
|
||||
void handleMotorStoped(int motorID, double pos);
|
||||
void handleCaptureComplete(double index);
|
||||
void handleError(const QString& error);
|
||||
|
||||
private:
|
||||
IrisMultiMotorController* m_motorCtrl;
|
||||
ImagerOperationBase* m_cameraCtrl;
|
||||
OneMotionCapturePathLine m_pathLine;
|
||||
mutable QMutex m_dataMutex;
|
||||
|
||||
bool m_isRunning;
|
||||
|
||||
std::vector<double> m_locBeforeStart;
|
||||
void getLocBeforeStart();
|
||||
void move2LocBeforeStart();
|
||||
};
|
||||
|
||||
class DarkAndWhiteCaptureCoordinator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DarkAndWhiteCaptureCoordinator(int model, IrisMultiMotorController* motorCtrl,
|
||||
ImagerOperationBase* cameraCtrl,
|
||||
QObject* parent = nullptr);
|
||||
~DarkAndWhiteCaptureCoordinator();
|
||||
|
||||
public slots:
|
||||
void startStepMotion(double speed);
|
||||
|
||||
void handleCaptureCompleteWhenFrameNumberMeet();
|
||||
|
||||
signals:
|
||||
void sequenceComplete(int);
|
||||
void moveTo(int, double, double, int);
|
||||
void moveSignal(int, bool, double, int);
|
||||
void stopMotorSignal(int axis);
|
||||
|
||||
void startRecordHSISignal();
|
||||
|
||||
private slots:
|
||||
void handleMotorStoped(int motorID, double pos);
|
||||
void handleCaptureComplete(double index);
|
||||
|
||||
private:
|
||||
IrisMultiMotorController* m_motorCtrl;
|
||||
ImagerOperationBase* m_cameraCtrl;
|
||||
mutable QMutex m_dataMutex;
|
||||
|
||||
bool m_isRunning;
|
||||
|
||||
double m_speed;
|
||||
int m_model;//0:dark,1:white
|
||||
|
||||
std::vector<double> m_locBeforeStart;
|
||||
void getLocBeforeStart();
|
||||
void move2LocBeforeStart();
|
||||
};
|
||||
259
HPPA/Carousel.cpp
Normal file
259
HPPA/Carousel.cpp
Normal file
@ -0,0 +1,259 @@
|
||||
#include "Carousel.h"
|
||||
#include <QContextMenuEvent>
|
||||
#include <QDebug>
|
||||
|
||||
MyCarousel::MyCarousel(QWidget* parent)
|
||||
: QWidget(parent),
|
||||
m_stackedWidget(new QStackedWidget(this)),
|
||||
m_bottomButtonOverlay(nullptr),
|
||||
m_bottomButtonLayout(nullptr),
|
||||
m_bottomButtonGroup(nullptr),
|
||||
m_currentIndex(0),
|
||||
m_isPlaying(false),
|
||||
m_isLocked(false),
|
||||
m_lockedIndex(-1),
|
||||
m_playInterval(2000),
|
||||
m_intervalButtonSize(40)
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->addWidget(m_stackedWidget);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
m_autoPlayerTimer = new QTimer(this);
|
||||
connect(m_autoPlayerTimer, &QTimer::timeout,
|
||||
this, &MyCarousel::slideRight);
|
||||
|
||||
m_nomalQSS= R"(
|
||||
QPushButton
|
||||
{
|
||||
background-color: #FFFFFF;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #FFFFFF;
|
||||
}
|
||||
QPushButton:checked
|
||||
{
|
||||
background-color: #08F8E8;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #08F8E8;
|
||||
}
|
||||
QPushButton:hover
|
||||
{
|
||||
background-color: red;
|
||||
border-radius: 5px;
|
||||
border: 1px solid red;
|
||||
}
|
||||
/*QPushButton:!checked {
|
||||
background-color: #FFFFFF;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #FFFFFF;
|
||||
}*/
|
||||
)";
|
||||
|
||||
m_lockedQSS = R"(
|
||||
QPushButton
|
||||
{
|
||||
background-color: #FFFFFF;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #FFFFFF;
|
||||
}
|
||||
QPushButton:checked
|
||||
{
|
||||
background-color: #08F8E8;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #08F8E8;
|
||||
}
|
||||
QPushButton:hover
|
||||
{
|
||||
background-color: red;
|
||||
border-radius: 5px;
|
||||
border: 1px solid red;
|
||||
}
|
||||
)";
|
||||
}
|
||||
|
||||
void MyCarousel::addWidget(QWidget* w)
|
||||
{
|
||||
m_widgets.append(w);
|
||||
m_stackedWidget->addWidget(w);
|
||||
updateStackedWidgetVisibility();
|
||||
}
|
||||
|
||||
void MyCarousel::play()
|
||||
{
|
||||
if (m_widgets.isEmpty())
|
||||
return;
|
||||
|
||||
m_isPlaying = true;
|
||||
|
||||
// 创建底部按钮
|
||||
m_bottomButtonLayout = new QHBoxLayout();
|
||||
m_bottomButtonGroup = new QButtonGroup(this);
|
||||
m_bottomButtons.clear();
|
||||
|
||||
for (int i = 0; i < m_widgets.size(); ++i) {
|
||||
QPushButton* btn = new QPushButton(this);
|
||||
btn->setCheckable(true);
|
||||
btn->setFixedSize(m_intervalButtonSize, 3);
|
||||
btn->setStyleSheet(m_nomalQSS);
|
||||
btn->setFixedHeight(10);
|
||||
btn->setFixedWidth(10);
|
||||
|
||||
m_bottomButtonLayout->addWidget(btn);
|
||||
m_bottomButtonGroup->addButton(btn, i);
|
||||
m_bottomButtons.append(btn);
|
||||
|
||||
connect(btn, &QPushButton::clicked, this, [this, i]() {
|
||||
onButtonClicked(i);
|
||||
});
|
||||
}
|
||||
|
||||
m_bottomButtonOverlay = new QWidget(this);
|
||||
m_bottomButtonOverlay->setLayout(m_bottomButtonLayout);
|
||||
m_bottomButtonOverlay->setAttribute(Qt::WA_TranslucentBackground);
|
||||
m_bottomButtonOverlay->show();
|
||||
|
||||
m_autoPlayerTimer->setInterval(m_playInterval);
|
||||
m_autoPlayerTimer->start();
|
||||
|
||||
updateStackedWidgetVisibility();
|
||||
}
|
||||
|
||||
void MyCarousel::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
showContextMenu(event->globalPos());
|
||||
}
|
||||
|
||||
void MyCarousel::showContextMenu(const QPoint& pos)
|
||||
{
|
||||
QMenu menu(this);
|
||||
|
||||
QAction* startAct = menu.addAction(QString::fromLocal8Bit("开始轮播"));
|
||||
QAction* stopAct = menu.addAction(QString::fromLocal8Bit("停止轮播"));
|
||||
|
||||
if (!m_isLocked)
|
||||
startAct->setEnabled(false);
|
||||
|
||||
if (m_isLocked)
|
||||
stopAct->setEnabled(false);
|
||||
|
||||
QAction* act = menu.exec(pos);
|
||||
|
||||
if (act == startAct)
|
||||
startAutoPlay();
|
||||
else if (act == stopAct)
|
||||
stopAutoPlay();
|
||||
}
|
||||
|
||||
void MyCarousel::startAutoPlay()
|
||||
{
|
||||
updateButtonState(m_currentIndex);
|
||||
}
|
||||
|
||||
void MyCarousel::stopAutoPlay()
|
||||
{
|
||||
updateButtonState(m_currentIndex);
|
||||
}
|
||||
|
||||
void MyCarousel::onButtonClicked(int index)
|
||||
{
|
||||
updateButtonState(index);
|
||||
gotoWidget(index);
|
||||
}
|
||||
|
||||
void MyCarousel::updateButtonState(int index)
|
||||
{
|
||||
if (m_isLocked)
|
||||
{
|
||||
if (index == m_lockedIndex) {
|
||||
// 解锁
|
||||
m_isLocked = false;
|
||||
m_lockedIndex = -1;
|
||||
|
||||
if (m_isPlaying)
|
||||
m_autoPlayerTimer->start();
|
||||
|
||||
restoreButtonStyle(index);
|
||||
}
|
||||
else {
|
||||
// 切换锁定
|
||||
restoreButtonStyle(m_lockedIndex);
|
||||
setButtonLocked(index);
|
||||
m_lockedIndex = index;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 初次锁定
|
||||
m_isLocked = true;
|
||||
m_lockedIndex = index;
|
||||
m_autoPlayerTimer->stop();
|
||||
setButtonLocked(index);
|
||||
}
|
||||
}
|
||||
|
||||
void MyCarousel::setButtonLocked(int index)
|
||||
{
|
||||
QPushButton* btn = m_bottomButtons[index];
|
||||
btn->setText("");
|
||||
btn->setStyleSheet(m_lockedQSS);
|
||||
}
|
||||
|
||||
void MyCarousel::restoreButtonStyle(int index)
|
||||
{
|
||||
if (index < 0)
|
||||
return;
|
||||
|
||||
QPushButton* btn = m_bottomButtons[index];
|
||||
btn->setText("");
|
||||
btn->setStyleSheet(m_nomalQSS);
|
||||
}
|
||||
|
||||
void MyCarousel::slideLeft()
|
||||
{
|
||||
if (m_widgets.isEmpty() || m_isLocked || !m_isPlaying)
|
||||
return;
|
||||
|
||||
m_currentIndex = (m_currentIndex - 1 + m_widgets.size()) % m_widgets.size();
|
||||
updateStackedWidgetVisibility();
|
||||
}
|
||||
|
||||
void MyCarousel::slideRight()
|
||||
{
|
||||
if (m_widgets.isEmpty() || m_isLocked || !m_isPlaying)
|
||||
return;
|
||||
|
||||
m_currentIndex = (m_currentIndex + 1) % m_widgets.size();
|
||||
updateStackedWidgetVisibility();
|
||||
}
|
||||
|
||||
void MyCarousel::gotoWidget(int index)
|
||||
{
|
||||
m_currentIndex = index;
|
||||
updateStackedWidgetVisibility();
|
||||
}
|
||||
|
||||
void MyCarousel::updateStackedWidgetVisibility()
|
||||
{
|
||||
if (m_widgets.isEmpty())
|
||||
return;
|
||||
|
||||
m_stackedWidget->setCurrentIndex(m_currentIndex);
|
||||
|
||||
if (!m_isLocked) {
|
||||
for (int i = 0; i < m_bottomButtons.size(); ++i)
|
||||
m_bottomButtons[i]->setChecked(i == m_currentIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void MyCarousel::resizeEvent(QResizeEvent*)
|
||||
{
|
||||
if (!m_bottomButtonOverlay)
|
||||
return;
|
||||
|
||||
int count = m_widgets.size();
|
||||
int totalWidth = m_intervalButtonSize * count + 10 * (count - 1);
|
||||
|
||||
int x = (width() - totalWidth) / 2;
|
||||
int y = height() - m_intervalButtonSize;
|
||||
|
||||
m_bottomButtonOverlay->setGeometry(x, y, totalWidth, m_intervalButtonSize);
|
||||
}
|
||||
66
HPPA/Carousel.h
Normal file
66
HPPA/Carousel.h
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QStackedWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QButtonGroup>
|
||||
#include <QTimer>
|
||||
#include <QMenu>
|
||||
|
||||
class MyCarousel : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MyCarousel(QWidget* parent = nullptr);
|
||||
|
||||
void addWidget(QWidget* w);
|
||||
void play();
|
||||
void gotoWidget(int index);
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent* event) override;
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void slideLeft();
|
||||
void slideRight();
|
||||
void onButtonClicked(int index);
|
||||
|
||||
private:
|
||||
// UI
|
||||
QStackedWidget* m_stackedWidget;
|
||||
QWidget* m_bottomButtonOverlay;
|
||||
QHBoxLayout* m_bottomButtonLayout;
|
||||
QButtonGroup* m_bottomButtonGroup;
|
||||
|
||||
QVector<QWidget*> m_widgets;
|
||||
QVector<QPushButton*> m_bottomButtons;
|
||||
QString m_nomalQSS;
|
||||
QString m_lockedQSS;
|
||||
|
||||
// ״ֵ̬
|
||||
int m_currentIndex;
|
||||
bool m_isPlaying;
|
||||
bool m_isLocked;
|
||||
int m_lockedIndex;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
int m_playInterval;
|
||||
int m_intervalButtonSize;
|
||||
|
||||
QTimer* m_autoPlayerTimer;
|
||||
|
||||
private:
|
||||
void updateStackedWidgetVisibility();
|
||||
void updateButtonState(int index);
|
||||
|
||||
void setButtonLocked(int index);
|
||||
void restoreButtonStyle(int index);
|
||||
|
||||
void showContextMenu(const QPoint& pos);
|
||||
|
||||
void startAutoPlay();
|
||||
void stopAutoPlay();
|
||||
};
|
||||
158
HPPA/Corning410Imager.cpp
Normal file
158
HPPA/Corning410Imager.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
#include "Corning410Imager.h"
|
||||
|
||||
Corning410Imager::Corning410Imager()
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>У<EFBFBD><D0A3>ʹ<EFBFBD><CDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
string CfgFile = getPathofEXE() + "\\corning410.cfg";
|
||||
m_configfile.setConfigfilePath(CfgFile);
|
||||
if (!m_configfile.isConfigfileExist())
|
||||
{
|
||||
m_configfile.createConfigFile();
|
||||
qDebug() << "create: " << QString::fromStdString(CfgFile);
|
||||
}
|
||||
m_configfile.parseConfigfile();
|
||||
qDebug() << "exist: " << QString::fromStdString(CfgFile);
|
||||
}
|
||||
|
||||
Corning410Imager::~Corning410Imager()
|
||||
{
|
||||
if (buffer != nullptr)
|
||||
{
|
||||
std::cout << "<EFBFBD>ͷŶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>" << std::endl;
|
||||
free(buffer);
|
||||
free(dark);
|
||||
free(white);
|
||||
}
|
||||
}
|
||||
|
||||
double Corning410Imager::getFramerate()
|
||||
{
|
||||
return m_imager.get_framerate();
|
||||
}
|
||||
|
||||
double Corning410Imager::getIntegrationTime()
|
||||
{
|
||||
return m_imager.get_integration_time() / 1000;
|
||||
}
|
||||
|
||||
double Corning410Imager::getGain()
|
||||
{
|
||||
return m_imager.get_gain();
|
||||
}
|
||||
|
||||
void Corning410Imager::setGain(const double gain)
|
||||
{
|
||||
m_imager.set_gain(gain);
|
||||
}
|
||||
|
||||
void Corning410Imager::setFramerate(const double frames_per_second)
|
||||
{
|
||||
m_imager.set_framerate(frames_per_second);
|
||||
m_RgbImage->m_iFramerate = frames_per_second;
|
||||
}
|
||||
|
||||
void Corning410Imager::setIntegrationTime(const double milliseconds)
|
||||
{
|
||||
m_imager.set_integration_time(milliseconds * 1000);
|
||||
}
|
||||
|
||||
int Corning410Imager::getStartBand()
|
||||
{
|
||||
return m_imager.get_start_band();
|
||||
}
|
||||
|
||||
int Corning410Imager::getEndBand()
|
||||
{
|
||||
return m_imager.get_end_band();
|
||||
}
|
||||
|
||||
void Corning410Imager::connectImager(const char* camera_sn)
|
||||
{
|
||||
m_imager.connect();
|
||||
|
||||
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>
|
||||
bool ret, ret1, ret2;
|
||||
|
||||
int spatialBin;
|
||||
int spectralBin;
|
||||
ret1 = m_configfile.getspatialBin(spatialBin);
|
||||
ret2 = m_configfile.getSpectralBin(spectralBin);
|
||||
if (ret1 && ret2)
|
||||
{
|
||||
bool haha = m_imager.setSpectralBin(spectralBin);
|
||||
bool haha2 = m_imager.setSpatialBin(spatialBin);
|
||||
|
||||
std::cout << "spectralBin<EFBFBD><EFBFBD>" << spectralBin << std::endl;
|
||||
std::cout << "spatialBin<EFBFBD><EFBFBD>" << spatialBin << std::endl;
|
||||
}
|
||||
|
||||
float gain, offset;
|
||||
ret = m_configfile.getGainOffset(gain, offset);
|
||||
if (ret)
|
||||
{
|
||||
m_imager.setGainOffset(gain, offset);
|
||||
}
|
||||
|
||||
int width = 0, offsetx = 0, height = 0, offsety = 0;
|
||||
ret = m_configfile.getEffectiveWindow(width, offsetx, height, offsety);
|
||||
if (ret)
|
||||
{
|
||||
m_imager.setEffectiveWindow(offsetx, width, offsety, height);
|
||||
}
|
||||
|
||||
|
||||
int bufferPolicy, acqBufferSize;
|
||||
ret1 = m_configfile.getBufferPolicy(bufferPolicy);
|
||||
if (ret1)
|
||||
{
|
||||
m_imager.setBufferPolicy(bufferPolicy);
|
||||
}
|
||||
ret1 = m_configfile.getAcqBufferSize(acqBufferSize);
|
||||
if (ret1)
|
||||
{
|
||||
m_imager.setAcqBufferSize(acqBufferSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Corning410Imager::disconnectImager()
|
||||
{
|
||||
m_imager.disconnect();
|
||||
}
|
||||
|
||||
void Corning410Imager::imagerStartCollect()
|
||||
{
|
||||
m_imager.start();
|
||||
}
|
||||
|
||||
void Corning410Imager::imagerStopCollect()
|
||||
{
|
||||
m_imager.stop();
|
||||
}
|
||||
|
||||
unsigned short* Corning410Imager::getFrame(unsigned short* buffer)
|
||||
{
|
||||
m_imager.get_frame(buffer);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void Corning410Imager::setSpectraBin(int new_spectral_bin)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
double Corning410Imager::getWavelengthAtBand(int band)
|
||||
{
|
||||
return m_imager.get_wavelength_at_band(band);
|
||||
}
|
||||
|
||||
int Corning410Imager::getBandCount()
|
||||
{
|
||||
return m_imager.get_band_count();
|
||||
}
|
||||
|
||||
int Corning410Imager::getSampleCount()
|
||||
{
|
||||
return m_imager.get_sample_count();
|
||||
}
|
||||
48
HPPA/Corning410Imager.h
Normal file
48
HPPA/Corning410Imager.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#include "ImagerOperationBase.h"
|
||||
#include "image2display.h"
|
||||
#include "fileOperation.h"
|
||||
|
||||
#include "irisximeaimager.h"
|
||||
#include "path_tc.h"
|
||||
#include "hppaConfigFile.h"
|
||||
|
||||
class Corning410Imager :public ImagerOperationBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Corning410Imager();
|
||||
~Corning410Imager();
|
||||
|
||||
Iris::IrisXimeaImager m_imager;
|
||||
|
||||
double getWavelengthAtBand(int band);
|
||||
int getBandCount();
|
||||
int getSampleCount();
|
||||
double getFramerate();
|
||||
double getIntegrationTime();
|
||||
double getGain();
|
||||
void setFramerate(const double frames_per_second);
|
||||
void setIntegrationTime(const double milliseconds);
|
||||
void setGain(const double gain);
|
||||
int getStartBand();
|
||||
int getEndBand();
|
||||
void connectImager(const char* camera_sn = NULL);
|
||||
void disconnectImager();
|
||||
void imagerStartCollect();
|
||||
void imagerStopCollect();
|
||||
unsigned short* getFrame(unsigned short* buffer);
|
||||
void setSpectraBin(int new_spectral_bin);
|
||||
|
||||
protected:
|
||||
private:
|
||||
CorningConfigfile m_configfile;
|
||||
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
};
|
||||
204
HPPA/CustomDockWidgetBase.cpp
Normal file
204
HPPA/CustomDockWidgetBase.cpp
Normal file
@ -0,0 +1,204 @@
|
||||
#include "CustomDockWidgetBase.h"
|
||||
|
||||
CustomDockWidgetBase::CustomDockWidgetBase(QMainWindow* parent)
|
||||
: QDockWidget(parent),
|
||||
m_mainWindow(parent),
|
||||
m_isMaximized(false)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
CustomDockWidgetBase::CustomDockWidgetBase(QString title, QMainWindow* parent)
|
||||
: QDockWidget(title, parent),
|
||||
m_mainWindow(parent),
|
||||
m_isMaximized(false)
|
||||
{
|
||||
initialize();
|
||||
setTile(title);
|
||||
}
|
||||
|
||||
void CustomDockWidgetBase::initialize()
|
||||
{
|
||||
QWidget* titleBar_Background = new QWidget(this);
|
||||
titleBar_Background->setObjectName("titleBar_Background");
|
||||
QGridLayout* layout_titleBar_Background = new QGridLayout(titleBar_Background);
|
||||
layout_titleBar_Background->setContentsMargins(0, 0, 0, 0);
|
||||
titleBar_Background->setStyleSheet(R"(
|
||||
QWidget #titleBar_Background{
|
||||
background: #040125;
|
||||
}
|
||||
)");
|
||||
|
||||
QWidget* titleBar = new QWidget(titleBar_Background);
|
||||
titleBar->setObjectName("titleBar");
|
||||
QHBoxLayout* layout = new QHBoxLayout(titleBar);
|
||||
titleBar->setFixedHeight(30);
|
||||
|
||||
title_label = new QLabel(titleBar);
|
||||
|
||||
layout->setContentsMargins(10, 0, 10, 0);
|
||||
layout->addWidget(title_label);
|
||||
layout->addStretch();
|
||||
|
||||
m_maxButton = new QToolButton(titleBar);
|
||||
m_maxButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarMaxButton));
|
||||
|
||||
layout->addWidget(m_maxButton);
|
||||
|
||||
titleBar->setStyleSheet(R"(
|
||||
QWidget #titleBar{
|
||||
background: #0E1C4C;
|
||||
/*border: 4px solid #2c586b;*/
|
||||
/*padding-top: 10px;
|
||||
padding-bottom: 10px;*/
|
||||
|
||||
border-top: 1px solid #2c586b;
|
||||
border-left: 1px solid #2c586b;
|
||||
border-right: 1px solid #2c586b;
|
||||
border-bottom: none; /* ȡ<><C8A1><EFBFBD>ײ<EFBFBD><D7B2>߿<EFBFBD> */
|
||||
|
||||
border-top-left-radius: 5px;
|
||||
border-top-right-radius: 5px;
|
||||
}
|
||||
)");
|
||||
title_label->setStyleSheet("color: white;");
|
||||
m_maxButton->setStyleSheet("");
|
||||
|
||||
layout_titleBar_Background->addWidget(titleBar);
|
||||
|
||||
setTitleBarWidget(titleBar_Background);
|
||||
setFeatures(QDockWidget::DockWidgetClosable);
|
||||
connect(m_maxButton, &QToolButton::clicked, this, &CustomDockWidgetBase::toggleMaximize);
|
||||
}
|
||||
|
||||
void CustomDockWidgetBase::setTile(QString title)
|
||||
{
|
||||
title_label->setText(title);
|
||||
}
|
||||
|
||||
void CustomDockWidgetBase::hideMaxButton()
|
||||
{
|
||||
m_maxButton->hide();
|
||||
}
|
||||
|
||||
void CustomDockWidgetBase::toggleMaximize()
|
||||
{
|
||||
if (!m_isMaximized)
|
||||
{
|
||||
m_hiddenDocks.clear();
|
||||
m_originalSizes.clear();
|
||||
|
||||
m_savedState = m_mainWindow->saveState();
|
||||
|
||||
const QList<QDockWidget*> docks = m_mainWindow->findChildren<QDockWidget*>();
|
||||
for (QDockWidget* dock : docks)
|
||||
{
|
||||
m_originalSizes[dock] = dock->size();
|
||||
if (dock != this && dock->isVisible())
|
||||
{
|
||||
dock->hide();
|
||||
m_hiddenDocks.append(dock);
|
||||
}
|
||||
}
|
||||
|
||||
m_isMaximized = true;
|
||||
emit maximizeStateChanged(m_isMaximized);
|
||||
m_maxButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarNormalButton));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (QDockWidget* dock : m_hiddenDocks)
|
||||
{
|
||||
dock->show();
|
||||
}
|
||||
|
||||
if (!m_savedState.isEmpty())
|
||||
{
|
||||
m_mainWindow->restoreState(m_savedState);
|
||||
m_savedState.clear();
|
||||
}
|
||||
|
||||
QList<QDockWidget*> docks;
|
||||
QList<int> widths, heights;
|
||||
for (auto it = m_originalSizes.begin(); it != m_originalSizes.end(); ++it)
|
||||
{
|
||||
docks.append(it.key());
|
||||
widths.append(it.value().width());
|
||||
heights.append(it.value().height());
|
||||
}
|
||||
|
||||
m_mainWindow->resizeDocks(docks, widths, Qt::Horizontal);
|
||||
m_mainWindow->resizeDocks(docks, heights, Qt::Vertical);
|
||||
|
||||
m_isMaximized = false;
|
||||
emit maximizeStateChanged(m_isMaximized);
|
||||
m_maxButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarMaxButton));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CustomDockWidgetHideAbove::CustomDockWidgetHideAbove(QString title, QMainWindow* parent)
|
||||
:CustomDockWidgetBase(title, parent)
|
||||
{
|
||||
|
||||
}
|
||||
CustomDockWidgetHideAbove::CustomDockWidgetHideAbove(QMainWindow* parent)
|
||||
:CustomDockWidgetBase(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CustomDockWidgetHideAbove::toggleMaximize()
|
||||
{
|
||||
if (!m_isMaximized)
|
||||
{
|
||||
m_hiddenDocks.clear();
|
||||
m_originalSizes.clear();
|
||||
|
||||
m_savedState = m_mainWindow->saveState();
|
||||
|
||||
const QList<QDockWidget*> docks = m_mainWindow->findChildren<QDockWidget*>();
|
||||
for (QDockWidget* dock : docks)
|
||||
{
|
||||
m_originalSizes[dock] = dock->size();
|
||||
if (dock->objectName().contains("mDockCarousel") && dock->isVisible())
|
||||
{
|
||||
dock->hide();
|
||||
m_hiddenDocks.append(dock);
|
||||
}
|
||||
}
|
||||
|
||||
m_isMaximized = true;
|
||||
emit maximizeStateChanged(m_isMaximized);
|
||||
m_maxButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarNormalButton));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (QDockWidget* dock : m_hiddenDocks)
|
||||
{
|
||||
dock->show();
|
||||
}
|
||||
|
||||
if (!m_savedState.isEmpty())
|
||||
{
|
||||
m_mainWindow->restoreState(m_savedState);
|
||||
m_savedState.clear();
|
||||
}
|
||||
|
||||
//QList<QDockWidget*> docks;
|
||||
//QList<int> widths, heights;
|
||||
//for (auto it = m_originalSizes.begin(); it != m_originalSizes.end(); ++it)
|
||||
//{
|
||||
// docks.append(it.key());
|
||||
// widths.append(it.value().width());
|
||||
// heights.append(it.value().height());
|
||||
//}
|
||||
|
||||
//m_mainWindow->resizeDocks(docks, widths, Qt::Horizontal);
|
||||
//m_mainWindow->resizeDocks(docks, heights, Qt::Vertical);
|
||||
|
||||
m_isMaximized = false;
|
||||
emit maximizeStateChanged(m_isMaximized);
|
||||
m_maxButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarMaxButton));
|
||||
}
|
||||
}
|
||||
53
HPPA/CustomDockWidgetBase.h
Normal file
53
HPPA/CustomDockWidgetBase.h
Normal file
@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
#include <QDockWidget>
|
||||
#include <QToolButton>
|
||||
#include <QStyle>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMainWindow>
|
||||
#include <QMap>
|
||||
#include <QSize>
|
||||
#include <QLabel>
|
||||
|
||||
class CustomDockWidgetBase :
|
||||
public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CustomDockWidgetBase(QString title, QMainWindow* parent = nullptr);
|
||||
explicit CustomDockWidgetBase(QMainWindow* parent = nullptr);
|
||||
void setTile(QString title);
|
||||
void hideMaxButton();
|
||||
|
||||
public slots:
|
||||
virtual void toggleMaximize();
|
||||
|
||||
signals:
|
||||
void maximizeStateChanged(bool isMaximized);
|
||||
|
||||
protected:
|
||||
QMainWindow* m_mainWindow = nullptr;
|
||||
QToolButton* m_maxButton = nullptr;
|
||||
bool m_isMaximized = false;
|
||||
|
||||
QList<QDockWidget*> m_hiddenDocks;
|
||||
QByteArray m_savedState;
|
||||
QMap<QDockWidget*, QSize> m_originalSizes;
|
||||
|
||||
QLabel* title_label;
|
||||
void initialize();
|
||||
};
|
||||
|
||||
class CustomDockWidgetHideAbove :
|
||||
public CustomDockWidgetBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CustomDockWidgetHideAbove(QString title, QMainWindow* parent = nullptr);
|
||||
explicit CustomDockWidgetHideAbove(QMainWindow* parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void toggleMaximize();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
@ -6,12 +6,12 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>332</height>
|
||||
<width>632</width>
|
||||
<height>444</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
<string>调焦</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="HPPA.qrc">
|
||||
@ -41,13 +41,10 @@
|
||||
<widget class="QComboBox" name="motorPort_comboBox"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<widget class="QRadioButton" name="ultrasound_radioButton">
|
||||
<property name="text">
|
||||
<string>超声</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
@ -57,14 +54,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QRadioButton" name="ultrasound_radioButton">
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QRadioButton" name="is_new_version_radioButton">
|
||||
<property name="text">
|
||||
<string>超声</string>
|
||||
<string>新版</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="connectMotor_btn">
|
||||
<property name="text">
|
||||
<string>连接线性平台</string>
|
||||
@ -81,20 +78,49 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>采样率</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="sample_ratio_lineEdit">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>20</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QProgressBar" name="autoFocusProgress_progressBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="autoFocus_btn">
|
||||
<property name="text">
|
||||
<string>自动调焦</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -107,7 +133,7 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="manualFocus_btn">
|
||||
<property name="text">
|
||||
<string>手动调焦</string>
|
||||
@ -132,16 +158,16 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>更新</string>
|
||||
<string>更新实时位置</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="currentLocation_lineEdit">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>46</height>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
@ -150,75 +176,101 @@
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="moveto_btn">
|
||||
<property name="text">
|
||||
<string>移动至</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="1" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="move2_lineEdit">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>10</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="add_btn">
|
||||
<property name="text">
|
||||
<string>+</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="addStepSize_lineEdit">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>46</height>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>50</string>
|
||||
<string>10</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="logicZero_btn">
|
||||
<property name="text">
|
||||
<string>LogicZero</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QPushButton" name="subtract_btn">
|
||||
<property name="text">
|
||||
<string>-</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="subtractStepSize_lineEdit">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>46</height>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>50</string>
|
||||
<string>10</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<item row="4" column="0">
|
||||
<widget class="QPushButton" name="logicZero_btn">
|
||||
<property name="text">
|
||||
<string>LogicZero</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="max_btn">
|
||||
<property name="text">
|
||||
<string>max</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QPushButton" name="rangeMeasurement_btn">
|
||||
<property name="text">
|
||||
<string>量程测量</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
3027
HPPA/HPPA.cpp
3027
HPPA/HPPA.cpp
File diff suppressed because it is too large
Load Diff
276
HPPA/HPPA.h
276
HPPA/HPPA.h
@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
@ -12,11 +12,14 @@
|
||||
#include <QLineSeries>
|
||||
#include <QChart>
|
||||
#include <QChartView>
|
||||
#include <QValueAxis>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QVector>
|
||||
#include <QItemSelection>
|
||||
|
||||
#include "ui_HPPA.h"
|
||||
#include "resononImager.h"
|
||||
@ -32,16 +35,41 @@
|
||||
#include "aboutWindow.h"
|
||||
#include "adjustTable.h"
|
||||
#include "PowerControl.h"
|
||||
#include "PathPlan.h"
|
||||
#include "RobotArmControl.h"
|
||||
#include "OneMotorControl.h"
|
||||
#include "TwoMotorControl.h"
|
||||
#include "imageControl.h"
|
||||
|
||||
#include "hppaConfigFile.h"
|
||||
#include "path_tc.h"
|
||||
|
||||
#include "ResononNirImager.h"
|
||||
#include "Corning410Imager.h"
|
||||
|
||||
#include "CustomDockWidgetBase.h"
|
||||
#include "Carousel.h"
|
||||
|
||||
#include "View3D.h"
|
||||
#include "TabManager.h"
|
||||
|
||||
#include "View3DModelManager.h"
|
||||
|
||||
#include "LayerTreeModel.h"
|
||||
#include "LayerTree.h"
|
||||
#include "MapLayer.h"
|
||||
#include "MapLayerStore.h"
|
||||
|
||||
#include "LayerTreeView.h"
|
||||
#include "LayerTreeViewMenuProvider.h"
|
||||
|
||||
#include "MapTool.h"
|
||||
#include "MapToolPan.h"
|
||||
#include "MapToolSpectral.h"
|
||||
#include "MapTools.h"
|
||||
|
||||
#define PI 3.1415926
|
||||
|
||||
QT_CHARTS_USE_NAMESPACE//QChartView ʹ<EFBFBD><EFBFBD> <20><>Ҫ<EFBFBD>Ӻ꣬ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
|
||||
QT_CHARTS_USE_NAMESPACE//QChartView 使用 需要加宏, 否则无法使用
|
||||
|
||||
class WorkerThread : public QThread
|
||||
{
|
||||
@ -68,11 +96,11 @@ public:
|
||||
// //double x = m_Imager->m_ResononImager.get_framerate();
|
||||
// int x = m_Imager->m_ResononImager.get_band_count();
|
||||
|
||||
// std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>slopeΪ<EFBFBD><EFBFBD>" << x << std::endl;
|
||||
// std::cout << "相机连接正常!slope为:" << x << std::endl;
|
||||
// }
|
||||
// catch (std::runtime_error *e)//CException *e
|
||||
// {
|
||||
// std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>" << e->what() << std::endl;
|
||||
// std::cout << "相机断开连接!" << e->what() << std::endl;
|
||||
// }
|
||||
// Sleep(1000);
|
||||
// }
|
||||
@ -120,34 +148,29 @@ signals:
|
||||
void threadSignal(QString s);
|
||||
};
|
||||
|
||||
|
||||
class ForLoopControl :public QObject
|
||||
class WidgetWithBackgroundPicture : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ForLoopControl();
|
||||
~ForLoopControl();
|
||||
|
||||
void setLoopCount(int loopCount);
|
||||
int getLoopCount() const;
|
||||
|
||||
bool m_boolRecordNextLine;
|
||||
bool m_boolQuitLoop;
|
||||
explicit WidgetWithBackgroundPicture(QWidget* parent = nullptr)
|
||||
: QWidget(parent),
|
||||
m_pixmap(".//icon//titile_bar_bgp.png") // 使用资源或绝对路径
|
||||
{
|
||||
// 可选:设置初始大小
|
||||
resize(800, 600);
|
||||
}
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override
|
||||
{
|
||||
QPainter painter(this);
|
||||
QPixmap scaled = m_pixmap.scaled(size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
||||
painter.drawPixmap(rect(), scaled);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_loopCount;
|
||||
|
||||
|
||||
public slots:
|
||||
void startLoop();
|
||||
|
||||
signals:
|
||||
//<2F><><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD>źţ<C5BA>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>źŷ<C5BA><C5B7><EFBFBD><EFBFBD><EFBFBD>ֵʱ<D6B5><CAB1>intֵ<74><D6B5><EFBFBD><EFBFBD><EFBFBD>òɼ<C3B2><C9BC>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD>ˣ<EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>źŷ<C5BA><C5B7>为ֵʱ<D6B5><CAB1>-1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ֹ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>-2<><32><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ֹ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
void recordSignal(int);
|
||||
QPixmap m_pixmap;
|
||||
};
|
||||
|
||||
class HPPA : public QMainWindow
|
||||
@ -158,17 +181,24 @@ public:
|
||||
HPPA(QWidget *parent = Q_NULLPTR);
|
||||
~HPPA();
|
||||
|
||||
void CalculateIntegratioinTimeRange();//ͨ<><CDA8>֡<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䷶Χ<E4B7B6><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>slider<65><72><EFBFBD><EFBFBD>ֵ
|
||||
static HPPA* instance();
|
||||
LayerTreeNode* rasterGroupNode() const;
|
||||
|
||||
WorkerThread * m_TestImagerStausThread;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD>߳<EFBFBD>
|
||||
void CalculateIntegratioinTimeRange();//通过帧率计算积分时间范围,设置slider最大值
|
||||
|
||||
WorkerThread * m_TestImagerStausThread;//检测相机连接状态的线程
|
||||
|
||||
private:
|
||||
static HPPA* s_instance;
|
||||
Ui::HPPAClass ui;
|
||||
QTabWidget* m_imageViewerTabWidget;
|
||||
|
||||
QMenu* mPanelMenu = nullptr;
|
||||
QMenu* mToolbarMenu = nullptr;
|
||||
|
||||
void initMenubarToolbar();
|
||||
void initPanelToolbar();
|
||||
void initControlTabwidget();
|
||||
|
||||
QLineEdit * frame_number;
|
||||
QLineEdit * m_FilenameLineEdit;
|
||||
@ -177,60 +207,33 @@ private:
|
||||
|
||||
Configfile mConfigfile;
|
||||
|
||||
ForLoopControl * m_ForLoopControl;
|
||||
ImagerOperationBase* m_Imager;//
|
||||
|
||||
int m_RecordState;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD>ȡ2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1 <20><> <20><><EFBFBD>ڲɼ<DAB2><C9BC><EFBFBD>0 <20><> ֹͣ<CDA3>ɼ<EFBFBD>
|
||||
int m_RecordState;//用来控制相机采集流程,取2的余数,1 → 正在采集,0 → 停止采集
|
||||
|
||||
QThread * m_ForLoopControlThread;//
|
||||
QThread * m_RecordThread;//Ӱ<EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
QThread * m_RgbCameraThread;//rgb<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡͼ<EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
QThread * m_CopyFileThread;//Ӱ<><D3B0><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
QThread * m_RecordThread;//影像采集线程
|
||||
QThread * m_RgbCameraThread;//rgb相机获取图像线程
|
||||
QThread * m_CopyFileThread;//影像文件复制线程
|
||||
FileOperation * m_FileOperation;
|
||||
|
||||
QChartView * m_chartView;
|
||||
QChart* m_chart;
|
||||
|
||||
//QLineSeries *series;
|
||||
//QChart *chart;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
VinceControl *m_yMotor;
|
||||
VinceControl *m_xMotor;
|
||||
|
||||
long m_lXmotorLocationOfStartRecord;//<2F><>ʼ<EFBFBD>ɼ<EFBFBD>ǰx<C7B0><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
long m_lYmotorLocationOfStartRecord;//<2F><>ʼ<EFBFBD>ɼ<EFBFBD>ǰy<C7B0><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
|
||||
unsigned long m_lManualSpeedOfXMotor;//X<><58><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD><CBB6>ٶȣ<D9B6>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+X<><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶȣ<D9B6>12000*0.00052734375=6.328125cm/s
|
||||
unsigned long m_lManualSpeedOfYMotor;//Y<><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD>X<EFBFBD><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ͬ<EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>װ<EFBFBD>ã<EFBFBD>ʵ<EFBFBD><CAB5>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>=X<><58><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>/5
|
||||
|
||||
int m_xConnectCount;//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>0<EFBFBD><30><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD>1<EFBFBD><31><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>״̬Ϊ1ʱ<31><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>
|
||||
int m_yConnectCount;
|
||||
|
||||
QTimer *m_timerMoveXmotor;
|
||||
QTimer *m_timerMoveYmotor;
|
||||
|
||||
QTimer *m_timerTestRangeOfxMotor;//<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>x<EFBFBD><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
QTimer *m_timerTestRangeOfyMotor;//<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
QTimer *m_timerLocationFeedBackOfMotor_x_y;//<2F><><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ƣ<EFBFBD>x/y<><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>Զ<EFBFBD><D4B6>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>slider<65><72>
|
||||
QTimer *m_timerYmotorLocationFeedBackAfterRecord;//<2F>ɼ<EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD>ɺ<C9BA><F3A3ACBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ʵʱ<CAB5><CAB1><EFBFBD>ص<EFBFBD>slider<65><72>
|
||||
|
||||
QString operateWidget;//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ŀؼ<C4BF><D8BC><EFBFBD>
|
||||
QString operateWidget;//当前操作的控件名
|
||||
|
||||
bool isMotorConnected(VinceControl *motor);//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD>true<75><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>false
|
||||
void SetXMotorWidgetEnable(bool enable);
|
||||
void SetYMotorWidgetEnable(bool enable);
|
||||
void setMotorRange();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̷<EFBFBD>Χ
|
||||
|
||||
//ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
double widthScale;//QGraphicsView<65><77>viewport<72><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>widthScale = rect.width() / maxDistance;
|
||||
double heightScale;//QGraphicsView<65><77>viewport<72>ߺ<EFBFBD><DFBA><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>heightScale = rect.height() / maxDistance;
|
||||
//模拟相机位置
|
||||
double widthScale;//QGraphicsView的viewport宽和真实距离比例:widthScale = rect.width() / maxDistance;
|
||||
double heightScale;//QGraphicsView的viewport高和真实距离比例:heightScale = rect.height() / maxDistance;
|
||||
void setImagerSimulationPos(double x, double y);//ui.graphicsView->imager->setPos(x, y);
|
||||
|
||||
//<EFBFBD>ɼ<EFBFBD><EFBFBD>߹滮
|
||||
int m_numberOfRecording;//<EFBFBD><EFBFBD>ʾui.recordLine_tableWidget<EFBFBD>еĵڼ<EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD>ڲɼ<DAB2><C9BC>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD>
|
||||
//采集线规划
|
||||
int m_numberOfRecording;//表示ui.recordLine_tableWidget中的第几行 → 正在采集第几条线
|
||||
|
||||
//
|
||||
int m_TabWidgetCurrentIndex;//<EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>ѡ<EFBFBD><EFBFBD>TabWidget<EFBFBD>ı<EFBFBD>ǩʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>仯<EFBFBD><EFBFBD><EFBFBD><EFBFBD>tab index
|
||||
int m_TabWidgetCurrentIndex;//当手动选择TabWidget的标签时,记录变化后的tab index
|
||||
RgbCameraOperation *m_RgbCamera;
|
||||
|
||||
void getRequest(QString str);
|
||||
@ -239,19 +242,60 @@ private:
|
||||
void createActionGroups();
|
||||
void selectingImager(QAction* selectedAction);
|
||||
|
||||
PathPlan* m_pathPlan;
|
||||
QActionGroup* moveplatformActionGroup = nullptr;
|
||||
void createMoveplatformActionGroup();
|
||||
void selectingMoveplatform(QAction* selectedAction);
|
||||
|
||||
QActionGroup* m_ScenarioActionGroup = nullptr;
|
||||
void createScenarioActionGroup();
|
||||
void selectScenario(QAction* selectedAction);
|
||||
|
||||
|
||||
|
||||
FILE* m_hTimesFile;
|
||||
|
||||
CustomDockWidgetBase* m_dock_carousel;
|
||||
|
||||
MyCarousel* m_carousel;
|
||||
QLabel* m_cam_label;
|
||||
QPushButton* m_open_rgb_camera_btn;
|
||||
QPushButton* m_close_rgb_camera_btn;
|
||||
|
||||
TabManager* m_tabManager;
|
||||
|
||||
ImageControl* m_ic;
|
||||
adjustTable* m_adt;
|
||||
PowerControl* m_pc;
|
||||
RobotArmControl* m_rac;
|
||||
OneMotorControl* m_omc;
|
||||
TwoMotorControl* m_tmc;
|
||||
|
||||
View3DModelManager* m_view3DModelManager;
|
||||
|
||||
LayerTreeView* m_layerTreeView;
|
||||
LayerTree* m_LayerTree = nullptr;
|
||||
LayerTreeModel* m_LayerTreeModel = nullptr;
|
||||
LayerTreeNode* m_RasterGroup = nullptr; // 指向 "Raster" 分组,便于后续添加 layer
|
||||
|
||||
MapLayerStore* m_MapLayerStore = nullptr;
|
||||
|
||||
// Map tools
|
||||
MapTools* m_mapTools = nullptr;
|
||||
QActionGroup* m_mapToolActionGroup = nullptr;
|
||||
void initMapTools();
|
||||
void setMapTool();
|
||||
|
||||
public Q_SLOTS:
|
||||
void onPlotHyperspectralImageRgbImage();
|
||||
void onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QString filePath);
|
||||
void PlotSpectral(int state);
|
||||
void onRecordFinishedSignal_WhenFrameNumberMeet();
|
||||
void onRecordFinishedSignal_WhenFrameNumberNotMeet();
|
||||
void onsequenceComplete();
|
||||
|
||||
void onExit();
|
||||
void onconnect();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void testImagerStatus();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
void onOpenImg();
|
||||
void onconnect();//连接相机
|
||||
void testImagerStatus();//获取相机状态:连接是否正常
|
||||
void onAutoExposure();
|
||||
void onFocus1();
|
||||
void onFocus2(int command);
|
||||
@ -261,88 +305,58 @@ public Q_SLOTS:
|
||||
void onReference();
|
||||
void recordWhiteFinish();
|
||||
void onStartRecordStep1();
|
||||
void onStartRecordStep2(int lineNumber);
|
||||
void onCreateTab(int trackNumber);
|
||||
QWidget* onCreateTab(QString tabName);
|
||||
void onTabWidgetCurrentChanged(int index);
|
||||
void onActionOpenDirectory();
|
||||
|
||||
void OnFramerateLineeditEditingFinished();//
|
||||
void OnFramerateSliderChanged(double framerate);//
|
||||
void OnFramerateSliderChanged(double framerate);//
|
||||
|
||||
void OnIntegratioinTimeEditingFinished();//
|
||||
void OnIntegratioinTimeSliderChanged(double IntegratioinTime);//
|
||||
void OnGainEditingFinished();//
|
||||
void OnGainSliderChanged(double Gain);//
|
||||
void OnIntegratioinTimeEditingFinished();//
|
||||
void OnIntegratioinTimeSliderChanged(double IntegratioinTime);//
|
||||
void OnGainEditingFinished();//
|
||||
void OnGainSliderChanged(double Gain);//
|
||||
|
||||
void onLeftMouseButtonPressed(int x, int y);//<2F><><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||
void onLeftMouseButtonPressed(int x, int y, QVector<double> wavelengths, QVector<double> spectrum);//点击影像像元显示光谱
|
||||
void setAxis(QValueAxis* axisX, QValueAxis* axisY);
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
void deleteMotor();
|
||||
void newMotor();
|
||||
void timerEvent(QTimerEvent *event);
|
||||
void setMotorParamMicroscope(VinceControl* motor);
|
||||
void setXMotorParamFromCfgFile(VinceControl* motor);
|
||||
void setYMotorParamFromCfgFile(VinceControl* motor);
|
||||
void timerEvent(QTimerEvent *event);
|
||||
//
|
||||
void onimagerSimulatorMove(int x, int y);
|
||||
void OnSendLogToCallClass(QString str);
|
||||
|
||||
void onPlotRgbImage();
|
||||
void onCloseRgbCamera();
|
||||
void onClearLabel();
|
||||
|
||||
void onxMotorLeft();
|
||||
void onxMotorRight();
|
||||
void onxMotorStop();
|
||||
void onCopyFinished();
|
||||
|
||||
void onyMotorForward();
|
||||
void onyMotorBackward();
|
||||
void onyMotorStop();
|
||||
void requestFinished(QNetworkReply* reply);
|
||||
|
||||
void onMotorReset();
|
||||
void recordFromRobotArm(int fileCounter);
|
||||
|
||||
void OnXmotorSpeedEditingFinished();
|
||||
void createOneMotorScenario();
|
||||
void createPlantPhenotypeScenario();
|
||||
void onCreated3DModelPlantPhenotype();
|
||||
void onCreated3DModelOneMotor();
|
||||
|
||||
void ontimerLocationFeedBackOfMotor_x_y();
|
||||
void ontimerYmotorLocationFeedBackAfterRecord();
|
||||
void onImageFileSaved(QString path, int fileIndex);
|
||||
|
||||
void OnXmotorSpeedLineeditEditingFinished();
|
||||
void OnXmotorSpeedSliderChanged(double speed);
|
||||
void OnXmotorLocationLineeditEditingFinished();
|
||||
void OnXmotorLocationSliderChanged(double location);
|
||||
void OnXmotorLocationSliderReleased();
|
||||
void onLayerCreatedFromFile(const QString& baseName, const QString& filePath, int fileIndex);
|
||||
void removeLayerByTreeIndex();
|
||||
void removeAllLayersInRasterGroup();
|
||||
|
||||
void onLayerTreeSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
|
||||
void onBandSelectionChanged(double rWave, double gWave, double bWave);
|
||||
|
||||
void OnYmotorLocationLineeditEditingFinished();
|
||||
void OnYmotorLocationSliderChanged(double location);
|
||||
void OnYmotorLocationSliderReleased();
|
||||
|
||||
|
||||
|
||||
void ontestRangeOfMotor_x_y();
|
||||
void ontimerTestRangeOfxMotor();
|
||||
void ontimerTestRangeOfyMotor();
|
||||
|
||||
void ontimerMoveXmotor();
|
||||
void ontimerMoveYmotor();
|
||||
|
||||
void onMotorSwitch();
|
||||
|
||||
//
|
||||
void onimagerSimulatorMove(int x, int y);
|
||||
void OnSendLogToCallClass(QString str);
|
||||
|
||||
void onPlotRgbImage();
|
||||
void onCloseRgbCamera();
|
||||
void onClearLabel();
|
||||
|
||||
void onCopyFinished();
|
||||
|
||||
void requestFinished(QNetworkReply* reply);
|
||||
|
||||
void onMapToolPanTriggered();
|
||||
void onMapToolSpectralTriggered();
|
||||
signals:
|
||||
void StartFocusSignal();
|
||||
void StartLoopSignal();
|
||||
void StartRecordSignal();
|
||||
void CopyFileThreadSignal(QString, QString);
|
||||
void BroadcastXMotorPosSignal(long long, int);
|
||||
|
||||
void RecordWhiteSignal();
|
||||
void RecordDarlSignal();
|
||||
};
|
||||
|
||||
|
||||
1981
HPPA/HPPA.ui
1981
HPPA/HPPA.ui
File diff suppressed because it is too large
Load Diff
@ -14,16 +14,16 @@
|
||||
<ProjectGuid>{E7886664-B69E-4781-BCBE-804574FB4033}</ProjectGuid>
|
||||
<Keyword>QtVS_v304</Keyword>
|
||||
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
|
||||
<WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
@ -31,8 +31,8 @@
|
||||
<Import Project="$(QtMsBuild)\qt_defaults.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
|
||||
<QtInstall>5.9_msvc2017_64</QtInstall>
|
||||
<QtModules>core;network;gui;widgets;serialport;websockets;charts</QtModules>
|
||||
<QtInstall>5.13.2_msvc2017_64</QtInstall>
|
||||
<QtModules>core;network;gui;widgets;serialport;websockets;3dcore;3danimation;3dextras;3dinput;3dlogic;3drender;3dquick;charts</QtModules>
|
||||
<QtBuildConfig>debug</QtBuildConfig>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
|
||||
@ -55,16 +55,16 @@
|
||||
</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;$(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;$(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;$(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;$(LibraryPath)</LibraryPath>
|
||||
</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;$(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;$(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;$(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;$(LibraryPath)</LibraryPath>
|
||||
</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;%(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;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>D:\cpp_project_vs2022\HPPA\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<ClCompile>
|
||||
@ -73,7 +73,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;%(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;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>D:\cpp_project_vs2022\HPPA\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
@ -86,7 +86,7 @@
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
@ -106,21 +106,49 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="aboutWindow.cpp" />
|
||||
<ClCompile Include="adjustTable.cpp" />
|
||||
<ClCompile Include="CaptureCoordinator.cpp" />
|
||||
<ClCompile Include="Carousel.cpp" />
|
||||
<ClCompile Include="Corning410Imager.cpp" />
|
||||
<ClCompile Include="CustomDockWidgetBase.cpp" />
|
||||
<ClCompile Include="hppaConfigFile.cpp" />
|
||||
<ClCompile Include="imageControl.cpp" />
|
||||
<ClCompile Include="ImagerOperationBase.cpp" />
|
||||
<ClCompile Include="PathPlan.cpp" />
|
||||
<ClCompile Include="imager_base.cpp" />
|
||||
<ClCompile Include="irisximeaimager.cpp" />
|
||||
<ClCompile Include="LayerTree.cpp" />
|
||||
<ClCompile Include="LayerTreeGroupNode.cpp" />
|
||||
<ClCompile Include="LayerTreeLayerNode.cpp" />
|
||||
<ClCompile Include="LayerTreeModel.cpp" />
|
||||
<ClCompile Include="LayerTreeNode.cpp" />
|
||||
<ClCompile Include="LayerTreeView.cpp" />
|
||||
<ClCompile Include="LayerTreeViewMenuProvider.cpp" />
|
||||
<ClCompile Include="MapLayer.cpp" />
|
||||
<ClCompile Include="MapLayerStore.cpp" />
|
||||
<ClCompile Include="MapTool.cpp" />
|
||||
<ClCompile Include="MapToolPan.cpp" />
|
||||
<ClCompile Include="MapTools.cpp" />
|
||||
<ClCompile Include="MapToolSpectral.cpp" />
|
||||
<ClCompile Include="OneMotorControl.cpp" />
|
||||
<ClCompile Include="path_tc.cpp" />
|
||||
<ClCompile Include="PowerControl.cpp" />
|
||||
<ClCompile Include="QDoubleSlider.cpp" />
|
||||
<ClCompile Include="QMotorDoubleSlider.cpp" />
|
||||
<ClCompile Include="RasterDataProvider.cpp" />
|
||||
<ClCompile Include="RasterLayer.cpp" />
|
||||
<ClCompile Include="RasterRenderer.cpp" />
|
||||
<ClCompile Include="resononImager.cpp" />
|
||||
<ClCompile Include="ResononNirImager.cpp" />
|
||||
<ClCompile Include="RgbCameraOperation.cpp" />
|
||||
<ClCompile Include="RobotArmControl.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TabManager.cpp" />
|
||||
<ClCompile Include="TwoMotorControl.cpp" />
|
||||
<ClCompile Include="utility_tc.cpp" />
|
||||
<ClCompile Include="View3D.cpp" />
|
||||
<ClCompile Include="View3DModelManager.cpp" />
|
||||
<QtRcc Include="HPPA.qrc" />
|
||||
<QtUic Include="about.ui" />
|
||||
<QtUic Include="adjustTable.ui" />
|
||||
@ -137,8 +165,14 @@
|
||||
<ClCompile Include="imagerSimulatioin.cpp" />
|
||||
<ClCompile Include="ImageViewer.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<QtUic Include="imgControl.ui" />
|
||||
<QtUic Include="oneMotorControl.ui" />
|
||||
<QtUic Include="PathPlan.ui" />
|
||||
<QtUic Include="PowerControl.ui" />
|
||||
<QtUic Include="RadianceConversion.ui" />
|
||||
<QtUic Include="ReflectanceConversion.ui" />
|
||||
<QtUic Include="RobotArmControl.ui" />
|
||||
<QtUic Include="twoMotorControl.ui" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="fileOperation.h" />
|
||||
@ -150,9 +184,37 @@
|
||||
<QtMoc Include="image2display.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="View3DModelManager.h" />
|
||||
<QtMoc Include="View3D.h" />
|
||||
<QtMoc Include="adjustTable.h" />
|
||||
<QtMoc Include="PowerControl.h" />
|
||||
<QtMoc Include="PathPlan.h" />
|
||||
<QtMoc Include="RobotArmControl.h" />
|
||||
<QtMoc Include="Corning410Imager.h" />
|
||||
<QtMoc Include="CaptureCoordinator.h" />
|
||||
<QtMoc Include="CustomDockWidgetBase.h" />
|
||||
<QtMoc Include="Carousel.h" />
|
||||
<QtMoc Include="imageControl.h" />
|
||||
<ClInclude Include="imager_base.h" />
|
||||
<ClInclude Include="irisximeaimager.h" />
|
||||
<QtMoc Include="OneMotorControl.h" />
|
||||
<QtMoc Include="TwoMotorControl.h" />
|
||||
<QtMoc Include="TabManager.h" />
|
||||
<QtMoc Include="LayerTreeModel.h" />
|
||||
<QtMoc Include="LayerTreeNode.h" />
|
||||
<QtMoc Include="LayerTree.h" />
|
||||
<QtMoc Include="LayerTreeGroupNode.h" />
|
||||
<QtMoc Include="LayerTreeLayerNode.h" />
|
||||
<QtMoc Include="MapLayer.h" />
|
||||
<QtMoc Include="RasterLayer.h" />
|
||||
<QtMoc Include="MapLayerStore.h" />
|
||||
<ClInclude Include="LayerTreeView.h" />
|
||||
<QtMoc Include="LayerTreeViewMenuProvider.h" />
|
||||
<QtMoc Include="MapTool.h" />
|
||||
<QtMoc Include="MapToolPan.h" />
|
||||
<QtMoc Include="MapToolSpectral.h" />
|
||||
<QtMoc Include="MapTools.h" />
|
||||
<ClInclude Include="RasterDataProvider.h" />
|
||||
<ClInclude Include="RasterRenderer.h" />
|
||||
<ClInclude Include="utility_tc.h" />
|
||||
<QtMoc Include="aboutWindow.h" />
|
||||
<ClInclude Include="hppaConfigFile.h" />
|
||||
|
||||
@ -103,7 +103,91 @@
|
||||
<ClCompile Include="PowerControl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="PathPlan.cpp">
|
||||
<ClCompile Include="RobotArmControl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Corning410Imager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="imager_base.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="irisximeaimager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="OneMotorControl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CaptureCoordinator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TwoMotorControl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CustomDockWidgetBase.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Carousel.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="View3D.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TabManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="View3DModelManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LayerTreeNode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LayerTreeModel.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LayerTree.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LayerTreeGroupNode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LayerTreeLayerNode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MapLayer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="RasterLayer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="RasterDataProvider.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="RasterRenderer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MapLayerStore.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LayerTreeView.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LayerTreeViewMenuProvider.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="imageControl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MapTool.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MapToolPan.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MapToolSpectral.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MapTools.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@ -150,7 +234,76 @@
|
||||
<QtMoc Include="PowerControl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="PathPlan.h">
|
||||
<QtMoc Include="RobotArmControl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="Corning410Imager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="OneMotorControl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="TwoMotorControl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="CaptureCoordinator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="CustomDockWidgetBase.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="Carousel.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="View3D.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="TabManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="View3DModelManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="LayerTreeModel.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="LayerTreeNode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="LayerTree.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="LayerTreeGroupNode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="LayerTreeLayerNode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="MapLayer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="RasterLayer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="MapLayerStore.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="LayerTreeViewMenuProvider.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="imageControl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="MapToolSpectral.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="MapToolPan.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="MapTool.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="MapTools.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
@ -179,6 +332,21 @@
|
||||
<ClInclude Include="utility_tc.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="imager_base.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="irisximeaimager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="RasterDataProvider.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="RasterRenderer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LayerTreeView.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtUic Include="FocusDialog.ui">
|
||||
@ -196,6 +364,24 @@
|
||||
<QtUic Include="PathPlan.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="RobotArmControl.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="oneMotorControl.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="RadianceConversion.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="ReflectanceConversion.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="twoMotorControl.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="imgControl.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
|
||||
@ -1,228 +1,294 @@
|
||||
#include "stdafx.h"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
#include <QWheelEvent>
|
||||
#include <QPoint>
|
||||
|
||||
#include "ImageViewer.h"
|
||||
#include "RasterLayer.h"
|
||||
#include "MapTool.h"
|
||||
|
||||
|
||||
#define VIEW_CENTER viewport()->rect().center()
|
||||
#define VIEW_WIDTH viewport()->rect().width()
|
||||
#define VIEW_HEIGHT viewport()->rect().height()
|
||||
|
||||
|
||||
ImageViewer::ImageViewer(QWidget* pParent) :QGraphicsView(pParent)
|
||||
Mapcavas::Mapcavas(QWidget* pParent) :QGraphicsView(pParent)
|
||||
{
|
||||
m_qtGraphicsScene = new QGraphicsScene(this);
|
||||
this->setScene(m_qtGraphicsScene);
|
||||
setRenderHint(QPainter::Antialiasing);
|
||||
setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
|
||||
m_framNumberLabel = new QLabel(this);
|
||||
m_framNumberLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_framNumberLabel->setAlignment(Qt::AlignVCenter);
|
||||
// ʹ<><CAB9> Qt Ĭ<><C4AC> anchor <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
setTransformationAnchor(QGraphicsView::NoAnchor);
|
||||
setResizeAnchor(QGraphicsView::NoAnchor);
|
||||
|
||||
QFont ft;
|
||||
ft.setPointSize(14);
|
||||
m_framNumberLabel->setFont(ft);
|
||||
m_qtGraphicsScene = new QGraphicsScene(this);
|
||||
this->setScene(m_qtGraphicsScene);
|
||||
m_qtGraphicsScene->setSceneRect(-1e6, -1e6, 2e6, 2e6);
|
||||
|
||||
m_framNumberLabel = new QLabel(this);
|
||||
m_framNumberLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_framNumberLabel->setAlignment(Qt::AlignVCenter);
|
||||
|
||||
QFont ft;
|
||||
ft.setPointSize(14);
|
||||
m_framNumberLabel->setFont(ft);
|
||||
m_framNumberLabel->setText("0");
|
||||
|
||||
|
||||
m_GraphicsPixmapItemHandle = nullptr;
|
||||
m_GraphicsPixmapItemHandle = nullptr;
|
||||
|
||||
m_scale = 1.0;
|
||||
m_zoomDelta = 0.1;
|
||||
m_translateSpeed = 1.0;
|
||||
m_bMouseTranslate = false;
|
||||
m_scale = 1.0;
|
||||
m_zoomDelta = 0.1;
|
||||
m_translateSpeed = 1.0;
|
||||
m_bMouseTranslate = false;
|
||||
|
||||
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
}
|
||||
|
||||
ImageViewer::~ImageViewer()
|
||||
Mapcavas::~Mapcavas()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ImageViewer::DisplayFrameNumber(int frameNumber)
|
||||
void Mapcavas::DisplayFrameNumber(int frameNumber)
|
||||
{
|
||||
m_framNumberLabel->setText(QString::number(frameNumber));
|
||||
m_framNumberLabel->adjustSize();
|
||||
m_framNumberLabel->setText(QString::number(frameNumber));
|
||||
m_framNumberLabel->adjustSize();
|
||||
}
|
||||
|
||||
void ImageViewer::SetImage(QPixmap *image)
|
||||
void Mapcavas::SetImage(QPixmap *image)
|
||||
{
|
||||
if (!HasImage())
|
||||
{
|
||||
m_GraphicsPixmapItemHandle = m_qtGraphicsScene->addPixmap(*image);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_GraphicsPixmapItemHandle->setPixmap(*image);
|
||||
}
|
||||
|
||||
setSceneRect(QRectF(image->rect()));
|
||||
|
||||
if (!HasImage())
|
||||
{
|
||||
m_GraphicsPixmapItemHandle = m_qtGraphicsScene->addPixmap(*image);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_GraphicsPixmapItemHandle->setPixmap(*image);
|
||||
}
|
||||
ensureSceneVisible();
|
||||
}
|
||||
|
||||
bool ImageViewer::HasImage()
|
||||
void Mapcavas::ensureSceneVisible()
|
||||
{
|
||||
if (m_GraphicsPixmapItemHandle == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
resetTransform();
|
||||
|
||||
auto view_rect = viewport()->rect();
|
||||
auto scene_rect = this->scene()->itemsBoundingRect();
|
||||
|
||||
double x_ratio = view_rect.width() / scene_rect.width();
|
||||
double y_ratio = view_rect.height() / scene_rect.height();
|
||||
double scale_factor = std::min(x_ratio, y_ratio) * 0.9;
|
||||
|
||||
scale(scale_factor, scale_factor);
|
||||
m_scale *= scale_factor;
|
||||
|
||||
centerOn(scene_rect.center());
|
||||
}
|
||||
|
||||
void ImageViewer::wheelEvent(QWheelEvent *event)
|
||||
bool Mapcavas::HasImage()
|
||||
{
|
||||
//qDebug() << "---------------+++++++++++++++++++++++++++++++++++++++++++++++++++ ";
|
||||
if (true)//HasImage()
|
||||
{
|
||||
//Χ<><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>https://blog.csdn.net/GoForwardToStep/article/details/77035287?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>view<65><77>λ<EFBFBD><CEBB>;
|
||||
QPointF cursorPoint = event->pos();
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>scene<6E><65>λ<EFBFBD><CEBB>;
|
||||
QPointF scenePos = this->mapToScene(QPoint(cursorPoint.x(), cursorPoint.y()));
|
||||
|
||||
// <20><>ȡview<65>Ŀ<EFBFBD><C4BF><EFBFBD>;
|
||||
qreal viewWidth = this->viewport()->width();
|
||||
qreal viewHeight = this->viewport()->height();
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>൱<EFBFBD><E0B5B1>view<65><77>С<EFBFBD>ĺ<EFBFBD><C4BA>ݱ<EFBFBD><DDB1><EFBFBD>;
|
||||
qreal hScale = cursorPoint.x() / viewWidth;
|
||||
qreal vScale = cursorPoint.y() / viewHeight;
|
||||
|
||||
|
||||
// <20><><EFBFBD>ֵĹ<D6B5><C4B9><EFBFBD><EFBFBD><EFBFBD>
|
||||
QPoint scrollAmount = event->angleDelta();
|
||||
// <20><>ֵ<EFBFBD><D6B5>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ʹ<EFBFBD><CAB9><EFBFBD>߷Ŵ<DFB7><C5B4><EFBFBD>ֵ<EFBFBD><D6B5>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
||||
scrollAmount.y() > 0 ? zoomIn() : zoomOut();
|
||||
|
||||
|
||||
// <20><>scene<6E><65><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
QPointF viewPoint = this->matrix().map(scenePos);
|
||||
// ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>view<65>Ŵ<EFBFBD><C5B4><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>չʾscene<6E><65>λ<EFBFBD><CEBB>;
|
||||
horizontalScrollBar()->setValue(int(viewPoint.x() - viewWidth * hScale));
|
||||
verticalScrollBar()->setValue(int(viewPoint.y() - viewHeight * vScale));
|
||||
}
|
||||
|
||||
QGraphicsView::wheelEvent(event);
|
||||
if (m_GraphicsPixmapItemHandle == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageViewer::scaling(qreal scaleFactor)
|
||||
void Mapcavas::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
//qDebug() << this->sceneRect();
|
||||
scale(scaleFactor, scaleFactor);
|
||||
// Always let the tool have a chance first
|
||||
if (m_mapTool)
|
||||
{
|
||||
m_mapTool->canvasWheelEvent(event);
|
||||
}
|
||||
|
||||
if (HasImage())
|
||||
{
|
||||
QPointF oldPos = mapToScene(event->pos());
|
||||
|
||||
QPoint scrollAmount = event->angleDelta();
|
||||
scrollAmount.y() > 0 ? zoomIn() : zoomOut();
|
||||
|
||||
QPointF newPos = mapToScene(event->pos());
|
||||
|
||||
QPointF delta = newPos - oldPos;
|
||||
translate(delta.x(), delta.y());
|
||||
}
|
||||
}
|
||||
|
||||
void ImageViewer::mousePressEvent(QMouseEvent *event)
|
||||
void Mapcavas::scaling(qreal scaleFactor)
|
||||
{
|
||||
if (event->button()==Qt::LeftButton)
|
||||
{
|
||||
m_bMouseTranslate = true;
|
||||
m_lastMousePos = event->pos();
|
||||
|
||||
//qDebug() << mapToScene(m_lastMousePos);
|
||||
|
||||
emit leftMouseButtonPressed(mapToScene(m_lastMousePos).x(), mapToScene(m_lastMousePos).y());
|
||||
}
|
||||
|
||||
|
||||
//If you do not perform all the necessary work in your implementation of the virtual function, you may need to call the base class's implementation.
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
scale(scaleFactor, scaleFactor);
|
||||
}
|
||||
|
||||
void ImageViewer::mouseMoveEvent(QMouseEvent *event)
|
||||
void Mapcavas::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_bMouseTranslate){
|
||||
QPointF mouseDelta = mapToScene(event->pos()) - mapToScene(m_lastMousePos);
|
||||
translate(mouseDelta);
|
||||
}
|
||||
|
||||
m_lastMousePos = event->pos();
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
if (m_mapTool)
|
||||
{
|
||||
m_mapTool->canvasMousePressEvent(event);
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
return;
|
||||
}
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void ImageViewer::mouseReleaseEvent(QMouseEvent *event)
|
||||
void Mapcavas::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
m_bMouseTranslate = false;
|
||||
QGraphicsView::mouseReleaseEvent(event);
|
||||
if (m_mapTool)
|
||||
{
|
||||
m_mapTool->canvasMouseMoveEvent(event);
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void ImageViewer::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
void Mapcavas::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsView::mouseDoubleClickEvent(event);
|
||||
if (m_mapTool)
|
||||
{
|
||||
m_mapTool->canvasMouseReleaseEvent(event);
|
||||
QGraphicsView::mouseReleaseEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void ImageViewer::zoomIn()
|
||||
void Mapcavas::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
zoom(1 + m_zoomDelta);
|
||||
if (m_mapTool)
|
||||
{
|
||||
m_mapTool->canvasMouseDoubleClickEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsView::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
void ImageViewer::zoomOut()
|
||||
void Mapcavas::zoomIn()
|
||||
{
|
||||
zoom(1 - m_zoomDelta);
|
||||
zoom(1 + m_zoomDelta);
|
||||
}
|
||||
|
||||
void ImageViewer::zoom(float scaleFactor)
|
||||
void Mapcavas::zoomOut()
|
||||
{
|
||||
// <20><>ֹ<EFBFBD><D6B9>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
|
||||
if (factor < 0.07 || factor > 100)
|
||||
return;
|
||||
|
||||
scale(scaleFactor, scaleFactor);
|
||||
m_scale *= scaleFactor;
|
||||
zoom(1 - m_zoomDelta);
|
||||
}
|
||||
|
||||
void ImageViewer::translate(QPointF delta)
|
||||
void Mapcavas::zoom(float scaleFactor)
|
||||
{
|
||||
// <20><><EFBFBD>ݵ<EFBFBD>ǰ zoom <20><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
|
||||
delta *= m_scale;
|
||||
delta *= m_translateSpeed;
|
||||
qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
|
||||
if (factor < 0.07 || factor > 100)
|
||||
return;
|
||||
|
||||
////<2F><><EFBFBD><EFBFBD>1<EFBFBD><31>
|
||||
//scene()->setSceneRect(scene()->sceneRect().x() - delta.x(), scene()->sceneRect().y() - delta.y(),
|
||||
// scene()->sceneRect().width(), scene()->sceneRect().height());
|
||||
//scene()->update();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32>
|
||||
// view <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µĵ<C2B5><C4B5><EFBFBD>Ϊê<CEAA><C3AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ scene
|
||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
QPoint newCenter(VIEW_WIDTH / 2 - delta.x(), VIEW_HEIGHT / 2 - delta.y());
|
||||
centerOn(mapToScene(newCenter));
|
||||
|
||||
// scene <20><> view <20><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>Ϊê<CEAA><C3AA>
|
||||
setTransformationAnchor(QGraphicsView::AnchorViewCenter);
|
||||
scale(scaleFactor, scaleFactor);
|
||||
m_scale *= scaleFactor;
|
||||
}
|
||||
|
||||
void ImageViewer::setTranslateSpeed(qreal speed)
|
||||
void Mapcavas::setTranslateSpeed(qreal speed)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ٶȷ<D9B6>Χ
|
||||
Q_ASSERT_X(speed >= 0.0 && speed <= 2.0,
|
||||
"InteractiveView::setTranslateSpeed", "Speed should be in range [0.0, 2.0].");
|
||||
m_translateSpeed = speed;
|
||||
Q_ASSERT_X(speed >= 0.0 && speed <= 2.0,
|
||||
"InteractiveView::setTranslateSpeed", "Speed should be in range [0.0, 2.0].");
|
||||
m_translateSpeed = speed;
|
||||
}
|
||||
|
||||
qreal ImageViewer::translateSpeed() const
|
||||
qreal Mapcavas::translateSpeed() const
|
||||
{
|
||||
return m_translateSpeed;
|
||||
return m_translateSpeed;
|
||||
}
|
||||
|
||||
void ImageViewer::setZoomDelta(qreal delta)
|
||||
void Mapcavas::setZoomDelta(qreal delta)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ
|
||||
Q_ASSERT_X(delta >= 0.0 && delta <= 1.0,
|
||||
"InteractiveView::setZoomDelta", "Delta should be in range [0.0, 1.0].");
|
||||
m_zoomDelta = delta;
|
||||
Q_ASSERT_X(delta >= 0.0 && delta <= 1.0,
|
||||
"InteractiveView::setZoomDelta", "Delta should be in range [0.0, 1.0].");
|
||||
m_zoomDelta = delta;
|
||||
}
|
||||
|
||||
qreal ImageViewer::zoomDelta() const
|
||||
qreal Mapcavas::zoomDelta() const
|
||||
{
|
||||
return m_zoomDelta;
|
||||
return m_zoomDelta;
|
||||
}
|
||||
|
||||
// new: set associated raster layer
|
||||
void Mapcavas::setLayers(RasterLayer* layer)
|
||||
{
|
||||
m_rasterLayer = layer;
|
||||
}
|
||||
|
||||
RasterLayer* Mapcavas::rasterLayer() const
|
||||
{
|
||||
return m_rasterLayer;
|
||||
}
|
||||
|
||||
// new: refresh the map by rendering using the RasterLayer's render method
|
||||
void Mapcavas::freshmap()
|
||||
{
|
||||
if (!m_rasterLayer) 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);
|
||||
if (img.isNull()) return;
|
||||
|
||||
QPixmap pm = QPixmap::fromImage(img);
|
||||
SetImage(&pm);
|
||||
}
|
||||
|
||||
// MapTool management
|
||||
void Mapcavas::setMapTool(MapTool* tool)
|
||||
{
|
||||
if (m_mapTool)
|
||||
{
|
||||
m_mapTool->deactivate();
|
||||
}
|
||||
|
||||
m_mapTool = tool;
|
||||
|
||||
if (m_mapTool)
|
||||
{
|
||||
// Disable built-in drag mode so the tool controls everything
|
||||
setDragMode(QGraphicsView::NoDrag);
|
||||
m_mapTool->activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Restore legacy drag mode when no tool
|
||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
}
|
||||
}
|
||||
|
||||
void Mapcavas::unsetMapTool(MapTool* tool)
|
||||
{
|
||||
if (m_mapTool && m_mapTool == tool)
|
||||
{
|
||||
m_mapTool->deactivate();
|
||||
m_mapTool = nullptr;
|
||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
}
|
||||
}
|
||||
|
||||
MapTool* Mapcavas::mapTool() const
|
||||
{
|
||||
return m_mapTool;
|
||||
}
|
||||
|
||||
@ -1,15 +1,20 @@
|
||||
#ifndef IMAGE_VIEWER
|
||||
#define IMAGE_VIEWER
|
||||
#ifndef MAPCAVAS_H
|
||||
#define MAPCAVAS_H
|
||||
|
||||
#include "QGraphicsView"
|
||||
#include "qlabel.h"
|
||||
class ImageViewer :public QGraphicsView
|
||||
#include <QVector>
|
||||
#include "RasterLayer.h"
|
||||
|
||||
class MapTool;
|
||||
|
||||
class Mapcavas : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ImageViewer(QWidget* pParent = NULL);
|
||||
~ImageViewer();
|
||||
Mapcavas(QWidget* pParent = NULL);
|
||||
~Mapcavas();
|
||||
|
||||
|
||||
void DisplayFrameNumber(int frameNumber);
|
||||
@ -22,6 +27,7 @@ public:
|
||||
|
||||
void SetImage(QPixmap *image);
|
||||
bool HasImage();
|
||||
void ensureSceneVisible();
|
||||
|
||||
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
|
||||
void scaling(qreal scaleFactor);
|
||||
@ -29,7 +35,6 @@ public:
|
||||
void zoomIn(); // <20>Ŵ<EFBFBD>
|
||||
void zoomOut(); // <20><>С
|
||||
void zoom(float scaleFactor); // <20><><EFBFBD><EFBFBD> - scaleFactor<6F><72><EFBFBD>ŵı<C5B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void translate(QPointF delta); // ƽ<><C6BD>
|
||||
|
||||
// ƽ<><C6BD><EFBFBD>ٶ<EFBFBD>
|
||||
void setTranslateSpeed(qreal speed);
|
||||
@ -38,12 +43,27 @@ public:
|
||||
// <20><><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
void setZoomDelta(qreal delta);
|
||||
qreal zoomDelta() const;
|
||||
|
||||
// new: set raster layer and refresh map
|
||||
void setLayers(RasterLayer* layer);
|
||||
void freshmap();
|
||||
void freshmap(const RasterLayer::RenderParams& params);
|
||||
|
||||
RasterLayer* rasterLayer() const;
|
||||
|
||||
// MapTool management
|
||||
void setMapTool(MapTool* tool);
|
||||
void unsetMapTool(MapTool* tool);
|
||||
MapTool* mapTool() const;
|
||||
|
||||
protected:
|
||||
QGraphicsScene *m_qtGraphicsScene;
|
||||
private:
|
||||
QGraphicsPixmapItem *m_GraphicsPixmapItemHandle;
|
||||
QLabel *m_framNumberLabel;//<2F><>ʾʵʱ<CAB5>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>
|
||||
|
||||
|
||||
RasterLayer* m_rasterLayer = nullptr; // associated raster layer
|
||||
MapTool* m_mapTool = nullptr; // current active map tool
|
||||
|
||||
qreal m_translateSpeed; // ƽ<><C6BD><EFBFBD>ٶ<EFBFBD>
|
||||
qreal m_zoomDelta; // <20><><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -53,6 +73,6 @@ private:
|
||||
|
||||
|
||||
signals:
|
||||
void leftMouseButtonPressed(int, int);
|
||||
void leftMouseButtonPressed(int, int, QVector<double>, QVector<double>);
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -6,7 +6,7 @@ ImagerOperationBase::ImagerOperationBase()
|
||||
m_bRecordControlState = true;
|
||||
|
||||
m_FileName2Save = "tmp_image";
|
||||
m_FileSavedCounter = 1;
|
||||
m_FileSavedCounter = 0;
|
||||
|
||||
m_RgbImage = new CImage();
|
||||
|
||||
@ -54,9 +54,9 @@ double ImagerOperationBase::auto_exposure()
|
||||
while (true)
|
||||
{
|
||||
getFrame(buffer);
|
||||
if (GetMaxValue(buffer, m_FrameSize) >= 4095)
|
||||
if (GetMaxValue(buffer, m_FrameSize) >= 4094)
|
||||
{
|
||||
setIntegrationTime(getIntegrationTime() * 0.8);
|
||||
setIntegrationTime(getIntegrationTime() * 0.95);
|
||||
std::cout << "<EFBFBD>Զ<EFBFBD><EFBFBD>ع<EFBFBD>-----------" << std::endl;
|
||||
}
|
||||
else
|
||||
@ -74,6 +74,8 @@ double ImagerOperationBase::auto_exposure()
|
||||
|
||||
void ImagerOperationBase::focus()
|
||||
{
|
||||
m_iFocusFramesNumber = 0;
|
||||
|
||||
m_iFocusFrameCounter = 1;
|
||||
//std::cout << "<22><><EFBFBD><EFBFBD>-----------" << std::endl;
|
||||
|
||||
@ -85,16 +87,42 @@ void ImagerOperationBase::focus()
|
||||
auto_exposure();
|
||||
std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ع<EFBFBD>ʱ<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>" << getIntegrationTime() << std::endl;
|
||||
|
||||
int iWidth, iHeight;
|
||||
GetFrameSize(iWidth, iHeight);
|
||||
unsigned short* tmp = new unsigned short[m_FrameSize];
|
||||
|
||||
imagerStartCollect();
|
||||
|
||||
//emit SpectralSignal(1);
|
||||
m_bFocusControlState = true;
|
||||
while (m_bFocusControlState)
|
||||
{
|
||||
////<2F><>֡ƽ<D6A1><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
||||
//memset((void*)buffer, 0, m_FrameSize * sizeof(unsigned short));
|
||||
//int fn = 5;
|
||||
//for (int i = 0; i < fn; i++)
|
||||
//{
|
||||
// getFrame(tmp);
|
||||
|
||||
// for (int j = 0; j < m_FrameSize; j++)
|
||||
// {
|
||||
// buffer[j] += tmp[j];
|
||||
// }
|
||||
//}
|
||||
//for (int j = 0; j < m_FrameSize; j++)
|
||||
//{
|
||||
// buffer[j] += buffer[j] / fn;
|
||||
//}
|
||||
|
||||
getFrame(buffer);
|
||||
|
||||
//m_RgbImage->FillFocusGrayImage(buffer);
|
||||
m_RgbImage->FillFocusGrayQImage(buffer);
|
||||
|
||||
double focusIndex = calcFocusIndexSobelPrivate(buffer);
|
||||
emit FocusIndexSobelSignal(focusIndex);
|
||||
std::cout << "focusIndex<EFBFBD><EFBFBD>" << focusIndex << std::endl;
|
||||
|
||||
emit SpectralSignal(1);
|
||||
|
||||
++m_iFocusFrameCounter;
|
||||
@ -102,6 +130,7 @@ void ImagerOperationBase::focus()
|
||||
emit SpectralSignal(0);
|
||||
|
||||
imagerStopCollect();
|
||||
delete[] tmp;
|
||||
|
||||
setFramerate(tmpFrmerate);
|
||||
setIntegrationTime(tmpIntegrationTime);
|
||||
@ -189,9 +218,9 @@ void ImagerOperationBase::record_white()
|
||||
|
||||
void ImagerOperationBase::start_record()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace std;
|
||||
|
||||
//std::cout << "------------------------------------------------------" << std::endl;
|
||||
//std::cout << "------------------------------------------------------" << std::endl;
|
||||
|
||||
m_iFrameCounter = 0;
|
||||
m_RgbImage->m_iFrameCounter = 0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>rgbͼ<62><CDBC><EFBFBD>ĵ<EFBFBD>0<EFBFBD><30>
|
||||
@ -204,7 +233,13 @@ void ImagerOperationBase::start_record()
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// <20>ڿ<EFBFBD>ʼ<EFBFBD>ɼ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Ϣ<EFBFBD><CFA2>UI <20><><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD> MapLayer <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// prepare file name that will be used for saving
|
||||
m_FileName2Save2 = m_FileName2Save + "_" + std::to_string(m_FileSavedCounter) + ".bil";
|
||||
QString baseName = QString::fromStdString(getFileNameFromPath(m_FileName2Save2));
|
||||
QString filePath = QString::fromStdString(m_FileName2Save2);
|
||||
emit LayerFileCreated(baseName, filePath, m_FileSavedCounter);
|
||||
|
||||
FILE* m_fImage = fopen(m_FileName2Save2.c_str(), "w+b");
|
||||
|
||||
size_t x;
|
||||
@ -270,7 +305,7 @@ void ImagerOperationBase::start_record()
|
||||
//ÿ<><C3BF>1s<31><73><EFBFBD><EFBFBD>һ<EFBFBD>ν<EFBFBD><CEBD><EFBFBD>ͼ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>
|
||||
if (m_iFrameCounter % (int)getFramerate() == 0)
|
||||
{
|
||||
emit PlotSignal();
|
||||
emit PlotSignal(m_FileSavedCounter, m_iFrameCounter, filePath);
|
||||
}
|
||||
|
||||
if (m_iFrameCounter >= m_iFrameNumber)
|
||||
@ -281,13 +316,18 @@ void ImagerOperationBase::start_record()
|
||||
}
|
||||
imagerStopCollect();
|
||||
|
||||
m_bRecordControlState = false;
|
||||
WriteHdr();
|
||||
m_FileSavedCounter++;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>λ<EFBFBD>ͼǰ<CDBC><C7B0>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//m_RgbImage
|
||||
emit PlotSignal();//<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>λ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>Է<EFBFBD><D4B7>ɼ<EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>ʵı<CAB5><C4B1><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>ȫ
|
||||
emit PlotSignal(m_FileSavedCounter, -1, filePath);
|
||||
|
||||
m_bRecordControlState = false;
|
||||
WriteHdr();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> ImageFileSaved <20>źţ<C5BA>֪ͨ UI <20><><EFBFBD>Ѹ<EFBFBD><D1B8>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// m_FileName2Save2 <20><><EFBFBD><EFBFBD><EFBFBD>˱<EFBFBD><CBB1><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD> .bil <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "tmp_image_0.bil"<22><>
|
||||
emit ImageFileSaved(QString::fromStdString(m_FileName2Save2), m_FileSavedCounter);
|
||||
|
||||
m_FileSavedCounter++;
|
||||
|
||||
if (m_iFrameCounter >= m_iFrameNumber)
|
||||
{
|
||||
@ -312,7 +352,7 @@ void ImagerOperationBase::setFrameNumber(int FrameNumber)
|
||||
void ImagerOperationBase::setFileName2Save(string FileName)
|
||||
{
|
||||
m_FileName2Save = FileName;
|
||||
m_FileSavedCounter = 1;
|
||||
m_FileSavedCounter = 0;
|
||||
}
|
||||
|
||||
void ImagerOperationBase::setFocusControlState(bool FocusControlState)
|
||||
@ -335,6 +375,61 @@ int ImagerOperationBase::GetFrameSize(int& iWidth, int& iHeight)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ImagerOperationBase::getFocusIndexSobel()
|
||||
{
|
||||
imagerStartCollect();
|
||||
getFrame(buffer);
|
||||
imagerStopCollect();
|
||||
|
||||
double focusIndex = calcFocusIndexSobelPrivate(buffer);
|
||||
|
||||
emit FocusIndexSobelSignal(focusIndex);
|
||||
}
|
||||
|
||||
double ImagerOperationBase::calcFocusIndexSobelPrivate(void* pvData)
|
||||
{
|
||||
int iSelection = 0;
|
||||
int iWidth, iHeight;
|
||||
GetFrameSize(iWidth, iHeight);
|
||||
|
||||
unsigned short* psData;
|
||||
psData = (unsigned short*)pvData;
|
||||
|
||||
cv::Mat gray(iHeight, iWidth, CV_16UC1, psData);//<2F><><EFBFBD><EFBFBD>֤<EFBFBD><D6A4>gray.data<74><61><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD>psDataһ<61><D2BB><EFBFBD><EFBFBD>
|
||||
/*string rgbFilePathNoStrech = "E:\\hppa\\delete\\focusImg_";
|
||||
string tmp1 = std::to_string(m_iFocusFramesNumber);
|
||||
string tmp2 = ".png";*/
|
||||
|
||||
string rgbFilePathNoStrech = "E:\\hppa\\delete\\focusImg_" + std::to_string(m_iFocusFramesNumber) + ".png";
|
||||
|
||||
//cv::imwrite(rgbFilePathNoStrech, gray);
|
||||
m_iFocusFramesNumber++;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD>
|
||||
//cv::Mat outputImage;
|
||||
//cv::Size kernelSize(5, 5);
|
||||
//double sigmaX = 1.5;
|
||||
//cv::GaussianBlur(gray, outputImage, kernelSize, sigmaX);
|
||||
|
||||
cv::Mat outputImage = gray;
|
||||
|
||||
cv::Mat gradX, gradY, absGradX, absGradY;
|
||||
|
||||
cv::Sobel(outputImage, gradX, CV_32F, 1, 0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪCV_16S<36><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cv::magnitude<64><65><EFBFBD><EFBFBD>
|
||||
cv::Sobel(outputImage, gradY, CV_32F, 0, 1);
|
||||
cv::convertScaleAbs(gradX, absGradX);
|
||||
cv::convertScaleAbs(gradY, absGradY);
|
||||
cv::Mat grad;
|
||||
cv::addWeighted(absGradX, 0.5, absGradY, 0.5, 0, grad);
|
||||
|
||||
cv::Mat magnitude, direction;
|
||||
cv::magnitude(gradX, gradY, magnitude);//
|
||||
cv::phase(gradX, gradY, direction, true); // true<75><65>ʾ<EFBFBD><CABE><EFBFBD>ؽǶȶ<C7B6><C8B6>ǻ<EFBFBD><C7BB><EFBFBD>
|
||||
|
||||
|
||||
return cv::mean(magnitude)[0];
|
||||
}
|
||||
|
||||
CImage* ImagerOperationBase::getRgbImage() const
|
||||
{
|
||||
return m_RgbImage;
|
||||
@ -365,6 +460,11 @@ void ImagerOperationBase::setRecordControlState(bool RecordControlState)
|
||||
m_bRecordControlState = RecordControlState;
|
||||
}
|
||||
|
||||
void ImagerOperationBase::stop_record()
|
||||
{
|
||||
m_bRecordControlState = false;
|
||||
}
|
||||
|
||||
int ImagerOperationBase::getFrameCounter() const
|
||||
{
|
||||
return m_iFrameCounter;
|
||||
@ -408,6 +508,7 @@ void ImagerOperationBase::WriteHdr()
|
||||
outfile << "interleave = bil\n";
|
||||
outfile << "data type = 12\n";
|
||||
outfile << "bit depth = 12\n";
|
||||
outfile << "byte order = 0\n";
|
||||
outfile << "samples = " << getSampleCount() << "\n";
|
||||
outfile << "bands = " << getBandCount() << "\n";
|
||||
outfile << "lines = " << m_iFrameCounter << "\n";
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
#include "ImagerOperationBase.h"
|
||||
#include "utility_tc.h"
|
||||
|
||||
class MapLayer; // forward declaration
|
||||
|
||||
class ImagerOperationBase :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -55,6 +57,7 @@ public:
|
||||
void setFocusControlState(bool FocusControlState);
|
||||
int GetFrameSize(int& iWidth, int& iHeight);
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
CImage* m_RgbImage;//<2F><>ʾ<EFBFBD><CABE>rgbͼ<62><CDBC>
|
||||
@ -85,16 +88,21 @@ protected:
|
||||
|
||||
|
||||
private:
|
||||
int m_iFocusFramesNumber;
|
||||
double calcFocusIndexSobelPrivate(void* pvData);
|
||||
|
||||
public slots:
|
||||
virtual void connect_imager(int frameNumber);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD>
|
||||
virtual double auto_exposure();
|
||||
virtual void focus();
|
||||
virtual void start_record();
|
||||
void stop_record();
|
||||
virtual void record_dark();
|
||||
virtual void record_white();
|
||||
|
||||
void getFocusIndexSobel();
|
||||
signals:
|
||||
void PlotSignal();//<2F><><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD>ź<EFBFBD>
|
||||
void PlotSignal(int, int, QString);//<2F><><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD>źţ<C5BA><C5A3><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>Ӱ<EFBFBD>ڶ<F1A3BBB5><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>-1<><31><EFBFBD><EFBFBD><EFBFBD>˴βɼ<CEB2><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>
|
||||
void RecordFinishedSignal_WhenFrameNumberMeet();//<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>źţ<C5BA><C5A3><EFBFBD>Ҫ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>m_iFrameNumber<65><72><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
void RecordFinishedSignal_WhenFrameNumberNotMeet();//<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>źţ<C5BA><C5A3><EFBFBD>Ҫ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>m_iFrameNumber<65><72>û<EFBFBD>вɼ<D0B2><C9BC><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD>;ֹͣ<CDA3>ɼ<EFBFBD>
|
||||
void SpectralSignal(int);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƹ<EFBFBD><C6B9>ף<EFBFBD><D7A3><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>
|
||||
@ -102,6 +110,14 @@ signals:
|
||||
void RecordWhiteFinishSignal();
|
||||
void RecordDarlFinishSignal();
|
||||
|
||||
void FocusIndexSobelSignal(double);
|
||||
|
||||
|
||||
void testImagerStatus();//<2F><>ʾ<EFBFBD><CABE><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ӱ<EFBFBD><D3B0><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>.bil/.hdr<64><72>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ɺ<C9BA><F3B7A2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳɼ<D3B2><C9BC>̷߳<DFB3><CCB7><EFBFBD><EFBFBD><EFBFBD>Qt <20><><EFBFBD><EFBFBD> queued connection<6F><6E>
|
||||
void ImageFileSaved(const QString& path, int fileIndex);
|
||||
|
||||
// <20>ģ<DEB8><C4A3><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD> MapLayer*<2A><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>UI <20>㸺<EFBFBD><EFBFBD> MapLayer <20><><EFBFBD><EFBFBD><F3B2A2B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void LayerFileCreated(const QString& baseName, const QString& filePath, int fileIndex);
|
||||
};
|
||||
|
||||
73
HPPA/LayerTree.cpp
Normal file
73
HPPA/LayerTree.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#include "LayerTree.h"
|
||||
#include "LayerTreeGroupNode.h"
|
||||
|
||||
LayerTree::LayerTree(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
// root <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> view <20><><EFBFBD><EFBFBD>ʾ
|
||||
m_root = new LayerTreeGroupNode("__root__", this);
|
||||
m_root->setVisible(Qt::Checked);
|
||||
}
|
||||
|
||||
LayerTree::~LayerTree()
|
||||
{
|
||||
delete m_root;
|
||||
m_root = nullptr;
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTree::root() const
|
||||
{
|
||||
return m_root;
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTree::insertNode(LayerTreeNode* parent, int row, LayerTreeNode* node)
|
||||
{
|
||||
if (!node) return nullptr;
|
||||
if (!parent) parent = m_root;
|
||||
|
||||
if (row < 0) row = parent->childCount();
|
||||
parent->insertChild(row, node);
|
||||
return node;
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTree::removeNode(LayerTreeNode* parent, int row)
|
||||
{
|
||||
if (!parent) parent = m_root;
|
||||
return parent->takeChild(row);
|
||||
}
|
||||
|
||||
void LayerTree::setChildrenVisible(LayerTreeNode* n, Qt::CheckState state)
|
||||
{
|
||||
if (!n) return;
|
||||
const auto& cs = n->children();
|
||||
for (LayerTreeNode* c : cs) {
|
||||
c->setVisible(state);
|
||||
setChildrenVisible(c, state);
|
||||
}
|
||||
}
|
||||
|
||||
void LayerTree::updateParentVisibleFromChildren(LayerTreeNode* p)
|
||||
{
|
||||
if (!p) return;
|
||||
if (p->childCount() == 0) return;
|
||||
|
||||
int checked = 0, unchecked = 0, partial = 0;
|
||||
const auto& cs = p->children();
|
||||
for (LayerTreeNode* c : cs) {
|
||||
auto s = c->visible();
|
||||
if (s == Qt::Checked) checked++;
|
||||
else if (s == Qt::Unchecked) unchecked++;
|
||||
else partial++;
|
||||
}
|
||||
|
||||
Qt::CheckState newState;
|
||||
if (partial > 0) newState = Qt::PartiallyChecked;
|
||||
else if (checked > 0 && unchecked == 0) newState = Qt::Checked;
|
||||
else if (unchecked > 0 && checked == 0) newState = Qt::Unchecked;
|
||||
else newState = Qt::PartiallyChecked;
|
||||
|
||||
if (p->visible() != newState) {
|
||||
p->setVisible(newState);
|
||||
updateParentVisibleFromChildren(p->parentNode());
|
||||
}
|
||||
}
|
||||
49
HPPA/LayerTree.h
Normal file
49
HPPA/LayerTree.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include "LayerTreeNode.h"
|
||||
|
||||
/**
|
||||
* LayerTree<65><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* - <20><><EFBFBD><EFBFBD> root
|
||||
* - <20>ṩ<EFBFBD><E1B9A9><EFBFBD><EFBFBD>/<2F>Ƴ<EFBFBD><C6B3>ڵ<EFBFBD><DAB5><EFBFBD> API
|
||||
* - <20>ṩ<EFBFBD>ɼ<EFBFBD><C9BC>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>븸<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>̬<EFBFBD><CCAC><EFBFBD>µľ<C2B5>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
||||
*
|
||||
* ע<>⣺beginInsertRows/endInsertRows <20><> Qt Model <20><><EFBFBD><EFBFBD>֪ͨӦ<D6AA><D3A6> Model <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>
|
||||
* LayerTree ֻ<><D6BB><EFBFBD><EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD><EFBFBD>ݽṹ<DDBD><E1B9B9>ȷ<EFBFBD>ԡ<EFBFBD>
|
||||
*/
|
||||
class LayerTree : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LayerTree(QObject* parent = nullptr);
|
||||
~LayerTree() override;
|
||||
|
||||
LayerTree(const LayerTree&) = delete;
|
||||
LayerTree& operator=(const LayerTree&) = delete;
|
||||
|
||||
LayerTreeNode* root() const;
|
||||
|
||||
// <20><><EFBFBD>룺parent Ϊ nullptr <20><>ʾ root<6F><74>row=-1 <20><>ʾ append
|
||||
LayerTreeNode* insertNode(LayerTreeNode* parent, int row, LayerTreeNode* node);
|
||||
|
||||
// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD> delete<74><65><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1>Ƴ<EFBFBD><C6B3>ڵ㣨<DAB5><E3A3A8><EFBFBD><EFBFBD><EFBFBD>߸<EFBFBD><DFB8><EFBFBD> delete <20><><EFBFBD><EFBFBD><EFBFBD>²<EFBFBD><C2B2>룩
|
||||
LayerTreeNode* removeNode(LayerTreeNode* parent, int row);
|
||||
|
||||
// <20>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD> Model <20><><EFBFBD>ã<EFBFBD>
|
||||
static void setChildrenVisible(LayerTreeNode* n, Qt::CheckState state);
|
||||
static void updateParentVisibleFromChildren(LayerTreeNode* parent);
|
||||
|
||||
static inline bool isLayer(LayerTreeNode* node)
|
||||
{
|
||||
return node && node->type() == LayerTreeNode::Type::Layer;
|
||||
}
|
||||
|
||||
static inline bool isGroup(LayerTreeNode* node)
|
||||
{
|
||||
return node && node->type() == LayerTreeNode::Type::Group;
|
||||
}
|
||||
|
||||
private:
|
||||
LayerTreeNode* m_root = nullptr; // owned
|
||||
};
|
||||
6
HPPA/LayerTreeGroupNode.cpp
Normal file
6
HPPA/LayerTreeGroupNode.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "LayerTreeGroupNode.h"
|
||||
|
||||
LayerTreeGroupNode::LayerTreeGroupNode(const QString& name, QObject* parent)
|
||||
: LayerTreeNode(name, parent)
|
||||
{
|
||||
}
|
||||
15
HPPA/LayerTreeGroupNode.h
Normal file
15
HPPA/LayerTreeGroupNode.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "LayerTreeNode.h"
|
||||
|
||||
/** Group <20>ڵ<EFBFBD> */
|
||||
class LayerTreeGroupNode : public LayerTreeNode
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LayerTreeGroupNode(const QString& name,
|
||||
QObject* parent = nullptr);
|
||||
|
||||
Type type() const override { return Type::Group; }
|
||||
|
||||
// <20>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><D5B9>collapsed / groupOpacity <20><>
|
||||
};
|
||||
22
HPPA/LayerTreeLayerNode.cpp
Normal file
22
HPPA/LayerTreeLayerNode.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "LayerTreeLayerNode.h"
|
||||
|
||||
LayerTreeLayerNode::LayerTreeLayerNode(MapLayer* layer, QObject* parent)
|
||||
: LayerTreeNode(layer ? layer->name() : QString(), parent), m_layer(layer)
|
||||
{
|
||||
}
|
||||
|
||||
LayerTreeNode::Type LayerTreeLayerNode::type() const
|
||||
{
|
||||
return Type::Layer;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> MapLayer ָ<>루<EFBFBD><EBA3A8>ӵ<EFBFBD>У<EFBFBD>
|
||||
void LayerTreeLayerNode::setMapLayer(MapLayer* layer)
|
||||
{
|
||||
m_layer = layer;
|
||||
}
|
||||
|
||||
MapLayer* LayerTreeLayerNode::mapLayer() const
|
||||
{
|
||||
return m_layer;
|
||||
}
|
||||
22
HPPA/LayerTreeLayerNode.h
Normal file
22
HPPA/LayerTreeLayerNode.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "LayerTreeNode.h"
|
||||
#include "MapLayer.h"
|
||||
|
||||
/** Layer <20>ڵ<EFBFBD> */
|
||||
class LayerTreeLayerNode : public LayerTreeNode
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LayerTreeLayerNode(MapLayer* layer, QObject* parent = nullptr);
|
||||
|
||||
Type type() const override;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> MapLayer ָ<>루<EFBFBD><EBA3A8>ӵ<EFBFBD>У<EFBFBD>
|
||||
void setMapLayer(MapLayer* layer);
|
||||
MapLayer* mapLayer() const;
|
||||
|
||||
private:
|
||||
MapLayer* m_layer = nullptr;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>չ<EFBFBD><D5B9>layerId / pointer / legendItems <20><>
|
||||
};
|
||||
182
HPPA/LayerTreeModel.cpp
Normal file
182
HPPA/LayerTreeModel.cpp
Normal file
@ -0,0 +1,182 @@
|
||||
#include "LayerTreeModel.h"
|
||||
#include "LayerTreeGroupNode.h"
|
||||
#include "LayerTreeLayerNode.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
LayerTreeModel::LayerTreeModel(LayerTree* tree, QObject* parent, bool cascadeCheck)
|
||||
: QAbstractItemModel(parent),
|
||||
m_tree(tree),
|
||||
m_cascadeCheck(cascadeCheck)
|
||||
{
|
||||
Q_ASSERT(m_tree && "LayerTreeModel requires a valid LayerTree*");
|
||||
}
|
||||
|
||||
QModelIndex LayerTreeModel::index(int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
if (column != 0 || row < 0) return {};
|
||||
|
||||
LayerTreeNode* parentNode = nodeFromIndex(parent);
|
||||
if (!parentNode) return {};
|
||||
|
||||
LayerTreeNode* child = parentNode->childAt(row);
|
||||
if (!child) return {};
|
||||
|
||||
return createIndex(row, column, child);
|
||||
}
|
||||
|
||||
QModelIndex LayerTreeModel::parent(const QModelIndex& child) const
|
||||
{
|
||||
LayerTreeNode* node = nodeFromIndex(child);
|
||||
if (!node || node == m_tree->root()) return {};
|
||||
|
||||
LayerTreeNode* p = node->parentNode();
|
||||
if (!p || p == m_tree->root()) return {};
|
||||
|
||||
return createIndex(p->rowInParent(), 0, p);
|
||||
}
|
||||
|
||||
int LayerTreeModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
LayerTreeNode* p = nodeFromIndex(parent);
|
||||
return p ? p->childCount() : 0;
|
||||
}
|
||||
|
||||
int LayerTreeModel::columnCount(const QModelIndex&) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant LayerTreeModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
LayerTreeNode* n = nodeFromIndex(index);
|
||||
if (!n || n == m_tree->root()) return {};
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return n->name();
|
||||
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
auto* tmp = nodeFromIndex(index);
|
||||
if (LayerTree::isGroup(tmp))
|
||||
return QIcon();
|
||||
else if (LayerTree::isLayer(tmp))
|
||||
{
|
||||
QString basePath = QCoreApplication::applicationDirPath();
|
||||
return QIcon(basePath + "/icons/mIconRaster.svg");
|
||||
}
|
||||
}
|
||||
|
||||
case Qt::CheckStateRole:
|
||||
return static_cast<int>(n->visible());
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
return (n->type() == LayerTreeNode::Type::Group) ? "Group" : "Layer";
|
||||
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
bool LayerTreeModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
{
|
||||
LayerTreeNode* n = nodeFromIndex(index);
|
||||
if (!n || n == m_tree->root()) return false;
|
||||
|
||||
if (role == Qt::CheckStateRole) {
|
||||
auto newState = static_cast<Qt::CheckState>(value.toInt());
|
||||
if (n->visible() == newState) return true;
|
||||
|
||||
n->setVisible(newState);
|
||||
|
||||
// 1) <20><> -> <20><> <20><><EFBFBD><EFBFBD>
|
||||
if (m_cascadeCheck) {
|
||||
LayerTree::setChildrenVisible(n, newState);
|
||||
}
|
||||
|
||||
// 2) <20><> -> <20><> <20><><EFBFBD><EFBFBD> PartiallyChecked
|
||||
LayerTree::updateParentVisibleFromChildren(n->parentNode());
|
||||
|
||||
// <20><EFBFBD><F2BBAFA3><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>滻Ϊ<E6BBBB><CEAA> dataChanged<65><64>
|
||||
emit layoutChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::ItemFlags LayerTreeModel::flags(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid()) return Qt::NoItemFlags;
|
||||
|
||||
LayerTreeNode* n = nodeFromIndex(index);
|
||||
if (!n || n == m_tree->root()) return Qt::NoItemFlags;
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTreeModel::root() const
|
||||
{
|
||||
return m_tree->root();
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTreeModel::addGroup(LayerTreeNode* parent, const QString& name, const QIcon& icon)
|
||||
{
|
||||
if (!parent) parent = m_tree->root();
|
||||
|
||||
const int row = parent->childCount();
|
||||
beginInsertRows(indexFromNode(parent), row, row);
|
||||
LayerTreeNode* g = m_tree->insertNode(parent, row, new LayerTreeGroupNode(name));
|
||||
endInsertRows();
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTreeModel::addLayer(LayerTreeNode* parent, LayerTreeLayerNode* layerNode, const QIcon& icon)
|
||||
{
|
||||
if (!parent) parent = m_tree->root();
|
||||
if (!layerNode) return nullptr;
|
||||
|
||||
const int row = parent->childCount();
|
||||
beginInsertRows(indexFromNode(parent), row, row);
|
||||
LayerTreeNode* l = m_tree->insertNode(parent, row, layerNode);
|
||||
endInsertRows();
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
void LayerTreeModel::setCascadeCheckEnabled(bool enabled)
|
||||
{
|
||||
m_cascadeCheck = enabled;
|
||||
}
|
||||
|
||||
bool LayerTreeModel::cascadeCheckEnabled() const
|
||||
{
|
||||
return m_cascadeCheck;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3>Ƴ<EFBFBD><C6B3>ӽڵ㲢<DAB5><E3B2A2> model <20>Ϸ<EFBFBD><CFB7><EFBFBD> begin/endRemoveRows
|
||||
LayerTreeNode* LayerTreeModel::removeNode(LayerTreeNode* parent, int row)
|
||||
{
|
||||
if (!parent) parent = m_tree->root();
|
||||
if (row < 0 || row >= parent->childCount()) return nullptr;
|
||||
|
||||
beginRemoveRows(indexFromNode(parent), row, row);
|
||||
LayerTreeNode* removed = m_tree->removeNode(parent, row);
|
||||
endRemoveRows();
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTreeModel::nodeFromIndex(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid()) return m_tree->root();
|
||||
return static_cast<LayerTreeNode*>(index.internalPointer());
|
||||
}
|
||||
|
||||
QModelIndex LayerTreeModel::indexFromNode(LayerTreeNode* n) const
|
||||
{
|
||||
if (!n || n == m_tree->root()) return {};
|
||||
return createIndex(n->rowInParent(), 0, n);
|
||||
}
|
||||
52
HPPA/LayerTreeModel.h
Normal file
52
HPPA/LayerTreeModel.h
Normal file
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
#include <QCoreApplication>
|
||||
#include <QAbstractItemModel>
|
||||
#include "LayerTree.h"
|
||||
|
||||
class LayerTreeLayerNode; // forward declare
|
||||
|
||||
/**
|
||||
* LayerTreeModel<65><6C>Qt <20><><EFBFBD><EFBFBD><EFBFBD>㣨<EFBFBD><E3A3A8><EFBFBD>ٹ<EFBFBD><D9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* - 1 <20>У<EFBFBD><D0A3><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD>ͼ<EFBFBD>꣩+ checkbox
|
||||
* - <20><>ѡ<EFBFBD>ɼ<EFBFBD><C9BC>ԣ<EFBFBD><D4A3><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
||||
*/
|
||||
class LayerTreeModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LayerTreeModel(LayerTree* tree,
|
||||
QObject* parent = nullptr,
|
||||
bool cascadeCheck = true);
|
||||
~LayerTreeModel() override = default;
|
||||
|
||||
// QAbstractItemModel <20><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex& parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex& child) const override;
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role) override;
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> API<50><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD> begin/endInsertRows<77><73>
|
||||
LayerTreeNode* root() const;
|
||||
|
||||
LayerTreeNode* addGroup(LayerTreeNode* parent, const QString& name, const QIcon& icon = QIcon());
|
||||
LayerTreeNode* addLayer(LayerTreeNode* parent, LayerTreeLayerNode* layerNode, const QIcon& icon = QIcon());
|
||||
|
||||
void setCascadeCheckEnabled(bool enabled);
|
||||
bool cascadeCheckEnabled() const;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӹ<EFBFBD><D3B8>ڵ<EFBFBD><DAB5>Ƴ<EFBFBD><C6B3>ӽڵ㣨<DAB5><E3A3A8>װ LayerTree::removeNode <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> model ֪ͨ<CDA8><D6AA>
|
||||
LayerTreeNode* removeNode(LayerTreeNode* parent, int row);
|
||||
|
||||
private:
|
||||
LayerTree* m_tree = nullptr; // not owned
|
||||
bool m_cascadeCheck = true;
|
||||
|
||||
private:
|
||||
LayerTreeNode* nodeFromIndex(const QModelIndex& index) const;
|
||||
QModelIndex indexFromNode(LayerTreeNode* n) const;
|
||||
};
|
||||
110
HPPA/LayerTreeNode.cpp
Normal file
110
HPPA/LayerTreeNode.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
#include "LayerTreeNode.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
LayerTreeNode::LayerTreeNode(const QString& name, QObject* parent)
|
||||
: QObject(parent), m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
LayerTreeNode::~LayerTreeNode()
|
||||
{
|
||||
qDeleteAll(m_children);
|
||||
m_children.clear();
|
||||
}
|
||||
|
||||
QString LayerTreeNode::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void LayerTreeNode::setName(const QString& name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QIcon LayerTreeNode::icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
void LayerTreeNode::setIcon(const QIcon& icon)
|
||||
{
|
||||
m_icon = icon;
|
||||
}
|
||||
|
||||
Qt::CheckState LayerTreeNode::visible() const
|
||||
{
|
||||
return m_visible;
|
||||
}
|
||||
|
||||
void LayerTreeNode::setVisible(Qt::CheckState s)
|
||||
{
|
||||
m_visible = s;
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTreeNode::parentNode() const
|
||||
{
|
||||
return m_parentNode;
|
||||
}
|
||||
|
||||
void LayerTreeNode::setParentNode(LayerTreeNode* p)
|
||||
{
|
||||
m_parentNode = p;
|
||||
// <20><> QObject <20><> parent Ҳ<><D2B2><EFBFBD>棨<EFBFBD><E6A3A8><EFBFBD><EFBFBD> Qt <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ι<EFBFBD><CEB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD> delete children<65><6E>
|
||||
if (p) this->setParent(p);
|
||||
else this->setParent(nullptr);
|
||||
}
|
||||
|
||||
int LayerTreeNode::rowInParent() const
|
||||
{
|
||||
if (!m_parentNode) return 0;
|
||||
|
||||
const auto& siblings = m_parentNode->m_children;
|
||||
for (int i = 0; i < siblings.size(); ++i)
|
||||
{
|
||||
if (siblings[i] == this) return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LayerTreeNode::childCount() const
|
||||
{
|
||||
return m_children.size();
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTreeNode::childAt(int row) const
|
||||
{
|
||||
if (row < 0 || row >= m_children.size()) return nullptr;
|
||||
return m_children[row];
|
||||
}
|
||||
|
||||
const QVector<LayerTreeNode*>& LayerTreeNode::children() const
|
||||
{
|
||||
return m_children;
|
||||
}
|
||||
|
||||
void LayerTreeNode::appendChild(LayerTreeNode* child)
|
||||
{
|
||||
insertChild(m_children.size(), child);
|
||||
}
|
||||
|
||||
void LayerTreeNode::insertChild(int row, LayerTreeNode* child)
|
||||
{
|
||||
if (!child) return;
|
||||
|
||||
if (row < 0 || row > m_children.size())
|
||||
row = m_children.size();
|
||||
|
||||
child->setParentNode(this);
|
||||
m_children.insert(row, child);
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTreeNode::takeChild(int row)
|
||||
{
|
||||
if (row < 0 || row >= m_children.size()) return nullptr;
|
||||
LayerTreeNode* taken = m_children.takeAt(row);
|
||||
if (taken) taken->setParentNode(nullptr);
|
||||
return taken;
|
||||
}
|
||||
65
HPPA/LayerTreeNode.h
Normal file
65
HPPA/LayerTreeNode.h
Normal file
@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QIcon>
|
||||
#include <QString>
|
||||
|
||||
/**
|
||||
* LayerTreeNode<64><65><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD>ࣨ<EFBFBD><E0A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD><EFBFBD>/ͼ<><CDBC>/<2F>ɼ<EFBFBD><C9BC><EFBFBD>/<2F><><EFBFBD>ӹ<EFBFBD>ϵ
|
||||
* - Group / Layer <20>ڵ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>̳<EFBFBD>ʵ<EFBFBD><CAB5>
|
||||
*
|
||||
* ˵<><CBB5><EFBFBD><EFBFBD>
|
||||
* - <20><><EFBFBD><EFBFBD>ͬʱά<CAB1><CEAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>롱<EFBFBD><EBA1B1>m_parentNode<64><65><EFBFBD><EFBFBD> QObject parent<6E><74><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
||||
* - children <20>ɽڵ<C9BD><DAB5>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷţ<CDB7><C5A3><EFBFBD><EFBFBD><EFBFBD>ʱ delete children<65><6E>
|
||||
*/
|
||||
class LayerTreeNode : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class Type { Group, Layer };
|
||||
|
||||
explicit LayerTreeNode(const QString& name,
|
||||
QObject* parent = nullptr);
|
||||
~LayerTreeNode() override;
|
||||
|
||||
LayerTreeNode(const LayerTreeNode&) = delete;
|
||||
LayerTreeNode& operator=(const LayerTreeNode&) = delete;
|
||||
|
||||
virtual Type type() const = 0;
|
||||
|
||||
// ---- properties ----
|
||||
QString name() const;
|
||||
void setName(const QString& name);
|
||||
|
||||
QIcon icon() const;
|
||||
void setIcon(const QIcon& icon);
|
||||
|
||||
Qt::CheckState visible() const;
|
||||
void setVisible(Qt::CheckState s);
|
||||
|
||||
// ---- tree relations ----
|
||||
LayerTreeNode* parentNode() const;
|
||||
int rowInParent() const;
|
||||
|
||||
int childCount() const;
|
||||
LayerTreeNode* childAt(int row) const;
|
||||
const QVector<LayerTreeNode*>& children() const;
|
||||
|
||||
// ---- structure mutation (used by LayerTree / Model) ----
|
||||
void appendChild(LayerTreeNode* child);
|
||||
void insertChild(int row, LayerTreeNode* child);
|
||||
LayerTreeNode* takeChild(int row); // remove but not delete
|
||||
|
||||
protected:
|
||||
void setParentNode(LayerTreeNode* p);
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QIcon m_icon;
|
||||
Qt::CheckState m_visible = Qt::Checked;
|
||||
|
||||
LayerTreeNode* m_parentNode = nullptr;
|
||||
QVector<LayerTreeNode*> m_children;
|
||||
};
|
||||
39
HPPA/LayerTreeView.cpp
Normal file
39
HPPA/LayerTreeView.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "LayerTreeView.h"
|
||||
#include "LayerTreeViewMenuProvider.h"
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMenu>
|
||||
|
||||
LayerTreeView::LayerTreeView(QWidget* parent)
|
||||
: QTreeView(parent), m_menuProvider(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
LayerTreeView::~LayerTreeView()
|
||||
{
|
||||
delete m_menuProvider;
|
||||
}
|
||||
|
||||
void LayerTreeView::setMenuProvider(LayerTreeViewMenuProvider* provider)
|
||||
{
|
||||
m_menuProvider = provider;
|
||||
}
|
||||
|
||||
void LayerTreeView::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
if (!m_menuProvider)
|
||||
return;
|
||||
|
||||
const QModelIndex idx = indexAt(event->pos());
|
||||
if (idx.isValid())
|
||||
setCurrentIndex(idx);
|
||||
else
|
||||
setCurrentIndex(QModelIndex());
|
||||
|
||||
QMenu* menu = m_menuProvider->createContextMenu();
|
||||
if (menu)
|
||||
{
|
||||
menu->exec(event->globalPos());
|
||||
delete menu;
|
||||
}
|
||||
//QTreeView::contextMenuEvent(event);
|
||||
}
|
||||
20
HPPA/LayerTreeView.h
Normal file
20
HPPA/LayerTreeView.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <QTreeView>
|
||||
|
||||
class LayerTreeViewMenuProvider;
|
||||
|
||||
class LayerTreeView : public QTreeView
|
||||
{
|
||||
public:
|
||||
explicit LayerTreeView(QWidget* parent = nullptr);
|
||||
~LayerTreeView() override;
|
||||
|
||||
void setMenuProvider(LayerTreeViewMenuProvider* provider);
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent* event) override;
|
||||
|
||||
private:
|
||||
LayerTreeViewMenuProvider* m_menuProvider = nullptr; // not owned
|
||||
};
|
||||
55
HPPA/LayerTreeViewMenuProvider.cpp
Normal file
55
HPPA/LayerTreeViewMenuProvider.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include "LayerTreeViewMenuProvider.h"
|
||||
#include "LayerTreeView.h"
|
||||
#include "LayerTreeModel.h"
|
||||
#include "LayerTreeNode.h"
|
||||
#include "HPPA.h"
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
|
||||
LayerTreeViewMenuProvider::LayerTreeViewMenuProvider(LayerTreeView* view, QObject* parent)
|
||||
: QObject(parent), m_view(view)
|
||||
{
|
||||
}
|
||||
|
||||
QMenu* LayerTreeViewMenuProvider::createContextMenu()
|
||||
{
|
||||
m_contextIndex = m_view->currentIndex();
|
||||
|
||||
QMenu* menu = new QMenu();
|
||||
|
||||
if (!m_contextIndex.isValid())
|
||||
{
|
||||
return menu;
|
||||
}
|
||||
|
||||
const LayerTreeModel* model = static_cast<const LayerTreeModel*>(m_contextIndex.model());
|
||||
if (!model)
|
||||
{
|
||||
return menu;
|
||||
}
|
||||
|
||||
LayerTreeNode* node = static_cast<LayerTreeNode*>(m_contextIndex.internalPointer());
|
||||
if (!node)
|
||||
{
|
||||
return menu;
|
||||
}
|
||||
|
||||
if (node->type() == LayerTreeNode::Type::Layer)
|
||||
{
|
||||
QAction* removeAction = new QAction(QStringLiteral("<EFBFBD>Ƴ<EFBFBD>ͼ<EFBFBD><EFBFBD>"), menu);
|
||||
connect(removeAction, &QAction::triggered, HPPA::instance(), &HPPA::removeLayerByTreeIndex);
|
||||
menu->addAction(removeAction);
|
||||
}
|
||||
else if (node->type() == LayerTreeNode::Type::Group)
|
||||
{
|
||||
HPPA* app = HPPA::instance();
|
||||
if (app && node == app->rasterGroupNode())
|
||||
{
|
||||
QAction* removeAllAction = new QAction(QStringLiteral("<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD>"), menu);
|
||||
connect(removeAllAction, &QAction::triggered, app, &HPPA::removeAllLayersInRasterGroup);
|
||||
menu->addAction(removeAllAction);
|
||||
}
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
24
HPPA/LayerTreeViewMenuProvider.h
Normal file
24
HPPA/LayerTreeViewMenuProvider.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMenu>
|
||||
#include <QObject>
|
||||
#include <QModelIndex>
|
||||
|
||||
class LayerTreeView;
|
||||
class LayerTreeModel;
|
||||
class MapLayer;
|
||||
|
||||
class LayerTreeViewMenuProvider : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LayerTreeViewMenuProvider(LayerTreeView* view, QObject* parent = nullptr);
|
||||
~LayerTreeViewMenuProvider() override = default;
|
||||
|
||||
// <20><><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD> index <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߸<EFBFBD><DFB8><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD> QMenu*
|
||||
QMenu* createContextMenu();
|
||||
|
||||
private:
|
||||
LayerTreeView* m_view = nullptr; // not owned
|
||||
QModelIndex m_contextIndex;
|
||||
};
|
||||
26
HPPA/MapLayer.cpp
Normal file
26
HPPA/MapLayer.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "MapLayer.h"
|
||||
|
||||
MapLayer::MapLayer(const QString& name, const QString& uri)
|
||||
: QObject(nullptr), m_name(name), m_uri(uri)
|
||||
{
|
||||
}
|
||||
|
||||
QString MapLayer::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void MapLayer::setName(const QString& n)
|
||||
{
|
||||
m_name = n;
|
||||
}
|
||||
|
||||
QString MapLayer::dataPath() const
|
||||
{
|
||||
return m_uri;
|
||||
}
|
||||
|
||||
void MapLayer::setDataPath(const QString& p)
|
||||
{
|
||||
m_uri = p;
|
||||
}
|
||||
30
HPPA/MapLayer.h
Normal file
30
HPPA/MapLayer.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QMetaType>
|
||||
|
||||
class MapLayer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class LayerType { Raster, Vector };
|
||||
|
||||
explicit MapLayer(const QString& name, const QString& uri);
|
||||
|
||||
virtual ~MapLayer() override = default;
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString& n);
|
||||
|
||||
QString dataPath() const;
|
||||
void setDataPath(const QString& p);
|
||||
|
||||
virtual LayerType layerType() const = 0;
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_uri;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(MapLayer*)
|
||||
83
HPPA/MapLayerStore.cpp
Normal file
83
HPPA/MapLayerStore.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
#include "MapLayerStore.h"
|
||||
#include "MapLayer.h"
|
||||
|
||||
MapLayerStore::MapLayerStore(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
int a = 1;
|
||||
}
|
||||
|
||||
void MapLayerStore::addLayer(MapLayer* layer, QWidget* widget)
|
||||
{
|
||||
if (!layer) return;
|
||||
MapLayer* raw = layer;
|
||||
m_layers.emplace_back(std::shared_ptr<MapLayer>(layer));
|
||||
if (widget)
|
||||
m_layerWidgets[raw] = widget;
|
||||
emit layerAdded(raw);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MapLayer* MapLayerStore::getLayer(const QString& name) const
|
||||
{
|
||||
for (const auto& l : m_layers) {
|
||||
if (l->name() == name) return l.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MapLayer* MapLayerStore::getLayerAt(int index) const
|
||||
{
|
||||
if (index < 0 || index >= (int)m_layers.size()) return nullptr;
|
||||
return m_layers[index].get();
|
||||
}
|
||||
|
||||
int MapLayerStore::layerCount() const
|
||||
{
|
||||
return (int)m_layers.size();
|
||||
}
|
||||
|
||||
QWidget* MapLayerStore::widgetForLayer(MapLayer* layer) const
|
||||
{
|
||||
auto it = m_layerWidgets.find(layer);
|
||||
if (it == m_layerWidgets.end()) return nullptr;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
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;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
48
HPPA/MapLayerStore.h
Normal file
48
HPPA/MapLayerStore.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
class MapLayer;
|
||||
class QWidget;
|
||||
|
||||
class MapLayerStore : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
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);
|
||||
|
||||
// Remove by pointer or by name. Destruction happens when removed from store.
|
||||
public slots:
|
||||
void removeLayer(MapLayer* layer);
|
||||
void removeLayerByName(const QString& name);
|
||||
|
||||
// Queries
|
||||
MapLayer* getLayer(const QString& name) 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;
|
||||
|
||||
signals:
|
||||
void layerAdded(MapLayer* layer);
|
||||
// Emitted just before the layer is destroyed/removed from store
|
||||
void layerAboutToBeRemoved(MapLayer* layer);
|
||||
|
||||
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;
|
||||
};
|
||||
110
HPPA/MapTool.cpp
Normal file
110
HPPA/MapTool.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
#include "stdafx.h"
|
||||
#include "MapTool.h"
|
||||
#include "ImageViewer.h"
|
||||
#include <QAction>
|
||||
|
||||
MapTool::MapTool(QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_cursor(Qt::ArrowCursor)
|
||||
{
|
||||
}
|
||||
|
||||
MapTool::~MapTool()
|
||||
{
|
||||
if (m_canvas && m_canvas->mapTool() == this)
|
||||
{
|
||||
m_canvas->unsetMapTool(this);
|
||||
}
|
||||
}
|
||||
|
||||
QAction* MapTool::action() const
|
||||
{
|
||||
return m_action;
|
||||
}
|
||||
|
||||
void MapTool::setAction(QAction* action)
|
||||
{
|
||||
m_action = action;
|
||||
}
|
||||
|
||||
void MapTool::setMapcavas(Mapcavas* canvas)
|
||||
{
|
||||
if (m_canvas == canvas)
|
||||
return;
|
||||
|
||||
if (m_isActive && m_canvas)
|
||||
{
|
||||
deactivate();
|
||||
}
|
||||
|
||||
m_canvas = canvas;
|
||||
}
|
||||
|
||||
Mapcavas* MapTool::canvas() const
|
||||
{
|
||||
return m_canvas;
|
||||
}
|
||||
|
||||
void MapTool::setCursor(const QCursor& cursor)
|
||||
{
|
||||
m_cursor = cursor;
|
||||
}
|
||||
|
||||
QCursor MapTool::cursor() const
|
||||
{
|
||||
return m_cursor;
|
||||
}
|
||||
|
||||
void MapTool::activate()
|
||||
{
|
||||
if (m_canvas)
|
||||
{
|
||||
m_canvas->viewport()->setCursor(m_cursor);
|
||||
}
|
||||
if (m_action)
|
||||
{
|
||||
m_action->setChecked(true);
|
||||
}
|
||||
m_isActive = true;
|
||||
emit activated();
|
||||
}
|
||||
|
||||
void MapTool::deactivate()
|
||||
{
|
||||
if (m_action)
|
||||
{
|
||||
m_action->setChecked(false);
|
||||
}
|
||||
m_isActive = false;
|
||||
emit deactivated();
|
||||
}
|
||||
|
||||
bool MapTool::isActive() const
|
||||
{
|
||||
return m_isActive;
|
||||
}
|
||||
|
||||
void MapTool::canvasMousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
}
|
||||
|
||||
void MapTool::canvasMouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
}
|
||||
|
||||
void MapTool::canvasMouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
}
|
||||
|
||||
void MapTool::canvasMouseDoubleClickEvent(QMouseEvent* e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
}
|
||||
|
||||
void MapTool::canvasWheelEvent(QWheelEvent* e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
}
|
||||
63
HPPA/MapTool.h
Normal file
63
HPPA/MapTool.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef MAPTOOL_H
|
||||
#define MAPTOOL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QCursor>
|
||||
#include <QMouseEvent>
|
||||
#include <QAction>
|
||||
|
||||
class Mapcavas;
|
||||
class QAction;
|
||||
|
||||
class MapTool : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Flag
|
||||
{
|
||||
NoFlags = 0,
|
||||
Transient = 1 << 1,
|
||||
};
|
||||
Q_DECLARE_FLAGS(Flags, Flag)
|
||||
|
||||
MapTool(QObject* parent = nullptr);
|
||||
virtual ~MapTool();
|
||||
|
||||
virtual Flags flags() const { return NoFlags; }
|
||||
|
||||
QAction* action() const;
|
||||
void setAction(QAction* action);
|
||||
|
||||
void setMapcavas(Mapcavas* canvas);
|
||||
Mapcavas* canvas() const;
|
||||
|
||||
virtual void setCursor(const QCursor& cursor);
|
||||
QCursor cursor() const;
|
||||
|
||||
virtual void activate();
|
||||
virtual void deactivate();
|
||||
bool isActive() const;
|
||||
|
||||
virtual void canvasMousePressEvent(QMouseEvent* e);
|
||||
virtual void canvasMouseReleaseEvent(QMouseEvent* e);
|
||||
virtual void canvasMouseMoveEvent(QMouseEvent* e);
|
||||
virtual void canvasMouseDoubleClickEvent(QMouseEvent* e);
|
||||
virtual void canvasWheelEvent(QWheelEvent* e);
|
||||
|
||||
signals:
|
||||
void activated();
|
||||
void deactivated();
|
||||
|
||||
protected:
|
||||
Mapcavas* m_canvas = nullptr;
|
||||
|
||||
private:
|
||||
QAction* m_action = nullptr;
|
||||
QCursor m_cursor;
|
||||
bool m_isActive = false;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(MapTool::Flags)
|
||||
|
||||
#endif // MAPTOOL_H
|
||||
65
HPPA/MapToolPan.cpp
Normal file
65
HPPA/MapToolPan.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include "stdafx.h"
|
||||
#include "MapToolPan.h"
|
||||
#include "ImageViewer.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QGraphicsView>
|
||||
|
||||
MapToolPan::MapToolPan(QObject* parent)
|
||||
: MapTool(parent)
|
||||
{
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
||||
MapToolPan::~MapToolPan()
|
||||
{
|
||||
}
|
||||
|
||||
void MapToolPan::activate()
|
||||
{
|
||||
MapTool::activate();
|
||||
if (canvas())
|
||||
{
|
||||
canvas()->setDragMode(QGraphicsView::NoDrag);
|
||||
}
|
||||
}
|
||||
|
||||
void MapToolPan::deactivate()
|
||||
{
|
||||
m_dragging = false;
|
||||
MapTool::deactivate();
|
||||
}
|
||||
|
||||
void MapToolPan::canvasMousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
m_dragging = true;
|
||||
m_lastPos = e->pos();
|
||||
if (canvas())
|
||||
{
|
||||
canvas()->viewport()->setCursor(Qt::ClosedHandCursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapToolPan::canvasMouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
if (m_dragging && canvas())
|
||||
{
|
||||
QPointF delta = canvas()->mapToScene(e->pos()) - canvas()->mapToScene(m_lastPos);
|
||||
canvas()->translate(delta.x(), delta.y());
|
||||
m_lastPos = e->pos();
|
||||
}
|
||||
}
|
||||
|
||||
void MapToolPan::canvasMouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
m_dragging = false;
|
||||
if (canvas())
|
||||
{
|
||||
canvas()->viewport()->setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
HPPA/MapToolPan.h
Normal file
27
HPPA/MapToolPan.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef MAPTOOLPAN_H
|
||||
#define MAPTOOLPAN_H
|
||||
|
||||
#include "MapTool.h"
|
||||
#include <QPoint>
|
||||
|
||||
class MapToolPan : public MapTool
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MapToolPan(QObject* parent = nullptr);
|
||||
~MapToolPan();
|
||||
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
|
||||
void canvasMousePressEvent(QMouseEvent* e) override;
|
||||
void canvasMouseMoveEvent(QMouseEvent* e) override;
|
||||
void canvasMouseReleaseEvent(QMouseEvent* e) override;
|
||||
|
||||
private:
|
||||
bool m_dragging = false;
|
||||
QPoint m_lastPos;
|
||||
};
|
||||
|
||||
#endif // MAPTOOLPAN_H
|
||||
108
HPPA/MapToolSpectral.cpp
Normal file
108
HPPA/MapToolSpectral.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
#include "stdafx.h"
|
||||
#include "MapToolSpectral.h"
|
||||
#include "ImageViewer.h"
|
||||
#include "RasterLayer.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsLineItem>
|
||||
#include <QPen>
|
||||
#include <cmath>
|
||||
|
||||
const double MapToolSpectral::CrosshairHalfLen = 10.0;
|
||||
|
||||
MapToolSpectral::MapToolSpectral(QObject* parent)
|
||||
: MapTool(parent)
|
||||
{
|
||||
setCursor(Qt::CrossCursor);
|
||||
}
|
||||
|
||||
MapToolSpectral::~MapToolSpectral()
|
||||
{
|
||||
//removeCrosshair();//不需要在析构函数中调用removeCrosshair(),因为当MapToolSpectral被销毁时,它的canvas()也会被销毁,crosshair的scene也会被销毁,所以crosshair会自动被删除,不会造成内存泄漏。
|
||||
}
|
||||
|
||||
void MapToolSpectral::activate()
|
||||
{
|
||||
MapTool::activate();
|
||||
}
|
||||
|
||||
void MapToolSpectral::deactivate()
|
||||
{
|
||||
removeCrosshair();
|
||||
MapTool::deactivate();
|
||||
}
|
||||
|
||||
void MapToolSpectral::canvasMousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
if (!canvas())
|
||||
return;
|
||||
|
||||
const QPointF scenePt = canvas()->mapToScene(e->pos());
|
||||
const int x = static_cast<int>(std::floor(scenePt.x()));
|
||||
const int y = static_cast<int>(std::floor(scenePt.y()));
|
||||
|
||||
RasterLayer* rl = canvas()->rasterLayer();
|
||||
if (rl && rl->isValidPixel(x, y))
|
||||
{
|
||||
// Place crosshair at pixel center
|
||||
updateCrosshair(x + 0.5, y + 0.5);
|
||||
|
||||
QVector<double> wavelengths;
|
||||
QVector<double> spectrum;
|
||||
if (rl->readPixelSpectrum(x, y, wavelengths, spectrum))
|
||||
{
|
||||
emit spectralClicked(x, y, wavelengths, spectrum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapToolSpectral::updateCrosshair(double sceneX, double sceneY)
|
||||
{
|
||||
if (!canvas() || !canvas()->scene())
|
||||
return;
|
||||
|
||||
QGraphicsScene* scene = canvas()->scene();
|
||||
|
||||
QPen pen(Qt::red, 2.0);
|
||||
pen.setCosmetic(true); // constant screen-width regardless of zoom
|
||||
|
||||
if (!m_hLine)
|
||||
{
|
||||
m_hLine = scene->addLine(0, 0, 0, 0, pen);
|
||||
m_hLine->setZValue(1e9);
|
||||
}
|
||||
if (!m_vLine)
|
||||
{
|
||||
m_vLine = scene->addLine(0, 0, 0, 0, pen);
|
||||
m_vLine->setZValue(1e9);
|
||||
}
|
||||
|
||||
m_hLine->setPen(pen);
|
||||
m_vLine->setPen(pen);
|
||||
|
||||
m_hLine->setLine(sceneX - CrosshairHalfLen, sceneY,
|
||||
sceneX + CrosshairHalfLen, sceneY);
|
||||
m_vLine->setLine(sceneX, sceneY - CrosshairHalfLen,
|
||||
sceneX, sceneY + CrosshairHalfLen);
|
||||
}
|
||||
|
||||
void MapToolSpectral::removeCrosshair()
|
||||
{
|
||||
if (m_hLine)
|
||||
{
|
||||
if (m_hLine->scene())
|
||||
m_hLine->scene()->removeItem(m_hLine);
|
||||
delete m_hLine;
|
||||
m_hLine = nullptr;
|
||||
}
|
||||
if (m_vLine)
|
||||
{
|
||||
if (m_vLine->scene())
|
||||
m_vLine->scene()->removeItem(m_vLine);
|
||||
delete m_vLine;
|
||||
m_vLine = nullptr;
|
||||
}
|
||||
}
|
||||
35
HPPA/MapToolSpectral.h
Normal file
35
HPPA/MapToolSpectral.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef MAPTOOLSPECTRAL_H
|
||||
#define MAPTOOLSPECTRAL_H
|
||||
|
||||
#include "MapTool.h"
|
||||
#include <QVector>
|
||||
|
||||
class QGraphicsLineItem;
|
||||
|
||||
class MapToolSpectral : public MapTool
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MapToolSpectral(QObject* parent = nullptr);
|
||||
~MapToolSpectral();
|
||||
|
||||
void canvasMousePressEvent(QMouseEvent* e) override;
|
||||
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
|
||||
signals:
|
||||
void spectralClicked(int x, int y, QVector<double> wavelengths, QVector<double> spectrum);
|
||||
|
||||
private:
|
||||
void updateCrosshair(double sceneX, double sceneY);
|
||||
void removeCrosshair();
|
||||
|
||||
QGraphicsLineItem* m_hLine = nullptr; // horizontal line
|
||||
QGraphicsLineItem* m_vLine = nullptr; // vertical line
|
||||
|
||||
static const double CrosshairHalfLen;
|
||||
};
|
||||
|
||||
#endif // MAPTOOLSPECTRAL_H
|
||||
50
HPPA/MapTools.cpp
Normal file
50
HPPA/MapTools.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include "stdafx.h"
|
||||
#include "MapTools.h"
|
||||
#include "MapToolPan.h"
|
||||
#include "MapToolSpectral.h"
|
||||
|
||||
MapTools::MapTools(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_tools.insert(Pan, new MapToolPan(this));
|
||||
m_tools.insert(Spectral, new MapToolSpectral(this));
|
||||
}
|
||||
|
||||
MapTools::~MapTools()
|
||||
{
|
||||
qDeleteAll(m_tools);
|
||||
m_tools.clear();
|
||||
}
|
||||
|
||||
MapToolPan* MapTools::mapToolPan() const
|
||||
{
|
||||
return qobject_cast<MapToolPan*>(m_tools.value(Pan));
|
||||
}
|
||||
|
||||
MapToolSpectral* MapTools::mapToolSpectral() const
|
||||
{
|
||||
return qobject_cast<MapToolSpectral*>(m_tools.value(Spectral));
|
||||
}
|
||||
|
||||
MapTool* MapTools::mapTool(Tool tool) const
|
||||
{
|
||||
return m_tools.value(tool, nullptr);
|
||||
}
|
||||
|
||||
MapTool* MapTools::activeTool() const
|
||||
{
|
||||
return m_activeTool;
|
||||
}
|
||||
|
||||
void MapTools::setActiveTool(MapTool* tool)
|
||||
{
|
||||
m_activeTool = tool;
|
||||
}
|
||||
|
||||
void MapTools::setMapcavas(Mapcavas* canvas)
|
||||
{
|
||||
if (m_activeTool)
|
||||
{
|
||||
m_activeTool->setMapcavas(canvas);
|
||||
}
|
||||
}
|
||||
41
HPPA/MapTools.h
Normal file
41
HPPA/MapTools.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef MAPTOOLS_H
|
||||
#define MAPTOOLS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
|
||||
class MapTool;
|
||||
class MapToolPan;
|
||||
class MapToolSpectral;
|
||||
class Mapcavas;
|
||||
|
||||
class MapTools : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Tool
|
||||
{
|
||||
Pan,
|
||||
Spectral,
|
||||
};
|
||||
|
||||
MapTools(QObject* parent = nullptr);
|
||||
~MapTools();
|
||||
|
||||
MapToolPan* mapToolPan() const;
|
||||
MapToolSpectral* mapToolSpectral() const;
|
||||
|
||||
MapTool* mapTool(Tool tool) const;
|
||||
|
||||
MapTool* activeTool() const;
|
||||
void setActiveTool(MapTool* tool);
|
||||
|
||||
void setMapcavas(Mapcavas* canvas);
|
||||
|
||||
private:
|
||||
QHash<Tool, MapTool*> m_tools;
|
||||
MapTool* m_activeTool = nullptr;
|
||||
};
|
||||
|
||||
#endif // MAPTOOLS_H
|
||||
178
HPPA/OneMotorControl.cpp
Normal file
178
HPPA/OneMotorControl.cpp
Normal file
@ -0,0 +1,178 @@
|
||||
#include "OneMotorControl.h"
|
||||
|
||||
OneMotorControl::OneMotorControl(QWidget* parent) : QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
connect(this->ui.connect_btn, SIGNAL(pressed()), this, SLOT(onConnectMotor()));
|
||||
|
||||
}
|
||||
|
||||
OneMotorControl::~OneMotorControl()
|
||||
{
|
||||
m_motorThread.quit();
|
||||
m_motorThread.wait();
|
||||
}
|
||||
|
||||
void OneMotorControl::onConnectMotor()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
QString configFilePath = QString::fromStdString(directory) + "\\oneMotorConfigFile.cfg";
|
||||
|
||||
m_multiAxisController = new IrisMultiMotorController(configFilePath);
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
m_multiAxisController->moveToThread(&m_motorThread);
|
||||
connect(&m_motorThread, SIGNAL(finished()), m_multiAxisController, SLOT(deleteLater()));
|
||||
|
||||
connect(this->ui.right_btn, SIGNAL(pressed()), this, SLOT(onxMotorRight()));
|
||||
connect(this->ui.right_btn, SIGNAL(released()), this, SLOT(onxMotorStop()));
|
||||
connect(this->ui.left_btn, SIGNAL(pressed()), this, SLOT(onxMotorLeft()));
|
||||
connect(this->ui.left_btn, SIGNAL(released()), this, SLOT(onxMotorStop()));
|
||||
|
||||
connect(this->ui.move2loc_pushButton, SIGNAL(pressed()), this, SLOT(onxMove2Loc()));
|
||||
|
||||
connect(m_multiAxisController, SIGNAL(broadcastLocationSignal(std::vector<double>)), this, SLOT(display_x_loc(std::vector<double>)));
|
||||
|
||||
connect(this, SIGNAL(moveSignal(int, bool, double, int)), m_multiAxisController, SLOT(move(int, bool, double, int)));
|
||||
connect(this, SIGNAL(move2LocSignal(int, double, double, int)), m_multiAxisController, SLOT(moveTo(int, double, double, int)));
|
||||
connect(this, SIGNAL(stopSignal(int)), m_multiAxisController, SLOT(stop(int)));
|
||||
|
||||
connect(this->ui.zero_start_btn, SIGNAL(released()), this, SLOT(zeroStart()));
|
||||
connect(this, SIGNAL(zeroStartSignal(int)), m_multiAxisController, SLOT(zeroStart(int)));
|
||||
|
||||
connect(this->ui.rangeMeasurement_btn, SIGNAL(pressed()), this, SLOT(onx_rangeMeasurement()));
|
||||
connect(this, SIGNAL(rangeMeasurement(int, double, int)), m_multiAxisController, SLOT(rangeMeasurement(int, double, int)));
|
||||
|
||||
connect(this, SIGNAL(testConnectivitySignal(int, int)), m_multiAxisController, SLOT(testConnectivity(int, int)));
|
||||
connect(m_multiAxisController, SIGNAL(broadcastConnectivity(std::vector<int>)), this, SLOT(display_motors_connectivity(std::vector<int>)));
|
||||
|
||||
m_motorThread.start();
|
||||
emit testConnectivitySignal(0, 1000);
|
||||
}
|
||||
|
||||
void OneMotorControl::display_x_loc(std::vector<double> loc)
|
||||
{
|
||||
double tmp = round(loc[0] * 100) / 100;
|
||||
this->ui.realTimeLoc_lineEdit->setText(QString::number(tmp));
|
||||
|
||||
emit broadcastLocationSignal(loc);
|
||||
}
|
||||
|
||||
void OneMotorControl::display_motors_connectivity(std::vector<int> connectivity)
|
||||
{
|
||||
//std::cout << "-----------------------------------"<<connectivity.size()<< std::endl;
|
||||
if (connectivity[0])
|
||||
{
|
||||
this->ui.motor_state_label->setStyleSheet("QLabel{background-color:rgb(0,255,0);}");
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ui.motor_state_label->setStyleSheet("QLabel{background-color:rgb(255,0,0);}");
|
||||
}
|
||||
}
|
||||
|
||||
void OneMotorControl::zeroStart()
|
||||
{
|
||||
zeroStartSignal(0);
|
||||
}
|
||||
|
||||
void OneMotorControl::onx_rangeMeasurement()
|
||||
{
|
||||
double s0 = ui.speed_lineEdit->text().toDouble();
|
||||
emit rangeMeasurement(0, s0, 1000);
|
||||
}
|
||||
|
||||
void OneMotorControl::onxMove2Loc()
|
||||
{
|
||||
double s = ui.speed_lineEdit->text().toDouble();
|
||||
double l = ui.move2loc_lineEdit->text().toDouble();
|
||||
|
||||
emit move2LocSignal(0, l, s, 1000);
|
||||
}
|
||||
|
||||
void OneMotorControl::onxMotorRight()
|
||||
{
|
||||
double s = ui.speed_lineEdit->text().toDouble();
|
||||
|
||||
emit moveSignal(0, false, s, 1000);
|
||||
}
|
||||
|
||||
void OneMotorControl::onxMotorLeft()
|
||||
{
|
||||
double s = ui.speed_lineEdit->text().toDouble();
|
||||
|
||||
emit moveSignal(0, true, s, 1000);
|
||||
}
|
||||
|
||||
void OneMotorControl::onxMotorStop()
|
||||
{
|
||||
emit stopSignal(0);
|
||||
}
|
||||
|
||||
void OneMotorControl::setImager(ImagerOperationBase* imager)
|
||||
{
|
||||
m_Imager = imager;
|
||||
}
|
||||
|
||||
void OneMotorControl::record_dark()
|
||||
{
|
||||
double s = ui.speed_lineEdit->text().toDouble();
|
||||
|
||||
if (m_darkCaptureCoordinator == nullptr)
|
||||
{
|
||||
m_darkCaptureCoordinator = new DarkAndWhiteCaptureCoordinator(0, m_multiAxisController, m_Imager);
|
||||
}
|
||||
|
||||
m_darkCaptureCoordinator->startStepMotion(s);
|
||||
}
|
||||
|
||||
void OneMotorControl::record_white()
|
||||
{
|
||||
double s = ui.speed_lineEdit->text().toDouble();
|
||||
|
||||
if (m_whiteCaptureCoordinator == nullptr)
|
||||
{
|
||||
m_whiteCaptureCoordinator = new DarkAndWhiteCaptureCoordinator(1, m_multiAxisController, m_Imager);
|
||||
}
|
||||
|
||||
m_whiteCaptureCoordinator->startStepMotion(s);
|
||||
}
|
||||
|
||||
void OneMotorControl::run()
|
||||
{
|
||||
if (m_coordinator == nullptr)
|
||||
{
|
||||
qRegisterMetaType<OneMotionCapturePathLine>("OneMotionCapturePathLine");
|
||||
m_coordinator = new OneMotionCaptureCoordinator(m_multiAxisController, m_Imager);
|
||||
connect(this, SIGNAL(start(OneMotionCapturePathLine)), m_coordinator, SLOT(startStepMotion(OneMotionCapturePathLine)));
|
||||
connect(this, SIGNAL(stopStepMotionSignal()), m_coordinator, SLOT(stopStepMotion()));
|
||||
|
||||
connect(m_coordinator, SIGNAL(sequenceComplete(int)), this, SLOT(onSequenceComplete()));
|
||||
}
|
||||
|
||||
OneMotionCapturePathLine tmp;
|
||||
tmp.speedRecord = ui.speed_lineEdit->text().toDouble();
|
||||
tmp.speedBack = ui.return_speed_lineEdit->text().toDouble();
|
||||
|
||||
emit start(tmp);
|
||||
}
|
||||
|
||||
void OneMotorControl::stop()
|
||||
{
|
||||
emit stopStepMotionSignal();
|
||||
}
|
||||
|
||||
void OneMotorControl::onSequenceComplete()
|
||||
{
|
||||
emit sequenceComplete();
|
||||
}
|
||||
71
HPPA/OneMotorControl.h
Normal file
71
HPPA/OneMotorControl.h
Normal file
@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
#include <QThread>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "ui_oneMotorControl.h"
|
||||
|
||||
#include "IrisMultiMotorController.h"
|
||||
#include "fileOperation.h"
|
||||
#include "CaptureCoordinator.h"
|
||||
|
||||
class OneMotorControl : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OneMotorControl(QWidget* parent = nullptr);
|
||||
~OneMotorControl();
|
||||
|
||||
void setImager(ImagerOperationBase* imager);
|
||||
|
||||
void run();
|
||||
void stop();
|
||||
|
||||
void record_dark();
|
||||
void record_white();
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
void onConnectMotor();
|
||||
|
||||
void display_x_loc(std::vector<double> loc);
|
||||
void display_motors_connectivity(std::vector<int> connectivity);
|
||||
void onxMove2Loc();
|
||||
void zeroStart();
|
||||
void onx_rangeMeasurement();
|
||||
|
||||
void onxMotorRight();
|
||||
void onxMotorLeft();
|
||||
void onxMotorStop();
|
||||
|
||||
void onSequenceComplete();
|
||||
|
||||
signals:
|
||||
void moveSignal(int, bool, double, int);
|
||||
void move2LocSignal(int, double, double, int);
|
||||
void move2LocSignal(const std::vector<double>, const std::vector<double>, int);
|
||||
void stopSignal(int);
|
||||
|
||||
void rangeMeasurement(int, double, int);
|
||||
void zeroStartSignal(int);
|
||||
void testConnectivitySignal(int, int);
|
||||
|
||||
void start(OneMotionCapturePathLine);
|
||||
void stopStepMotionSignal();
|
||||
|
||||
void sequenceComplete();
|
||||
|
||||
void broadcastLocationSignal(std::vector<double>);
|
||||
|
||||
private:
|
||||
Ui::OneMotorControl_UI ui;
|
||||
|
||||
QThread m_motorThread;
|
||||
IrisMultiMotorController* m_multiAxisController;
|
||||
|
||||
OneMotionCaptureCoordinator* m_coordinator = nullptr;
|
||||
ImagerOperationBase* m_Imager;
|
||||
|
||||
DarkAndWhiteCaptureCoordinator* m_darkCaptureCoordinator = nullptr;
|
||||
DarkAndWhiteCaptureCoordinator* m_whiteCaptureCoordinator = nullptr;
|
||||
};
|
||||
@ -1,308 +0,0 @@
|
||||
#include "PathPlan.h"
|
||||
#include <iostream>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <fileOperation.h>
|
||||
|
||||
PathPlan::PathPlan(VinceControl* xMotor, VinceControl* yMotor, QMotorDoubleSlider* xSlider, QMotorDoubleSlider* ySlider, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
m_xMotor = xMotor;
|
||||
m_yMotor = yMotor;
|
||||
|
||||
m_xSlider = xSlider;
|
||||
m_ySlider = ySlider;
|
||||
|
||||
ui.recordLine_tableWidget->setFocusPolicy(Qt::NoFocus);
|
||||
ui.recordLine_tableWidget->setStyleSheet("selection-background-color:rgb(255,209,128)");//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8><EFBFBD>
|
||||
|
||||
ui.recordLine_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>λ
|
||||
//ui.recordLine_tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>ģʽ<C4A3><CABD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//QHeaderView* headerView = ui.recordLine_tableWidget->verticalHeader();
|
||||
//headerView->setHidden(true);//ȥ<><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
|
||||
|
||||
ui.recordLine_tableWidget->setColumnCount(2);
|
||||
ui.recordLine_tableWidget->setHorizontalHeaderLabels(QStringList() << "yPosition" << "xMaxPosition");
|
||||
|
||||
connect(ui.addRecordLine_btn, SIGNAL(clicked()), this, SLOT(onAddRecordLine_btn()));
|
||||
connect(ui.removeRecordLine_btn, SIGNAL(clicked()), this, SLOT(onRemoveRecordLine_btn()));
|
||||
connect(ui.generateRecordLine_btn, SIGNAL(clicked()), this, SLOT(onGenerateRecordLine_btn()));
|
||||
connect(ui.deleteRecordLine_btn, SIGNAL(clicked()), this, SLOT(onDeleteRecordLine_btn()));
|
||||
connect(ui.saveRecordLine2File_btn, SIGNAL(clicked()), this, SLOT(onSaveRecordLine2File_btn()));
|
||||
connect(ui.readRecordLineFile_btn, SIGNAL(clicked()), this, SLOT(onReadRecordLineFile_btn()));
|
||||
}
|
||||
|
||||
PathPlan::~PathPlan()
|
||||
{}
|
||||
|
||||
void PathPlan::setMotor(VinceControl* xMotor, VinceControl* yMotor)
|
||||
{
|
||||
m_xMotor = xMotor;
|
||||
m_yMotor = yMotor;
|
||||
}
|
||||
|
||||
QTableWidget* PathPlan::getRecordLineTableWidget()
|
||||
{
|
||||
return ui.recordLine_tableWidget;
|
||||
}
|
||||
|
||||
void PathPlan::onAddRecordLine_btn()
|
||||
{
|
||||
//<><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ByteBack MotorState = m_yMotor->GetState();
|
||||
double currentPosOfYmotor = m_ySlider->getDistanceFromPulse(MotorState.Location);
|
||||
double maxRangeOfXmotro = m_xSlider->maximum();
|
||||
|
||||
//<2F><>ȡѡ<C8A1><D1A1><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
int currentRow = ui.recordLine_tableWidget->currentRow();
|
||||
std::cout << "currentRow<EFBFBD><EFBFBD>" << currentRow << std::endl;
|
||||
|
||||
QTableWidgetItem* Item1 = new QTableWidgetItem(QString::number(currentPosOfYmotor, 10, 2));
|
||||
QTableWidgetItem* Item2 = new QTableWidgetItem(QString::number(maxRangeOfXmotro, 10, 2));
|
||||
Item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
Item2->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
if (currentRow == -1)//<2F><>û<EFBFBD><C3BB>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ʱ
|
||||
{
|
||||
int RowCount = ui.recordLine_tableWidget->rowCount();//Returns the number of rows. <20><>1<EFBFBD><31>ʼ<EFBFBD><CABC>
|
||||
ui.recordLine_tableWidget->insertRow(RowCount);//<2F><><EFBFBD><EFBFBD>һ<EFBFBD>У<EFBFBD><D0A3>β<EFBFBD><CEB2>Ǵ<EFBFBD>0<EFBFBD><30>ʼ<EFBFBD><CABC>
|
||||
|
||||
ui.recordLine_tableWidget->setItem(RowCount, 0, Item1);
|
||||
ui.recordLine_tableWidget->setItem(RowCount, 1, Item2);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.recordLine_tableWidget->insertRow(currentRow + 1);//<2F><><EFBFBD><EFBFBD>һ<EFBFBD>У<EFBFBD><D0A3>β<EFBFBD><CEB2>Ǵ<EFBFBD>0<EFBFBD><30>ʼ<EFBFBD><CABC>
|
||||
|
||||
ui.recordLine_tableWidget->setItem(currentRow + 1, 0, Item1);
|
||||
ui.recordLine_tableWidget->setItem(currentRow + 1, 1, Item2);
|
||||
}
|
||||
}
|
||||
|
||||
void PathPlan::onRemoveRecordLine_btn()
|
||||
{
|
||||
int rowIndex = ui.recordLine_tableWidget->currentRow();
|
||||
if (rowIndex != -1)
|
||||
ui.recordLine_tableWidget->removeRow(rowIndex);
|
||||
}
|
||||
|
||||
void PathPlan::onGenerateRecordLine_btn()
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
double height = ui.height_lineEdit->text().toDouble();
|
||||
double fov = ui.fov_lineEdit->text().toDouble();
|
||||
double swath = (height * tan(fov / 2 * PI / 180)) * 2;//tan<61><6E><EFBFBD><EFBFBD><EFBFBD>ǻ<EFBFBD><C7BB><EFBFBD>
|
||||
ui.swath_lineEdit->setText(QString::number(swath));
|
||||
|
||||
|
||||
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ
|
||||
double xMotorRange = m_xSlider->maximum();
|
||||
double yMotorRange = m_ySlider->maximum();
|
||||
|
||||
|
||||
//ȷ<><C8B7><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC>ߣ<EFBFBD><DFA3><EFBFBD>ʽ<EFBFBD><CABD>numberOfRecordLine_tmp * swath - repetitiveLength<74><68>numberOfRecordLine_tmp - 1<><31> = overallLength
|
||||
double overallLength = yMotorRange + swath;
|
||||
double repetitiveRate = ui.repetitiveRate_lineEdit->text().toDouble() / 100;
|
||||
double repetitiveLength = repetitiveRate * swath;
|
||||
double offset = ui.offset_lineEdit->text().toDouble();
|
||||
|
||||
double numberOfRecordLine_tmp = (overallLength - repetitiveLength - offset) / (swath - repetitiveLength);
|
||||
double tmp = numberOfRecordLine_tmp - (int)numberOfRecordLine_tmp;
|
||||
int numberOfRecordLine;
|
||||
double threshold = ui.LastLineThreshold_lineEdit->text().toDouble();//<2F><>numberOfRecordLine_tmpΪС<CEAA><D0A1>ʱ<EFBFBD><CAB1><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>
|
||||
if (tmp > threshold)
|
||||
{
|
||||
numberOfRecordLine = (int)numberOfRecordLine_tmp + 1;
|
||||
//std::cout << "<22><><EFBFBD>ڣ<EFBFBD>" << threshold << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
numberOfRecordLine = (int)numberOfRecordLine_tmp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//ȥ<><C8A5>tableWidget<65><74><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>
|
||||
int rowCount = ui.recordLine_tableWidget->rowCount();
|
||||
for (size_t i = 0; i < rowCount; i++)
|
||||
{
|
||||
ui.recordLine_tableWidget->removeRow(0);
|
||||
}
|
||||
|
||||
|
||||
//<2F><>tableWidget<65><74><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ɼ<EFBFBD><C9BC>ߣ<EFBFBD>
|
||||
QTableWidgetItem* tmpItem;
|
||||
for (size_t i = 0; i < numberOfRecordLine; i++)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
int RowCount = ui.recordLine_tableWidget->rowCount();
|
||||
ui.recordLine_tableWidget->insertRow(RowCount);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>yPosition
|
||||
if (tmp > threshold && i == numberOfRecordLine - 1)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>е<EFBFBD>yPosition
|
||||
{
|
||||
tmpItem = new QTableWidgetItem(QString::number(yMotorRange, 10, 2));
|
||||
tmpItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
ui.recordLine_tableWidget->setItem(i, 0, tmpItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
double x = swath * i - i * repetitiveLength + offset;
|
||||
tmpItem = new QTableWidgetItem(QString::number(x, 10, 2));
|
||||
tmpItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
ui.recordLine_tableWidget->setItem(i, 0, tmpItem);
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>x<EFBFBD><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>λ<EFBFBD><CEBB> <20><> ֵ<><D6B5><EFBFBD><EFBFBD>Ϊx<CEAA><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
tmpItem = new QTableWidgetItem(QString::number(xMotorRange, 10, 2));
|
||||
tmpItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
ui.recordLine_tableWidget->setItem(i, 1, tmpItem);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PathPlan::onDeleteRecordLine_btn()
|
||||
{
|
||||
int rowCount = ui.recordLine_tableWidget->rowCount();
|
||||
for (size_t i = 0; i < rowCount; i++)
|
||||
{
|
||||
ui.recordLine_tableWidget->removeRow(0);
|
||||
}
|
||||
}
|
||||
|
||||
void PathPlan::onSaveRecordLine2File_btn()
|
||||
{
|
||||
//ȷ<><C8B7><EFBFBD>ɼ<EFBFBD><C9BC>ߴ<EFBFBD><DFB4><EFBFBD>
|
||||
if (ui.recordLine_tableWidget->rowCount() <= 0)
|
||||
{
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ켣<EFBFBD><EFBFBD>"));
|
||||
return;
|
||||
}
|
||||
|
||||
double height = ui.height_lineEdit->text().toDouble();
|
||||
double fov = ui.fov_lineEdit->text().toDouble();
|
||||
double swath = ui.swath_lineEdit->text().toDouble();
|
||||
double offset = ui.offset_lineEdit->text().toDouble();
|
||||
double repetitiveRate = ui.repetitiveRate_lineEdit->text().toDouble();
|
||||
double LastLineThreshold = ui.LastLineThreshold_lineEdit->text().toDouble();
|
||||
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
|
||||
QString RecordLineFilePath = QFileDialog::getSaveFileName(this, tr("Save RecordLine File"),
|
||||
QString::fromStdString(directory),
|
||||
tr("RecordLineFile (*.RecordLine)"));
|
||||
|
||||
if (RecordLineFilePath.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* RecordLineFileHandle = fopen(RecordLineFilePath.toStdString().c_str(), "wb+");
|
||||
|
||||
fwrite(&height, sizeof(double), 1, RecordLineFileHandle);
|
||||
fwrite(&fov, sizeof(double), 1, RecordLineFileHandle);
|
||||
fwrite(&swath, sizeof(double), 1, RecordLineFileHandle);
|
||||
fwrite(&offset, sizeof(double), 1, RecordLineFileHandle);
|
||||
fwrite(&repetitiveRate, sizeof(double), 1, RecordLineFileHandle);
|
||||
fwrite(&LastLineThreshold, sizeof(double), 1, RecordLineFileHandle);
|
||||
|
||||
double number = ui.recordLine_tableWidget->rowCount() * ui.recordLine_tableWidget->columnCount();
|
||||
fwrite(&number, sizeof(double), 1, RecordLineFileHandle);
|
||||
|
||||
double* data = new double[number];
|
||||
//double data[number];
|
||||
for (size_t i = 0; i < ui.recordLine_tableWidget->rowCount(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < ui.recordLine_tableWidget->columnCount(); j++)
|
||||
{
|
||||
data[i * ui.recordLine_tableWidget->columnCount() + j] = ui.recordLine_tableWidget->item(i, j)->text().toDouble();
|
||||
}
|
||||
}
|
||||
|
||||
fwrite(data, sizeof(double), number, RecordLineFileHandle);
|
||||
|
||||
fclose(RecordLineFileHandle);
|
||||
delete[] data;
|
||||
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>"));
|
||||
}
|
||||
|
||||
void PathPlan::onReadRecordLineFile_btn()
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
//string RecordLineFilePath = directory + "\\test.RecordLine";
|
||||
|
||||
QString RecordLineFilePath = QFileDialog::getOpenFileName(this, tr("Open RecordLine File"),
|
||||
QString::fromStdString(directory),
|
||||
tr("RecordLineFile (*.RecordLine)"));
|
||||
|
||||
if (RecordLineFilePath.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* RecordLineFileHandle = fopen(RecordLineFilePath.toStdString().c_str(), "rb");
|
||||
double height, fov, swath, offset, repetitiveRate, LastLineThreshold, number;
|
||||
|
||||
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
fread(&height, sizeof(double), 1, RecordLineFileHandle);
|
||||
fread(&fov, sizeof(double), 1, RecordLineFileHandle);
|
||||
fread(&swath, sizeof(double), 1, RecordLineFileHandle);
|
||||
fread(&offset, sizeof(double), 1, RecordLineFileHandle);
|
||||
fread(&repetitiveRate, sizeof(double), 1, RecordLineFileHandle);
|
||||
fread(&LastLineThreshold, sizeof(double), 1, RecordLineFileHandle);
|
||||
fread(&number, sizeof(double), 1, RecordLineFileHandle);
|
||||
|
||||
double* data = new double[number];
|
||||
for (size_t i = 0; i < number; i++)
|
||||
{
|
||||
fread(data + i, sizeof(double), 1, RecordLineFileHandle);
|
||||
//std::cout << *(data + i) << std::endl;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д
|
||||
ui.height_lineEdit->setText(QString::number(height));
|
||||
ui.fov_lineEdit->setText(QString::number(fov));
|
||||
ui.swath_lineEdit->setText(QString::number(swath));
|
||||
ui.offset_lineEdit->setText(QString::number(offset));
|
||||
ui.repetitiveRate_lineEdit->setText(QString::number(repetitiveRate));
|
||||
ui.LastLineThreshold_lineEdit->setText(QString::number(LastLineThreshold));
|
||||
|
||||
|
||||
//<2F><>tableWidget<65><74><EFBFBD>Ӳɼ<D3B2><C9BC><EFBFBD>
|
||||
//<2F><>1<EFBFBD><31>ȥ<EFBFBD><C8A5>tableWidget<65><74><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>
|
||||
int rowCount = ui.recordLine_tableWidget->rowCount();
|
||||
for (size_t i = 0; i < rowCount; i++)
|
||||
{
|
||||
ui.recordLine_tableWidget->removeRow(0);
|
||||
}
|
||||
//<2F><>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ɼ<EFBFBD><C9BC>ߣ<EFBFBD>
|
||||
int RecordLineCount = number / ui.recordLine_tableWidget->columnCount();
|
||||
for (size_t i = 0; i < RecordLineCount; i++)
|
||||
{
|
||||
ui.recordLine_tableWidget->insertRow(0);
|
||||
|
||||
}
|
||||
//<2F><>3<EFBFBD><33><EFBFBD><EFBFBD>tableWidget<65><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for (size_t i = 0; i < ui.recordLine_tableWidget->rowCount(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < ui.recordLine_tableWidget->columnCount(); j++)
|
||||
{
|
||||
QTableWidgetItem* tmp = new QTableWidgetItem(QString::number(data[i * ui.recordLine_tableWidget->columnCount() + j], 10, 5));
|
||||
tmp->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
ui.recordLine_tableWidget->setItem(i, j, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(RecordLineFileHandle);
|
||||
delete[] data;
|
||||
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD>ȡ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>"));
|
||||
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "ui_PathPlan.h"
|
||||
#include "vincecontrol.h"
|
||||
#include <QMotorDoubleSlider.h>
|
||||
|
||||
#define PI 3.1415926
|
||||
|
||||
class PathPlan : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PathPlan(VinceControl* xMotor, VinceControl* yMotor, QMotorDoubleSlider* xSlider, QMotorDoubleSlider* ySlider, QWidget* parent = nullptr);
|
||||
~PathPlan();
|
||||
|
||||
void setMotor(VinceControl* xMotor, VinceControl* yMotor);
|
||||
QTableWidget* getRecordLineTableWidget();
|
||||
|
||||
private:
|
||||
Ui::PathPlanClass ui;
|
||||
|
||||
VinceControl* m_xMotor;
|
||||
VinceControl* m_yMotor;
|
||||
|
||||
QMotorDoubleSlider* m_xSlider;
|
||||
QMotorDoubleSlider* m_ySlider;
|
||||
|
||||
public Q_SLOTS:
|
||||
void onAddRecordLine_btn();
|
||||
void onRemoveRecordLine_btn();
|
||||
void onGenerateRecordLine_btn();
|
||||
void onDeleteRecordLine_btn();
|
||||
void onSaveRecordLine2File_btn();
|
||||
void onReadRecordLineFile_btn();
|
||||
};
|
||||
@ -15,19 +15,19 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_16">
|
||||
@ -349,12 +349,6 @@
|
||||
<widget class="QTableWidget" name="recordLine_tableWidget"/>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>layoutWidget</zorder>
|
||||
<zorder>layoutWidget_2</zorder>
|
||||
<zorder>recordLine_tableWidget</zorder>
|
||||
<zorder>layoutWidget_3</zorder>
|
||||
<zorder>layoutWidget_4</zorder>
|
||||
<zorder>label_7</zorder>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
|
||||
@ -6,114 +6,246 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>294</width>
|
||||
<height>119</height>
|
||||
<width>432</width>
|
||||
<height>346</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>PowerControl</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_20">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_17">
|
||||
<property name="text">
|
||||
<string>卤素灯</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="lamp_power_open_btn">
|
||||
<property name="text">
|
||||
<string>打开</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="lamp_power_close_btn">
|
||||
<property name="text">
|
||||
<string>关闭</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_19">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_21">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_18">
|
||||
<property name="text">
|
||||
<string>马 达</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="motor_power_open_btn">
|
||||
<property name="text">
|
||||
<string>打开</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="motor_power_close_btn">
|
||||
<property name="text">
|
||||
<string>关闭</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_20">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QGroupBox
|
||||
{
|
||||
border: 12px solid transparent;
|
||||
color: #ACCDFF;
|
||||
}
|
||||
|
||||
QPushButton
|
||||
{
|
||||
/*width: 172px;
|
||||
height: 56px;*/
|
||||
font: 19pt "新宋体";
|
||||
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_3" rowstretch="1,1,1,1" columnstretch="1,3,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>42</height>
|
||||
<height>145</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>151</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<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>20</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="lamp_power_open_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="lamp_power_close_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>151</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>151</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<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>20</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="motor_power_open_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="motor_power_close_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_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>151</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>144</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
|
||||
167
HPPA/RadianceConversion.ui
Normal file
167
HPPA/RadianceConversion.ui
Normal file
@ -0,0 +1,167 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RadianceConversion_UI</class>
|
||||
<widget class="QDialog" name="RadianceConversion_UI">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>544</width>
|
||||
<height>177</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>辐亮度转换</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>影像</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>定标文件</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="imgPath_lineEdit">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="calFilePath_lineEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(255, 255, 255);</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QPushButton" name="imgSelect_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="calFileSelect_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="conversion_btn">
|
||||
<property name="text">
|
||||
<string>转换</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>191</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
225
HPPA/RasterDataProvider.cpp
Normal file
225
HPPA/RasterDataProvider.cpp
Normal file
@ -0,0 +1,225 @@
|
||||
#include "RasterDataProvider.h"
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#if HPPA_HAVE_GDAL
|
||||
#include <gdal_priv.h>
|
||||
#include <cpl_conv.h>
|
||||
#endif
|
||||
|
||||
RasterDataProvider::RasterDataProvider(const QString& uri)
|
||||
: m_uri(uri), m_dataset(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
RasterDataProvider::~RasterDataProvider()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
bool RasterDataProvider::open()
|
||||
{
|
||||
#if HPPA_HAVE_GDAL
|
||||
GDALAllRegister();
|
||||
m_dataset = (GDALDataset*)GDALOpen((const char*)m_uri.toLocal8Bit().constData(), GA_ReadOnly);
|
||||
if (!m_dataset) {
|
||||
qWarning() << "RasterDataProvider: failed to open dataset:" << m_uri;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
Q_UNUSED(m_uri);
|
||||
qWarning() << "RasterDataProvider: GDAL not available, open will fail.";
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void RasterDataProvider::close()
|
||||
{
|
||||
#if HPPA_HAVE_GDAL
|
||||
if (m_dataset) {
|
||||
GDALClose((GDALDatasetH)m_dataset);
|
||||
m_dataset = nullptr;
|
||||
}
|
||||
#else
|
||||
m_dataset = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
int RasterDataProvider::bandCount() const
|
||||
{
|
||||
#if HPPA_HAVE_GDAL
|
||||
if (!m_dataset) return 0;
|
||||
return m_dataset->GetRasterCount();
|
||||
#else
|
||||
Q_UNUSED(this);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int RasterDataProvider::width() const
|
||||
{
|
||||
#if HPPA_HAVE_GDAL
|
||||
if (!m_dataset) return 0;
|
||||
return m_dataset->GetRasterXSize();
|
||||
#else
|
||||
Q_UNUSED(this);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int RasterDataProvider::height() const
|
||||
{
|
||||
#if HPPA_HAVE_GDAL
|
||||
if (!m_dataset) return 0;
|
||||
return m_dataset->GetRasterYSize();
|
||||
#else
|
||||
Q_UNUSED(this);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RasterDataProvider::isValidPixel(int x, int y) const
|
||||
{
|
||||
const int w = width();
|
||||
const int h = height();
|
||||
return x >= 0 && y >= 0 && x < w && y < h;
|
||||
}
|
||||
|
||||
std::vector<double> RasterDataProvider::parseEnviHdrWavelengths() const
|
||||
{
|
||||
std::vector<double> res;
|
||||
|
||||
QFileInfo fi(m_uri);
|
||||
QString hdrPath = fi.path() + "/" + fi.completeBaseName() + ".hdr";
|
||||
QFile hdr(hdrPath);
|
||||
if (!hdr.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return res;
|
||||
}
|
||||
|
||||
QString text = QString::fromLocal8Bit(hdr.readAll());
|
||||
hdr.close();
|
||||
|
||||
QRegularExpression rx("wavelength\\s*=\\s*\\{([^}]*)\\}", QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption);
|
||||
QRegularExpressionMatch m = rx.match(text);
|
||||
if (!m.hasMatch()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
const QString body = m.captured(1);
|
||||
const QStringList parts = body.split(',', QString::SkipEmptyParts);
|
||||
res.reserve(parts.size());
|
||||
for (const QString& p : parts) {
|
||||
bool ok = false;
|
||||
double v = p.trimmed().toDouble(&ok);
|
||||
if (ok) {
|
||||
res.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<double> RasterDataProvider::bandWavelengths() const
|
||||
{
|
||||
std::vector<double> res;
|
||||
#if HPPA_HAVE_GDAL
|
||||
if (!m_dataset) return res;
|
||||
|
||||
// 1) Try ENVI dataset-level metadata first: wavelength = { ... }
|
||||
const char* dsWave = m_dataset->GetMetadataItem("wavelength", "ENVI");
|
||||
if (!dsWave) dsWave = m_dataset->GetMetadataItem("Wavelength", "ENVI");
|
||||
if (dsWave) {
|
||||
QString dsWaveStr = QString::fromLocal8Bit(dsWave);
|
||||
dsWaveStr.remove('{').remove('}');
|
||||
const QStringList parts = dsWaveStr.split(',', QString::SkipEmptyParts);
|
||||
res.reserve(parts.size());
|
||||
for (const QString& p : parts) {
|
||||
bool ok = false;
|
||||
double v = p.trimmed().toDouble(&ok);
|
||||
if (ok) res.push_back(v);
|
||||
}
|
||||
if (!res.empty()) return res;
|
||||
}
|
||||
|
||||
// 2) Try per-band metadata
|
||||
for (int i = 1; i <= m_dataset->GetRasterCount(); ++i) {
|
||||
GDALRasterBand* band = m_dataset->GetRasterBand(i);
|
||||
if (!band) continue;
|
||||
const char* val = band->GetMetadataItem("Wavelength");
|
||||
if (!val) val = band->GetMetadataItem("wavelength");
|
||||
if (val) {
|
||||
bool ok = false;
|
||||
double v = QString::fromLocal8Bit(val).trimmed().toDouble(&ok);
|
||||
res.push_back(ok ? v : -1.0);
|
||||
} else {
|
||||
res.push_back(-1.0);
|
||||
}
|
||||
}
|
||||
if (!res.empty()) return res;
|
||||
#endif
|
||||
|
||||
// 3) Fallback: parse ENVI .hdr directly
|
||||
return parseEnviHdrWavelengths();
|
||||
}
|
||||
|
||||
bool RasterDataProvider::readPixelSpectrum(int x, int y, std::vector<double>& outSpectrum) const
|
||||
{
|
||||
#if HPPA_HAVE_GDAL
|
||||
outSpectrum.clear();
|
||||
if (!m_dataset) return false;
|
||||
if (!isValidPixel(x, y)) return false;
|
||||
|
||||
const int bands = m_dataset->GetRasterCount();
|
||||
if (bands <= 0) return false;
|
||||
|
||||
outSpectrum.resize(bands);
|
||||
for (int i = 0; i < bands; ++i) {
|
||||
GDALRasterBand* band = m_dataset->GetRasterBand(i + 1);
|
||||
if (!band) return false;
|
||||
|
||||
float value = 0.0f;
|
||||
CPLErr err = band->RasterIO(
|
||||
GF_Read,
|
||||
x, y,
|
||||
1, 1,
|
||||
&value,
|
||||
1, 1,
|
||||
GDT_Float32,
|
||||
0, 0);
|
||||
|
||||
if (err != CE_None) return false;
|
||||
outSpectrum[i] = static_cast<double>(value);
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
Q_UNUSED(x);
|
||||
Q_UNUSED(y);
|
||||
Q_UNUSED(outSpectrum);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RasterDataProvider::readBandAsFloat(int bandIndex, std::vector<float>& outBuffer) const
|
||||
{
|
||||
#if HPPA_HAVE_GDAL
|
||||
if (!m_dataset) return false;
|
||||
int bands = m_dataset->GetRasterCount();
|
||||
if (bandIndex < 0 || bandIndex >= bands) return false;
|
||||
GDALRasterBand* band = m_dataset->GetRasterBand(bandIndex + 1);
|
||||
if (!band) return false;
|
||||
int w = m_dataset->GetRasterXSize();
|
||||
int h = m_dataset->GetRasterYSize();
|
||||
outBuffer.assign(w * h, 0.0f);
|
||||
CPLErr err = band->RasterIO(GF_Read, 0, 0, w, h, outBuffer.data(), w, h, GDT_Float32, 0, 0);
|
||||
return err == CE_None;
|
||||
#else
|
||||
Q_UNUSED(bandIndex);
|
||||
Q_UNUSED(outBuffer);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
50
HPPA/RasterDataProvider.h
Normal file
50
HPPA/RasterDataProvider.h
Normal file
@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
#if __has_include(<gdal_priv.h>)
|
||||
#define HPPA_HAVE_GDAL 1
|
||||
#include <gdal_priv.h>
|
||||
#include <cpl_conv.h>
|
||||
#else
|
||||
#define HPPA_HAVE_GDAL 0
|
||||
#endif
|
||||
|
||||
class RasterDataProvider
|
||||
{
|
||||
public:
|
||||
explicit RasterDataProvider(const QString& uri);
|
||||
~RasterDataProvider();
|
||||
|
||||
bool open();
|
||||
void close();
|
||||
|
||||
int bandCount() const;
|
||||
int width() const;
|
||||
int height() const;
|
||||
|
||||
bool isValidPixel(int x, int y) const;
|
||||
|
||||
// Returns per-band wavelength metadata if available. If not available, returns empty vector.
|
||||
std::vector<double> bandWavelengths() const;
|
||||
|
||||
// Read spectrum of one pixel (x,y) across all bands.
|
||||
bool readPixelSpectrum(int x, int y, std::vector<double>& outSpectrum) const;
|
||||
|
||||
// Read a single band (0-based index) into a float buffer of size width()*height().
|
||||
// Returns true on success.
|
||||
bool readBandAsFloat(int bandIndex, std::vector<float>& outBuffer) const;
|
||||
|
||||
QString uri() const { return m_uri; }
|
||||
|
||||
private:
|
||||
QString m_uri;
|
||||
std::vector<double> parseEnviHdrWavelengths() const;
|
||||
#if HPPA_HAVE_GDAL
|
||||
GDALDataset* m_dataset = nullptr;
|
||||
#else
|
||||
// no-op when GDAL not available
|
||||
void* m_dataset = nullptr;
|
||||
#endif
|
||||
};
|
||||
116
HPPA/RasterLayer.cpp
Normal file
116
HPPA/RasterLayer.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool RasterLayer::isValidPixel(int x, int y)
|
||||
{
|
||||
if (!m_provider) {
|
||||
if (!openDataProvider()) return false;
|
||||
}
|
||||
return m_provider->isValidPixel(x, y);
|
||||
}
|
||||
|
||||
bool RasterLayer::readPixelSpectrum(int x, int y, QVector<double>& wavelengths, QVector<double>& spectrum)
|
||||
{
|
||||
if (!m_provider) {
|
||||
if (!openDataProvider()) return false;
|
||||
}
|
||||
|
||||
std::vector<double> wl;
|
||||
std::vector<double> sp;
|
||||
|
||||
if (!m_provider->readPixelSpectrum(x, y, sp)) return false;
|
||||
|
||||
wl = m_provider->bandWavelengths();
|
||||
|
||||
wavelengths = QVector<double>::fromStdVector(wl);
|
||||
spectrum = QVector<double>::fromStdVector(sp);
|
||||
|
||||
if (wavelengths.size() != spectrum.size()) {
|
||||
wavelengths.resize(spectrum.size());
|
||||
for (int i = 0; i < wavelengths.size(); ++i) {
|
||||
wavelengths[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
if (wl.empty()) return false;
|
||||
minWave = *std::min_element(wl.begin(), wl.end());
|
||||
maxWave = *std::max_element(wl.begin(), wl.end());
|
||||
return true;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
55
HPPA/RasterLayer.h
Normal file
55
HPPA/RasterLayer.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "MapLayer.h"
|
||||
#include <memory>
|
||||
#include <QImage>
|
||||
#include <QVector>
|
||||
|
||||
class RasterDataProvider;
|
||||
class RasterRenderer;
|
||||
|
||||
class RasterLayer : public MapLayer
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RasterLayer(const QString& name, const QString& uri);
|
||||
~RasterLayer();
|
||||
|
||||
LayerType layerType() const override;
|
||||
|
||||
// Access provider/renderer
|
||||
RasterDataProvider* dataProvider() const;
|
||||
RasterRenderer* renderer() const;
|
||||
|
||||
// Create or open provider based on this layer's uri
|
||||
bool openDataProvider();
|
||||
|
||||
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:
|
||||
std::unique_ptr<RasterDataProvider> m_provider;
|
||||
std::unique_ptr<RasterRenderer> m_renderer;
|
||||
RenderParams m_currentParams;
|
||||
};
|
||||
86
HPPA/RasterRenderer.cpp
Normal file
86
HPPA/RasterRenderer.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
#include "RasterRenderer.h"
|
||||
#include "RasterDataProvider.h"
|
||||
#include <QDebug>
|
||||
#include <algorithm>
|
||||
|
||||
RasterRenderer::RasterRenderer(RasterDataProvider* provider)
|
||||
: m_provider(provider)
|
||||
{
|
||||
}
|
||||
|
||||
void RasterRenderer::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);
|
||||
}
|
||||
}
|
||||
|
||||
QImage RasterRenderer::render(const Params& params)
|
||||
{
|
||||
if (!m_provider) return QImage();
|
||||
int bands = m_provider->bandCount();
|
||||
int w = m_provider->width();
|
||||
int h = m_provider->height();
|
||||
if (w <= 0 || h <= 0) return QImage();
|
||||
|
||||
// Find nearest bands for requested wavelengths if wavelengths available
|
||||
std::vector<double> wavelengths = m_provider->bandWavelengths();
|
||||
|
||||
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 >= 1) return 0;
|
||||
return -1;
|
||||
}
|
||||
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; }
|
||||
}
|
||||
if (best >= 0) return best;
|
||||
// fallback
|
||||
return std::min(2, bands-1);
|
||||
};
|
||||
|
||||
int rIdx = chooseBandIndexForWave(params.rWave);
|
||||
int gIdx = chooseBandIndexForWave(params.gWave);
|
||||
int bIdx = chooseBandIndexForWave(params.bWave);
|
||||
|
||||
std::vector<float> rbuf, gbuf, bbuf;
|
||||
if (rIdx >= 0) m_provider->readBandAsFloat(rIdx, rbuf);
|
||||
if (gIdx >= 0) m_provider->readBandAsFloat(gIdx, gbuf);
|
||||
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);
|
||||
if (!rbuf.empty()) stretchTo8bit(rbuf, r8, minV, maxV);
|
||||
if (!gbuf.empty()) stretchTo8bit(gbuf, g8, minV, maxV);
|
||||
if (!bbuf.empty()) stretchTo8bit(bbuf, b8, minV, maxV);
|
||||
|
||||
QImage out(w, h, QImage::Format_RGB888);
|
||||
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;
|
||||
unsigned char rc = (r8.size() > (size_t)idx) ? r8[idx] : 0;
|
||||
unsigned char gc = (g8.size() > (size_t)idx) ? g8[idx] : 0;
|
||||
unsigned char bc = (b8.size() > (size_t)idx) ? b8[idx] : 0;
|
||||
scan[x*3 + 0] = rc;
|
||||
scan[x*3 + 1] = gc;
|
||||
scan[x*3 + 2] = bc;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
29
HPPA/RasterRenderer.h
Normal file
29
HPPA/RasterRenderer.h
Normal file
@ -0,0 +1,29 @@
|
||||
#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);
|
||||
};
|
||||
167
HPPA/ReflectanceConversion.ui
Normal file
167
HPPA/ReflectanceConversion.ui
Normal file
@ -0,0 +1,167 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ReflectanceConversion_UI</class>
|
||||
<widget class="QDialog" name="ReflectanceConversion_UI">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>544</width>
|
||||
<height>177</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>反射率转换</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>影像</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>白板影像</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="imgPath_lineEdit">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="whiteImgPath_lineEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(255, 255, 255);</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QPushButton" name="imgSelect_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="whiteImgSelect_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="conversion_btn">
|
||||
<property name="text">
|
||||
<string>转换</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>191</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@ -286,6 +286,7 @@ void ResononNirImager::start_record()
|
||||
}
|
||||
|
||||
m_FileName2Save2 = m_FileName2Save + "_" + std::to_string(m_FileSavedCounter) + ".bil";
|
||||
QString filePath = QString::fromStdString(m_FileName2Save2);
|
||||
FILE* m_fImage = fopen(m_FileName2Save2.c_str(), "w+b");
|
||||
|
||||
size_t x;
|
||||
@ -353,7 +354,7 @@ void ResononNirImager::start_record()
|
||||
//ÿ<><C3BF>1s<31><73><EFBFBD><EFBFBD>һ<EFBFBD>ν<EFBFBD><CEBD><EFBFBD>ͼ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>
|
||||
if (m_iFrameCounter % (int)getFramerate() == 0)
|
||||
{
|
||||
emit PlotSignal();
|
||||
emit PlotSignal(m_FileSavedCounter, m_iFrameCounter, filePath);
|
||||
}
|
||||
|
||||
if (m_iFrameCounter >= m_iFrameNumber)
|
||||
@ -365,14 +366,14 @@ void ResononNirImager::start_record()
|
||||
}
|
||||
imagerStopCollect();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>λ<EFBFBD>ͼǰ<CDBC><C7B0>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//m_RgbImage
|
||||
emit PlotSignal(m_FileSavedCounter, -1, filePath);//<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>λ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>Է<EFBFBD><D4B7>ɼ<EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>ʵı<CAB5><C4B1><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>ȫ
|
||||
|
||||
m_bRecordControlState = false;
|
||||
WriteHdr();
|
||||
m_FileSavedCounter++;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>λ<EFBFBD>ͼǰ<CDBC><C7B0>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//m_RgbImage
|
||||
emit PlotSignal();//<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>λ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>Է<EFBFBD><D4B7>ɼ<EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>ʵı<CAB5><C4B1><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>ȫ
|
||||
|
||||
if (m_iFrameCounter >= m_iFrameNumber)
|
||||
{
|
||||
emit RecordFinishedSignal_WhenFrameNumberMeet();
|
||||
@ -399,6 +400,7 @@ void ResononNirImager::WriteHdr()
|
||||
outfile << "interleave = bil\n";
|
||||
outfile << "data type = 12\n";
|
||||
outfile << "bit depth = 12\n";
|
||||
outfile << "byte order = 0\n";
|
||||
outfile << "samples = " << getSampleCount() << "\n";
|
||||
outfile << "bands = " << getBandCount() << "\n";
|
||||
outfile << "lines = " << m_iFrameCounter << "\n";
|
||||
|
||||
639
HPPA/RobotArmControl.cpp
Normal file
639
HPPA/RobotArmControl.cpp
Normal file
@ -0,0 +1,639 @@
|
||||
#include "RobotArmControl.h"
|
||||
|
||||
RobotArmControl::RobotArmControl(QWidget* parent): QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
robotController = new RobotController(this);
|
||||
|
||||
connect(ui.get_task_list_btn, SIGNAL(clicked()), this, SLOT(getTaskList()));
|
||||
connect(ui.get_pose_btn, SIGNAL(clicked()), this, SLOT(getPose()));
|
||||
connect(ui.connect2arm_btn, SIGNAL(clicked()), this, SLOT(connectRobotArm()));
|
||||
|
||||
connect(ui.execute_task_btn, SIGNAL(clicked()), this, SLOT(executeTaskWithoutHyperImager()));
|
||||
connect(ui.pause_task_btn, SIGNAL(clicked()), this, SLOT(pauseTask()));
|
||||
connect(ui.continue_task_btn, SIGNAL(clicked()), this, SLOT(continueTask()));
|
||||
|
||||
robotMonitor = new EC8056;
|
||||
connect(robotMonitor, &EC8056::dataReceived, this, &RobotArmControl::monitorRobotArm);
|
||||
|
||||
|
||||
m_pModel = new QStringListModel(ui.taskList_listView);
|
||||
|
||||
ui.taskList_listView->setModel(m_pModel);
|
||||
}
|
||||
|
||||
RobotArmControl::~RobotArmControl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RobotArmControl::monitorRobotArm(const ECData& data)
|
||||
{
|
||||
double x = data.machinePose[0];
|
||||
double y = data.machinePose[1];
|
||||
double z = data.machinePose[2];
|
||||
|
||||
ui.pose_x_label->setText(QString::number(x));
|
||||
ui.pose_y_label->setText(QString::number(y));
|
||||
ui.pose_z_label->setText(QString::number(z));
|
||||
}
|
||||
|
||||
void RobotArmControl::onCommandResponse(QString str, const QJsonObject& response)
|
||||
{
|
||||
//qDebug() << "response:" << response;
|
||||
|
||||
QString re;
|
||||
if (response.contains("result"))
|
||||
{
|
||||
re = response["result"].toVariant().toString();
|
||||
ui.textEdit->append(str + " Result: " + re);
|
||||
}
|
||||
else if (response.contains("error"))
|
||||
{
|
||||
//auto delete11 = response["error"].toObject();
|
||||
//qDebug() << "response[\"error\"]:" << delete11;
|
||||
|
||||
auto errorStr = response["error"].toObject()["message"].toString();
|
||||
|
||||
ui.textEdit->append(str + " Error: " + errorStr);
|
||||
}
|
||||
}
|
||||
|
||||
void RobotArmControl::getTaskList()
|
||||
{
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
|
||||
QString pythonScript = QString::fromStdString(directory) + "\\get_jbi_filename.py";
|
||||
|
||||
QProcess process;
|
||||
|
||||
process.start("python.exe", QStringList() << pythonScript);
|
||||
process.waitForFinished();
|
||||
QString output = process.readAllStandardOutput();
|
||||
|
||||
QStringList files;
|
||||
//files.append("tc20250324down.jbi");
|
||||
//files.append("tc20250324circle.jbi");
|
||||
//files.append("tc20250324side.jbi");
|
||||
QStringList lines = output.split('\n', QString::SkipEmptyParts);
|
||||
for (const QString& line : lines)
|
||||
{
|
||||
files.append(line.trimmed());
|
||||
}
|
||||
|
||||
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//for (size_t i = 0; i < files.length(); i++)
|
||||
//{
|
||||
// int row = m_pModel->rowCount();
|
||||
// m_pModel->insertRow(row);
|
||||
// QModelIndex index = m_pModel->index(row);
|
||||
// m_pModel->setData(index, files[i]);
|
||||
//}
|
||||
|
||||
m_pModel->setStringList(files);
|
||||
}
|
||||
|
||||
void RobotArmControl::getPose()
|
||||
{
|
||||
QJsonObject response;
|
||||
bool x = robotController->getRobotPose(response);
|
||||
onCommandResponse("getPose", response);
|
||||
}
|
||||
|
||||
void RobotArmControl::connectRobotArm()
|
||||
{
|
||||
bool re = robotController->connectToRobot("192.168.1.100");
|
||||
robotMonitor->connectToHost("192.168.1.100");
|
||||
}
|
||||
|
||||
void RobotArmControl::executeTaskWithHyperImager()
|
||||
{
|
||||
QModelIndex index = ui.taskList_listView->currentIndex();
|
||||
if (-1 == index.row())
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>û<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>ļ<EFBFBD>
|
||||
ui.textEdit->append("Please select file on the left!");
|
||||
return;
|
||||
}
|
||||
QString fileName = index.data(Qt::DisplayRole).toString();
|
||||
|
||||
QJsonObject response;
|
||||
bool x;
|
||||
|
||||
x = robotController->checkJbiExist(fileName, response);
|
||||
onCommandResponse("checkJbiExist", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
x = robotController->setServoStatus(1, response);
|
||||
onCommandResponse("setServoStatus", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
x = robotController->runJbi(fileName, response, true);
|
||||
onCommandResponse("runJbi", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void RobotArmControl::executeTaskWithoutHyperImager()
|
||||
{
|
||||
QModelIndex index = ui.taskList_listView->currentIndex();
|
||||
if (-1 == index.row())
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>û<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>ļ<EFBFBD>
|
||||
ui.textEdit->append("Please select file on the left!");
|
||||
return;
|
||||
}
|
||||
QString fileName = index.data(Qt::DisplayRole).toString();
|
||||
|
||||
QJsonObject response;
|
||||
bool x;
|
||||
|
||||
x = robotController->checkJbiExist(fileName, response);
|
||||
onCommandResponse("checkJbiExist", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
x = robotController->setServoStatus(1, response);
|
||||
onCommandResponse("setServoStatus", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
x = robotController->runJbi(fileName, response, false);
|
||||
onCommandResponse("runJbi", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void RobotArmControl::pauseTask()
|
||||
{
|
||||
QJsonObject response;
|
||||
bool x;
|
||||
|
||||
x = robotController->pauseTask(response);
|
||||
onCommandResponse("pauseTask", response);
|
||||
}
|
||||
|
||||
void RobotArmControl::continueTask()
|
||||
{
|
||||
QJsonObject response;
|
||||
bool x;
|
||||
|
||||
x = robotController->continueTask(response);
|
||||
onCommandResponse("continueTask", response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RobotController::RobotController(QObject* parent) : QObject(parent), socket(new QTcpSocket(this))
|
||||
{
|
||||
//connect(socket, &QTcpSocket::readyRead, this, &RobotController::onReadyRead);
|
||||
|
||||
m_timer = new QTimer(this);
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(getPoint()));
|
||||
}
|
||||
|
||||
RobotController::~RobotController()
|
||||
{
|
||||
disconnectFromRobot();
|
||||
}
|
||||
|
||||
bool RobotController::connectToRobot(const QString& ip, quint16 port)
|
||||
{
|
||||
socket->setProxy(QNetworkProxy::NoProxy);
|
||||
|
||||
socket->connectToHost(ip, port);
|
||||
|
||||
if (!socket->waitForConnected(3000)) {
|
||||
qDebug() << "Connection failed:" << socket->errorString();
|
||||
return false;
|
||||
}
|
||||
qDebug() << "Connected successfully!";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RobotController::disconnectFromRobot()
|
||||
{
|
||||
if (socket->isOpen())
|
||||
{
|
||||
socket->close();
|
||||
}
|
||||
}
|
||||
|
||||
bool RobotController::processResponse(QJsonObject response, QString& result)
|
||||
{
|
||||
//qDebug() << "response:" << response;
|
||||
|
||||
if (response.contains("result"))
|
||||
{
|
||||
result = response["result"].toVariant().toString();
|
||||
|
||||
//qDebug() << "result1:" << result;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (response.contains("error"))
|
||||
{
|
||||
result = response["error"].toObject()["message"].toString();
|
||||
//qDebug() << "result2:" << result;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool RobotController::processResponse_getJbiState(QJsonObject response, QString& result)
|
||||
{
|
||||
//qDebug() << "response:" << response;
|
||||
|
||||
if (response.contains("result"))
|
||||
{
|
||||
QString resultStr = response["result"].toString();
|
||||
|
||||
QJsonDocument resultDoc = QJsonDocument::fromJson(resultStr.toUtf8());
|
||||
QJsonObject resultObj = resultDoc.object();
|
||||
//qDebug() << "resultObj:" << resultObj;
|
||||
|
||||
int runState = resultObj["runState"].toInt();
|
||||
//qDebug() << "runState:" << runState;
|
||||
|
||||
result = QString::number(runState);
|
||||
//qDebug() << "result:" << result;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (response.contains("error"))
|
||||
{
|
||||
result = response["error"].toObject()["message"].toString();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::getPoint()
|
||||
{
|
||||
QJsonObject response;
|
||||
getJbiState(response);//0 ֹͣ״̬,1 <20><>ͣ״̬,2 <20><>ͣ״̬,3 <20><><EFBFBD><EFBFBD>״̬,4 <20><><EFBFBD><EFBFBD>״̬
|
||||
QString result;
|
||||
bool x = processResponse_getJbiState(response, result);
|
||||
//qDebug() << "getJbiState:" << result;
|
||||
|
||||
if (result.toInt() != 3)
|
||||
{
|
||||
m_timer->stop();
|
||||
|
||||
m_iCurrentJbiJobLine = 0;
|
||||
m_iFileCounter = 0;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>źţ<C5BA><C5A3><EFBFBD><EFBFBD><EFBFBD>ֹͣ<CDA3>ɼ<EFBFBD>
|
||||
emit hsiRecordSignal(-1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject response2;
|
||||
getCurrentJobLine(response2);
|
||||
QString result2;
|
||||
bool x2 = processResponse(response2, result2);
|
||||
|
||||
int m_iCurrentJbiJobLine_tmp = result2.toInt();
|
||||
|
||||
|
||||
if (m_iCurrentJbiJobLine_tmp != m_iCurrentJbiJobLine)
|
||||
{
|
||||
m_iFileCounter++;
|
||||
|
||||
qDebug() << "Changed! CurrentJobLine:" << m_iCurrentJbiJobLine_tmp;
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>źţ<C5BA><C5A3><EFBFBD><EFBFBD><EFBFBD>ֹͣ<CDA3>ɼ<EFBFBD>
|
||||
emit hsiRecordSignal(-1);
|
||||
|
||||
m_iCurrentJbiJobLine = m_iCurrentJbiJobLine_tmp;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>źţ<C5BA><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ɼ<EFBFBD>
|
||||
emit hsiRecordSignal(m_iFileCounter);
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::sendCommand(const QString& cmd, const QJsonValue& params, int id)
|
||||
{
|
||||
QJsonObject request;
|
||||
request["method"] = cmd;
|
||||
request["params"] = params;
|
||||
request["jsonrpc"] = "2.0";
|
||||
request["id"] = id;
|
||||
|
||||
QJsonDocument doc(request);
|
||||
QByteArray data = doc.toJson(QJsonDocument::Compact) + "\n";
|
||||
//qDebug() << "send command:" << data.constData();
|
||||
|
||||
socket->write(data);
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
bool RobotController::onReadyRead(QJsonObject& re)
|
||||
{
|
||||
QByteArray data = socket->readAll();
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||||
if (!doc.isNull() && doc.isObject())
|
||||
{
|
||||
re = doc.object();
|
||||
//qDebug() << "Received all:" << re;
|
||||
|
||||
if (re.contains("result"))
|
||||
{
|
||||
//qDebug() << "Received result:" << re["result"].toVariant();
|
||||
return true;
|
||||
}
|
||||
else if (re.contains("error"))
|
||||
{
|
||||
//qDebug() << "Received error:" << re["error"];
|
||||
return false;
|
||||
}
|
||||
|
||||
//emit commandResponse(true, doc.object());
|
||||
}
|
||||
else
|
||||
{
|
||||
//emit commandResponse(false, QJsonObject());
|
||||
|
||||
re = QJsonObject();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool RobotController::getRobotPose(QJsonObject& re)
|
||||
{
|
||||
sendCommand("getRobotPose");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::getRobotState(QJsonObject& re)
|
||||
{
|
||||
sendCommand("getRobotState");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::getJbiState(QJsonObject& re)
|
||||
{
|
||||
sendCommand("getJbiState");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::getCurrentJobLine(QJsonObject& re)
|
||||
{
|
||||
sendCommand("getCurrentJobLine");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::getRobotMode(QJsonObject& re)
|
||||
{
|
||||
sendCommand("getRobotMode");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::checkJbiExist(const QString& jbiFilename, QJsonObject& re)
|
||||
{
|
||||
QJsonObject paramsRunJbi;
|
||||
paramsRunJbi["filename"] = jbiFilename;//ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ṹ
|
||||
|
||||
sendCommand("checkJbiExist", paramsRunJbi);
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::setServoStatus(int status, QJsonObject& re)
|
||||
{
|
||||
QJsonObject params_set_servo_status;
|
||||
params_set_servo_status["status"] = status;//ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ṹ
|
||||
|
||||
sendCommand("set_servo_status", params_set_servo_status);
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::runJbi(const QString& jbiFilename, QJsonObject& re, bool isRecordHsi)
|
||||
{
|
||||
QJsonObject paramsRunJbi;
|
||||
paramsRunJbi["filename"] = jbiFilename;//ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ṹ
|
||||
|
||||
sendCommand("runJbi", paramsRunJbi);
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
if (isRecordHsi)
|
||||
{
|
||||
m_timer->start(1000);
|
||||
}
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::pauseTask(QJsonObject& re)
|
||||
{
|
||||
sendCommand("pause");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::run(QJsonObject& re)
|
||||
{
|
||||
sendCommand("run");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::continueTask(QJsonObject& re)
|
||||
{
|
||||
sendCommand("run");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::setRobotPowerStatus(int status, QJsonObject& re)
|
||||
{
|
||||
sendCommand("set_robot_power_status", QJsonArray{ status });
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
EC8056::EC8056(QObject* parent) : QObject(parent), socket(new QTcpSocket(this))
|
||||
{
|
||||
connect(socket, &QTcpSocket::readyRead, this, &EC8056::onReadyRead);
|
||||
/*connect(socket, QOverload<QAbstractSocket::SocketError>::of(&QTcpSocket::errorOccurred),
|
||||
this, &EC8056::onSocketError);*/
|
||||
//connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||
// this, SLOT(onSocketError(QAbstractSocket::SocketError)));
|
||||
}
|
||||
|
||||
void EC8056::connectToHost(const QString& host, quint16 port)
|
||||
{
|
||||
socket->setProxy(QNetworkProxy::NoProxy);
|
||||
|
||||
socket->connectToHost(QHostAddress(host), port);
|
||||
|
||||
if (!socket->waitForConnected(3000)) {
|
||||
qDebug() << "Connection failed:" << socket->errorString();
|
||||
return;
|
||||
}
|
||||
qDebug() << "Connected successfully!";
|
||||
}
|
||||
|
||||
quint8 EC8056::readUInt8(const QByteArray& buf, int& offset)
|
||||
{
|
||||
return static_cast<quint8>(buf[offset++]);
|
||||
}
|
||||
|
||||
quint32 EC8056::readUInt32(const QByteArray& buf, int& offset)
|
||||
{
|
||||
quint32 val;
|
||||
memcpy(&val, buf.constData() + offset, sizeof(val));
|
||||
offset += sizeof(val);
|
||||
return qFromBigEndian(val);
|
||||
}
|
||||
|
||||
qint32 EC8056::readInt32(const QByteArray& buf, int& offset)
|
||||
{
|
||||
qint32 val;
|
||||
memcpy(&val, buf.constData() + offset, sizeof(val));
|
||||
offset += sizeof(val);
|
||||
return qFromBigEndian(val);
|
||||
}
|
||||
|
||||
quint64 EC8056::readUInt64(const QByteArray& buf, int& offset)
|
||||
{
|
||||
quint64 val;
|
||||
memcpy(&val, buf.constData() + offset, sizeof(val));
|
||||
offset += sizeof(val);
|
||||
return qFromBigEndian(val);
|
||||
}
|
||||
|
||||
double EC8056::readDouble(const QByteArray& buf, int& offset)
|
||||
{
|
||||
QByteArray b = buf.mid(offset, sizeof(double));
|
||||
offset += sizeof(double);
|
||||
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian)
|
||||
std::reverse(b.begin(), b.end());
|
||||
|
||||
double val;
|
||||
memcpy(&val, b.constData(), sizeof(double));
|
||||
return val;
|
||||
}
|
||||
|
||||
void EC8056::onReadyRead()
|
||||
{
|
||||
buffer.append(socket->readAll());
|
||||
|
||||
if (buffer.size() < 1024)
|
||||
return;
|
||||
|
||||
int offset = 0;
|
||||
ECData data;
|
||||
|
||||
data.msgSize = readUInt32(buffer, offset);
|
||||
offset = 1020;
|
||||
data.matchingWord = readUInt32(buffer, offset);
|
||||
|
||||
if ((data.msgSize == 1024)/* && (data.matchingWord == 3967833836)*/)
|
||||
{
|
||||
offset = 0;
|
||||
|
||||
data.msgSize = readUInt32(buffer, offset);
|
||||
data.timeStamp = readUInt64(buffer, offset);
|
||||
data.auto_cycle = readUInt8(buffer, offset);
|
||||
|
||||
for (int i = 0; i < 8; ++i) data.machinePos[i] = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 6; ++i) data.machinePose[i] = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 6; ++i) data.machineUserPose[i] = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 8; ++i) data.torque[i] = readDouble(buffer, offset);
|
||||
|
||||
data.robotState = readUInt32(buffer, offset);
|
||||
data.servoReady = readUInt32(buffer, offset);
|
||||
data.can_motor_run = readUInt32(buffer, offset);
|
||||
|
||||
for (int i = 0; i < 8; ++i) data.motor_speed[i] = readInt32(buffer, offset);
|
||||
|
||||
data.robotMode = readUInt32(buffer, offset);
|
||||
|
||||
for (int i = 0; i < 3; ++i) data.analog_ioInput[i] = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 5; ++i) data.analog_ioOutput[i] = readDouble(buffer, offset);
|
||||
|
||||
data.digital_ioInput = readUInt64(buffer, offset);
|
||||
data.digital_ioOutput = readUInt64(buffer, offset);
|
||||
|
||||
data.collision = readUInt8(buffer, offset);
|
||||
|
||||
for (int i = 0; i < 6; ++i) data.machineFlangePose[i] = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 6; ++i) data.machineUserFlangePose[i] = readDouble(buffer, offset);
|
||||
|
||||
data.emergencyStopState = readUInt8(buffer, offset);
|
||||
data.tcpSpeed = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 8; ++i) data.joIntSpeed[i] = readDouble(buffer, offset);
|
||||
data.tcpAcc = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 8; ++i) data.joIntAcc[i] = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 6; ++i) data.joIntTemperature[i] = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 6; ++i) data.joIntTorque[i] = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 6; ++i) data.extJoIntTorques[i] = readDouble(buffer, offset);
|
||||
for (int i = 0; i < 6; ++i) data.exTcpForceIntool[i] = readDouble(buffer, offset);
|
||||
|
||||
data.dragState = readUInt8(buffer, offset);
|
||||
data.sensor_connected_state = readUInt8(buffer, offset);
|
||||
data.reserved = readUInt8(buffer, offset);
|
||||
data.matchingWord = readUInt32(buffer, offset);
|
||||
|
||||
/*if (data.msgSize != 1024 || data.matchingWord != 0xec8056ec) {
|
||||
buffer.clear();
|
||||
emit errorOccurred("Invalid packet received");
|
||||
return;
|
||||
}*/
|
||||
|
||||
emit dataReceived(data);
|
||||
}
|
||||
|
||||
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
void EC8056::onSocketError(QAbstractSocket::SocketError socketError)
|
||||
{
|
||||
Q_UNUSED(socketError)
|
||||
emit errorOccurred(socket->errorString());
|
||||
}
|
||||
164
HPPA/RobotArmControl.h
Normal file
164
HPPA/RobotArmControl.h
Normal file
@ -0,0 +1,164 @@
|
||||
#pragma once
|
||||
#include <qdialog.h>
|
||||
#include <QTcpSocket>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
#include <QNetworkProxy>
|
||||
#include <QtEndian>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QAuthenticator>
|
||||
#include <QDebug>
|
||||
#include <QRegularExpression>
|
||||
#include <QProcess>
|
||||
#include <QStringListModel>
|
||||
#include <QTimer>
|
||||
|
||||
#include "ui_RobotArmControl.h"
|
||||
#include "fileOperation.h"
|
||||
|
||||
|
||||
struct ECData
|
||||
{
|
||||
quint32 msgSize;
|
||||
quint64 timeStamp;
|
||||
quint8 auto_cycle;
|
||||
double machinePos[8];//<2F>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
double machinePose[6];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
double machineUserPose[6];//<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
double torque[8];//<2F>ؽڶ<DAB6><EEB6A8><EFBFBD>ذٷֱ<D9B7>
|
||||
quint32 robotState;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
quint32 servoReady;//<2F>ŷ<EFBFBD>ʹ<EFBFBD><CAB9>״̬
|
||||
quint32 can_motor_run;//ͬ<><CDAC>״̬
|
||||
qint32 motor_speed[8];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
|
||||
quint32 robotMode;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||||
double analog_ioInput[3];//ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
double analog_ioOutput[5];//ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
quint64 digital_ioInput;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĶ<DDB5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
||||
quint64 digital_ioOutput;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĶ<DDB5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
||||
quint8 collision;//<2F><>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD>״̬
|
||||
double machineFlangePose[6];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µķ<C2B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
double machineUserFlangePose[6];//<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µķ<C2B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
quint8 emergencyStopState;//<2F><>ǰ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڼ<EFBFBD>ͣ״̬
|
||||
double tcpSpeed;//tcp<63>˶<EFBFBD><CBB6>ٶ<EFBFBD>
|
||||
double joIntSpeed[8];//<2F>ؽ<EFBFBD><D8BD>˶<EFBFBD><CBB6>¸<EFBFBD><C2B8>ؽ<EFBFBD><D8BD>˶<EFBFBD><CBB6>ٶ<EFBFBD>
|
||||
double tcpAcc;//tcp<63><70><EFBFBD>ٶ<EFBFBD>
|
||||
double joIntAcc[8];//<2F>ؽ<EFBFBD><D8BD>˶<EFBFBD><CBB6>¸<EFBFBD><C2B8>ؽڼ<D8BD><DABC>ٶ<EFBFBD>
|
||||
double joIntTemperature[6];//<2F>¶<EFBFBD>
|
||||
double joIntTorque[6];//<2F><><EFBFBD><EFBFBD>Ť<EFBFBD><C5A4>
|
||||
double extJoIntTorques[6];//<2F>ⲿ<EFBFBD>ؽ<EFBFBD>Ť<EFBFBD><C5A4>ֵ
|
||||
double exTcpForceIntool[6];//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>µ<EFBFBD><C2B5>ⲿĩ<E2B2BF><C4A9><EFBFBD><EFBFBD>/<2F><><EFBFBD>ع<EFBFBD><D8B9><EFBFBD>ֵ
|
||||
quint8 dragState;//<2F>϶<EFBFBD>ʹ<EFBFBD><CAB9>״̬
|
||||
quint8 sensor_connected_state;//<2F><><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
quint8 reserved;
|
||||
quint32 matchingWord;
|
||||
};
|
||||
|
||||
class EC8056 : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EC8056(QObject* parent = nullptr);
|
||||
void connectToHost(const QString& host, quint16 port= 8056);
|
||||
|
||||
signals:
|
||||
void dataReceived(const ECData& data);
|
||||
void errorOccurred(const QString& error);
|
||||
|
||||
private slots:
|
||||
void onReadyRead();
|
||||
void onSocketError(QAbstractSocket::SocketError socketError);
|
||||
|
||||
private:
|
||||
QTcpSocket* socket;
|
||||
QByteArray buffer;
|
||||
|
||||
double readDouble(const QByteArray& buf, int& offset);
|
||||
quint64 readUInt64(const QByteArray& buf, int& offset);
|
||||
quint32 readUInt32(const QByteArray& buf, int& offset);
|
||||
qint32 readInt32(const QByteArray& buf, int& offset);
|
||||
quint8 readUInt8(const QByteArray& buf, int& offset);
|
||||
};
|
||||
|
||||
class RobotController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RobotController(QObject* parent = nullptr);
|
||||
~RobotController();
|
||||
|
||||
bool connectToRobot(const QString& ip, quint16 port = 8055);
|
||||
void disconnectFromRobot();
|
||||
void sendCommand(const QString& cmd, const QJsonValue& params = QJsonArray(), int id = 1);
|
||||
bool processResponse(QJsonObject response, QString& re);
|
||||
bool processResponse_getJbiState(QJsonObject response, QString& result);
|
||||
|
||||
bool getRobotPose(QJsonObject& re);
|
||||
bool getRobotState(QJsonObject& re);//ֹͣ״̬ 0<><30><EFBFBD><EFBFBD>ͣ״̬ 1<><31><EFBFBD><EFBFBD>ͣ״̬ 2<><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ 3<><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ 4<><34><EFBFBD><EFBFBD>ײ״̬ 5
|
||||
bool getJbiState(QJsonObject& re);//0 ֹͣ״̬,1 <20><>ͣ״̬,2 <20><>ͣ״̬,3 <20><><EFBFBD><EFBFBD>״̬,4 <20><><EFBFBD><EFBFBD>״̬
|
||||
bool getCurrentJobLine(QJsonObject& re);
|
||||
bool getRobotMode(QJsonObject& re);//ʾ<><CABE>ģʽ 0<><30><EFBFBD>Զ<EFBFBD>ģʽ 1<><31>Զ<EFBFBD><D4B6>ģʽ 2
|
||||
bool checkJbiExist(const QString& jbiFilename, QJsonObject& re);
|
||||
bool setServoStatus(int status, QJsonObject& re);
|
||||
bool runJbi(const QString& jbiFilename, QJsonObject& re, bool isRecordHsi);
|
||||
bool pauseTask(QJsonObject& re);
|
||||
bool run(QJsonObject& re);
|
||||
bool continueTask(QJsonObject& re);
|
||||
bool setRobotPowerStatus(int status, QJsonObject& re);
|
||||
|
||||
bool onReadyRead(QJsonObject& re);
|
||||
|
||||
private:
|
||||
QTcpSocket* socket;
|
||||
|
||||
QTimer* m_timer;
|
||||
int m_iTimeout = 3000;
|
||||
int m_iCurrentJbiJobLine = 0;
|
||||
int m_iFileCounter = 0;
|
||||
|
||||
signals:
|
||||
void commandResponse(bool success, const QJsonObject& response);
|
||||
void hsiRecordSignal(int);
|
||||
|
||||
private slots:
|
||||
void getPoint();
|
||||
};
|
||||
|
||||
class RobotArmControl : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RobotArmControl(QWidget* parent = nullptr);
|
||||
~RobotArmControl();
|
||||
RobotController* robotController;
|
||||
|
||||
void onCommandResponse(QString str, const QJsonObject& response);
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
void getTaskList();
|
||||
void getPose();
|
||||
|
||||
void connectRobotArm();
|
||||
void executeTaskWithHyperImager();
|
||||
void executeTaskWithoutHyperImager();
|
||||
void pauseTask();
|
||||
void continueTask();
|
||||
|
||||
void monitorRobotArm(const ECData& data);
|
||||
|
||||
signals:
|
||||
//void Opened();
|
||||
//void Closed();
|
||||
|
||||
private:
|
||||
Ui::RobotArmControl_UI ui;
|
||||
|
||||
EC8056* robotMonitor;
|
||||
QStringListModel* m_pModel;
|
||||
};
|
||||
138
HPPA/RobotArmControl.ui
Normal file
138
HPPA/RobotArmControl.ui
Normal file
@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RobotArmControl_UI</class>
|
||||
<widget class="QDialog" name="RobotArmControl_UI">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>424</width>
|
||||
<height>364</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="pause_task_btn">
|
||||
<property name="text">
|
||||
<string>暂停任务</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="connect2arm_btn">
|
||||
<property name="text">
|
||||
<string>连接机械臂</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="execute_task_btn">
|
||||
<property name="text">
|
||||
<string>执行任务</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="get_pose_btn">
|
||||
<property name="text">
|
||||
<string>获取pose</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QPushButton" name="continue_task_btn">
|
||||
<property name="text">
|
||||
<string>继续任务</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QTextEdit" name="textEdit"/>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="6">
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="horizontalSpacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="get_task_list_btn">
|
||||
<property name="text">
|
||||
<string>获取任务列表</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QListView" name="taskList_listView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="pose_z_label">
|
||||
<property name="text">
|
||||
<string>z</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="pose_x_label">
|
||||
<property name="text">
|
||||
<string>x</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="pose_y_label">
|
||||
<property name="text">
|
||||
<string>y</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
62
HPPA/TabManager.cpp
Normal file
62
HPPA/TabManager.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include "TabManager.h"
|
||||
|
||||
TabManager::TabManager(QTabWidget* tabWidget, QObject* parent)
|
||||
: QObject(parent),
|
||||
m_tabWidget(tabWidget)
|
||||
{
|
||||
Q_ASSERT(m_tabWidget);
|
||||
}
|
||||
|
||||
void TabManager::hideTab(QWidget* page)
|
||||
{
|
||||
if (!page || !m_tabWidget)
|
||||
return;
|
||||
|
||||
int index = m_tabWidget->indexOf(page);
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
if (m_hiddenTabs.contains(page))
|
||||
return;
|
||||
|
||||
TabInfo info;
|
||||
info.index = index;
|
||||
info.text = m_tabWidget->tabText(index);
|
||||
info.icon = m_tabWidget->tabIcon(index);
|
||||
info.toolTip = m_tabWidget->tabToolTip(index);
|
||||
|
||||
m_hiddenTabs.insert(page, info);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5>ǵ<EFBFBD>ǰҳ<C7B0><D2B3><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>հ<EFBFBD>
|
||||
if (m_tabWidget->currentIndex() == index)
|
||||
{
|
||||
int next = (index > 0) ? index - 1 : 0;
|
||||
m_tabWidget->setCurrentIndex(next);
|
||||
}
|
||||
|
||||
m_tabWidget->removeTab(index);
|
||||
emit tabHidden(page);
|
||||
}
|
||||
|
||||
void TabManager::showTab(QWidget* page)
|
||||
{
|
||||
if (!page || !m_tabWidget)
|
||||
return;
|
||||
|
||||
if (!m_hiddenTabs.contains(page))
|
||||
return;
|
||||
|
||||
TabInfo info = m_hiddenTabs.take(page);
|
||||
|
||||
//int insertIndex = qMin(info.index, m_tabWidget->count());
|
||||
int insertIndex = m_tabWidget->count();
|
||||
m_tabWidget->insertTab(insertIndex, page, info.icon, info.text);
|
||||
m_tabWidget->setTabToolTip(insertIndex, info.toolTip);
|
||||
|
||||
emit tabShown(page);
|
||||
}
|
||||
|
||||
bool TabManager::isHidden(QWidget* page) const
|
||||
{
|
||||
return m_hiddenTabs.contains(page);
|
||||
}
|
||||
32
HPPA/TabManager.h
Normal file
32
HPPA/TabManager.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QTabWidget>
|
||||
#include <QHash>
|
||||
|
||||
class TabManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TabManager(QTabWidget* tabWidget, QObject* parent = nullptr);
|
||||
|
||||
void hideTab(QWidget* page);
|
||||
void showTab(QWidget* page);
|
||||
bool isHidden(QWidget* page) const;
|
||||
|
||||
signals:
|
||||
void tabHidden(QWidget* page);
|
||||
void tabShown(QWidget* page);
|
||||
|
||||
private:
|
||||
struct TabInfo
|
||||
{
|
||||
int index;
|
||||
QString text;
|
||||
QIcon icon;
|
||||
QString toolTip;
|
||||
};
|
||||
|
||||
QTabWidget* m_tabWidget = nullptr;
|
||||
QHash<QWidget*, TabInfo> m_hiddenTabs;
|
||||
};
|
||||
503
HPPA/TwoMotorControl.cpp
Normal file
503
HPPA/TwoMotorControl.cpp
Normal file
@ -0,0 +1,503 @@
|
||||
#include "TwoMotorControl.h"
|
||||
|
||||
TwoMotorControl::TwoMotorControl(QWidget* parent) : QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
ui.recordLine_tableWidget->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
ui.recordLine_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);//设置选择行为,以行为单位
|
||||
//ui.recordLine_tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);//设置选择模式,选择单行
|
||||
//QHeaderView* headerView = ui.recordLine_tableWidget->verticalHeader();
|
||||
//headerView->setHidden(true);//去除左边默认自带序列号
|
||||
|
||||
connect(this->ui.connect_btn, SIGNAL(pressed()), this, SLOT(onConnectMotor()));
|
||||
|
||||
connect(ui.addRecordLine_btn, SIGNAL(clicked()), this, SLOT(onAddRecordLine_btn()));
|
||||
connect(ui.removeRecordLine_btn, SIGNAL(clicked()), this, SLOT(onRemoveRecordLine_btn()));
|
||||
connect(ui.deleteRecordLine_btn, SIGNAL(clicked()), this, SLOT(onDeleteRecordLine_btn()));
|
||||
connect(ui.saveRecordLine2File_btn, SIGNAL(clicked()), this, SLOT(onSaveRecordLine2File_btn()));
|
||||
connect(ui.readRecordLineFile_btn, SIGNAL(clicked()), this, SLOT(onReadRecordLineFile_btn()));
|
||||
}
|
||||
|
||||
void TwoMotorControl::setImager(ImagerOperationBase* imager)
|
||||
{
|
||||
m_Imager = imager;
|
||||
}
|
||||
|
||||
void TwoMotorControl::setPosFileName(QString posFileName)
|
||||
{
|
||||
isWritePosFile = true;
|
||||
m_posFileName = posFileName;
|
||||
m_posFileHandle = fopen(posFileName.toStdString().c_str(), "w+");
|
||||
}
|
||||
|
||||
bool TwoMotorControl::getState()
|
||||
{
|
||||
QEventLoop loop;
|
||||
bool tmp = false;
|
||||
bool received = false;
|
||||
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
|
||||
QMetaObject::Connection conn = QObject::connect(
|
||||
m_coordinator, &TwoMotionCaptureCoordinator::recordState,
|
||||
[&](bool state) {
|
||||
tmp = state;
|
||||
received = true;
|
||||
loop.quit();
|
||||
});
|
||||
|
||||
QMetaObject::invokeMethod(m_coordinator, "getRecordState", Qt::QueuedConnection);
|
||||
timer.start(3000);
|
||||
|
||||
loop.exec();
|
||||
|
||||
disconnect(conn);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void TwoMotorControl::record_dark()
|
||||
{
|
||||
double s = ui.xmotor_move_speed_lineEdit->text().toDouble();
|
||||
|
||||
if (m_darkCaptureCoordinator == nullptr)
|
||||
{
|
||||
m_darkCaptureCoordinator = new DarkAndWhiteCaptureCoordinator(0, m_multiAxisController, m_Imager);
|
||||
}
|
||||
|
||||
m_darkCaptureCoordinator->startStepMotion(s);
|
||||
}
|
||||
|
||||
void TwoMotorControl::record_white()
|
||||
{
|
||||
double s = ui.xmotor_move_speed_lineEdit->text().toDouble();
|
||||
|
||||
if (m_whiteCaptureCoordinator == nullptr)
|
||||
{
|
||||
m_whiteCaptureCoordinator = new DarkAndWhiteCaptureCoordinator(1, m_multiAxisController, m_Imager);
|
||||
}
|
||||
|
||||
m_whiteCaptureCoordinator->startStepMotion(s);
|
||||
}
|
||||
|
||||
void TwoMotorControl::run()
|
||||
{
|
||||
if (m_coordinator==nullptr)
|
||||
{
|
||||
qRegisterMetaType<QVector<PathLine>>("QVector<PathLine>");
|
||||
m_coordinator = new TwoMotionCaptureCoordinator(m_multiAxisController, m_Imager);
|
||||
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()));
|
||||
m_coordinatorThread.start();
|
||||
}
|
||||
|
||||
if (getState())
|
||||
{
|
||||
//std::cout << "已经开始运行,请勿重复点击!!!!!!!!" << std::endl;
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("已经开始运行,请勿重复点击!!!!!!!!!"));
|
||||
return;
|
||||
}
|
||||
|
||||
QVector<PathLine> pathLines;
|
||||
int rowCount = ui.recordLine_tableWidget->rowCount();
|
||||
//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(240, 240, 240));
|
||||
}
|
||||
}
|
||||
|
||||
emit start(pathLines);
|
||||
}
|
||||
|
||||
void TwoMotorControl::stop()
|
||||
{
|
||||
emit stopSignal();
|
||||
}
|
||||
|
||||
TwoMotorControl::~TwoMotorControl()
|
||||
{
|
||||
m_motorThread.quit();
|
||||
m_motorThread.wait();
|
||||
|
||||
m_coordinatorThread.quit();
|
||||
m_coordinatorThread.wait();
|
||||
}
|
||||
|
||||
void TwoMotorControl::onConnectMotor()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
QString configFilePath = QString::fromStdString(directory) + "\\twoMotorConfigFile.cfg";
|
||||
|
||||
m_multiAxisController = new IrisMultiMotorController(configFilePath);
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QString::fromLocal8Bit("请连接马达!"));
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
m_multiAxisController->moveToThread(&m_motorThread);
|
||||
connect(&m_motorThread, SIGNAL(finished()), m_multiAxisController, SLOT(deleteLater()));
|
||||
|
||||
connect(this->ui.xmotor_right_btn, SIGNAL(pressed()), this, SLOT(onxMotorRight()));
|
||||
connect(this->ui.xmotor_right_btn, SIGNAL(released()), this, SLOT(onxMotorStop()));
|
||||
connect(this->ui.xmotor_left_btn, SIGNAL(pressed()), this, SLOT(onxMotorLeft()));
|
||||
connect(this->ui.xmotor_left_btn, SIGNAL(released()), this, SLOT(onxMotorStop()));
|
||||
|
||||
connect(this->ui.ymotor_forward_btn, SIGNAL(pressed()), this, SLOT(onyMotorforward()));
|
||||
connect(this->ui.ymotor_forward_btn, SIGNAL(released()), this, SLOT(onyMotorStop()));
|
||||
connect(this->ui.ymotor_backward_btn, SIGNAL(pressed()), this, SLOT(onyMotorbackward()));
|
||||
connect(this->ui.ymotor_backward_btn, SIGNAL(released()), this, SLOT(onyMotorStop()));
|
||||
|
||||
connect(this->ui.move2loc_x_pushButton, SIGNAL(pressed()), this, SLOT(onxMove2Loc()));
|
||||
connect(this->ui.move2loc_y_pushButton, SIGNAL(pressed()), this, SLOT(onyMove2Loc()));
|
||||
|
||||
connect(m_multiAxisController, SIGNAL(broadcastLocationSignal(std::vector<double>)), this, SLOT(displayRealTimeLoc(std::vector<double>)));
|
||||
|
||||
connect(this, SIGNAL(moveSignal(int, bool, double, int)), m_multiAxisController, SLOT(move(int, bool, double, int)));
|
||||
connect(this, SIGNAL(move2LocSignal(int, double, double, int)), m_multiAxisController, SLOT(moveTo(int, double, double, int)));
|
||||
connect(this, SIGNAL(stopSignal(int)), m_multiAxisController, SLOT(stop(int)));
|
||||
|
||||
connect(this->ui.zero_start_btn, SIGNAL(released()), this, SLOT(zeroStart()));
|
||||
connect(this, SIGNAL(zeroStartSignal(int)), m_multiAxisController, SLOT(zeroStart(int)));
|
||||
|
||||
connect(this->ui.rangeMeasurement_btn, SIGNAL(pressed()), this, SLOT(on_rangeMeasurement()));
|
||||
connect(this, SIGNAL(rangeMeasurement(int, double, int)), m_multiAxisController, SLOT(rangeMeasurement(int, double, int)));
|
||||
|
||||
connect(this, SIGNAL(testConnectivitySignal(int, int)), m_multiAxisController, SLOT(testConnectivity(int, int)));
|
||||
connect(m_multiAxisController, SIGNAL(broadcastConnectivity(std::vector<int>)), this, SLOT(display_motors_connectivity(std::vector<int>)));
|
||||
|
||||
m_motorThread.start();
|
||||
emit testConnectivitySignal(0, 1000);
|
||||
emit testConnectivitySignal(1, 1000);
|
||||
}
|
||||
|
||||
void TwoMotorControl::receiveStartRecordLineNum(int lineNum)
|
||||
{
|
||||
emit startLineNumSignal(lineNum);
|
||||
for (size_t i = 0; i < ui.recordLine_tableWidget->columnCount(); i++)
|
||||
{
|
||||
ui.recordLine_tableWidget->item(lineNum, i)->setBackgroundColor(QColor(255, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void TwoMotorControl::receiveFinishRecordLineNum(int lineNum)
|
||||
{
|
||||
for (size_t i = 0; i < ui.recordLine_tableWidget->columnCount(); i++)
|
||||
{
|
||||
ui.recordLine_tableWidget->item(lineNum, i)->setBackgroundColor(QColor(0, 255, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void TwoMotorControl::onSequenceComplete()
|
||||
{
|
||||
isWritePosFile = false;
|
||||
fclose(m_posFileHandle);
|
||||
|
||||
emit sequenceComplete();
|
||||
}
|
||||
|
||||
void TwoMotorControl::display_motors_connectivity(std::vector<int> connectivity)
|
||||
{
|
||||
//std::cout << "-----------------------------------"<<connectivity.size()<< std::endl;
|
||||
if (connectivity[0])
|
||||
{
|
||||
this->ui.xMotorStateLabel->setStyleSheet("QLabel{background-color:rgb(0,255,0);}");
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ui.xMotorStateLabel->setStyleSheet("QLabel{background-color:rgb(255,0,0);}");
|
||||
}
|
||||
|
||||
if (connectivity[1])
|
||||
{
|
||||
this->ui.yMotorStateLabel->setStyleSheet("QLabel{background-color:rgb(0,255,0);}");
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ui.yMotorStateLabel->setStyleSheet("QLabel{background-color:rgb(255,0,0);}");
|
||||
}
|
||||
}
|
||||
|
||||
void TwoMotorControl::onxMotorRight()
|
||||
{
|
||||
double s = ui.xmotor_move_speed_lineEdit->text().toDouble();
|
||||
|
||||
emit moveSignal(0, false, s, 1000);
|
||||
}
|
||||
|
||||
void TwoMotorControl::onxMotorLeft()
|
||||
{
|
||||
double s = ui.xmotor_move_speed_lineEdit->text().toDouble();
|
||||
|
||||
emit moveSignal(0, true, s, 1000);
|
||||
}
|
||||
|
||||
void TwoMotorControl::onxMotorStop()
|
||||
{
|
||||
emit stopSignal(0);
|
||||
}
|
||||
|
||||
void TwoMotorControl::onyMotorforward()
|
||||
{
|
||||
double s = ui.ymotor_move_speed_lineEdit->text().toDouble();
|
||||
|
||||
emit moveSignal(1, false, s, 1000);
|
||||
}
|
||||
|
||||
void TwoMotorControl::onyMotorbackward()
|
||||
{
|
||||
double s = ui.ymotor_move_speed_lineEdit->text().toDouble();
|
||||
|
||||
emit moveSignal(1, true, s, 1000);
|
||||
}
|
||||
|
||||
void TwoMotorControl::onyMotorStop()
|
||||
{
|
||||
emit stopSignal(1);
|
||||
}
|
||||
|
||||
void TwoMotorControl::onxMove2Loc()
|
||||
{
|
||||
double s = ui.xmotor_move_speed_lineEdit->text().toDouble();
|
||||
double l = ui.move2loc_x_lineEdit->text().toDouble();
|
||||
|
||||
emit move2LocSignal(0, l, s, 1000);
|
||||
}
|
||||
|
||||
void TwoMotorControl::onyMove2Loc()
|
||||
{
|
||||
double s = ui.ymotor_move_speed_lineEdit->text().toDouble();
|
||||
double l = ui.move2loc_y_lineEdit->text().toDouble();
|
||||
|
||||
emit move2LocSignal(1, l, s, 1000);
|
||||
}
|
||||
|
||||
void TwoMotorControl::displayRealTimeLoc(std::vector<double> loc)
|
||||
{
|
||||
double tmp = round(loc[0] * 100) / 100;
|
||||
if (isWritePosFile)
|
||||
{
|
||||
long long timeOs = getNanosecondsSinceMidnight();
|
||||
fprintf(m_posFileHandle, "%lld,%f\n", timeOs, loc[0]);
|
||||
}
|
||||
this->ui.xmotor_realTimeLoc_lineEdit->setText(QString::number(tmp));
|
||||
|
||||
tmp = round(loc[1] * 100) / 100;
|
||||
this->ui.ymotor_realTimeLoc_lineEdit->setText(QString::number(tmp));
|
||||
|
||||
emit broadcastLocationSignal(loc);
|
||||
}
|
||||
|
||||
void TwoMotorControl::zeroStart()
|
||||
{
|
||||
zeroStartSignal(0);
|
||||
zeroStartSignal(1);
|
||||
}
|
||||
|
||||
void TwoMotorControl::on_rangeMeasurement()
|
||||
{
|
||||
double s0 = ui.xmotor_move_speed_lineEdit->text().toDouble();
|
||||
emit rangeMeasurement(0, s0, 1000);
|
||||
|
||||
s0 = ui.ymotor_move_speed_lineEdit->text().toDouble();
|
||||
emit rangeMeasurement(1, s0, 1000);
|
||||
}
|
||||
|
||||
void TwoMotorControl::onAddRecordLine_btn()
|
||||
{
|
||||
//准备数据:获取y马达的当前位置,获取x马达的当前位置和最大位置
|
||||
double currentPosOfYmotor = 15;
|
||||
|
||||
double currentPosOfXmotor = 0;
|
||||
double maxRangeOfXmotor = 50;
|
||||
|
||||
//获取选中行的索引
|
||||
int currentRow = ui.recordLine_tableWidget->currentRow();
|
||||
std::cout << "currentRow:" << currentRow << std::endl;
|
||||
|
||||
QTableWidgetItem* Item1 = new QTableWidgetItem(QString::number(currentPosOfYmotor, 10, 2));
|
||||
QTableWidgetItem* Item2 = new QTableWidgetItem(QString::number(1, 10, 2));
|
||||
QTableWidgetItem* Item3 = new QTableWidgetItem(QString::number(currentPosOfXmotor, 10, 2));
|
||||
QTableWidgetItem* Item4 = new QTableWidgetItem(QString::number(1, 10, 2));
|
||||
QTableWidgetItem* Item5 = new QTableWidgetItem(QString::number(maxRangeOfXmotor, 10, 2));
|
||||
QTableWidgetItem* Item6 = new QTableWidgetItem(QString::number(1, 10, 2));
|
||||
Item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
Item2->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
Item3->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
Item4->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
Item5->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
Item6->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
if (currentRow == -1)//当没有选中行时
|
||||
{
|
||||
int RowCount = ui.recordLine_tableWidget->rowCount();//Returns the number of rows. 从1开始的
|
||||
ui.recordLine_tableWidget->insertRow(RowCount);//增加一行,形参是从0开始的
|
||||
|
||||
ui.recordLine_tableWidget->setItem(RowCount, 0, Item1);
|
||||
ui.recordLine_tableWidget->setItem(RowCount, 1, Item2);
|
||||
ui.recordLine_tableWidget->setItem(RowCount, 2, Item3);
|
||||
ui.recordLine_tableWidget->setItem(RowCount, 3, Item4);
|
||||
ui.recordLine_tableWidget->setItem(RowCount, 4, Item5);
|
||||
ui.recordLine_tableWidget->setItem(RowCount, 5, Item6);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.recordLine_tableWidget->insertRow(currentRow + 1);//增加一行,形参是从0开始的
|
||||
|
||||
ui.recordLine_tableWidget->setItem(currentRow + 1, 0, Item1);
|
||||
ui.recordLine_tableWidget->setItem(currentRow + 1, 1, Item2);
|
||||
ui.recordLine_tableWidget->setItem(currentRow + 1, 2, Item3);
|
||||
ui.recordLine_tableWidget->setItem(currentRow + 1, 3, Item4);
|
||||
ui.recordLine_tableWidget->setItem(currentRow + 1, 4, Item5);
|
||||
ui.recordLine_tableWidget->setItem(currentRow + 1, 5, Item6);
|
||||
}
|
||||
}
|
||||
|
||||
void TwoMotorControl::onRemoveRecordLine_btn()
|
||||
{
|
||||
int rowIndex = ui.recordLine_tableWidget->currentRow();
|
||||
if (rowIndex != -1)
|
||||
ui.recordLine_tableWidget->removeRow(rowIndex);
|
||||
}
|
||||
|
||||
void TwoMotorControl::onDeleteRecordLine_btn()
|
||||
{
|
||||
int rowCount = ui.recordLine_tableWidget->rowCount();
|
||||
for (size_t i = 0; i < rowCount; i++)
|
||||
{
|
||||
ui.recordLine_tableWidget->removeRow(0);
|
||||
}
|
||||
}
|
||||
|
||||
void TwoMotorControl::onSaveRecordLine2File_btn()
|
||||
{
|
||||
//确保采集线存在
|
||||
if (ui.recordLine_tableWidget->rowCount() <= 0)
|
||||
{
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请先生成轨迹!"));
|
||||
return;
|
||||
}
|
||||
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
|
||||
QString RecordLineFilePath = QFileDialog::getSaveFileName(this, tr("Save RecordLine3 File"),
|
||||
QString::fromStdString(directory),
|
||||
tr("RecordLineFile3 (*.RecordLine3)"));
|
||||
|
||||
if (RecordLineFilePath.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* RecordLineFileHandle = fopen(RecordLineFilePath.toStdString().c_str(), "wb+");
|
||||
|
||||
double number = ui.recordLine_tableWidget->rowCount() * ui.recordLine_tableWidget->columnCount();
|
||||
fwrite(&number, sizeof(double), 1, RecordLineFileHandle);
|
||||
|
||||
double* data = new double[number];
|
||||
//double data[number];
|
||||
for (size_t i = 0; i < ui.recordLine_tableWidget->rowCount(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < ui.recordLine_tableWidget->columnCount(); j++)
|
||||
{
|
||||
data[i * ui.recordLine_tableWidget->columnCount() + j] = ui.recordLine_tableWidget->item(i, j)->text().toDouble();
|
||||
}
|
||||
}
|
||||
|
||||
fwrite(data, sizeof(double), number, RecordLineFileHandle);
|
||||
|
||||
fclose(RecordLineFileHandle);
|
||||
delete[] data;
|
||||
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("保存成功!"));
|
||||
}
|
||||
|
||||
void TwoMotorControl::onReadRecordLineFile_btn()
|
||||
{
|
||||
//打开文件
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
|
||||
QString RecordLineFilePath = QFileDialog::getOpenFileName(this, tr("Open RecordLine3 File"),
|
||||
QString::fromStdString(directory),
|
||||
tr("RecordLineFile (*.RecordLine3)"));
|
||||
|
||||
if (RecordLineFilePath.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* RecordLineFileHandle = fopen(RecordLineFilePath.toStdString().c_str(), "rb");
|
||||
double number;
|
||||
|
||||
//读取数据
|
||||
fread(&number, sizeof(double), 1, RecordLineFileHandle);
|
||||
|
||||
double* data = new double[number];
|
||||
for (size_t i = 0; i < number; i++)
|
||||
{
|
||||
fread(data + i, sizeof(double), 1, RecordLineFileHandle);
|
||||
//std::cout << *(data + i) << std::endl;
|
||||
}
|
||||
|
||||
//向tableWidget添加采集线
|
||||
//(1)去掉tableWidget中所有的行
|
||||
int rowCount = ui.recordLine_tableWidget->rowCount();
|
||||
for (size_t i = 0; i < rowCount; i++)
|
||||
{
|
||||
ui.recordLine_tableWidget->removeRow(0);
|
||||
}
|
||||
//(2)添加行(采集线)
|
||||
int RecordLineCount = number / ui.recordLine_tableWidget->columnCount();
|
||||
for (size_t i = 0; i < RecordLineCount; i++)
|
||||
{
|
||||
ui.recordLine_tableWidget->insertRow(0);
|
||||
|
||||
}
|
||||
//(3)向tableWidget填充数据
|
||||
for (size_t i = 0; i < ui.recordLine_tableWidget->rowCount(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < ui.recordLine_tableWidget->columnCount(); j++)
|
||||
{
|
||||
QTableWidgetItem* tmp = new QTableWidgetItem(QString::number(data[i * ui.recordLine_tableWidget->columnCount() + j], 10, 5));
|
||||
tmp->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
ui.recordLine_tableWidget->setItem(i, j, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(RecordLineFileHandle);
|
||||
delete[] data;
|
||||
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("读取成功!"));
|
||||
}
|
||||
98
HPPA/TwoMotorControl.h
Normal file
98
HPPA/TwoMotorControl.h
Normal file
@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
#include <QThread>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include "ui_twoMotorControl.h"
|
||||
|
||||
#include "IrisMultiMotorController.h"
|
||||
#include "fileOperation.h"
|
||||
#include "CaptureCoordinator.h"
|
||||
|
||||
#define PI 3.1415926
|
||||
|
||||
|
||||
|
||||
class TwoMotorControl : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TwoMotorControl(QWidget* parent = nullptr);
|
||||
~TwoMotorControl();
|
||||
|
||||
void setImager(ImagerOperationBase* imager);
|
||||
void setPosFileName(QString posFileName);
|
||||
|
||||
void record_dark();
|
||||
void record_white();
|
||||
|
||||
private:
|
||||
ImagerOperationBase* m_Imager;
|
||||
bool getState();
|
||||
|
||||
bool isWritePosFile = false;
|
||||
QString m_posFileName;
|
||||
FILE* m_posFileHandle;
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
void onConnectMotor();
|
||||
|
||||
void displayRealTimeLoc(std::vector<double> loc);
|
||||
void display_motors_connectivity(std::vector<int> connectivity);
|
||||
//void onxMove2Loc();
|
||||
void zeroStart();
|
||||
void on_rangeMeasurement();
|
||||
|
||||
void onxMotorRight();
|
||||
void onxMotorLeft();
|
||||
void onxMotorStop();
|
||||
void onxMove2Loc();
|
||||
|
||||
void onyMotorforward();
|
||||
void onyMotorbackward();
|
||||
void onyMotorStop();
|
||||
void onyMove2Loc();
|
||||
|
||||
void onAddRecordLine_btn();
|
||||
void onRemoveRecordLine_btn();
|
||||
void onDeleteRecordLine_btn();
|
||||
void onSaveRecordLine2File_btn();
|
||||
void onReadRecordLineFile_btn();
|
||||
|
||||
void run();
|
||||
void stop();
|
||||
void receiveStartRecordLineNum(int lineNum);
|
||||
void receiveFinishRecordLineNum(int lineNum);
|
||||
void onSequenceComplete();
|
||||
|
||||
signals:
|
||||
void moveSignal(int, bool, double, int);
|
||||
void move2LocSignal(int, double, double, int);
|
||||
void move2LocSignal(const std::vector<double>, const std::vector<double>, int);
|
||||
void stopSignal(int);
|
||||
|
||||
void rangeMeasurement(int, double, int);
|
||||
void zeroStartSignal(int);
|
||||
void testConnectivitySignal(int, int);
|
||||
|
||||
void start(QVector<PathLine>);
|
||||
void stopSignal();
|
||||
|
||||
void startLineNumSignal(int lineNum);
|
||||
void sequenceComplete();//所有采集线正常运行完成
|
||||
|
||||
void broadcastLocationSignal(std::vector<double>);
|
||||
|
||||
private:
|
||||
Ui::twoMotorControl_UI ui;
|
||||
QThread m_coordinatorThread;
|
||||
TwoMotionCaptureCoordinator* m_coordinator = nullptr;
|
||||
|
||||
DarkAndWhiteCaptureCoordinator* m_darkCaptureCoordinator = nullptr;
|
||||
DarkAndWhiteCaptureCoordinator* m_whiteCaptureCoordinator = nullptr;
|
||||
|
||||
QThread m_motorThread;
|
||||
IrisMultiMotorController* m_multiAxisController;
|
||||
};
|
||||
375
HPPA/View3D.cpp
Normal file
375
HPPA/View3D.cpp
Normal file
@ -0,0 +1,375 @@
|
||||
#include "View3D.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QShowEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <Qt3DExtras/QForwardRenderer>
|
||||
#include <QtMath>
|
||||
#include <Qt3DRender/QAttribute>
|
||||
#include <QGeometryRenderer>
|
||||
|
||||
View3DBase::View3DBase(const QString& baseModelPath,
|
||||
const QString& armModelPath,
|
||||
QWidget* parent)
|
||||
: QWidget(parent),
|
||||
m_container(nullptr),
|
||||
m_baseModelPath(baseModelPath),
|
||||
m_armModelPath(armModelPath)
|
||||
{
|
||||
m_view = new Qt3DExtras::Qt3DWindow();
|
||||
// 部分 Qt5.9 构建可能需要强转 frame graph,但 defaultFrameGraph() 通常可用
|
||||
QColor c1("#0D1233");
|
||||
m_view->defaultFrameGraph()->setClearColor(c1);
|
||||
|
||||
m_rootEntity = new Qt3DCore::QEntity();
|
||||
|
||||
initScene();
|
||||
initCamera();
|
||||
|
||||
// 自动旋转臂(如果不需要可注释掉 timer/connect)
|
||||
//connect(&m_timer, &QTimer::timeout, this, [=]() {
|
||||
// m_angle += 1.0f;
|
||||
// m_t += 1.0f;
|
||||
// if (m_angle >= 360.0f) m_angle = 0.0f;
|
||||
// if (m_armTransform)
|
||||
// {
|
||||
// //m_armTransform->setRotationX(m_angle);
|
||||
// //m_armTransform->setTranslation(QVector3D(m_t, 0, 0));
|
||||
//
|
||||
// Qt3DCore::QTransform transform;
|
||||
// transform.setTranslation(QVector3D(2, 0, 0));
|
||||
|
||||
// QMatrix4x4 M = m_armTransform->matrix();
|
||||
// M = transform.matrix() * M; // 左乘:在世界坐标系叠加
|
||||
// m_armTransform->setMatrix(M);
|
||||
|
||||
// qDebug() << m_armTransform->matrix();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
void View3DBase::setViewCenter(float x, float y, float z)
|
||||
{
|
||||
m_viewCenter.setX(x);
|
||||
m_viewCenter.setY(y);
|
||||
m_viewCenter.setZ(z);
|
||||
}
|
||||
|
||||
void View3DBase::setDistance(float distance)
|
||||
{
|
||||
m_distance = distance;
|
||||
}
|
||||
|
||||
void View3DBase::initScene()
|
||||
{
|
||||
/*auto* lightEntity = new Qt3DCore::QEntity(m_rootEntity);
|
||||
|
||||
auto* light = new Qt3DRender::QPointLight(lightEntity);
|
||||
light->setColor(Qt::white);
|
||||
light->setIntensity(1.2f);
|
||||
|
||||
auto* lightTransform = new Qt3DCore::QTransform(lightEntity);
|
||||
lightTransform->setTranslation(QVector3D(500, 500, 500));
|
||||
|
||||
lightEntity->addComponent(light);
|
||||
lightEntity->addComponent(lightTransform);*/
|
||||
|
||||
// ===== 创建 base 根节点 =====
|
||||
auto* baseModel = new Qt3DCore::QEntity(m_rootEntity);
|
||||
auto* baseLoader = new Qt3DRender::QSceneLoader(baseModel);
|
||||
baseLoader->setSource(QUrl::fromLocalFile(m_baseModelPath));
|
||||
|
||||
//connect(baseLoader, &Qt3DRender::QSceneLoader::statusChanged,
|
||||
// this, &View3DBase::onSceneLoaderStatusChanged);
|
||||
|
||||
|
||||
m_baseTransform = new Qt3DCore::QTransform();
|
||||
m_baseTransform->setTranslation(QVector3D(0, 0, 0));
|
||||
baseModel->addComponent(baseLoader);
|
||||
baseModel->addComponent(m_baseTransform);
|
||||
|
||||
connect(baseLoader, &Qt3DRender::QSceneLoader::statusChanged,
|
||||
this, [=](Qt3DRender::QSceneLoader::Status status) {
|
||||
|
||||
if (status == Qt3DRender::QSceneLoader::Ready) {
|
||||
applyWhiteMaterialRecursive(baseModel);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// ===== 创建 arm 根节点 =====
|
||||
auto* armModel = new Qt3DCore::QEntity(m_rootEntity);
|
||||
auto* armLoader = new Qt3DRender::QSceneLoader(armModel);
|
||||
armLoader->setSource(QUrl::fromLocalFile(m_armModelPath));
|
||||
|
||||
m_armTransform = new Qt3DCore::QTransform();
|
||||
m_armTransform->setTranslation(QVector3D(0, 0, 0));
|
||||
armModel->addComponent(armLoader);
|
||||
armModel->addComponent(m_armTransform);
|
||||
|
||||
connect(armLoader, &Qt3DRender::QSceneLoader::statusChanged,
|
||||
this, [=](Qt3DRender::QSceneLoader::Status status) {
|
||||
|
||||
if (status == Qt3DRender::QSceneLoader::Ready) {
|
||||
applyWhiteMaterialRecursive(armModel);
|
||||
}
|
||||
});
|
||||
|
||||
// 坐标轴依然挂在 root,不会被移动
|
||||
//createAxes();
|
||||
|
||||
m_view->setRootEntity(m_rootEntity);
|
||||
|
||||
qDebug() << m_baseTransform->matrix();
|
||||
qDebug() << m_armTransform->matrix();
|
||||
|
||||
//m_armTransform->setTranslation(QVector3D(2000, 0, 0));
|
||||
//m_baseTransform->setTranslation(QVector3D(-1000, -1000, -1000));
|
||||
|
||||
qDebug() << m_baseTransform->matrix();
|
||||
qDebug() << m_armTransform->matrix();
|
||||
}
|
||||
|
||||
void View3DBase::applyWhiteMaterialRecursive(Qt3DCore::QEntity* entity)
|
||||
{
|
||||
// 如果这个 entity 有 mesh,就给它加白色材质
|
||||
auto meshes = entity->componentsOfType<Qt3DRender::QGeometryRenderer>();
|
||||
if (!meshes.isEmpty()) {
|
||||
auto* mat = new Qt3DExtras::QPhongMaterial(entity);
|
||||
QColor c1("#cccccc");
|
||||
mat->setDiffuse(c1);
|
||||
mat->setAmbient(c1);
|
||||
mat->setSpecular(c1);
|
||||
mat->setShininess(50.0f);
|
||||
entity->addComponent(mat);
|
||||
}
|
||||
|
||||
// 递归处理子节点
|
||||
const auto children = entity->children();
|
||||
for (QObject* obj : children) {
|
||||
auto* childEntity = qobject_cast<Qt3DCore::QEntity*>(obj);
|
||||
if (childEntity)
|
||||
applyWhiteMaterialRecursive(childEntity);
|
||||
}
|
||||
}
|
||||
|
||||
void View3DBase::createAxes()
|
||||
{
|
||||
// 参数
|
||||
float axisLength = 500.0f;
|
||||
float axisRadius = 50.0f;
|
||||
|
||||
// ----- X axis (red) -----
|
||||
Qt3DCore::QEntity* xAxis = new Qt3DCore::QEntity(m_rootEntity);
|
||||
auto* xMesh = new Qt3DExtras::QCylinderMesh();
|
||||
xMesh->setRadius(axisRadius);
|
||||
xMesh->setLength(axisLength);
|
||||
xMesh->setRings(16);
|
||||
xMesh->setSlices(16);
|
||||
|
||||
auto* xTrans = new Qt3DCore::QTransform();
|
||||
// cylinder 默认沿 Y 轴,绕 Z 轴 90 度让其沿 X
|
||||
xTrans->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0, 0, 1), 90.0f));
|
||||
xTrans->setTranslation(QVector3D(axisLength / 2.0f, 0.0f, 0.0f));
|
||||
|
||||
auto* xMat = new Qt3DExtras::QPhongMaterial();
|
||||
xMat->setDiffuse(QColor(Qt::red));
|
||||
|
||||
xAxis->addComponent(xMesh);
|
||||
xAxis->addComponent(xTrans);
|
||||
xAxis->addComponent(xMat);
|
||||
|
||||
// ----- Y axis (green) -----
|
||||
Qt3DCore::QEntity* yAxis = new Qt3DCore::QEntity(m_rootEntity);
|
||||
auto* yMesh = new Qt3DExtras::QCylinderMesh();
|
||||
yMesh->setRadius(axisRadius);
|
||||
yMesh->setLength(axisLength*2);
|
||||
yMesh->setRings(16);
|
||||
yMesh->setSlices(16);
|
||||
|
||||
auto* yTrans = new Qt3DCore::QTransform();
|
||||
// Y 轴无需旋转(cylinder 默认沿 Y)
|
||||
yTrans->setTranslation(QVector3D(0.0f, axisLength / 2.0f, 0.0f));
|
||||
|
||||
auto* yMat = new Qt3DExtras::QPhongMaterial();
|
||||
yMat->setDiffuse(QColor(Qt::green));
|
||||
|
||||
yAxis->addComponent(yMesh);
|
||||
yAxis->addComponent(yTrans);
|
||||
yAxis->addComponent(yMat);
|
||||
|
||||
// ----- Z axis (blue) -----
|
||||
Qt3DCore::QEntity* zAxis = new Qt3DCore::QEntity(m_rootEntity);
|
||||
auto* zMesh = new Qt3DExtras::QCylinderMesh();
|
||||
zMesh->setRadius(axisRadius);
|
||||
zMesh->setLength(axisLength*3);
|
||||
zMesh->setRings(16);
|
||||
zMesh->setSlices(16);
|
||||
|
||||
auto* zTrans = new Qt3DCore::QTransform();
|
||||
// 让 cylinder 沿 Z:绕 X 轴 90 度
|
||||
zTrans->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 90.0f));
|
||||
zTrans->setTranslation(QVector3D(0.0f, 0.0f, axisLength / 2.0f));
|
||||
|
||||
auto* zMat = new Qt3DExtras::QPhongMaterial();
|
||||
zMat->setDiffuse(QColor(Qt::blue));
|
||||
|
||||
zAxis->addComponent(zMesh);
|
||||
zAxis->addComponent(zTrans);
|
||||
zAxis->addComponent(zMat);
|
||||
}
|
||||
|
||||
void View3DBase::initCamera()
|
||||
{
|
||||
m_camera = m_view->camera();
|
||||
// 16:10 假设窗口比例,后续 resize 时相机透视会保持
|
||||
m_camera->lens()->setPerspectiveProjection(50.0f, 16.0f / 10.0f, 0.1f, 10000.0f);
|
||||
updateCameraPosition();
|
||||
}
|
||||
|
||||
void View3DBase::updateCameraPosition()
|
||||
{
|
||||
float yaw = qDegreesToRadians(m_yawDeg);
|
||||
float pitch = qDegreesToRadians(m_pitchDeg);
|
||||
|
||||
float x = m_distance * qCos(pitch) * qSin(yaw);
|
||||
float y = m_distance * qSin(pitch);
|
||||
float z = m_distance * qCos(pitch) * qCos(yaw);
|
||||
|
||||
QVector3D camPos = m_viewCenter + QVector3D(x, y, z);
|
||||
m_camera->setPosition(camPos);
|
||||
m_camera->setViewCenter(m_viewCenter);
|
||||
}
|
||||
|
||||
void View3DBase::showEvent(QShowEvent* event)
|
||||
{
|
||||
QWidget::showEvent(event);
|
||||
|
||||
if (!m_container) {
|
||||
m_container = QWidget::createWindowContainer(m_view, this);
|
||||
m_view->installEventFilter(this);
|
||||
|
||||
auto* layout = new QHBoxLayout(this);
|
||||
layout->addWidget(m_container);
|
||||
layout->setMargin(0);
|
||||
setLayout(layout);
|
||||
|
||||
// 启动自动旋转 timer(如果你不需要可以注释)
|
||||
m_timer.start(100);
|
||||
}
|
||||
}
|
||||
|
||||
bool View3DBase::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
if (obj == m_view)
|
||||
{
|
||||
// 鼠标按下
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
auto* e = static_cast<QMouseEvent*>(event);
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
m_mouseDragging = true;
|
||||
m_lastMousePos = e->pos();
|
||||
}
|
||||
else if (e->button() == Qt::MiddleButton) {
|
||||
m_middleDragging = true;
|
||||
m_lastMousePos = e->pos();
|
||||
}
|
||||
}
|
||||
// 鼠标释放
|
||||
else if (event->type() == QEvent::MouseButtonRelease) {
|
||||
auto* e = static_cast<QMouseEvent*>(event);
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
m_mouseDragging = false;
|
||||
}
|
||||
else if (e->button() == Qt::MiddleButton) {
|
||||
m_middleDragging = false;
|
||||
}
|
||||
}
|
||||
// 鼠标移动
|
||||
else if (event->type() == QEvent::MouseMove) {
|
||||
auto* e = static_cast<QMouseEvent*>(event);
|
||||
QPoint pos = e->pos();
|
||||
QPoint delta = pos - m_lastMousePos;
|
||||
|
||||
// 左键:orbit(旋转)
|
||||
if (m_mouseDragging) {
|
||||
float sensitivity = 0.3f;
|
||||
m_yawDeg -= delta.x() * sensitivity;
|
||||
m_pitchDeg += delta.y() * sensitivity;
|
||||
|
||||
if (m_pitchDeg > 89.0f) m_pitchDeg = 89.0f;
|
||||
if (m_pitchDeg < -89.0f) m_pitchDeg = -89.0f;
|
||||
|
||||
updateCameraPosition();
|
||||
}
|
||||
|
||||
// 中键:pan(平移 viewCenter)
|
||||
if (m_middleDragging) {
|
||||
float speed = 2.0f;
|
||||
|
||||
// 根据摄像机方向计算平移方向
|
||||
QVector3D camPos = m_camera->position();
|
||||
QVector3D forward = (m_viewCenter - camPos).normalized();
|
||||
QVector3D up(0, 1, 0);
|
||||
QVector3D right = QVector3D::crossProduct(forward, up).normalized();
|
||||
|
||||
// 世界坐标变化量
|
||||
QVector3D deltaMove =
|
||||
-right * (delta.x() * speed) +
|
||||
up * (delta.y() * speed);
|
||||
|
||||
// 将平移应用到两个模型根 Transform
|
||||
if (m_baseRootTransform)
|
||||
m_baseRootTransform->setTranslation(
|
||||
m_baseRootTransform->translation() + deltaMove*-1);
|
||||
|
||||
if (m_armRootTransform)
|
||||
m_armRootTransform->setTranslation(
|
||||
m_armRootTransform->translation() + deltaMove*-1);
|
||||
}
|
||||
|
||||
m_lastMousePos = pos;
|
||||
}
|
||||
// 滚轮缩放
|
||||
else if (event->type() == QEvent::Wheel) {
|
||||
auto* e = static_cast<QWheelEvent*>(event);
|
||||
// Qt5: angleDelta 返回像素值(通常为 120 per notch)
|
||||
int delta = e->angleDelta().y();
|
||||
if (delta == 0) delta = e->delta(); // 备选
|
||||
m_distance -= delta * 2.0f; // 缩放速度
|
||||
if (m_distance < 2.0f) m_distance = 2.0f;
|
||||
if (m_distance > 10000.0f) m_distance = 10000.0f;
|
||||
updateCameraPosition();
|
||||
}
|
||||
}
|
||||
|
||||
// 让 Qt 继续处理(保持原行为)
|
||||
return QWidget::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
View3DPlantPhenotype::View3DPlantPhenotype(const QString& baseModelPath, const QString& armModelPath, QWidget* parent)
|
||||
:View3DBase(baseModelPath, armModelPath, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void View3DPlantPhenotype::setLoc(std::vector<double> loc)
|
||||
{
|
||||
double x = round(loc[0] * 100) / 100;
|
||||
double y = round(loc[1] * 100) / 100;
|
||||
|
||||
m_armTransform->setTranslation(QVector3D(x, y, 0));
|
||||
}
|
||||
|
||||
View3DLinearStage::View3DLinearStage(const QString& baseModelPath, const QString& armModelPath, QWidget* parent)
|
||||
:View3DBase(baseModelPath, armModelPath, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void View3DLinearStage::setLoc(std::vector<double> loc)
|
||||
{
|
||||
double x = round(loc[0] * 100) / 100;
|
||||
|
||||
m_armTransform->setTranslation(QVector3D(x, 0, 0));
|
||||
}
|
||||
112
HPPA/View3D.h
Normal file
112
HPPA/View3D.h
Normal file
@ -0,0 +1,112 @@
|
||||
#ifndef VIEW3D_H
|
||||
#define VIEW3D_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QPoint>
|
||||
#include <QString>
|
||||
#include <QQuaternion>
|
||||
#include <QColor>
|
||||
|
||||
#include <Qt3DCore/QEntity>
|
||||
#include <Qt3DCore/QTransform>
|
||||
#include <Qt3DExtras/Qt3DWindow>
|
||||
#include <Qt3DRender/QCamera>
|
||||
#include <Qt3DExtras/QOrbitCameraController>
|
||||
#include <Qt3DExtras/QPhongMaterial>
|
||||
#include <Qt3DRender/QSceneLoader>
|
||||
#include <Qt3DExtras/QCylinderMesh>
|
||||
#include <QPointLight>
|
||||
|
||||
class View3DBase : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit View3DBase(const QString& baseModelPath,
|
||||
const QString& armModelPath,
|
||||
QWidget* parent = nullptr);
|
||||
void setViewCenter(float x, float y, float z);
|
||||
void setDistance(float distance);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
void initScene();
|
||||
void initCamera();
|
||||
void updateCameraPosition();
|
||||
void createAxes();
|
||||
|
||||
QString m_baseModelPath;
|
||||
QString m_armModelPath;
|
||||
|
||||
Qt3DExtras::Qt3DWindow* m_view;
|
||||
QWidget* m_container;
|
||||
Qt3DCore::QEntity* m_rootEntity;
|
||||
|
||||
Qt3DCore::QEntity* m_baseEntity;
|
||||
Qt3DCore::QEntity* m_armEntity;
|
||||
Qt3DCore::QTransform* m_armTransform;
|
||||
Qt3DCore::QTransform* m_baseTransform;
|
||||
|
||||
QTimer m_timer;
|
||||
float m_angle = 0; // arm auto rotation
|
||||
float m_t = 0;
|
||||
|
||||
// ----- Camera control -----
|
||||
Qt3DRender::QCamera* m_camera = nullptr;
|
||||
float m_distance = 5000.0f;
|
||||
float m_yawDeg = 0.0f;
|
||||
float m_pitchDeg = 0.0f;
|
||||
QVector3D m_viewCenter = QVector3D(1000, 1000, -1000);
|
||||
|
||||
// Mouse state
|
||||
bool m_mouseDragging = false; // left button: orbit
|
||||
bool m_middleDragging = false; // middle button: pan
|
||||
QPoint m_lastMousePos;
|
||||
|
||||
Qt3DCore::QTransform* m_baseRootTransform = nullptr;
|
||||
Qt3DCore::QTransform* m_armRootTransform = nullptr;
|
||||
|
||||
void applyWhiteMaterialRecursive(Qt3DCore::QEntity* entity);
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void setLoc(std::vector<double> loc) = 0;
|
||||
};
|
||||
|
||||
class View3DPlantPhenotype : public View3DBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
View3DPlantPhenotype(const QString& baseModelPath,
|
||||
const QString& armModelPath,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
|
||||
public Q_SLOTS:
|
||||
void setLoc(std::vector<double> loc);
|
||||
};
|
||||
|
||||
class View3DLinearStage : public View3DBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
View3DLinearStage(const QString& baseModelPath,
|
||||
const QString& armModelPath,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
|
||||
public Q_SLOTS:
|
||||
void setLoc(std::vector<double> loc);
|
||||
};
|
||||
#endif // VIEW3D_H
|
||||
68
HPPA/View3DModelManager.cpp
Normal file
68
HPPA/View3DModelManager.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include "View3DModelManager.h"
|
||||
|
||||
View3DModelManager::View3DModelManager(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
m_stackedWidget = new QStackedWidget();
|
||||
m_stackedWidget->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->addWidget(m_stackedWidget);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void View3DModelManager::switchScenario(ScenarioType type)
|
||||
{
|
||||
if (type == ScenarioType::PlantPhenotype) {
|
||||
ensurePlantPhenotypeView();
|
||||
m_stackedWidget->setCurrentWidget(m_viewPlant);
|
||||
}
|
||||
else {
|
||||
ensureOneMotorView();
|
||||
m_stackedWidget->setCurrentWidget(m_viewMotor);
|
||||
}
|
||||
|
||||
emit scenarioChanged(type);
|
||||
}
|
||||
|
||||
void View3DModelManager::ensurePlantPhenotypeView()
|
||||
{
|
||||
if (m_viewPlant)
|
||||
return;
|
||||
|
||||
QString basePath = QCoreApplication::applicationDirPath();
|
||||
|
||||
m_viewPlant = new View3DPlantPhenotype(
|
||||
basePath + "/3DModel/HPPA_frame.obj",
|
||||
basePath + "/3DModel/HPPA_camera.obj",
|
||||
m_stackedWidget
|
||||
);
|
||||
|
||||
m_viewPlant->setViewCenter(1000, 1000, -1000);
|
||||
m_viewPlant->setDistance(5000);
|
||||
|
||||
m_stackedWidget->addWidget(m_viewPlant);
|
||||
|
||||
emit created3DModelPlantPhenotype();
|
||||
}
|
||||
|
||||
void View3DModelManager::ensureOneMotorView()
|
||||
{
|
||||
if (m_viewMotor)
|
||||
return;
|
||||
|
||||
QString basePath = QCoreApplication::applicationDirPath();
|
||||
|
||||
m_viewMotor = new View3DLinearStage(
|
||||
basePath + "/3DModel/linear_stage_indoor1.obj",
|
||||
basePath + "/3DModel/linear_stage_indoor2.obj",
|
||||
m_stackedWidget
|
||||
);
|
||||
|
||||
m_viewMotor->setViewCenter(500, 100, 500);
|
||||
m_viewMotor->setDistance(1000);
|
||||
|
||||
m_stackedWidget->addWidget(m_viewMotor);
|
||||
|
||||
emit created3DModelOneMotor();
|
||||
}
|
||||
40
HPPA/View3DModelManager.h
Normal file
40
HPPA/View3DModelManager.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <QStackedWidget>
|
||||
#include <QCoreApplication>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "View3D.h"
|
||||
|
||||
class View3DPlantPhenotype;
|
||||
class View3DLinearStage;
|
||||
|
||||
class View3DModelManager : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class ScenarioType {
|
||||
PlantPhenotype,
|
||||
OneMotor
|
||||
};
|
||||
|
||||
explicit View3DModelManager(QWidget* parent = nullptr);
|
||||
|
||||
void switchScenario(ScenarioType type);
|
||||
|
||||
View3DPlantPhenotype* m_viewPlant = nullptr;
|
||||
View3DLinearStage* m_viewMotor = nullptr;
|
||||
|
||||
signals:
|
||||
void scenarioChanged(ScenarioType type);
|
||||
void created3DModelPlantPhenotype();
|
||||
void created3DModelOneMotor();
|
||||
|
||||
private:
|
||||
void ensurePlantPhenotypeView();
|
||||
void ensureOneMotorView();
|
||||
|
||||
private:
|
||||
QStackedWidget* m_stackedWidget = nullptr;
|
||||
};
|
||||
@ -70,7 +70,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>版本:1.8.7</string>
|
||||
<string>版本:2.0</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_4">
|
||||
|
||||
@ -6,24 +6,127 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>687</width>
|
||||
<height>389</height>
|
||||
<width>501</width>
|
||||
<height>363</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>adjustTable</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<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 "新宋体";
|
||||
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>252号升降台</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_10">
|
||||
<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="objective_table252_up_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -33,10 +136,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="objective_table252_down_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -46,10 +149,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="objective_table252_stop_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -62,16 +165,63 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<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>253号升降台</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_11">
|
||||
<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="objective_table1_up_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -81,10 +231,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="objective_table1_down_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -94,10 +244,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="objective_table1_stop_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -110,16 +260,63 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<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>254号升降台</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_9">
|
||||
<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="0">
|
||||
<widget class="QPushButton" name="objective_table2_up_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -129,10 +326,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="objective_table2_down_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -142,10 +339,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="objective_table2_stop_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -158,6 +355,32 @@
|
||||
</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"/>
|
||||
|
||||
@ -17,7 +17,7 @@ public:
|
||||
~FileOperation();
|
||||
|
||||
string getDirectoryOfExe();//getDirectoryOfExe
|
||||
string getDirectoryFromString(string directory="C:/HPPA_image");
|
||||
string getDirectoryFromString(string directory="C:\\HPPA_image");
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
#include "stdafx.h"
|
||||
#include "stdafx.h"
|
||||
#include "focusWindow.h"
|
||||
|
||||
focusWindow::focusWindow(QWidget *parent, ImagerOperationBase* imager)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
//<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
//读取配置文件
|
||||
string HPPACfgFile = getPathofEXE() + "\\HPPA.cfg";
|
||||
Configfile configfile;
|
||||
configfile.setConfigfilePath(HPPACfgFile);
|
||||
@ -18,7 +18,7 @@ focusWindow::focusWindow(QWidget *parent, ImagerOperationBase* imager)
|
||||
|
||||
disableBeforeConnect(true);
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);//<EFBFBD><EFBFBD><EFBFBD>ùرմ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
setAttribute(Qt::WA_DeleteOnClose);//设置关闭窗体就调用窗体的析构函数
|
||||
|
||||
m_Imager = imager;
|
||||
m_FocusState = 0;
|
||||
@ -38,7 +38,9 @@ focusWindow::focusWindow(QWidget *parent, ImagerOperationBase* imager)
|
||||
connect(this->ui.updateCurrentLocation_btn, SIGNAL(clicked()), this, SLOT(onUpdateCurrentLocation()));
|
||||
connect(this->ui.moveto_btn, SIGNAL(clicked()), this, SLOT(onMoveto()));
|
||||
|
||||
//<2F><><EFBFBD>ҿ<EFBFBD><D2BF>ô<EFBFBD><C3B4>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>ʾ
|
||||
connect(this->ui.rangeMeasurement_btn, SIGNAL(pressed()), this, SLOT(onx_rangeMeasurement()));
|
||||
|
||||
//查找可用串口,并显示
|
||||
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
|
||||
{
|
||||
QSerialPort serial;
|
||||
@ -51,20 +53,29 @@ focusWindow::focusWindow(QWidget *parent, ImagerOperationBase* imager)
|
||||
}
|
||||
}
|
||||
|
||||
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//设置自动调焦进度条
|
||||
ui.autoFocusProgress_progressBar->setMinimum(0);
|
||||
ui.autoFocusProgress_progressBar->setMaximum(100);
|
||||
ui.autoFocusProgress_progressBar->reset();
|
||||
|
||||
m_dSpeed = 1.0;
|
||||
|
||||
}
|
||||
|
||||
focusWindow::~focusWindow()
|
||||
{
|
||||
printf("destroy focusWindow-------------------------\n");
|
||||
|
||||
emit StartManualFocusSignal(0);//<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>û<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>ֹͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رմ<EFBFBD><EFBFBD><EFBFBD>
|
||||
emit StartManualFocusSignal(0);//当用户没有点击停止调焦就关闭窗口
|
||||
|
||||
delete m_ctrlFocusMotor;
|
||||
//delete thread1, progressThread;
|
||||
|
||||
m_motorThread.quit();
|
||||
m_motorThread.wait();
|
||||
|
||||
m_MotionCaptureCoordinatorThread.quit();
|
||||
m_MotionCaptureCoordinatorThread.wait();
|
||||
}
|
||||
|
||||
void focusWindow::disableBeforeConnect(bool disable)
|
||||
@ -92,142 +103,239 @@ bool test(void *pCaller, int *x, int *y, void **pvdata)
|
||||
|
||||
void focusWindow::onConnectMotor()
|
||||
{
|
||||
if (m_ctrlFocusMotor != nullptr)
|
||||
if (ui.is_new_version_radioButton->isChecked())
|
||||
{
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-------------------------\n");
|
||||
return;
|
||||
}
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
QString configFilePath = QString::fromStdString(directory) + "\\oneMotorConfigFile_focus.cfg";
|
||||
|
||||
bool isUltrasound = ui.ultrasound_radioButton->isChecked();
|
||||
|
||||
QString motorPortTmp = ui.motorPort_comboBox->currentText();
|
||||
QString ultrasoundPortTmp = ui.ultrasoundPort_comboBox->currentText();
|
||||
|
||||
QRegExp rx("\\d+$");
|
||||
rx.indexIn(motorPortTmp, 0);
|
||||
int motorPort = rx.cap(0).toInt();
|
||||
rx.indexIn(ultrasoundPortTmp, 0);
|
||||
int ultrasoundPort = rx.cap(0).toInt();
|
||||
|
||||
|
||||
|
||||
if (isUltrasound)
|
||||
{
|
||||
PortInfo motor;
|
||||
motor.iPortType = 0;
|
||||
motor.indexParity = 0;
|
||||
m_multiAxisController = new IrisMultiMotorController(configFilePath);
|
||||
m_multiAxisController->moveToThread(&m_motorThread);
|
||||
connect(&m_motorThread, SIGNAL(finished()), m_multiAxisController, SLOT(deleteLater()));
|
||||
connect(this, SIGNAL(rmoveSignal(int, double, double, int)), m_multiAxisController, SLOT(rmove(int, double, double, int)));
|
||||
connect(this, SIGNAL(move2LocSignal(int, double, double, int)), m_multiAxisController, SLOT(moveTo(int, double, double, int)));
|
||||
connect(this, SIGNAL(rangeMeasurementSignal(int, double, int)), m_multiAxisController, SLOT(rangeMeasurement(int, double, int)));
|
||||
connect(this, SIGNAL(zeroStartSignal(int)), m_multiAxisController, SLOT(zeroStart(int)));
|
||||
connect(this, SIGNAL(move2MaxLocSignal(int, double, int)), m_multiAxisController, SLOT(moveToMax(int, double, int)));
|
||||
connect(m_multiAxisController, SIGNAL(broadcastLocationSignal(std::vector<double>)), this, SLOT(display_x_loc(std::vector<double>)));
|
||||
connect(m_multiAxisController, SIGNAL(motorStopSignal(int, double)), this, SLOT(moveAfterAutoFocus(int, double)));
|
||||
m_motorThread.start();
|
||||
|
||||
motor.iPortNumber = motorPort;
|
||||
motor.indexBaudRate = 0x13;
|
||||
motor.indexBytesize = 3;
|
||||
motor.indexStopBits = 0;
|
||||
//归零
|
||||
//emit zeroStartSignal(0);
|
||||
|
||||
PortInfo ultrasound;
|
||||
ultrasound.iPortType = 0;
|
||||
ultrasound.indexParity = 0;
|
||||
ultrasound.iPortNumber = ultrasoundPort;
|
||||
ultrasound.indexBaudRate = 0x0C;
|
||||
ultrasound.indexBytesize = 3;
|
||||
ultrasound.indexStopBits = 0;
|
||||
|
||||
m_ctrlFocusMotor = new CFocusMotorControl();
|
||||
|
||||
m_ctrlFocusMotor->SetLogicZero(m_iMinPos);
|
||||
m_ctrlFocusMotor->SetLimit(m_iMinPos, m_iMaxPos);
|
||||
m_ctrlFocusMotor->InitSystem(motor, ultrasound, test, this);
|
||||
//m_ctrlFocusMotor->MoveToLogicZero();
|
||||
//自动调焦逻辑
|
||||
m_coordinator = new MotionCaptureCoordinator(m_multiAxisController, m_Imager);
|
||||
m_coordinator->moveToThread(&m_MotionCaptureCoordinatorThread);
|
||||
connect(&m_MotionCaptureCoordinatorThread, SIGNAL(finished()), m_coordinator, SLOT(deleteLater()));
|
||||
connect(this, SIGNAL(startStepMotion(double, int, double, double)), m_coordinator, SLOT(startStepMotion(double, int, double, double)));
|
||||
connect(m_coordinator, SIGNAL(progressChanged(int)), this, SLOT(onAutoFocusProgress(int)));
|
||||
connect(m_coordinator, SIGNAL(sequenceComplete()), this, SLOT(onAutoFocusFinished()));
|
||||
m_MotionCaptureCoordinatorThread.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
PortInfo motor;
|
||||
motor.iPortType = 0;
|
||||
motor.indexParity = 0;
|
||||
motor.iPortNumber = motorPort;
|
||||
motor.indexBaudRate = 0x13;
|
||||
motor.indexBytesize = 3;
|
||||
motor.indexStopBits = 0;
|
||||
if (m_ctrlFocusMotor != nullptr)
|
||||
{
|
||||
printf("不能重复连接-------------------------\n");
|
||||
return;
|
||||
}
|
||||
|
||||
m_ctrlFocusMotor = new CFocusMotorControl();
|
||||
bool isUltrasound = ui.ultrasound_radioButton->isChecked();
|
||||
|
||||
m_ctrlFocusMotor->SetLogicZero(m_iMinPos);
|
||||
m_ctrlFocusMotor->SetLimit(m_iMinPos, m_iMaxPos);
|
||||
m_ctrlFocusMotor->InitSystem(motor, test, this);
|
||||
m_ctrlFocusMotor->MoveToLogicZero();
|
||||
QString motorPortTmp = ui.motorPort_comboBox->currentText();
|
||||
QString ultrasoundPortTmp = ui.ultrasoundPort_comboBox->currentText();
|
||||
|
||||
QRegExp rx("\\d+$");
|
||||
rx.indexIn(motorPortTmp, 0);
|
||||
int motorPort = rx.cap(0).toInt();
|
||||
rx.indexIn(ultrasoundPortTmp, 0);
|
||||
int ultrasoundPort = rx.cap(0).toInt();
|
||||
|
||||
|
||||
|
||||
if (isUltrasound)
|
||||
{
|
||||
PortInfo motor;
|
||||
motor.iPortType = 0;
|
||||
motor.indexParity = 0;
|
||||
|
||||
motor.iPortNumber = motorPort;
|
||||
motor.indexBaudRate = 0x13;
|
||||
motor.indexBytesize = 3;
|
||||
motor.indexStopBits = 0;
|
||||
|
||||
PortInfo ultrasound;
|
||||
ultrasound.iPortType = 0;
|
||||
ultrasound.indexParity = 0;
|
||||
ultrasound.iPortNumber = ultrasoundPort;
|
||||
ultrasound.indexBaudRate = 0x0C;
|
||||
ultrasound.indexBytesize = 3;
|
||||
ultrasound.indexStopBits = 0;
|
||||
|
||||
m_ctrlFocusMotor = new CFocusMotorControl();
|
||||
|
||||
m_ctrlFocusMotor->SetLogicZero(m_iMinPos);
|
||||
m_ctrlFocusMotor->SetLimit(m_iMinPos, m_iMaxPos);
|
||||
m_ctrlFocusMotor->InitSystem(motor, ultrasound, test, this);
|
||||
//m_ctrlFocusMotor->MoveToLogicZero();
|
||||
}
|
||||
else
|
||||
{
|
||||
PortInfo motor;
|
||||
motor.iPortType = 0;
|
||||
motor.indexParity = 0;
|
||||
motor.iPortNumber = motorPort;
|
||||
motor.indexBaudRate = 0x13;
|
||||
motor.indexBytesize = 3;
|
||||
motor.indexStopBits = 0;
|
||||
|
||||
m_ctrlFocusMotor = new CFocusMotorControl();
|
||||
|
||||
m_ctrlFocusMotor->SetLogicZero(m_iMinPos);
|
||||
m_ctrlFocusMotor->SetLimit(m_iMinPos, m_iMaxPos);
|
||||
m_ctrlFocusMotor->InitSystem(motor, test, this);
|
||||
m_ctrlFocusMotor->MoveToLogicZero();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
disableBeforeConnect(false);
|
||||
}
|
||||
|
||||
void focusWindow::display_x_loc(std::vector<double> loc)
|
||||
{
|
||||
double tmp = round(loc[0] * 100) / 100;
|
||||
this->ui.currentLocation_lineEdit->setText(QString::number(tmp));
|
||||
}
|
||||
|
||||
void focusWindow::onx_rangeMeasurement()
|
||||
{
|
||||
emit rangeMeasurementSignal(0, m_dSpeed, 1000);
|
||||
}
|
||||
|
||||
void focusWindow::onMove2MotorLogicZero()
|
||||
{
|
||||
m_ctrlFocusMotor->MoveToLogicZero();
|
||||
if (ui.is_new_version_radioButton->isChecked())
|
||||
{
|
||||
emit zeroStartSignal(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ctrlFocusMotor->MoveToLogicZero();
|
||||
}
|
||||
}
|
||||
|
||||
void focusWindow::onMove2MotorMax()
|
||||
{
|
||||
m_ctrlFocusMotor->MoveToPos(m_iMaxPos);
|
||||
if (ui.is_new_version_radioButton->isChecked())
|
||||
{
|
||||
emit move2MaxLocSignal(0, m_dSpeed, 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ctrlFocusMotor->MoveToPos(m_iMaxPos);
|
||||
}
|
||||
}
|
||||
|
||||
void focusWindow::onAdd()
|
||||
{
|
||||
DriverInfo di;
|
||||
m_ctrlFocusMotor->GetDriverStatus(di);
|
||||
double rdistance = ui.addStepSize_lineEdit->text().toDouble();
|
||||
|
||||
int stepSize = ui.addStepSize_lineEdit->text().toInt();
|
||||
if (ui.is_new_version_radioButton->isChecked())
|
||||
{
|
||||
emit rmoveSignal(0, (double)abs(rdistance), m_dSpeed, 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
DriverInfo di;
|
||||
m_ctrlFocusMotor->GetDriverStatus(di);
|
||||
|
||||
m_ctrlFocusMotor->MoveToPos(di.iAbsPosition + stepSize);
|
||||
m_ctrlFocusMotor->MoveToPos(di.iAbsPosition + rdistance);
|
||||
}
|
||||
}
|
||||
|
||||
void focusWindow::onSubtract()
|
||||
{
|
||||
DriverInfo di;
|
||||
m_ctrlFocusMotor->GetDriverStatus(di);
|
||||
double rdistance = ui.subtractStepSize_lineEdit->text().toDouble();
|
||||
|
||||
int stepSize = ui.subtractStepSize_lineEdit->text().toInt();
|
||||
if (ui.is_new_version_radioButton->isChecked())
|
||||
{
|
||||
emit rmoveSignal(0, (double)abs(rdistance) * -1, m_dSpeed, 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
DriverInfo di;
|
||||
m_ctrlFocusMotor->GetDriverStatus(di);
|
||||
|
||||
m_ctrlFocusMotor->MoveToPos(di.iAbsPosition - stepSize);
|
||||
m_ctrlFocusMotor->MoveToPos(di.iAbsPosition - rdistance);
|
||||
}
|
||||
}
|
||||
|
||||
void focusWindow::onAutoFocus()
|
||||
{
|
||||
bool isUltrasound = ui.ultrasound_radioButton->isChecked();
|
||||
WorkerThread2 *thread1 = new WorkerThread2(m_ctrlFocusMotor, isUltrasound);
|
||||
if (ui.is_new_version_radioButton->isChecked())
|
||||
{
|
||||
//先按照一定间隔从负极限到正极限获取一系列(位置,调焦指数)
|
||||
m_iStepSize = ui.sample_ratio_lineEdit->text().toInt();
|
||||
ui.autoFocusProgress_progressBar->setMinimum(0);
|
||||
ui.autoFocusProgress_progressBar->setMaximum(m_iStepSize);
|
||||
ui.autoFocusProgress_progressBar->reset();
|
||||
|
||||
connect(thread1, SIGNAL(AutoFocusFinishedSignal()), this, SLOT(onAutoFocusFinished()));
|
||||
//获取马达最大位置
|
||||
std::vector<double> maxRangeLocations = m_multiAxisController->getMaxPos();
|
||||
double maxPos = maxRangeLocations[0];
|
||||
emit startStepMotion(m_dSpeed, m_iStepSize, 0, maxPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool isUltrasound = ui.ultrasound_radioButton->isChecked();
|
||||
WorkerThread2* thread1 = new WorkerThread2(m_ctrlFocusMotor, isUltrasound);
|
||||
|
||||
thread1->start();
|
||||
connect(thread1, SIGNAL(AutoFocusFinishedSignal()), this, SLOT(onAutoFocusFinished()));
|
||||
|
||||
thread1->start();
|
||||
|
||||
WorkerThread4* progressThread = new WorkerThread4(m_ctrlFocusMotor);
|
||||
connect(progressThread, SIGNAL(AutoFocusProgressSignal(int)), this, SLOT(onAutoFocusProgress(int)));
|
||||
progressThread->start();
|
||||
ui.autoFocusProgress_progressBar->reset();
|
||||
}
|
||||
this->setDisabled(true);
|
||||
|
||||
WorkerThread4 *progressThread = new WorkerThread4(m_ctrlFocusMotor);
|
||||
connect(progressThread, SIGNAL(AutoFocusProgressSignal(int)), this, SLOT(onAutoFocusProgress(int)));
|
||||
progressThread->start();
|
||||
ui.autoFocusProgress_progressBar->reset();
|
||||
}
|
||||
|
||||
void focusWindow::onManualFocus()
|
||||
{
|
||||
if (ui.is_new_version_radioButton->isChecked())
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
m_FocusState += 1;
|
||||
std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><EFBFBD>" << std::endl;
|
||||
std::cout << "点击调焦按钮!" << std::endl;
|
||||
|
||||
|
||||
if (m_FocusState % 2 == 1)
|
||||
{
|
||||
//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//开始调焦
|
||||
emit StartManualFocusSignal(1);
|
||||
ui.manualFocus_btn->setText(QString::fromLocal8Bit("ֹͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
||||
ui.manualFocus_btn->setText(QString::fromLocal8Bit("停止调焦"));
|
||||
|
||||
ui.manualFocus_btn->setStyleSheet("QWidget{background-color:rgb(255,0,0);}");
|
||||
|
||||
ui.autoFocus_btn->setDisabled(true);
|
||||
|
||||
//std::cout << "------------------------------------------<EFBFBD><EFBFBD>" << m_FocusState << std::endl;
|
||||
//std::cout << "------------------------------------------:" << m_FocusState << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
emit StartManualFocusSignal(0);
|
||||
m_Imager->setFocusControlState(false);
|
||||
|
||||
ui.manualFocus_btn->setText(QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
||||
ui.manualFocus_btn->setText(QString::fromLocal8Bit("调焦"));
|
||||
|
||||
ui.manualFocus_btn->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||||
|
||||
@ -237,30 +345,192 @@ void focusWindow::onManualFocus()
|
||||
|
||||
void focusWindow::onUpdateCurrentLocation()
|
||||
{
|
||||
DriverInfo di;
|
||||
m_ctrlFocusMotor->GetDriverStatus(di);
|
||||
ui.currentLocation_lineEdit->setText(QString::number(di.iAbsPosition));
|
||||
if (ui.is_new_version_radioButton->isChecked())
|
||||
{
|
||||
//因为新版的马达控制是实时反馈位置信息,所以不需要做任何事
|
||||
}
|
||||
else
|
||||
{
|
||||
DriverInfo di;
|
||||
m_ctrlFocusMotor->GetDriverStatus(di);
|
||||
ui.currentLocation_lineEdit->setText(QString::number(di.iAbsPosition));
|
||||
}
|
||||
}
|
||||
|
||||
void focusWindow::onMoveto()
|
||||
{
|
||||
int pos = ui.currentLocation_lineEdit->text().toInt();
|
||||
//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD>鿴<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>Χ<EFBFBD><CEA7>
|
||||
double pos = ui.move2_lineEdit->text().toDouble();
|
||||
|
||||
if (ui.is_new_version_radioButton->isChecked())
|
||||
{
|
||||
emit move2LocSignal(0, (double)pos, m_dSpeed, 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
//需要做参数有效性验证,查看是否在有效范围内
|
||||
|
||||
m_ctrlFocusMotor->MoveToPos(pos);
|
||||
m_ctrlFocusMotor->MoveToPos(pos);
|
||||
}
|
||||
}
|
||||
|
||||
void focusWindow::onAutoFocusFinished()
|
||||
{
|
||||
this->setDisabled(false);
|
||||
if (ui.is_new_version_radioButton->isChecked())
|
||||
{
|
||||
//通过高斯拟合获取最佳位置
|
||||
QVector<PositionData> positionData = m_coordinator->getAllPositionData();
|
||||
|
||||
onUpdateCurrentLocation();
|
||||
std::vector<double> actualPositions;
|
||||
std::vector<double> cameraIndices;
|
||||
|
||||
actualPositions.reserve(positionData.size());
|
||||
cameraIndices.reserve(positionData.size());
|
||||
|
||||
int scaleFactor = 100;
|
||||
for (const auto& data : positionData)
|
||||
{
|
||||
actualPositions.push_back(data.actualPosition * scaleFactor);
|
||||
cameraIndices.push_back(data.cameraIndex);
|
||||
}
|
||||
double a_init, mu_init, sigma_init, c_init;
|
||||
getGaussianInitParam(actualPositions, cameraIndices, a_init, mu_init, sigma_init, c_init);
|
||||
|
||||
double a = a_init, mu = mu_init, sigma = sigma_init, c = c_init;
|
||||
gaussian_fit(actualPositions, cameraIndices, a, mu, sigma, c);
|
||||
|
||||
mu_init = mu_init / scaleFactor;
|
||||
mu = mu / scaleFactor;
|
||||
|
||||
std::cout << "mu 初值:" << mu_init << std::endl << "mu 拟合值:" << mu << std::endl;
|
||||
|
||||
//对拟合值进行判断,排除错误拟合情况(地物没有纹理)
|
||||
std::vector<double> maxRangeLocations = m_multiAxisController->getMaxPos();
|
||||
double maxPos = maxRangeLocations[0];
|
||||
if (mu < 0 || mu > maxPos)
|
||||
{
|
||||
std::cout << "拟合失败!!!!!" << std::endl;
|
||||
m_goodPos = mu_init;
|
||||
m_isAutoFocusSuccess = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "拟合成功!!!!!" << std::endl;
|
||||
m_goodPos = mu;
|
||||
m_isAutoFocusSuccess = true;
|
||||
}
|
||||
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QString format1 = "yyyyMMdd_HHmmss";
|
||||
QString fileName = now.toString("yyyyMMdd_HHmmss");
|
||||
|
||||
QString fitDataFile = QDir::cleanPath(QString::fromStdString(directory) + QDir::separator() + fileName + "_" + QString::number(m_iStepSize) + "interval_" + QString::number(mu) + ".csv");
|
||||
m_coordinator->saveToCsv(fitDataFile);
|
||||
|
||||
//由于马达移动准确性较低,自动调焦完成后,直接移动到m_goodPos效果不好,所以先移动到tmpPos,然后移动到m_goodPos
|
||||
double tmpPos = m_goodPos - positionData[positionData.size() - 1].actualPosition / 10;
|
||||
m_isMoveAfterAutoFocus = true;
|
||||
emit move2LocSignal(0, (double)tmpPos, m_dSpeed, 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
onUpdateCurrentLocation();
|
||||
}
|
||||
|
||||
this->setDisabled(false);
|
||||
}
|
||||
|
||||
void focusWindow::moveAfterAutoFocus(int motorID, double location)
|
||||
{
|
||||
if (!m_isMoveAfterAutoFocus)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "\n已经到达位置:" << location << std::endl;
|
||||
|
||||
//移动马达到最佳位置
|
||||
emit move2LocSignal(0, (double)m_goodPos, m_dSpeed, 1000);
|
||||
|
||||
double tmp = abs(location - m_goodPos) / m_goodPos * 100;
|
||||
if (tmp<5)
|
||||
{
|
||||
if (!m_isAutoFocusSuccess)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QString::fromLocal8Bit("纹理较弱,自动调焦效果不佳!请使用调焦纸进行自动调焦!"));
|
||||
msgBox.exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QString::fromLocal8Bit("自动调焦成功!"));
|
||||
msgBox.exec();
|
||||
}
|
||||
m_isMoveAfterAutoFocus = false;
|
||||
}
|
||||
}
|
||||
|
||||
void focusWindow::getGaussianInitParam(const std::vector<double>& pos, const std::vector<double>& index, double& a_init, double& mu_init, double& sigma_init, double& c_init)
|
||||
{
|
||||
auto minmax_element = std::minmax_element(index.begin(), index.end());
|
||||
a_init = *minmax_element.second - *minmax_element.first;
|
||||
mu_init = pos[std::distance(index.begin(), minmax_element.second)];
|
||||
c_init = *minmax_element.first;
|
||||
|
||||
//sigma_init
|
||||
double half_max = (*minmax_element.second + *minmax_element.first) / 2.0;
|
||||
size_t peak_idx = std::distance(index.begin(), minmax_element.second);
|
||||
size_t left_idx = peak_idx;// 找左半高点
|
||||
while (left_idx > 0 && index[left_idx] > half_max) left_idx--;
|
||||
size_t right_idx = peak_idx;// 找右半高点
|
||||
while (right_idx < index.size() - 1 && index[right_idx] > half_max) right_idx++;
|
||||
double fwhm = pos[right_idx] - pos[left_idx];
|
||||
sigma_init = fwhm / 2.3548;
|
||||
}
|
||||
|
||||
// 使用 Gauss-Newton 进行高斯拟合
|
||||
void focusWindow::gaussian_fit(const std::vector<double>& x_data,
|
||||
const std::vector<double>& y_data,
|
||||
double& a, double& mu, double& sigma, double& c)
|
||||
{
|
||||
const int max_iter = 100;
|
||||
for (int iter = 0; iter < max_iter; iter++)
|
||||
{
|
||||
Eigen::MatrixXd J(x_data.size(), 4);
|
||||
Eigen::VectorXd r(x_data.size());
|
||||
|
||||
for (size_t i = 0; i < x_data.size(); i++)
|
||||
{
|
||||
double xi = x_data[i];
|
||||
double yi = y_data[i];
|
||||
double exp_part = std::exp(-(xi - mu) * (xi - mu) / (2 * sigma * sigma));
|
||||
double fi = a * exp_part + c;
|
||||
|
||||
r(i) = yi - fi;
|
||||
|
||||
// 雅可比
|
||||
J(i, 0) = -exp_part; // ∂f/∂a
|
||||
J(i, 1) = -a * exp_part * ((xi - mu) / (sigma * sigma)); // ∂f/∂mu
|
||||
J(i, 2) = -a * exp_part * ((xi - mu) * (xi - mu) / (sigma * sigma * sigma)); // ∂f/∂sigma
|
||||
J(i, 3) = -1.0; // ∂f/∂c
|
||||
}
|
||||
|
||||
Eigen::VectorXd delta = (J.transpose() * J).ldlt().solve(-J.transpose() * r);
|
||||
|
||||
a += delta(0);
|
||||
mu += delta(1);
|
||||
sigma += delta(2);
|
||||
c += delta(3);
|
||||
|
||||
if (delta.norm() < 1e-8) break;
|
||||
}
|
||||
}
|
||||
|
||||
void focusWindow::onAutoFocusProgress(int progress)
|
||||
{
|
||||
//std::cout << "<EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD>" << progress << std::endl;
|
||||
//std::cout << "进度:" << progress << std::endl;
|
||||
|
||||
ui.autoFocusProgress_progressBar->setValue(progress);
|
||||
}
|
||||
@ -287,7 +557,7 @@ WorkerThread2::WorkerThread2(CFocusMotorControl * ctrlFocusMotor, bool isUltraso
|
||||
|
||||
void WorkerThread2::run()
|
||||
{
|
||||
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
//配置文件
|
||||
string HPPACfgFile = getPathofEXE() + "\\HPPA.cfg";
|
||||
Configfile configfile;
|
||||
configfile.setConfigfilePath(HPPACfgFile);
|
||||
@ -326,15 +596,185 @@ void WorkerThread4::run()
|
||||
{
|
||||
int progress = m_ctrlFocusMotor->GetProgressIndex();
|
||||
|
||||
//std::cout << "WorkerThread4::run----<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD>" << progress << std::endl;
|
||||
//std::cout << "WorkerThread4::run----自动调焦进度:" << progress << std::endl;
|
||||
|
||||
emit AutoFocusProgressSignal(progress);
|
||||
if (progress == 100)
|
||||
{
|
||||
//std::cout << "<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>" << std::endl;
|
||||
//std::cout << "自动调焦完成!" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
msleep(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
MotionCaptureCoordinator::MotionCaptureCoordinator(
|
||||
IrisMultiMotorController* motorCtrl,
|
||||
ImagerOperationBase* cameraCtrl,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_motorCtrl(motorCtrl)
|
||||
, m_cameraCtrl(cameraCtrl)
|
||||
, m_currentPos(0)
|
||||
, m_endPos(0)
|
||||
, m_isRunning(false)
|
||||
{
|
||||
//这些信号槽是按照逻辑顺序的
|
||||
connect(this, SIGNAL(moveTo(int, double, double, int)),
|
||||
m_motorCtrl, SLOT(moveTo(int, double, double, int)));
|
||||
|
||||
connect(m_motorCtrl, &IrisMultiMotorController::motorStopSignal,
|
||||
this, &MotionCaptureCoordinator::handlePositionReached);
|
||||
//connect(m_motorCtrl, &IrisMultiMotorController::moveFailed,
|
||||
// this, &MotionCaptureCoordinator::handleError);
|
||||
|
||||
connect(this, SIGNAL(getFocusIndexSobel()),
|
||||
m_cameraCtrl, SLOT(getFocusIndexSobel()));
|
||||
|
||||
connect(m_cameraCtrl, &ImagerOperationBase::FocusIndexSobelSignal,
|
||||
this, &MotionCaptureCoordinator::handleCaptureComplete);
|
||||
//connect(m_cameraCtrl, &ImagerOperationBase::captureFailed,
|
||||
// this, &MotionCaptureCoordinator::handleError);
|
||||
}
|
||||
|
||||
MotionCaptureCoordinator::~MotionCaptureCoordinator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MotionCaptureCoordinator::startStepMotion(double speed, int stepInterval, double startPos, double endPos)
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
if (m_isRunning)
|
||||
{
|
||||
emit errorOccurred("Sequence already running");
|
||||
return;
|
||||
}
|
||||
|
||||
m_counter = 0;
|
||||
|
||||
m_positionData.clear();
|
||||
|
||||
m_speed = speed;
|
||||
m_iStepInterval = stepInterval;
|
||||
m_iStepIntervalRealTime = 1;
|
||||
m_currentPos = startPos;
|
||||
m_endPos = endPos;
|
||||
m_posInternal = (endPos - startPos) / stepInterval;
|
||||
|
||||
m_isRunning = true;
|
||||
|
||||
processNextPosition();
|
||||
}
|
||||
|
||||
void MotionCaptureCoordinator::stopStepMotion()
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
m_isRunning = false;
|
||||
emit sequenceStopped();
|
||||
}
|
||||
|
||||
QVector<PositionData> MotionCaptureCoordinator::getAllPositionData() const
|
||||
{
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
return m_positionData;
|
||||
}
|
||||
|
||||
bool MotionCaptureCoordinator::saveToCsv(const QString& filename)
|
||||
{
|
||||
//QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
out << "Timestamp,targetPosition,ActualPosition,FocusIndex\n";
|
||||
|
||||
for (const auto& data : m_positionData)
|
||||
{
|
||||
out << data.timestamp.toString("yyyy-MM-dd HH:mm:ss.zzz") << ","
|
||||
<< QString::number(data.targetPosition, 'f', 4) << ","
|
||||
<< QString::number(data.actualPosition, 'f', 4) << ","
|
||||
<< QString::number(data.cameraIndex, 'f', 4) << "\n";
|
||||
}
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void MotionCaptureCoordinator::handlePositionReached(int motorID, double pos)
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
//验证马达运动位置是否到达指定位置
|
||||
//if (pos != m_currentPos) return;
|
||||
|
||||
// 记录位置信息
|
||||
PositionData data;
|
||||
data.targetPosition = m_currentPos;
|
||||
data.actualPosition = pos;
|
||||
data.timestamp = QDateTime::currentDateTime();
|
||||
m_positionData.append(data);
|
||||
|
||||
// 开始采集
|
||||
emit getFocusIndexSobel();
|
||||
}
|
||||
|
||||
void MotionCaptureCoordinator::handleCaptureComplete(double index)
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
|
||||
// 更新最近一条记录的相机指数
|
||||
//if (!m_positionData.isEmpty() &&
|
||||
// m_positionData.last().targetPosition == m_positionData.last().actualPosition)
|
||||
//{
|
||||
// m_positionData.last().cameraIndex = index;
|
||||
//}
|
||||
m_positionData.last().cameraIndex = index;
|
||||
|
||||
m_currentPos += m_posInternal;
|
||||
m_iStepIntervalRealTime++;
|
||||
emit progressChanged(m_iStepIntervalRealTime);
|
||||
|
||||
m_counter += 1;
|
||||
|
||||
std::cout << "第" << m_counter << "次采集:" << std::endl;
|
||||
std::cout << "目标位置:" << m_positionData.last().targetPosition << std::endl;
|
||||
std::cout << "实际位置:" << m_positionData.last().actualPosition << std::endl;
|
||||
|
||||
processNextPosition();
|
||||
}
|
||||
|
||||
void MotionCaptureCoordinator::handleError(const QString& error)
|
||||
{
|
||||
QMutexLocker locker(&m_dataMutex);
|
||||
m_isRunning = false;
|
||||
emit errorOccurred(error);
|
||||
}
|
||||
|
||||
void MotionCaptureCoordinator::processNextPosition()
|
||||
{
|
||||
if (!m_isRunning) return;
|
||||
|
||||
if (m_currentPos > m_endPos)
|
||||
{
|
||||
m_isRunning = false;
|
||||
emit sequenceComplete();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
emit moveTo(0, m_currentPos, m_speed, 1000);
|
||||
}
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
#include <QFileDialog>
|
||||
#include <QtSerialPort/QSerialPort>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
||||
#include <QDateTime>
|
||||
#include <QMutex>
|
||||
|
||||
#include "ui_FocusDialog.h"
|
||||
#include "AbstractPortMiscDefines.h"
|
||||
@ -26,6 +28,71 @@
|
||||
#include "hppaConfigFile.h"
|
||||
#include "path_tc.h"
|
||||
#include "ImagerOperationBase.h"
|
||||
#include "IrisMultiMotorController.h"
|
||||
|
||||
#include <Eigen/Dense>
|
||||
#include <cmath>
|
||||
|
||||
// <20><><EFBFBD>ݼ<EFBFBD>¼<EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
struct PositionData {
|
||||
double targetPosition; // Ŀ<><C4BF>λ<EFBFBD><CEBB>
|
||||
double actualPosition; // ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
double cameraIndex; // <20><><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>ָ<EFBFBD><D6B8>
|
||||
QDateTime timestamp; // ʱ<><CAB1><EFBFBD><EFBFBD>
|
||||
|
||||
PositionData(double target = 0, double actual = 0.0, double index = 0.0)
|
||||
: targetPosition(target), actualPosition(actual),
|
||||
cameraIndex(index), timestamp(QDateTime::currentDateTime()) {}
|
||||
};
|
||||
|
||||
// Э<><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
class MotionCaptureCoordinator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MotionCaptureCoordinator(IrisMultiMotorController* motorCtrl,
|
||||
ImagerOperationBase* cameraCtrl,
|
||||
QObject* parent = nullptr);
|
||||
~MotionCaptureCoordinator();
|
||||
|
||||
QVector<PositionData> getAllPositionData() const;
|
||||
bool saveToCsv(const QString& filename);
|
||||
|
||||
public slots:
|
||||
void startStepMotion(double speed, int stepInterval = 100, double startPos = 0, double endPos = -1);//-1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զλ<D4B6><CEBB>
|
||||
void stopStepMotion();
|
||||
|
||||
signals:
|
||||
void progressChanged(int progress);
|
||||
void sequenceComplete();
|
||||
void sequenceStopped();
|
||||
void errorOccurred(const QString& error);
|
||||
void moveTo(int, double, double, int);
|
||||
void getFocusIndexSobel();
|
||||
|
||||
private slots:
|
||||
void handlePositionReached(int motorID, double pos);
|
||||
void handleCaptureComplete(double index);
|
||||
void handleError(const QString& error);
|
||||
|
||||
private:
|
||||
void processNextPosition();
|
||||
|
||||
IrisMultiMotorController* m_motorCtrl;
|
||||
ImagerOperationBase* m_cameraCtrl;
|
||||
QVector<PositionData> m_positionData;
|
||||
mutable QMutex m_dataMutex;
|
||||
|
||||
double m_posInternal;
|
||||
double m_currentPos;
|
||||
double m_endPos;
|
||||
bool m_isRunning;
|
||||
double m_speed;
|
||||
|
||||
int m_iStepInterval;
|
||||
int m_iStepIntervalRealTime;
|
||||
int m_counter;
|
||||
};
|
||||
|
||||
class focusWindow:public QDialog
|
||||
{
|
||||
@ -50,6 +117,21 @@ private:
|
||||
|
||||
void disableBeforeConnect(bool disable);
|
||||
|
||||
QThread m_motorThread;
|
||||
IrisMultiMotorController* m_multiAxisController;
|
||||
double m_dSpeed;
|
||||
|
||||
QThread m_MotionCaptureCoordinatorThread;
|
||||
MotionCaptureCoordinator* m_coordinator;
|
||||
|
||||
int m_iStepSize;
|
||||
double m_goodPos;
|
||||
bool m_isAutoFocusSuccess;
|
||||
bool m_isMoveAfterAutoFocus = false;
|
||||
void getGaussianInitParam(const std::vector<double>& pos, const std::vector<double>& index, double& a_init, double& mu_init, double& sigma_init, double& c_init);
|
||||
void gaussian_fit(const std::vector<double>& x_data, const std::vector<double>& y_data, double& a, double& mu, double& sigma, double& c);
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
void onConnectMotor();
|
||||
void onMove2MotorLogicZero();
|
||||
@ -64,8 +146,21 @@ public Q_SLOTS:
|
||||
void onAutoFocusProgress(int progress);
|
||||
void onUltrasound_radioButton();
|
||||
|
||||
void display_x_loc(std::vector<double> loc);
|
||||
void onx_rangeMeasurement();
|
||||
|
||||
void moveAfterAutoFocus(int motorID, double location);
|
||||
|
||||
signals:
|
||||
void StartManualFocusSignal(int);//1<><31><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
void move2LocSignal(int, double, double, int);
|
||||
void move2MaxLocSignal(int, double, int);
|
||||
void rmoveSignal(int, double, double, int);
|
||||
void rangeMeasurementSignal(int, double, int);
|
||||
void zeroStartSignal(int);
|
||||
|
||||
void startStepMotion(double speed, int stepInterval = 100, double startPos = 0, double endPos = -1);
|
||||
};
|
||||
|
||||
class WorkerThread2 : public QThread
|
||||
|
||||
@ -397,3 +397,529 @@ bool Configfile::updateConfigFile()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
CorningConfigfile::CorningConfigfile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CorningConfigfile::setConfigfilePath(string configfilePath)
|
||||
{
|
||||
m_configfilePath = configfilePath;
|
||||
}
|
||||
|
||||
bool CorningConfigfile::isConfigfileExist()
|
||||
{
|
||||
QFileInfo info(QString::fromStdString(m_configfilePath));
|
||||
|
||||
return info.exists();
|
||||
}
|
||||
|
||||
bool CorningConfigfile::parseConfigfile()
|
||||
{
|
||||
// Read the file. If there is an error, report it and exit.
|
||||
try
|
||||
{
|
||||
cfg.readFile(m_configfilePath);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (const FileIOException& fioex)
|
||||
{
|
||||
std::cerr << "I/O error while reading file." << std::endl;
|
||||
return false;
|
||||
}
|
||||
catch (const ParseException& pex)
|
||||
{
|
||||
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
|
||||
<< " - " << pex.getError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getSpectralBin(int& spectralBin)
|
||||
{
|
||||
try
|
||||
{
|
||||
spectralBin = cfg.lookup("spectralBin");
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
cerr << "No 'spectralBin' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getspatialBin(int& spatialBin)
|
||||
{
|
||||
try
|
||||
{
|
||||
spatialBin = cfg.lookup("spatialBin");
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
cerr << "No 'spatialBin' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getEffectiveWindow(int& width, int& offsetx, int& height, int& offsety)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
int spatialBin;
|
||||
int spectralBin;
|
||||
getspatialBin(spatialBin);
|
||||
getSpectralBin(spectralBin);
|
||||
|
||||
string spatialBinString;
|
||||
if (spatialBin == 1)
|
||||
{
|
||||
spatialBinString = "bin1";
|
||||
}
|
||||
else
|
||||
{
|
||||
spatialBinString = "bin2";
|
||||
}
|
||||
const Setting& spatialArgument = root["effective_window"][spatialBinString]["spatial"];
|
||||
if (!(spatialArgument.lookupValue("width", width)
|
||||
&& spatialArgument.lookupValue("offsetx", offsetx)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string spectralBinString;
|
||||
if (spectralBin == 1)
|
||||
{
|
||||
spectralBinString = "bin1";
|
||||
}
|
||||
else
|
||||
{
|
||||
spectralBinString = "bin2";
|
||||
}
|
||||
const Setting& spectralArgument = root["effective_window"][spectralBinString]["spectral"];
|
||||
if (!(spectralArgument.lookupValue("height", height)
|
||||
&& spectralArgument.lookupValue("offsety", offsety)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getEffectiveWindowRoi(int& width, int& offsetx)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting& effective_window = root["effective_window_roi"];
|
||||
int count = effective_window.getLength();
|
||||
|
||||
int spatialBin;
|
||||
getspatialBin(spatialBin);
|
||||
|
||||
string spatialBinString;
|
||||
if (spatialBin == 1)
|
||||
{
|
||||
spatialBinString = "spatialBin1";
|
||||
}
|
||||
else
|
||||
{
|
||||
spatialBinString = "spatialBin2";
|
||||
}
|
||||
|
||||
const Setting& window = effective_window[spatialBinString];
|
||||
string name = window.getName();
|
||||
|
||||
if (!(window.lookupValue("width", width)
|
||||
&& window.lookupValue("offsetx", offsetx)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getPushFlowParam(int& flowSwitch, int& rgbHeight, int& framerateVideo)
|
||||
{
|
||||
Setting& root = cfg.getRoot();
|
||||
|
||||
if (!root.exists("push_flow_param"))
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB2BB><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Setting& push_flow_param = root.add("push_flow_param", Setting::TypeGroup);
|
||||
|
||||
push_flow_param.add("flow_switch", Setting::TypeInt) = 0;
|
||||
push_flow_param.add("rgb_height", Setting::TypeInt) = 720;
|
||||
push_flow_param.add("framerate_video", Setting::TypeInt) = 5;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ĺ<DEB8><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ļ<EFBFBD>
|
||||
try
|
||||
{
|
||||
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
|
||||
bool ret = createDir(fileInfo[0]);
|
||||
|
||||
cfg.writeFile(m_configfilePath.c_str());
|
||||
std::cout << "Config item 'push_flow_param' added." << std::endl;
|
||||
|
||||
flowSwitch = 0;
|
||||
rgbHeight = 720;
|
||||
framerateVideo = 5;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (const libconfig::FileIOException& fioex)
|
||||
{
|
||||
std::cerr << "I/O error while writing file." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
const Setting& push_flow_param = root["push_flow_param"];
|
||||
|
||||
if (!(push_flow_param.lookupValue("rgb_height", rgbHeight)
|
||||
&& push_flow_param.lookupValue("framerate_video", framerateVideo)
|
||||
&& push_flow_param.lookupValue("flow_switch", flowSwitch)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getWindowOffsety_HeightOfSpectral(int& offsety, int& height, string spectralBinString)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting& spectralArgument = root["effective_window"][spectralBinString]["spectral"];
|
||||
if (!(spectralArgument.lookupValue("height", height)
|
||||
&& spectralArgument.lookupValue("offsety", offsety)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getGainOffset(float& gain, float& offset)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting& gainOffset = root["gainOffset"];
|
||||
int count = gainOffset.getLength();
|
||||
|
||||
int spectralBin;
|
||||
getSpectralBin(spectralBin);
|
||||
|
||||
string spectralBinString;
|
||||
if (spectralBin == 1)
|
||||
{
|
||||
spectralBinString = "spectralBin1";
|
||||
}
|
||||
else
|
||||
{
|
||||
spectralBinString = "spectralBin2";
|
||||
}
|
||||
|
||||
const Setting& gainOffsetSetting = gainOffset[spectralBinString];
|
||||
string name = gainOffsetSetting.getName();
|
||||
|
||||
if (!(gainOffsetSetting.lookupValue("gain", gain)
|
||||
&& gainOffsetSetting.lookupValue("offset", offset)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getGainOffsetOfSpectralBin1(float& gain, float& offset)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting& gainOffset = root["gainOffset"];
|
||||
int count = gainOffset.getLength();
|
||||
|
||||
string spectralBinString = "spectralBin1";
|
||||
|
||||
const Setting& gainOffsetSetting = gainOffset[spectralBinString];
|
||||
string name = gainOffsetSetting.getName();
|
||||
|
||||
if (!(gainOffsetSetting.lookupValue("gain", gain)
|
||||
&& gainOffsetSetting.lookupValue("offset", offset)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getSN(QString& SN)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string SN_tem = cfg.lookup("SN");
|
||||
SN = QString::fromStdString(SN_tem);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
cerr << "No 'spectralBin' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getBufferPolicy(int& bufferPolicy)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
const Setting& ximeadll = root["ximeadll"];
|
||||
|
||||
try
|
||||
{
|
||||
if (!(ximeadll.lookupValue("buffer_policy", bufferPolicy)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
cerr << "No 'spectralBin' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CorningConfigfile::getAcqBufferSize(int& acqBufferSize)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
const Setting& ximeadll = root["ximeadll"];
|
||||
|
||||
try
|
||||
{
|
||||
if (!(ximeadll.lookupValue("acq_buffer_size", acqBufferSize)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
cerr << "No 'spectralBin' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CorningConfigfile::createConfigFile()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace libconfig;
|
||||
|
||||
Config cfg;
|
||||
|
||||
Setting& root = cfg.getRoot();
|
||||
|
||||
// Add some settings to the configuration.
|
||||
Setting& SN = root.add("SN", Setting::TypeString) = "0098";
|
||||
Setting& spatialBin = root.add("spatialBin", Setting::TypeInt) = 2;
|
||||
Setting& SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2;
|
||||
|
||||
Setting& effective_window = root.add("effective_window", Setting::TypeGroup);
|
||||
Setting& effective_window_Bin1 = effective_window.add("bin1", Setting::TypeGroup);
|
||||
Setting& effective_window_Bin1_spatial = effective_window_Bin1.add("spatial", Setting::TypeGroup);
|
||||
Setting& effective_window_Bin1_Spectral = effective_window_Bin1.add("spectral", Setting::TypeGroup);
|
||||
Setting& effective_window_Bin2 = effective_window.add("bin2", Setting::TypeGroup);
|
||||
Setting& effective_window_Bin2_spatial = effective_window_Bin2.add("spatial", Setting::TypeGroup);
|
||||
Setting& effective_window_Bin2_Spectral = effective_window_Bin2.add("spectral", Setting::TypeGroup);
|
||||
|
||||
effective_window_Bin1_spatial.add("width", Setting::TypeInt) = 1368;
|
||||
effective_window_Bin1_spatial.add("offsetx", Setting::TypeInt) = 288;
|
||||
effective_window_Bin1_Spectral.add("height", Setting::TypeInt) = 300;
|
||||
effective_window_Bin1_Spectral.add("offsety", Setting::TypeInt) = 348;
|
||||
|
||||
effective_window_Bin2_spatial.add("width", Setting::TypeInt) = 688;
|
||||
effective_window_Bin2_spatial.add("offsetx", Setting::TypeInt) = 144;
|
||||
effective_window_Bin2_Spectral.add("height", Setting::TypeInt) = 150;
|
||||
effective_window_Bin2_Spectral.add("offsety", Setting::TypeInt) = 174;
|
||||
|
||||
Setting& effective_window_roi = root.add("effective_window_roi", Setting::TypeGroup);
|
||||
Setting& effective_window_roi_spatialBin1 = effective_window_roi.add("spatialBin1", Setting::TypeGroup);
|
||||
Setting& effective_window_roi_spatialBin2 = effective_window_roi.add("spatialBin2", Setting::TypeGroup);
|
||||
|
||||
effective_window_roi_spatialBin1.add("width", Setting::TypeInt) = 1364;
|
||||
effective_window_roi_spatialBin1.add("offsetx", Setting::TypeInt) = 14;
|
||||
// effective_window_roi_Bin1.add("height", Setting::TypeInt) = 300;
|
||||
// effective_window_roi_Bin1.add("offsety", Setting::TypeInt) = 348;
|
||||
|
||||
effective_window_roi_spatialBin2.add("width", Setting::TypeInt) = 682;
|
||||
effective_window_roi_spatialBin2.add("offsetx", Setting::TypeInt) = 15;
|
||||
// effective_window_roi_Bin2.add("height", Setting::TypeInt) = 151;
|
||||
// effective_window_roi_Bin2.add("offsety", Setting::TypeInt) = 174;
|
||||
|
||||
Setting& gainOffset = root.add("gainOffset", Setting::TypeGroup);
|
||||
Setting& gainOffsetSpectralBin1 = gainOffset.add("spectralBin1", Setting::TypeGroup);
|
||||
Setting& gainOffsetSpectralBin2 = gainOffset.add("spectralBin2", Setting::TypeGroup);
|
||||
|
||||
gainOffsetSpectralBin1.add("gain", Setting::TypeFloat) = 2.00313433;
|
||||
gainOffsetSpectralBin1.add("offset", Setting::TypeFloat) = -300.46283157590585;
|
||||
|
||||
gainOffsetSpectralBin2.add("gain", Setting::TypeFloat) = 4.00626868;
|
||||
gainOffsetSpectralBin2.add("offset", Setting::TypeFloat) = -299.46126663407176;
|
||||
|
||||
|
||||
Setting& ximeadll = root.add("ximeadll", Setting::TypeGroup);
|
||||
ximeadll.add("buffer_policy", Setting::TypeInt) = 0;
|
||||
ximeadll.add("acq_buffer_size", Setting::TypeInt) = 400;
|
||||
|
||||
Setting& push_flow_param = root.add("push_flow_param", Setting::TypeGroup);
|
||||
push_flow_param.add("flow_switch", Setting::TypeInt) = 1;
|
||||
push_flow_param.add("rgb_height", Setting::TypeInt) = 720;
|
||||
push_flow_param.add("framerate_video", Setting::TypeInt) = 5;
|
||||
|
||||
// Write out the new configuration.
|
||||
try
|
||||
{
|
||||
cfg.writeFile(m_configfilePath.c_str());
|
||||
cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
|
||||
|
||||
}
|
||||
catch (const FileIOException& fioex)
|
||||
{
|
||||
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CorningConfigfile::updateConfigFile()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace libconfig;
|
||||
|
||||
static const char* output_file = "updated.cfg";
|
||||
|
||||
Config cfg;
|
||||
|
||||
cfg.setOptions(Config::OptionFsync
|
||||
| Config::OptionSemicolonSeparators
|
||||
| Config::OptionColonAssignmentForGroups
|
||||
| Config::OptionOpenBraceOnSeparateLine);
|
||||
|
||||
// Read the file. If there is an error, report it and exit.
|
||||
try
|
||||
{
|
||||
cfg.readFile("example.cfg");
|
||||
}
|
||||
catch (const FileIOException& fioex)
|
||||
{
|
||||
std::cerr << "I/O error while reading file." << std::endl;
|
||||
return false;
|
||||
}
|
||||
catch (const ParseException& pex)
|
||||
{
|
||||
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
|
||||
<< " - " << pex.getError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find the 'movies' setting. Add intermediate settings if they don't yet
|
||||
// exist.
|
||||
Setting& root = cfg.getRoot();
|
||||
|
||||
if (!root.exists("inventory"))
|
||||
root.add("inventory", Setting::TypeGroup);
|
||||
|
||||
Setting& inventory = root["inventory"];
|
||||
|
||||
if (!inventory.exists("movies"))
|
||||
inventory.add("movies", Setting::TypeList);
|
||||
|
||||
Setting& movies = inventory["movies"];
|
||||
|
||||
// Create the new movie entry.
|
||||
Setting& movie = movies.add(Setting::TypeGroup);
|
||||
|
||||
movie.add("title", Setting::TypeString) = "Buckaroo Banzai";
|
||||
movie.add("media", Setting::TypeString) = "DVD";
|
||||
movie.add("price", Setting::TypeFloat) = 12.99;
|
||||
movie.add("qty", Setting::TypeInt) = 20;
|
||||
|
||||
// Write out the updated configuration.
|
||||
try
|
||||
{
|
||||
cfg.writeFile(output_file);
|
||||
cerr << "Updated configuration successfully written to: " << output_file
|
||||
<< endl;
|
||||
|
||||
}
|
||||
catch (const FileIOException& fioex)
|
||||
{
|
||||
cerr << "I/O error while writing file: " << output_file << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -45,6 +45,36 @@ public:
|
||||
bool createConfigFile();
|
||||
bool updateConfigFile();
|
||||
|
||||
private:
|
||||
string m_configfilePath;
|
||||
Config cfg;
|
||||
};
|
||||
|
||||
class CorningConfigfile
|
||||
{
|
||||
public:
|
||||
CorningConfigfile();
|
||||
void setConfigfilePath(string configfilePath);
|
||||
bool isConfigfileExist();
|
||||
bool parseConfigfile();
|
||||
|
||||
bool getSpectralBin(int& spectralBin);
|
||||
bool getspatialBin(int& spatialBin);
|
||||
bool getEffectiveWindow(int& width, int& offsetx, int& height, int& offsety);
|
||||
bool getEffectiveWindowRoi(int& width, int& offsetx);
|
||||
bool getWindowOffsety_HeightOfSpectral(int& offsety, int& height, string spectralBinString);//spectralBinString = "bin1"<22><><EFBFBD>ߡ<EFBFBD>bin2<6E><32>
|
||||
bool getGainOffset(float& gain, float& offset);
|
||||
bool getGainOffsetOfSpectralBin1(float& gain, float& offset);
|
||||
bool getSN(QString& SN);
|
||||
|
||||
bool getBufferPolicy(int& bufferPolicy);
|
||||
bool getAcqBufferSize(int& acqBufferSize);
|
||||
|
||||
bool getPushFlowParam(int& flowSwitch, int& rgbHeight, int& framerateVideo);
|
||||
|
||||
bool createConfigFile();
|
||||
bool updateConfigFile();
|
||||
|
||||
private:
|
||||
string m_configfilePath;
|
||||
Config cfg;
|
||||
|
||||
@ -172,7 +172,7 @@ void CImage::FillFocusGrayQImage(unsigned short * datacube)
|
||||
}
|
||||
}
|
||||
|
||||
m_qimageFocusGrayImage->save("D:/delete/2222222222/test.bmp");
|
||||
//m_qimageFocusGrayImage->save("D:/delete/2222222222/test.bmp");
|
||||
|
||||
|
||||
|
||||
|
||||
299
HPPA/imageControl.cpp
Normal file
299
HPPA/imageControl.cpp
Normal file
@ -0,0 +1,299 @@
|
||||
#include "imageControl.h"
|
||||
#include "RasterLayer.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
ImageControl::ImageControl(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
// Spinbox valueChanged: only sync the paired slider (no render)
|
||||
connect(ui.spinRed, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &ImageControl::onSpinRedValueChanged);
|
||||
connect(ui.spinGreen, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &ImageControl::onSpinGreenValueChanged);
|
||||
connect(ui.spinBlue, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &ImageControl::onSpinBlueValueChanged);
|
||||
|
||||
// Spinbox editingFinished: commit on Enter key / focus lost (trigger render)
|
||||
connect(ui.spinRed, &QDoubleSpinBox::editingFinished, this, &ImageControl::onSpinRedEditingFinished);
|
||||
connect(ui.spinGreen, &QDoubleSpinBox::editingFinished, this, &ImageControl::onSpinGreenEditingFinished);
|
||||
connect(ui.spinBlue, &QDoubleSpinBox::editingFinished, this, &ImageControl::onSpinBlueEditingFinished);
|
||||
|
||||
// Slider valueChanged: only sync the paired spinbox (no render)
|
||||
// Slider now represents band index (0 .. N-1)
|
||||
connect(ui.sliderRed, &QSlider::valueChanged, this, &ImageControl::onSliderRedValueChanged);
|
||||
connect(ui.sliderGreen, &QSlider::valueChanged, this, &ImageControl::onSliderGreenValueChanged);
|
||||
connect(ui.sliderBlue, &QSlider::valueChanged, this, &ImageControl::onSliderBlueValueChanged);
|
||||
|
||||
// Slider sliderReleased: commit on mouse release (trigger render)
|
||||
connect(ui.sliderRed, &QSlider::sliderReleased, this, &ImageControl::onSliderRedReleased);
|
||||
connect(ui.sliderGreen, &QSlider::sliderReleased, this, &ImageControl::onSliderGreenReleased);
|
||||
connect(ui.sliderBlue, &QSlider::sliderReleased, this, &ImageControl::onSliderBlueReleased);
|
||||
|
||||
// Connect preset buttons
|
||||
connect(ui.btnTrueColor, &QPushButton::clicked, this, &ImageControl::onTrueColorClicked);
|
||||
connect(ui.btnColorInfrared, &QPushButton::clicked, this, &ImageControl::onColorInfraredClicked);
|
||||
|
||||
// Spinbox only commits on Enter, not on every keystroke
|
||||
ui.spinRed->setKeyboardTracking(false);
|
||||
ui.spinGreen->setKeyboardTracking(false);
|
||||
ui.spinBlue->setKeyboardTracking(false);
|
||||
}
|
||||
|
||||
ImageControl::~ImageControl()
|
||||
{
|
||||
}
|
||||
|
||||
void ImageControl::setActiveLayer(RasterLayer* layer)
|
||||
{
|
||||
m_activeLayer = layer;
|
||||
|
||||
if (!layer) {
|
||||
setEnabled(false);
|
||||
m_wavelengths.clear();
|
||||
return;
|
||||
}
|
||||
setEnabled(true);
|
||||
|
||||
// Get band wavelengths from the layer's header
|
||||
m_wavelengths = layer->bandWavelengths();
|
||||
std::sort(m_wavelengths.begin(), m_wavelengths.end());
|
||||
|
||||
if (m_wavelengths.empty()) {
|
||||
setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
m_minWave = m_wavelengths.front();
|
||||
m_maxWave = m_wavelengths.back();
|
||||
|
||||
// Compute spinbox step as the average wavelength interval between adjacent bands
|
||||
double step = 1.0;
|
||||
if (m_wavelengths.size() >= 2) {
|
||||
step = (m_maxWave - m_minWave) / (m_wavelengths.size() - 1);
|
||||
}
|
||||
|
||||
blockAllSignals(true);
|
||||
|
||||
// Configure spinbox ranges and step
|
||||
ui.spinRed->setMinimum(m_minWave);
|
||||
ui.spinRed->setMaximum(m_maxWave);
|
||||
ui.spinRed->setSingleStep(step);
|
||||
ui.spinGreen->setMinimum(m_minWave);
|
||||
ui.spinGreen->setMaximum(m_maxWave);
|
||||
ui.spinGreen->setSingleStep(step);
|
||||
ui.spinBlue->setMinimum(m_minWave);
|
||||
ui.spinBlue->setMaximum(m_maxWave);
|
||||
ui.spinBlue->setSingleStep(step);
|
||||
|
||||
// Slider now represents band index (0 .. N-1), step = 1
|
||||
int maxIdx = static_cast<int>(m_wavelengths.size()) - 1;
|
||||
ui.sliderRed->setMinimum(0);
|
||||
ui.sliderRed->setMaximum(maxIdx);
|
||||
ui.sliderRed->setSingleStep(1);
|
||||
ui.sliderRed->setPageStep(1);
|
||||
ui.sliderGreen->setMinimum(0);
|
||||
ui.sliderGreen->setMaximum(maxIdx);
|
||||
ui.sliderGreen->setSingleStep(1);
|
||||
ui.sliderGreen->setPageStep(1);
|
||||
ui.sliderBlue->setMinimum(0);
|
||||
ui.sliderBlue->setMaximum(maxIdx);
|
||||
ui.sliderBlue->setSingleStep(1);
|
||||
ui.sliderBlue->setPageStep(1);
|
||||
|
||||
// Set current values from layer's render params
|
||||
auto params = layer->currentRenderParams();
|
||||
|
||||
int rIdx = nearestBandIndex(params.rWave);
|
||||
int gIdx = nearestBandIndex(params.gWave);
|
||||
int bIdx = nearestBandIndex(params.bWave);
|
||||
|
||||
ui.spinRed->setValue(m_wavelengths[rIdx]);
|
||||
ui.spinGreen->setValue(m_wavelengths[gIdx]);
|
||||
ui.spinBlue->setValue(m_wavelengths[bIdx]);
|
||||
|
||||
ui.sliderRed->setValue(rIdx);
|
||||
ui.sliderGreen->setValue(gIdx);
|
||||
ui.sliderBlue->setValue(bIdx);
|
||||
|
||||
blockAllSignals(false);
|
||||
}
|
||||
|
||||
RasterLayer* ImageControl::activeLayer() const
|
||||
{
|
||||
return m_activeLayer;
|
||||
}
|
||||
|
||||
int ImageControl::nearestBandIndex(double wave) const
|
||||
{
|
||||
if (m_wavelengths.empty()) return 0;
|
||||
int best = 0;
|
||||
double bestDiff = std::abs(m_wavelengths[0] - wave);
|
||||
for (int i = 1; i < static_cast<int>(m_wavelengths.size()); ++i) {
|
||||
double d = std::abs(m_wavelengths[i] - wave);
|
||||
if (d < bestDiff) {
|
||||
bestDiff = d;
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
void ImageControl::setControlsToBandIndex(QDoubleSpinBox* spin, QSlider* slider, int idx)
|
||||
{
|
||||
if (idx < 0 || idx >= static_cast<int>(m_wavelengths.size())) return;
|
||||
double wv = m_wavelengths[idx];
|
||||
spin->blockSignals(true);
|
||||
spin->setValue(wv);
|
||||
spin->blockSignals(false);
|
||||
slider->blockSignals(true);
|
||||
slider->setValue(idx);
|
||||
slider->blockSignals(false);
|
||||
}
|
||||
|
||||
// --- Spinbox valueChanged: snap to nearest band, sync slider, no render ---
|
||||
|
||||
void ImageControl::onSpinRedValueChanged(double val)
|
||||
{
|
||||
int idx = nearestBandIndex(val);
|
||||
ui.sliderRed->blockSignals(true);
|
||||
ui.sliderRed->setValue(idx);
|
||||
ui.sliderRed->blockSignals(false);
|
||||
}
|
||||
|
||||
void ImageControl::onSpinGreenValueChanged(double val)
|
||||
{
|
||||
int idx = nearestBandIndex(val);
|
||||
ui.sliderGreen->blockSignals(true);
|
||||
ui.sliderGreen->setValue(idx);
|
||||
ui.sliderGreen->blockSignals(false);
|
||||
}
|
||||
|
||||
void ImageControl::onSpinBlueValueChanged(double val)
|
||||
{
|
||||
int idx = nearestBandIndex(val);
|
||||
ui.sliderBlue->blockSignals(true);
|
||||
ui.sliderBlue->setValue(idx);
|
||||
ui.sliderBlue->blockSignals(false);
|
||||
}
|
||||
|
||||
// --- Slider valueChanged: map band index to wavelength, sync spinbox, no render ---
|
||||
|
||||
void ImageControl::onSliderRedValueChanged(int val)
|
||||
{
|
||||
if (val < 0 || val >= static_cast<int>(m_wavelengths.size())) return;
|
||||
ui.spinRed->blockSignals(true);
|
||||
ui.spinRed->setValue(m_wavelengths[val]);
|
||||
ui.spinRed->blockSignals(false);
|
||||
}
|
||||
|
||||
void ImageControl::onSliderGreenValueChanged(int val)
|
||||
{
|
||||
if (val < 0 || val >= static_cast<int>(m_wavelengths.size())) return;
|
||||
ui.spinGreen->blockSignals(true);
|
||||
ui.spinGreen->setValue(m_wavelengths[val]);
|
||||
ui.spinGreen->blockSignals(false);
|
||||
}
|
||||
|
||||
void ImageControl::onSliderBlueValueChanged(int val)
|
||||
{
|
||||
if (val < 0 || val >= static_cast<int>(m_wavelengths.size())) return;
|
||||
ui.spinBlue->blockSignals(true);
|
||||
ui.spinBlue->setValue(m_wavelengths[val]);
|
||||
ui.spinBlue->blockSignals(false);
|
||||
}
|
||||
|
||||
// --- Spinbox editingFinished: snap to nearest band wavelength, then commit ---
|
||||
|
||||
void ImageControl::onSpinRedEditingFinished()
|
||||
{
|
||||
int idx = nearestBandIndex(ui.spinRed->value());
|
||||
setControlsToBandIndex(ui.spinRed, ui.sliderRed, idx);
|
||||
emitBandChange();
|
||||
}
|
||||
|
||||
void ImageControl::onSpinGreenEditingFinished()
|
||||
{
|
||||
int idx = nearestBandIndex(ui.spinGreen->value());
|
||||
setControlsToBandIndex(ui.spinGreen, ui.sliderGreen, idx);
|
||||
emitBandChange();
|
||||
}
|
||||
|
||||
void ImageControl::onSpinBlueEditingFinished()
|
||||
{
|
||||
int idx = nearestBandIndex(ui.spinBlue->value());
|
||||
setControlsToBandIndex(ui.spinBlue, ui.sliderBlue, idx);
|
||||
emitBandChange();
|
||||
}
|
||||
|
||||
// --- Slider sliderReleased: commit on mouse release ---
|
||||
|
||||
void ImageControl::onSliderRedReleased()
|
||||
{
|
||||
emitBandChange();
|
||||
}
|
||||
|
||||
void ImageControl::onSliderGreenReleased()
|
||||
{
|
||||
emitBandChange();
|
||||
}
|
||||
|
||||
void ImageControl::onSliderBlueReleased()
|
||||
{
|
||||
emitBandChange();
|
||||
}
|
||||
|
||||
// --- Preset buttons ---
|
||||
|
||||
void ImageControl::onTrueColorClicked()
|
||||
{
|
||||
blockAllSignals(true);
|
||||
int rIdx = nearestBandIndex(665.0);
|
||||
int gIdx = nearestBandIndex(560.0);
|
||||
int bIdx = nearestBandIndex(490.0);
|
||||
setControlsToBandIndex(ui.spinRed, ui.sliderRed, rIdx);
|
||||
setControlsToBandIndex(ui.spinGreen, ui.sliderGreen, gIdx);
|
||||
setControlsToBandIndex(ui.spinBlue, ui.sliderBlue, bIdx);
|
||||
blockAllSignals(false);
|
||||
emitBandChange();
|
||||
}
|
||||
|
||||
void ImageControl::onColorInfraredClicked()
|
||||
{
|
||||
blockAllSignals(true);
|
||||
int rIdx = nearestBandIndex(800.0);
|
||||
int gIdx = nearestBandIndex(665.0);
|
||||
int bIdx = nearestBandIndex(560.0);
|
||||
setControlsToBandIndex(ui.spinRed, ui.sliderRed, rIdx);
|
||||
setControlsToBandIndex(ui.spinGreen, ui.sliderGreen, gIdx);
|
||||
setControlsToBandIndex(ui.spinBlue, ui.sliderBlue, bIdx);
|
||||
blockAllSignals(false);
|
||||
emitBandChange();
|
||||
}
|
||||
|
||||
void ImageControl::emitBandChange()
|
||||
{
|
||||
double r = ui.spinRed->value();
|
||||
double g = ui.spinGreen->value();
|
||||
double b = ui.spinBlue->value();
|
||||
|
||||
// Update active layer's stored render params
|
||||
if (m_activeLayer) {
|
||||
auto params = m_activeLayer->currentRenderParams();
|
||||
params.rWave = r;
|
||||
params.gWave = g;
|
||||
params.bWave = b;
|
||||
m_activeLayer->setCurrentRenderParams(params);
|
||||
}
|
||||
|
||||
emit bandSelectionChanged(r, g, b);
|
||||
}
|
||||
|
||||
void ImageControl::blockAllSignals(bool block)
|
||||
{
|
||||
ui.spinRed->blockSignals(block);
|
||||
ui.spinGreen->blockSignals(block);
|
||||
ui.spinBlue->blockSignals(block);
|
||||
ui.sliderRed->blockSignals(block);
|
||||
ui.sliderGreen->blockSignals(block);
|
||||
ui.sliderBlue->blockSignals(block);
|
||||
}
|
||||
69
HPPA/imageControl.h
Normal file
69
HPPA/imageControl.h
Normal file
@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <vector>
|
||||
|
||||
#include "ui_imgControl.h"
|
||||
|
||||
class RasterLayer;
|
||||
|
||||
class ImageControl : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
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;
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
Q_SIGNALS:
|
||||
// Emitted when user changes any of the R/G/B wavelength values
|
||||
void bandSelectionChanged(double rWave, double gWave, double bWave);
|
||||
|
||||
private Q_SLOTS:
|
||||
// Sync slider position while dragging spinbox (no render)
|
||||
void onSpinRedValueChanged(double val);
|
||||
void onSpinGreenValueChanged(double val);
|
||||
void onSpinBlueValueChanged(double val);
|
||||
|
||||
// Sync spinbox display while dragging slider (no render)
|
||||
void onSliderRedValueChanged(int val);
|
||||
void onSliderGreenValueChanged(int val);
|
||||
void onSliderBlueValueChanged(int val);
|
||||
|
||||
// Commit: spinbox Enter key pressed / focus lost
|
||||
void onSpinRedEditingFinished();
|
||||
void onSpinGreenEditingFinished();
|
||||
void onSpinBlueEditingFinished();
|
||||
|
||||
// Commit: slider mouse released
|
||||
void onSliderRedReleased();
|
||||
void onSliderGreenReleased();
|
||||
void onSliderBlueReleased();
|
||||
|
||||
void onTrueColorClicked();
|
||||
void onColorInfraredClicked();
|
||||
|
||||
private:
|
||||
void emitBandChange();
|
||||
void blockAllSignals(bool block);
|
||||
|
||||
// Find the band index whose wavelength is closest to the given value
|
||||
int nearestBandIndex(double wave) const;
|
||||
// Set spinbox and slider to wavelength of the given band index
|
||||
void setControlsToBandIndex(QDoubleSpinBox* spin, QSlider* slider, int idx);
|
||||
|
||||
Ui::ImageControl ui;
|
||||
RasterLayer* m_activeLayer = nullptr;
|
||||
double m_minWave = 374.5;
|
||||
double m_maxWave = 948.1;
|
||||
std::vector<double> m_wavelengths; // band wavelengths from header
|
||||
};
|
||||
165
HPPA/imager_base.cpp
Normal file
165
HPPA/imager_base.cpp
Normal file
@ -0,0 +1,165 @@
|
||||
#include "imager_base.h"
|
||||
Iris::ImagerBase::ImagerBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Iris::ImagerBase::~ImagerBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Iris::ImagerBase::set_spectral_bin(int new_spectral_bin)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_spectral_bin()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_min_spectral_bin()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_max_spectral_bin()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_start_band()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Iris::ImagerBase::set_start_band(int band)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_min_start_band()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_max_start_band()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_inc_start_band()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_end_band()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Iris::ImagerBase::set_end_band(int band)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_min_end_band()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_max_end_band()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_inc_end_band()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_start_sample()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Iris::ImagerBase::set_start_sample(int sample)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_min_start_sample()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_max_start_sample()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_inc_start_sample()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_end_sample()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Iris::ImagerBase::set_end_sample(int sample)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_min_end_sample()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_max_end_sample()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Iris::ImagerBase::get_inc_end_sample()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Iris::ImagerBase::set_gain(const double gain)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
double Iris::ImagerBase::get_gain()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
double Iris::ImagerBase::get_min_gain()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
double Iris::ImagerBase::get_max_gain()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Iris::ImagerBase::set_internal_trigger()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Iris::ImagerBase::set_external_trigger(unsigned int signal_line, bool rising_edge)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Iris::ImagerBase::is_trigger_external()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
93
HPPA/imager_base.h
Normal file
93
HPPA/imager_base.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Iris API
|
||||
*
|
||||
* By using this API, the user agrees to the terms and conditions as stated in the
|
||||
* document "Terms of Use", located on the Resonon website
|
||||
* at: http://www.resonon.com/downloads/Resonon_API_Terms_of_Use.pdf.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GUARD_Iris_IMAGER_BASE_H
|
||||
#define __GUARD_Iris_IMAGER_BASE_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cstdint>
|
||||
//#include "irisximeaimager_global.h"
|
||||
|
||||
/**
|
||||
* The Iris namespace contains all public classes.
|
||||
*/
|
||||
namespace Iris
|
||||
{
|
||||
/**
|
||||
* An abstract base class which provides a common interface for all imagers.
|
||||
*/
|
||||
class ImagerBase
|
||||
{
|
||||
public:
|
||||
ImagerBase();
|
||||
virtual ~ImagerBase();
|
||||
|
||||
|
||||
virtual void connect(const char * camera_sn=NULL)=0;
|
||||
virtual void disconnect()=0;
|
||||
virtual void start()=0;
|
||||
virtual void stop()=0;
|
||||
virtual void get_imager_type(char *buffer, int buffer_size)=0;
|
||||
virtual void get_serial_number(char *buffer, int buffer_size)=0;
|
||||
virtual void get_camera_serial_number(char *buffer, int buffer_size)=0;
|
||||
virtual void generate_configuration_report(char *buffer, int buffer_size)=0;
|
||||
virtual float get_coeff_a()=0;
|
||||
virtual float get_coeff_b()=0;
|
||||
virtual float get_coeff_c()=0;
|
||||
virtual double get_wavelength_at_band(const int band)=0;
|
||||
int get_nearest_band_to_wavelength(const double wavelength);
|
||||
virtual int get_frame_buffer_size_in_bytes()=0;
|
||||
virtual unsigned short* get_frame(unsigned short* buffer)=0;
|
||||
virtual std::uint64_t get_last_timestamp()=0;
|
||||
virtual std::uint64_t ticks_per_second()=0;
|
||||
virtual void set_spectral_bin(int new_spectral_bin);
|
||||
virtual int get_spectral_bin();
|
||||
virtual int get_min_spectral_bin();
|
||||
virtual int get_max_spectral_bin();
|
||||
virtual int get_band_count()=0;
|
||||
virtual int get_start_band();
|
||||
virtual void set_start_band(int band);
|
||||
virtual int get_min_start_band();
|
||||
virtual int get_max_start_band();
|
||||
virtual int get_inc_start_band();
|
||||
virtual int get_end_band();
|
||||
virtual void set_end_band(int band);
|
||||
virtual int get_min_end_band();
|
||||
virtual int get_max_end_band();
|
||||
virtual int get_inc_end_band();
|
||||
virtual int get_sample_count()=0;
|
||||
virtual int get_start_sample();
|
||||
virtual void set_start_sample(int sample);
|
||||
virtual int get_min_start_sample();
|
||||
virtual int get_max_start_sample();
|
||||
virtual int get_inc_start_sample();
|
||||
virtual int get_end_sample();
|
||||
virtual void set_end_sample(int sample);
|
||||
virtual int get_min_end_sample();
|
||||
virtual int get_max_end_sample();
|
||||
virtual int get_inc_end_sample();
|
||||
virtual void set_framerate(const double frames_per_second)=0;
|
||||
virtual double get_framerate()=0;
|
||||
virtual double get_min_framerate()=0;
|
||||
virtual double get_max_framerate()=0;
|
||||
virtual double get_min_integration_time()=0;
|
||||
virtual double get_max_integration_time()=0;
|
||||
virtual void set_integration_time(const double milliseconds)=0;
|
||||
virtual double get_integration_time()=0;
|
||||
virtual void set_gain(const double gain);
|
||||
virtual double get_gain();
|
||||
virtual double get_min_gain();
|
||||
virtual double get_max_gain();
|
||||
virtual void set_internal_trigger();
|
||||
virtual void set_external_trigger(unsigned int signal_line, bool rising_edge=true);
|
||||
virtual bool is_trigger_external();
|
||||
};
|
||||
} //end namespace Iris
|
||||
#endif //end ifndef __GUARD_Iris_IMAGER_BASE_H
|
||||
210
HPPA/imgControl.ui
Normal file
210
HPPA/imgControl.ui
Normal file
@ -0,0 +1,210 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ImageControl</class>
|
||||
<widget class="QWidget" name="ImageControl">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>520</width>
|
||||
<height>360</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Color Adjust</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QLabel {
|
||||
color: rgb(255, 255, 255);
|
||||
}
|
||||
|
||||
QSlider::groove:horizontal {
|
||||
height: 10px;
|
||||
background: #1e2a44;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* 已滑过:渐变蓝 */
|
||||
QSlider::sub-page:horizontal {
|
||||
background: qlineargradient(
|
||||
x1:0, y1:0, x2:1, y2:0,
|
||||
stop:0 #1f4fff,
|
||||
stop:0.5 #2f6bff,
|
||||
stop:1 #5fa0ff
|
||||
);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* 未滑过 */
|
||||
QSlider::add-page:horizontal {
|
||||
height: 10px;
|
||||
background: #2a3550;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* ===== 滑块按钮 ===== */
|
||||
QSlider::handle:horizontal {
|
||||
width: 15px;
|
||||
height: 10px;
|
||||
|
||||
/* 蓝色实心 */
|
||||
background: #2f6bff;
|
||||
|
||||
/* 白色外圈 */
|
||||
border: 2px solid #ffffff;
|
||||
border-radius: 5px;
|
||||
|
||||
/* 垂直居中 */
|
||||
margin: -5px 0;
|
||||
}
|
||||
|
||||
/* 悬停 */
|
||||
QSlider::handle:horizontal:hover {
|
||||
background: #4d8dff;
|
||||
}
|
||||
|
||||
/* 按下 */
|
||||
QSlider::handle:horizontal:pressed {
|
||||
background: #1f4fff;
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupAdjustments">
|
||||
<property name="title">
|
||||
<string>调整</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelRed">
|
||||
<property name="text">
|
||||
<string>红</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="spinRed">
|
||||
<property name="minimum">
|
||||
<double>374.500000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>948.100000000000023</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>643.100000000000023</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QSlider" name="sliderRed">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="labelRedNm">
|
||||
<property name="text">
|
||||
<string>nm</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelGreen">
|
||||
<property name="text">
|
||||
<string>绿</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="spinGreen">
|
||||
<property name="minimum">
|
||||
<double>374.500000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>948.100000000000023</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>548.799999999999955</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QSlider" name="sliderGreen">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLabel" name="labelGreenNm">
|
||||
<property name="text">
|
||||
<string>nm</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labelBlue">
|
||||
<property name="text">
|
||||
<string>蓝</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="spinBlue">
|
||||
<property name="minimum">
|
||||
<double>374.500000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>948.100000000000023</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>461.600000000000023</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QSlider" name="sliderBlue">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QLabel" name="labelBlueNm">
|
||||
<property name="text">
|
||||
<string>nm</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupPresets">
|
||||
<property name="title">
|
||||
<string>预设</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="presetLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnTrueColor">
|
||||
<property name="text">
|
||||
<string>真彩色</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnColorInfrared">
|
||||
<property name="text">
|
||||
<string>假彩色</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
565
HPPA/irisximeaimager.cpp
Normal file
565
HPPA/irisximeaimager.cpp
Normal file
@ -0,0 +1,565 @@
|
||||
#include "irisximeaimager.h"
|
||||
using namespace Iris;
|
||||
|
||||
void Iris::IrisXimeaImager::setGainOffset(float gain, float offset)
|
||||
{
|
||||
m_fGain = gain;
|
||||
m_fOffset = offset;
|
||||
}
|
||||
|
||||
bool Iris::IrisXimeaImager::setSpectralBin(int spectralBin)
|
||||
{
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_SELECTOR, XI_BIN_SELECT_HOST_CPU));//用:XI_BIN_SELECT_HOST_CPU;默认为XI_BIN_SELECT_SENSOR(会报错),不可用:XI_BIN_SELECT_DEVICE_FPGA
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_VERTICAL_MODE, XI_BIN_MODE_AVERAGE));
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_VERTICAL, spectralBin));
|
||||
printf("Iris::IrisXimeaImager::setSpectralBin----2 设置bin模式为XI_PRM_BINNING_SELECTOR XI_BIN_MODE_AVERAGE !\n");
|
||||
|
||||
|
||||
// CE(xiSetParamInt(m_xiH, XI_PRM_DECIMATION_SELECTOR, XI_DEC_SELECT_SENSOR));
|
||||
// CE(xiSetParamInt(m_xiH, XI_PRM_DECIMATION_VERTICAL, spectralBin));
|
||||
|
||||
|
||||
m_iSpectralBin = spectralBin;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Iris::IrisXimeaImager::setSpatialBin(int spatialBin)
|
||||
{
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_SELECTOR, XI_BIN_SELECT_HOST_CPU));//用:XI_BIN_SELECT_HOST_CPU;默认为XI_BIN_SELECT_SENSOR(会报错),不可用:XI_BIN_SELECT_DEVICE_FPGA
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL_MODE, XI_BIN_MODE_AVERAGE));
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL, spatialBin));
|
||||
printf("Iris::IrisXimeaImager::setSpatialBin----2 设置bin模式为XI_PRM_BINNING_SELECTOR XI_BIN_MODE_AVERAGE !\n");
|
||||
|
||||
|
||||
// CE(xiSetParamInt(m_xiH, XI_PRM_DECIMATION_SELECTOR, XI_DEC_SELECT_SENSOR));
|
||||
// CE(xiSetParamInt(m_xiH, XI_PRM_DECIMATION_HORIZONTAL, spatialBin));
|
||||
|
||||
m_iSpatialBin = spatialBin;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::getSpectralBin()
|
||||
{
|
||||
int spectralBin = 0;
|
||||
CE(xiGetParamInt(m_xiH, XI_PRM_BINNING_VERTICAL, &spectralBin));
|
||||
|
||||
// CE(xiGetParamInt(m_xiH, XI_PRM_DECIMATION_VERTICAL, &spectralBin));
|
||||
|
||||
return spectralBin;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::getSpatialBin()
|
||||
{
|
||||
int spatialBin = 0;
|
||||
CE(xiGetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL, &spatialBin));
|
||||
|
||||
// CE(xiGetParamInt(m_xiH, XI_PRM_DECIMATION_HORIZONTAL, &spatialBin));
|
||||
|
||||
return spatialBin;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::setEffectiveWindow(int OffsetX, int width, int OffsetY, int height)
|
||||
{
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_WIDTH, width));
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_OFFSET_X, OffsetX));
|
||||
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_HEIGHT, height));
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_OFFSET_Y, OffsetY));
|
||||
|
||||
m_iEffectiveWindow_OffsetX = OffsetX;
|
||||
m_iEffectiveWindow_width = width;
|
||||
m_iEffectiveWindow_OffsetY = OffsetY;
|
||||
m_iEffectiveWindow_height = height;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::setEffectiveWindowRoi(int OffsetX, int width)
|
||||
{
|
||||
m_iEffectiveWindowRoi_OffsetX = OffsetX;
|
||||
m_iEffectiveWindowRoi_width = width;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::getBufferSizeOfOneFrame()
|
||||
{
|
||||
// if(m_xiH==NULL)
|
||||
// return 0;
|
||||
//
|
||||
// start();
|
||||
//
|
||||
// //清空image缓存
|
||||
// memset(&m_image, 0, sizeof(m_image));
|
||||
// m_image.size = sizeof(XI_IMG);
|
||||
//
|
||||
// CE(xiGetImage(m_xiH, 5000, &m_image)); // getting next image from the camera opened
|
||||
//
|
||||
// stop();
|
||||
//
|
||||
// return static_cast<int>(m_image.bp_size);
|
||||
|
||||
// //比实际大小(m_iEffectiveWindow_height * m_iEffectiveWindow_width * 2)大,why?
|
||||
// int value = 0;
|
||||
// xiGetParamInt(m_xiH, XI_PRM_IMAGE_PAYLOAD_SIZE, &value);
|
||||
|
||||
|
||||
return m_iEffectiveWindow_height * m_iEffectiveWindow_width * 2;
|
||||
}
|
||||
|
||||
float Iris::IrisXimeaImager::getTemperature()
|
||||
{
|
||||
float temperature = 0.0;
|
||||
CE(xiGetParamFloat(m_xiH, XI_PRM_TEMP, &temperature));
|
||||
|
||||
return temperature;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::setBufferPolicy(int bufferPolicy)
|
||||
{
|
||||
if (bufferPolicy==0)
|
||||
{
|
||||
xiSetParamInt(m_xiH, XI_PRM_BUFFER_POLICY, XI_BP_UNSAFE);
|
||||
printf("Iris::IrisXimeaImager::connect---- XI_PRM_BUFFER_POLICY: XI_BP_UNSAFE\n");
|
||||
}
|
||||
else if (bufferPolicy==1)
|
||||
{
|
||||
xiSetParamInt(m_xiH, XI_PRM_BUFFER_POLICY, XI_BP_SAFE);
|
||||
printf("Iris::IrisXimeaImager::connect---- XI_PRM_BUFFER_POLICY: XI_BP_SAFE\n");
|
||||
}
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::setAcqBufferSize(int acqBufferSize)
|
||||
{
|
||||
XI_RETURN stat = XI_OK;
|
||||
|
||||
// set unit to 1 MiB
|
||||
xiSetParamInt(m_xiH, XI_PRM_ACQ_BUFFER_SIZE_UNIT, 1024*1024);
|
||||
int value = 0;
|
||||
xiGetParamInt(m_xiH, XI_PRM_ACQ_BUFFER_SIZE, &value);
|
||||
printf("Iris::IrisXimeaImager::connect---- XI_PRM_ACQ_BUFFER_SIZE: %d MiB.\n", value);
|
||||
|
||||
xiSetParamInt(m_xiH, XI_PRM_ACQ_BUFFER_SIZE, acqBufferSize);
|
||||
|
||||
xiGetParamInt(m_xiH, XI_PRM_ACQ_BUFFER_SIZE, &value);
|
||||
printf("Iris::IrisXimeaImager::connect---- XI_PRM_ACQ_BUFFER_SIZE: %d MiB.\n", value);
|
||||
|
||||
// set maximum number of queue
|
||||
int number_of_field_buffers = 0;
|
||||
xiGetParamInt(m_xiH, XI_PRM_BUFFERS_QUEUE_SIZE XI_PRM_INFO_MAX, &number_of_field_buffers);
|
||||
printf("Iris::IrisXimeaImager::connect---- XI_PRM_BUFFERS_QUEUE_SIZE XI_PRM_INFO_MAX: %d.\n", number_of_field_buffers);
|
||||
HandleResult(stat,"xiGetParam (number_of_field_buffers maximum)");
|
||||
xiSetParamInt(m_xiH, XI_PRM_BUFFERS_QUEUE_SIZE, number_of_field_buffers);
|
||||
HandleResult(stat,"xiSetParam (number_of_field_buffers)");
|
||||
}
|
||||
|
||||
Iris::IrisXimeaImager::IrisXimeaImager()
|
||||
{
|
||||
m_xiH=NULL;
|
||||
|
||||
//std::cout<<"ximeaControlDll 版本:"<< "21." <<std::endl;
|
||||
}
|
||||
|
||||
Iris::IrisXimeaImager::~IrisXimeaImager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::connect(const char *camera_serial_number)
|
||||
{
|
||||
printf("Iris::IrisXimeaImager::connect----1 打开相机(xiOpenDevice)\n");
|
||||
CE(xiOpenDevice(0, &m_xiH));//没有插上ximea相机,这句代码都过不去
|
||||
|
||||
//add-----------------------------------------------------------------------------------------------------------------------
|
||||
XI_RETURN stat = XI_OK;
|
||||
|
||||
int payload=0;
|
||||
stat = xiGetParamInt(m_xiH, XI_PRM_IMAGE_PAYLOAD_SIZE, &payload);
|
||||
HandleResult(stat,"xiGetParam (payload)");
|
||||
|
||||
int transport_buffer_size_default = 0;
|
||||
int transport_buffer_size_increment = 0;
|
||||
int transport_buffer_size_minimum = 0;
|
||||
// get default transport buffer size - that should be OK on all controllers
|
||||
stat = xiGetParamInt(m_xiH, XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE, &transport_buffer_size_default);
|
||||
HandleResult(stat,"xiGetParamInt (transport buffer size)");
|
||||
stat = xiGetParamInt(m_xiH, XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE XI_PRM_INFO_INCREMENT, &transport_buffer_size_increment);
|
||||
HandleResult(stat,"xiGetParamInt (transport buffer size increment)");
|
||||
stat = xiGetParamInt(m_xiH, XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE XI_PRM_INFO_MIN, &transport_buffer_size_minimum);
|
||||
HandleResult(stat,"xiGetParamInt (transport buffer size minimum)");
|
||||
|
||||
// check if payload size is less than default transport buffer size
|
||||
if(payload < transport_buffer_size_default + transport_buffer_size_increment)
|
||||
{
|
||||
// use optimized transport buffer size, as nearest increment to payload
|
||||
int transport_buffer_size = payload;
|
||||
if (transport_buffer_size_increment)
|
||||
{
|
||||
// round up to nearest increment
|
||||
int remainder = transport_buffer_size % transport_buffer_size_increment;
|
||||
if (remainder)
|
||||
transport_buffer_size += transport_buffer_size_increment - remainder;
|
||||
}
|
||||
// check the minimum
|
||||
if (transport_buffer_size < transport_buffer_size_minimum)
|
||||
transport_buffer_size = transport_buffer_size_minimum;
|
||||
stat = xiSetParamInt(m_xiH, XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE, transport_buffer_size);
|
||||
HandleResult(stat,"xiSetParam (transport buffer size)");
|
||||
}
|
||||
//add---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// set unit to 1 MiB
|
||||
xiSetParamInt(m_xiH, XI_PRM_ACQ_BUFFER_SIZE_UNIT, 1024*1024);
|
||||
int value = 0;
|
||||
xiGetParamInt(m_xiH, XI_PRM_ACQ_BUFFER_SIZE, &value);
|
||||
printf("Iris::IrisXimeaImager::connect---- XI_PRM_ACQ_BUFFER_SIZE: %d MiB.\n", value);
|
||||
|
||||
|
||||
int NUM_THREADS = 0;
|
||||
xiGetParamInt(m_xiH, XI_PRM_PROC_NUM_THREADS, &NUM_THREADS);
|
||||
printf("Iris::IrisXimeaImager::connect---- XI_PRM_PROC_NUM_THREADS默认值为%d\n", NUM_THREADS);
|
||||
xiSetParamInt(m_xiH, XI_PRM_PROC_NUM_THREADS, 8);
|
||||
|
||||
//设置数据格式
|
||||
printf("Iris::IrisXimeaImager::connect----2 设置数据格式(xiSetParamInt)\n");
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_IMAGE_DATA_FORMAT, XI_RAW16));//Default value: XI_MONO8
|
||||
// //设置packing, 使用xiGetImage接收影像时不执行unpacking
|
||||
// CE(xiSetParamInt(m_xiH, XI_PRM_OUTPUT_DATA_BIT_DEPTH, 12));//set 12 bit transport data width
|
||||
// CE(xiSetParamInt(m_xiH, XI_PRM_OUTPUT_DATA_PACKING, XI_ON));//enable packing
|
||||
// //使用xiGetImage接收影像时不执行unpacking
|
||||
// CE(xiSetParamInt(m_xiH, XI_PRM_IMAGE_DATA_FORMAT, XI_FRM_TRANSPORT_DATA));//in this case, the function xiGetImage just set pointer to transport-buffer without any processing
|
||||
|
||||
//判断数据格式设置是否成功
|
||||
int dataFortmat;
|
||||
CE(xiGetParamInt(m_xiH, XI_PRM_IMAGE_DATA_FORMAT, &dataFortmat));
|
||||
if(dataFortmat==XI_RAW16)
|
||||
{
|
||||
printf("Iris::IrisXimeaImager::connect----当前数据格式设置成功, 设置为: XI_RAW16\n");
|
||||
}
|
||||
else if(dataFortmat==XI_FRM_TRANSPORT_DATA)
|
||||
{
|
||||
printf("Iris::IrisXimeaImager::connect----当前数据格式设置成功, 设置为: XI_FRM_TRANSPORT_DATA\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Iris::IrisXimeaImager::connect----2 数据格式设置失败!\n");
|
||||
printf("Iris::IrisXimeaImager::connect----当前数据格式为:%d\n",dataFortmat);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::disconnect()
|
||||
{
|
||||
printf("Closing camera...\n");
|
||||
CE(xiCloseDevice(m_xiH));
|
||||
|
||||
m_xiH=NULL;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::start()
|
||||
{
|
||||
CE(xiStartAcquisition(m_xiH));
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::stop()
|
||||
{
|
||||
//printf("Stopping acquisition...\n");
|
||||
CE(xiStopAcquisition(m_xiH));
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::get_imager_type(char *buffer, int buffer_size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::get_serial_number(char *buffer, int buffer_size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::get_camera_serial_number(char *buffer, int buffer_size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::generate_configuration_report(char *buffer, int buffer_size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Iris::IrisXimeaImager::get_coeff_a()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
float Iris::IrisXimeaImager::get_coeff_b()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
float Iris::IrisXimeaImager::get_coeff_c()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double Iris::IrisXimeaImager::get_wavelength_at_band(const int band)
|
||||
{
|
||||
//sn008
|
||||
float a=1.999564;
|
||||
float b=-279.893;
|
||||
//
|
||||
float wavelength=band*m_fGain + m_fOffset;
|
||||
return wavelength;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_frame_buffer_size_in_bytes()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned short *Iris::IrisXimeaImager::get_frame(unsigned short *buffer)
|
||||
{
|
||||
//清空image缓存
|
||||
memset(&m_image, 0, sizeof(m_image));
|
||||
m_image.size = sizeof(XI_IMG);
|
||||
|
||||
CE(xiGetImage(m_xiH, 5000, &m_image)); // getting next image from the camera opened
|
||||
|
||||
//方法1:memcpy
|
||||
memcpy(buffer,m_image.bp,m_image.bp_size);
|
||||
// //方法2:此做法是错误的,虽然是指针,也是传值!
|
||||
// buffer = (unsigned short *)m_image.bp;
|
||||
|
||||
// for(int i=0;i<m_iEffectiveWindow_height;i++)
|
||||
// {
|
||||
// memcpy(buffer+i*m_iEffectiveWindowRoi_width, (unsigned short *)m_image.bp + i*m_iEffectiveWindow_width + m_iEffectiveWindowRoi_OffsetX, m_iEffectiveWindowRoi_width*2);
|
||||
// }
|
||||
|
||||
//强制将指针从高精度(uint64_t*)转换到低精度(unsigned short *),会有精度降低的问题???????????????????????????????????????????????????
|
||||
return (unsigned short *)&m_timestampOfCamera;
|
||||
}
|
||||
|
||||
uint64_t Iris::IrisXimeaImager::get_last_timestamp()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t Iris::IrisXimeaImager::ticks_per_second()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::set_spectral_bin(int new_spectral_bin)
|
||||
{
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_spectral_bin()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_min_spectral_bin()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_max_spectral_bin()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_band_count()
|
||||
{
|
||||
return m_iEffectiveWindow_height;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_start_band()
|
||||
{
|
||||
int WindowStartLine;
|
||||
CE(xiGetParamInt(m_xiH, XI_PRM_OFFSET_Y, &WindowStartLine));
|
||||
|
||||
return WindowStartLine;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::set_start_band(int band)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_min_start_band()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_max_start_band()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_inc_start_band()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_end_band()
|
||||
{
|
||||
int height;
|
||||
CE(xiGetParamInt(m_xiH, XI_PRM_HEIGHT, &height));
|
||||
return get_start_band()+height;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::set_end_band(int band)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_min_end_band()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_max_end_band()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_inc_end_band()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_sample_count()
|
||||
{
|
||||
return m_iEffectiveWindow_width;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_start_sample()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::set_start_sample(int sample)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_min_start_sample()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_max_start_sample()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_inc_start_sample()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_end_sample()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::set_end_sample(int sample)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_min_end_sample()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_max_end_sample()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::get_inc_end_sample()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::set_framerate(const double frames_per_second)
|
||||
{
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_ACQ_TIMING_MODE, XI_ACQ_TIMING_MODE_FRAME_RATE_LIMIT));
|
||||
|
||||
CE(xiSetParamFloat(m_xiH, XI_PRM_FRAMERATE, frames_per_second));
|
||||
}
|
||||
|
||||
double Iris::IrisXimeaImager::get_framerate()
|
||||
{
|
||||
float framerate;
|
||||
CE(xiGetParamFloat(m_xiH, XI_PRM_FRAMERATE, &framerate));
|
||||
return framerate;
|
||||
}
|
||||
|
||||
double Iris::IrisXimeaImager::get_min_framerate()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double Iris::IrisXimeaImager::get_max_framerate()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double Iris::IrisXimeaImager::get_min_integration_time()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double Iris::IrisXimeaImager::get_max_integration_time()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::set_integration_time(const double microsecond)
|
||||
{
|
||||
CE(xiSetParamInt(m_xiH, XI_PRM_EXPOSURE, microsecond));//time_in_us(microseconds)
|
||||
}
|
||||
|
||||
double Iris::IrisXimeaImager::get_integration_time()
|
||||
{
|
||||
float exposureTime;
|
||||
CE(xiGetParamFloat(m_xiH, XI_PRM_EXPOSURE, &exposureTime));//time_in_us(microseconds)
|
||||
return exposureTime;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::set_gain(const double gain)
|
||||
{
|
||||
CE(xiSetParamFloat(m_xiH, XI_PRM_GAIN, gain));//gain_in_db
|
||||
}
|
||||
|
||||
double Iris::IrisXimeaImager::get_gain()
|
||||
{
|
||||
float gain;
|
||||
CE(xiGetParamFloat(m_xiH, XI_PRM_GAIN, &gain));
|
||||
return gain;
|
||||
}
|
||||
|
||||
double Iris::IrisXimeaImager::get_min_gain()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double Iris::IrisXimeaImager::get_max_gain()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::set_internal_trigger()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::set_external_trigger(unsigned int signal_line, bool rising_edge)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Iris::IrisXimeaImager::is_trigger_external()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
123
HPPA/irisximeaimager.h
Normal file
123
HPPA/irisximeaimager.h
Normal file
@ -0,0 +1,123 @@
|
||||
#ifndef IRISXIMEAIMAGER_H
|
||||
#define IRISXIMEAIMAGER_H
|
||||
|
||||
#include <memory.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
//#include "irisximeaimager_global.h"
|
||||
#include "imager_base.h"
|
||||
#ifdef WIN32
|
||||
#include <xiApi.h> // Windows
|
||||
#else
|
||||
#include <m3api/xiApi.h> // Linux, OSX
|
||||
#endif
|
||||
|
||||
#define CE(func) {XI_RETURN stat = (func); if (XI_OK!=stat) {printf("Error:%d returned from function:"#func"\n",stat);throw stat;}}
|
||||
#define HandleResult(res,place) if (res!=XI_OK) {printf("Error after %s (%d)\n",place,res);}
|
||||
|
||||
namespace Iris
|
||||
{
|
||||
class IrisXimeaImager:public ImagerBase
|
||||
{
|
||||
public:
|
||||
HANDLE m_xiH;
|
||||
void setGainOffset(float gain, float offset);
|
||||
bool setSpectralBin(int spectralBin);
|
||||
bool setSpatialBin(int spatialBin);
|
||||
int getSpectralBin();
|
||||
int getSpatialBin();
|
||||
void setEffectiveWindow(int OffsetX, int width, int OffsetY, int height);
|
||||
void setEffectiveWindowRoi(int OffsetX, int width);
|
||||
int getBufferSizeOfOneFrame();
|
||||
float getTemperature();
|
||||
|
||||
XI_IMG m_image; // image buffer
|
||||
|
||||
void setBufferPolicy(int bufferPolicy);//0:XI_BP_UNSAFE; 1:XI_BP_SAFE;
|
||||
void setAcqBufferSize(int acqBufferSize);//单位MiB
|
||||
|
||||
public:
|
||||
//继承基类的
|
||||
IrisXimeaImager();//11111111111111111111
|
||||
virtual ~IrisXimeaImager();
|
||||
|
||||
void connect(const char * camera_serial_number=NULL);//111111111111111111111111111111111
|
||||
void disconnect();//111111111111111111111111111111
|
||||
void start();//111111111111111111111
|
||||
void stop();//1111111111111111111111
|
||||
void get_imager_type(char *buffer, int buffer_size);
|
||||
void get_serial_number(char *buffer, int buffer_size);
|
||||
void get_camera_serial_number(char *buffer, int buffer_size);
|
||||
void generate_configuration_report(char *buffer, int buffer_size);
|
||||
float get_coeff_a();
|
||||
float get_coeff_b();
|
||||
float get_coeff_c();
|
||||
double get_wavelength_at_band(const int band);//11111111111111111111
|
||||
int get_frame_buffer_size_in_bytes();
|
||||
unsigned short* get_frame(unsigned short* buffer);//11111111111111111111111
|
||||
std::uint64_t get_last_timestamp();
|
||||
std::uint64_t ticks_per_second();
|
||||
void set_spectral_bin(int new_spectral_bin);//11111111111111111111111111111111
|
||||
int get_spectral_bin();
|
||||
int get_min_spectral_bin();
|
||||
int get_max_spectral_bin();
|
||||
int get_band_count();//11111111111111111111
|
||||
int get_start_band();//对应上一版本api的函数:get_window_start_band
|
||||
void set_start_band(int band);
|
||||
int get_min_start_band();
|
||||
int get_max_start_band();
|
||||
int get_inc_start_band();
|
||||
int get_end_band();//对应上一版本api的函数:get_window_end_band
|
||||
void set_end_band(int band);
|
||||
int get_min_end_band();
|
||||
int get_max_end_band();
|
||||
int get_inc_end_band();
|
||||
int get_sample_count();//11111111111111111
|
||||
int get_start_sample();
|
||||
void set_start_sample(int sample);
|
||||
int get_min_start_sample();
|
||||
int get_max_start_sample();
|
||||
int get_inc_start_sample();
|
||||
int get_end_sample();
|
||||
void set_end_sample(int sample);
|
||||
int get_min_end_sample();
|
||||
int get_max_end_sample();
|
||||
int get_inc_end_sample();
|
||||
void set_framerate(const double frames_per_second);//11111111111111111111111111111111
|
||||
double get_framerate();//1111111111111111111111
|
||||
double get_min_framerate();
|
||||
double get_max_framerate();
|
||||
double get_min_integration_time();
|
||||
double get_max_integration_time();
|
||||
void set_integration_time(const double microsecond);//111111111111111111111
|
||||
double get_integration_time();//1111111111111111111111111111111
|
||||
void set_gain(const double gain);//111111111111
|
||||
double get_gain();//111111111111
|
||||
double get_min_gain();
|
||||
double get_max_gain();
|
||||
void set_internal_trigger();
|
||||
void set_external_trigger(unsigned int signal_line, bool rising_edge=true);
|
||||
bool is_trigger_external();
|
||||
protected:
|
||||
private:
|
||||
uint64_t m_timestampOfCamera;
|
||||
|
||||
int m_iSpectralBin;
|
||||
int m_iSpatialBin;
|
||||
|
||||
int m_iEffectiveWindow_OffsetX;
|
||||
int m_iEffectiveWindow_width;
|
||||
int m_iEffectiveWindow_OffsetY;
|
||||
int m_iEffectiveWindow_height;
|
||||
|
||||
int m_iEffectiveWindowRoi_OffsetX;
|
||||
int m_iEffectiveWindowRoi_width;
|
||||
|
||||
float m_fGain;
|
||||
float m_fOffset;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // IRISXIMEAIMAGER_H
|
||||
404
HPPA/oneMotorControl.ui
Normal file
404
HPPA/oneMotorControl.ui
Normal file
@ -0,0 +1,404 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OneMotorControl_UI</class>
|
||||
<widget class="QDialog" name="OneMotorControl_UI">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>678</width>
|
||||
<height>480</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>一轴马达控制</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QPushButton
|
||||
{
|
||||
/*width: 172px;
|
||||
height: 56px;
|
||||
font: 19pt "新宋体";*/
|
||||
background-color: qlineargradient(
|
||||
spread:pad,
|
||||
x1:0.5, y1:0, x2:0.5, y2:1,
|
||||
stop:0 #283D86,
|
||||
stop:1 #0F1A40
|
||||
);
|
||||
color: white;
|
||||
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;
|
||||
}
|
||||
QLabel
|
||||
{
|
||||
color: #ACCDFF;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
QLineEdit:hover {
|
||||
border: 1px solid #4d8dff;
|
||||
}
|
||||
|
||||
QLineEdit:focus {
|
||||
border: 1px solid #6aa2ff;
|
||||
background-color: #23345c;
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2" rowstretch="1,3,1" columnstretch="1,3,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>87</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>127</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>实时位置</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="realTimeLoc_lineEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>88</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="connect_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="1" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>运行速度</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="speed_lineEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>88</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0.1</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="zero_start_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="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>返回速度</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="return_speed_lineEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>88</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>2</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="rangeMeasurement_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="3" column="1">
|
||||
<widget class="QLineEdit" name="move2loc_lineEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>88</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="move2loc_pushButton">
|
||||
<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="4" column="1">
|
||||
<widget class="QPushButton" name="left_btn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>←0</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QPushButton" name="right_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="5" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>状态</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="motor_state_label">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>8</width>
|
||||
<height>8</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeIncrement">
|
||||
<size>
|
||||
<width>8</width>
|
||||
<height>8</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: red;
|
||||
border-radius: 4px;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>127</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>87</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
1011
HPPA/twoMotorControl.ui
Normal file
1011
HPPA/twoMotorControl.ui
Normal file
File diff suppressed because it is too large
Load Diff
@ -112,6 +112,24 @@ std::string removeFileExtension(std::string filename)
|
||||
|
||||
}
|
||||
|
||||
// 从绝对路径中提取文件名(不包含扩展名)
|
||||
std::string getFileNameFromPath(const std::string &fullPath)
|
||||
{
|
||||
// 找到最后一个路径分隔符,支持 '/' 和 '\\'
|
||||
size_t lastSlash = fullPath.find_last_of("/\\");
|
||||
size_t start = (lastSlash == std::string::npos) ? 0 : lastSlash + 1;
|
||||
|
||||
// 找到最后一个点,确保点在文件名范围内
|
||||
size_t lastDot = fullPath.find_last_of('.');
|
||||
if (lastDot == std::string::npos || lastDot < start) {
|
||||
// 没有扩展名或点在路径之前,直接返回从 start 到结尾的子串
|
||||
return fullPath.substr(start);
|
||||
}
|
||||
|
||||
// 返回从 start 到 lastDot 之间的文件名(不含扩展名)
|
||||
return fullPath.substr(start, lastDot - start);
|
||||
}
|
||||
|
||||
QList<QString> getFileInfo(QString file)
|
||||
{
|
||||
QFileInfo fileInfo = QFileInfo(file);
|
||||
|
||||
@ -20,6 +20,7 @@ void swap(unsigned short * a, unsigned short * b);
|
||||
|
||||
bool createDir(QString fullPath);
|
||||
std::string removeFileExtension(std::string filename);
|
||||
std::string getFileNameFromPath(const std::string& fullPath);
|
||||
|
||||
QList<QString> getFileInfo(QString file);
|
||||
|
||||
|
||||
43
cfg_file_backup/HPPA.cfg
Normal file
43
cfg_file_backup/HPPA.cfg
Normal file
@ -0,0 +1,43 @@
|
||||
SN = "2004";
|
||||
autoFocus :
|
||||
{
|
||||
PositionRestriction :
|
||||
{
|
||||
max = 1000;
|
||||
min = 120;
|
||||
};
|
||||
TuningStepSize :
|
||||
{
|
||||
coarse = 10;
|
||||
fine = 2;
|
||||
};
|
||||
FitParams :
|
||||
{
|
||||
fa = 0.0017;
|
||||
fb = 0.3277;
|
||||
};
|
||||
AutoFocusRange :
|
||||
{
|
||||
max = 688;
|
||||
min = 144;
|
||||
};
|
||||
};
|
||||
motionPlatform :
|
||||
{
|
||||
x :
|
||||
{
|
||||
StepAnglemar = 1.8;
|
||||
Lead = 1.0;
|
||||
SubdivisionMultiples = 8;
|
||||
ScaleFactor = 1.0;
|
||||
MaxRange = 30.742266;
|
||||
};
|
||||
y :
|
||||
{
|
||||
StepAnglemar = 1.8;
|
||||
Lead = 1.0;
|
||||
SubdivisionMultiples = 8;
|
||||
ScaleFactor = 1.0;
|
||||
MaxRange = 31.283163;
|
||||
};
|
||||
};
|
||||
60
cfg_file_backup/oneMotorConfigFile.cfg
Normal file
60
cfg_file_backup/oneMotorConfigFile.cfg
Normal file
@ -0,0 +1,60 @@
|
||||
SN = "0";
|
||||
motors :
|
||||
{
|
||||
motor1 :
|
||||
{
|
||||
platformParams :
|
||||
{
|
||||
hardwareParams :
|
||||
{
|
||||
StepAngle = 1.8;
|
||||
Lead = 4.0;
|
||||
ScaleFactor = 1.0;
|
||||
};
|
||||
runParams :
|
||||
{
|
||||
RecordSpeed = 1.8;
|
||||
MoveSpeed = 1.8;
|
||||
ReturnSpeed = 1.8;
|
||||
MaxRange = 120.0;
|
||||
};
|
||||
};
|
||||
motorParams :
|
||||
{
|
||||
Manufacturer = 0;
|
||||
CommunicationProtocol = 0;
|
||||
connectionParams :
|
||||
{
|
||||
SerialPortNumber = "COM10";
|
||||
BaudRate = 9600;
|
||||
};
|
||||
initParams :
|
||||
{
|
||||
limit :
|
||||
{
|
||||
msr = 1;
|
||||
msv = 0;
|
||||
psr = 2;
|
||||
psv = 0;
|
||||
};
|
||||
other :
|
||||
{
|
||||
acc = 20000.0;
|
||||
cra = 4.0;
|
||||
crh = 1.0;
|
||||
crn = 4.0;
|
||||
dec = 20000.0;
|
||||
mcs = 7;
|
||||
};
|
||||
zeroStart :
|
||||
{
|
||||
osv = 0;
|
||||
snr = 0;
|
||||
zmd = 2;
|
||||
zsd = 3000;
|
||||
zsp = 2400;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
60
cfg_file_backup/oneMotorConfigFile_focus.cfg
Normal file
60
cfg_file_backup/oneMotorConfigFile_focus.cfg
Normal file
@ -0,0 +1,60 @@
|
||||
SN = "0";
|
||||
motors :
|
||||
{
|
||||
motor1 :
|
||||
{
|
||||
platformParams :
|
||||
{
|
||||
hardwareParams :
|
||||
{
|
||||
StepAngle = 1.8;
|
||||
Lead = 1.37;
|
||||
ScaleFactor = 1.0;
|
||||
};
|
||||
runParams :
|
||||
{
|
||||
RecordSpeed = 1.0;
|
||||
MoveSpeed = 1.0;
|
||||
ReturnSpeed = 1.0;
|
||||
MaxRange = 11.559696;
|
||||
};
|
||||
};
|
||||
motorParams :
|
||||
{
|
||||
Manufacturer = 0;
|
||||
CommunicationProtocol = 1;
|
||||
connectionParams :
|
||||
{
|
||||
SerialPortNumber = "COM10";
|
||||
BaudRate = 9600;
|
||||
};
|
||||
initParams :
|
||||
{
|
||||
limit :
|
||||
{
|
||||
msr = 1;
|
||||
msv = 1;
|
||||
psr = 2;
|
||||
psv = 1;
|
||||
};
|
||||
other :
|
||||
{
|
||||
acc = 19200.0;
|
||||
cra = 0.2;
|
||||
crh = 0.0;
|
||||
crn = 0.2;
|
||||
dec = 19200.0;
|
||||
mcs = 6;
|
||||
};
|
||||
zeroStart :
|
||||
{
|
||||
osv = 1;
|
||||
snr = 0;
|
||||
zmd = 1;
|
||||
zsd = 4000;
|
||||
zsp = 2400;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user