Files
HPPA/HPPA/HPPA.h
tangchao0503 cb5a74f576 add:
山地所贡嘎山,部分完成:(1)右下角添加控制is11的界面(2)添加is11(鉴知)控制库
2026-07-01 23:16:14 +08:00

460 lines
12 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <cstdio>
#include <iostream>
#include <exception>
#include <stdexcept>
#include <cmath>
#include <io.h>
#include <QtWidgets/QMainWindow>
#include <QThread>
#include <QLineSeries>
#include <QChart>
#include <QChartView>
#include <QValueAxis>
#include <QPointer>
#include <QFileDialog>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include <QVector>
#include <QItemSelection>
#include "ui_HPPA.h"
#include "resononImager.h"
#include "ImageViewer.h"
#include "vincecontrol.h"
#include "ImagerPositionSimulation.h"
#include "fileOperation.h"
#include "RgbCameraOperation.h"
#include "imageProcessor.h"
#include "fileOperation.h"
#include "focusWindow.h"
#include "aboutWindow.h"
#include "adjustTable.h"
#include "PowerControl.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"
#include "AspectRatioLabel.h"
#include "HyperImagerControl.h"
#include "recordFrameCounter.h"
#include "setWindow.h"
#include "AppSettings.h"
#include "FileNameLineEdit.h"
#include "rgbCameraWindow.h"
#include "DepthCameraWindow.h"
#include "SingleLensReflexCameraWindow.h"
#include "LayerTreeImageNode.h"
#include "TimedDataCollection.h"
#include "PowerControl3D.h"
#include "FodisWindow.h"
#include <algorithm>
#define PI 3.1415926
QT_CHARTS_USE_NAMESPACE//QChartView 使用 需要加宏, 否则无法使用
class WorkerThread : public QThread
{
Q_OBJECT
private:
public:
ImagerOperationBase*m_Imager;
WorkerThread(ImagerOperationBase* Imager)
{
m_Imager = Imager;
}
//void run() override
//{
// while (true)
// {
// try
// {
// //double x = m_Imager->get_framerate();
//
// //double x = m_Imager->m_ResononImager.get_framerate();
// int x = m_Imager->m_ResononImager.get_band_count();
// std::cout << "相机连接正常!slope为:" << x << std::endl;
// }
// catch (std::runtime_error *e)//CException *e
// {
// std::cout << "相机断开连接!" << e->what() << std::endl;
// }
// Sleep(1000);
// }
// QString result;
// emit resultReady(result);
//}
signals:
void resultReady(const QString &s);
};
class WorkerThread3 : public QThread
{
Q_OBJECT
private:
public:
WorkerThread3(CFocusMotorControl * ctrlFocusMotor);
CFocusMotorControl *m_ctrlFocusMotor;
protected:
void run();
signals:
void AutoFocusFinishedSignal();
};
class myClocks : public QThread
{
Q_OBJECT
public:
myClocks(QObject *parent = 0);
public:
void setCallback(void(*func)(QString));
protected:
virtual void run();
private:
std::function<void(QString)> m_func;
signals:
void threadSignal(QString s);
};
class WidgetWithBackgroundPicture : public QWidget
{
Q_OBJECT
public:
explicit WidgetWithBackgroundPicture(QWidget* parent = nullptr)
: QWidget(parent),
m_pixmap(":/png/resources/icons/png/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:
QPixmap m_pixmap;
};
class ImageStretchWorker : public QObject
{
Q_OBJECT
public:
explicit ImageStretchWorker(QObject* parent = nullptr);
~ImageStretchWorker();
public slots:
void processImage(const cv::Mat& rgbImage, int fileNumber, const QString& filePath, float ratio = 0.02f);
signals:
void imageReady(int fileNumber, const QString& filePath, QPixmap& pixmap);
void processingError(int fileNumber, const QString& filePath, const QString& error);
private:
cv::Mat CStretch(const cv::Mat& img, float ratio);
cv::Mat CStretchDeal(const cv::Mat& img, uint minnum, uint maxnum);
std::vector<cv::Point2f> CHistogram(const cv::Mat& img);
uint MaxRatio(const std::vector<cv::Point2f>& data, float ratio);
uint MinRatio(const std::vector<cv::Point2f>& data, float ratio);
QImage Mat2QImage(const cv::Mat& cvImg);
};
class HPPA : public QMainWindow
{
Q_OBJECT
public:
HPPA(QWidget *parent = Q_NULLPTR);
~HPPA();
static HPPA* instance();
LayerTreeNode* rasterGroupNode() const;
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();
QWidget* tmp(QWidget* a);
QLineEdit * frame_number;
FileNameLineEdit * m_FilenameLineEdit;
QLabel * xmotor_state_label1;
QLabel * ymotor_state_label1;
Configfile mConfigfile;
ImagerOperationBase* m_Imager;//
int m_RecordState;//用来控制相机采集流程,取2的余数,1 → 正在采集,0 → 停止采集
QThread * m_RecordThread;//影像采集线程
QThread * m_CopyFileThread;//影像文件复制线程
FileOperation * m_FileOperation;
QChartView * m_chartView;
QChart* m_chart;
//QLineSeries *series;
//QChart *chart;
QString operateWidget;//当前操作的控件名
//模拟相机位置
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);
//采集线规划
int m_numberOfRecording;//表示ui.recordLine_tableWidget中的第几行 → 正在采集第几条线
//
int m_TabWidgetCurrentIndex;//当手动选择TabWidget的标签时,记录变化后的tab index
void getRequest(QString str);
QActionGroup* mImagerGroup = nullptr;
void createActionGroups();
void selectingImager(QAction* selectedAction);
void updateImagerPicture(const QString& actionName);
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;
QLabel* m_SingleLensReflexCamera_label;
QLabel* m_depthCamera_label;
QPushButton* m_open_rgb_camera_btn;
QPushButton* m_close_rgb_camera_btn;
TabManager* m_tabManager;
HyperImagerControl* m_hic;
rgbCameraWindow* m_rgbCameraControlWindow;
ImageControl* m_ic;
DepthCameraWindow* m_depthCameraWindow;
SingleLensReflexCameraWindow* m_singleLensReflexCameraWindow;
adjustTable* m_adt;
PowerControl* m_pc;
PowerControl3D* m_pc3D;
RobotArmControl* m_rac;
OneMotorControl* m_omc;
TwoMotorControl* m_tmc;
FodisWindow* m_fodisWindow;
QPointer<TimedDataCollection> m_tdc;
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();
QWidget* m_focusTab=nullptr;
recordFrameCounter* m_recordFrameCounter = nullptr;
bool testImagerVality();
void showMessageBox(QString msg, QString title= QString::fromLocal8Bit("提示"));
bool showResultMessageBox(QString title, QString msg);
void disconnectImagerAndCleanup();
void initTimedDataCollection();
QThread* m_ImageStretchThread = nullptr;
ImageStretchWorker* m_ImageStretchWorker = nullptr;
// 用于临时显示的未拉伸图像(可选,用于快速预览)
void showQuickPreview(int fileNumber, const QString& filePath, const cv::Mat& rgbImage);
public Q_SLOTS:
void onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QString filePath);
void focusPlotSpectralImg(int state);
void onRecordFinishedSignal_WhenFrameNumberMeet();
void onRecordFinishedSignal_WhenFrameNumberNotMeet();
void onsequenceComplete();
void onExit();
void onOpenImg();
void onconnect();//连接相机
void testImagerStatus();//获取相机状态:连接是否正常
void autoExposureFinished();
void onAutoExposure();
void onFocus1();
void onFocus2(int command);
void onFocusWindowClosed();
void onAbout();
void settingWindow();
void onDark();
void recordDarkFinish();
void onReference();
void recordWhiteFinish();
void onStartRecordStep1();
QWidget* onCreateTab(QString tabName);
void onTabWidgetCurrentChanged(int index);
void onActionOpenDirectory();
void onFramerateChanged(double framerate);
void onIntegrationTimeChanged(double integrationTime);
void onGainChanged(double gain);
void onLeftMouseButtonPressed(int x, int y, QVector<double> wavelengths, QVector<double> spectrum);//点击影像像元显示光谱
void setAxis(QValueAxis* axisX, QValueAxis* axisY);
void timerEvent(QTimerEvent *event);
//
void onimagerSimulatorMove(int x, int y);
void OnSendLogToCallClass(QString str);
void onPlotRgbImage();
void onPlotDepthImage();
void onLiveViewImageReady(const QImage& image);
void HPPA::onLiveViewStopped();
void onClearLabel();
void onClearDepthLabel();
void onCopyFinished();
void requestFinished(QNetworkReply* reply);
void recordFromRobotArm(int fileCounter);
void createOneMotorScenario();
void createGonggaRotatingPlatformScenario();
void createPlantPhenotypeScenario();
void create3DPlantPhenotypeScenario();
void onCreated3DModelPlantPhenotype();
void onCreated3DModelMicroscopicMotion();
void createMicroscopicMotionControlScenario();
void onCreated3DModelOneMotor();
void addLayer(const QString& baseName, const QString& filePath, bool refresh, bool isAddImage = true);
void newImage(RasterLayer* ml, RasterImageLayer::RendererType, LayerTreeNode* parent, bool refresh=true);
void onLayerCreatedFromFile(const QString& baseName, const QString& filePath, int fileIndex);
void removeLayerByTreeIndex();
void removeLayerByNode(LayerTreeNode* node);
void showColorImageByTreeIndex();
void removeImageByTreeIndex();
void removeAllLayersInRasterGroup();
void onLayerTreeSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
void onBandSelectionChanged(double rWave, double gWave, double bWave);
void onMapToolPanTriggered();
void onMapToolSpectralTriggered();
void onTimedDataCollection();
void setTimedDataCollectionHyperCamParm(int camType, double f, double e, QString filePath, QString fileName);
void setTimedDataCollectionCamParm(int camType, int captureIntervalSeconds, QString folder);
void setTimedDataCollectionMotorParm(QString pathLineFilePath);
void onStartTimedDataCollection(int camType);
void onStretchedImageReady(int fileNumber, const QString& filePath, QPixmap& pixmap);
void onStretchProcessingError(int fileNumber, const QString& filePath, const QString& error);
protected:
void closeEvent(QCloseEvent* event) override;
signals:
void StartFocusSignal();
void StartRecordSignal();
void CopyFileThreadSignal(QString, QString);
void RecordWhiteSignal();
void RecordDarlSignal();
void updateRecordingFileInfoSignal(const QString& filePath, const QString& baseName, int frameNumber);
};