#ifndef BELTTEARINGTCPPROTOCOLTEST_MAINWINDOW_H #define BELTTEARINGTCPPROTOCOLTEST_MAINWINDOW_H #include #include #include #include #include #include #include #include #include class QCheckBox; class QDoubleSpinBox; class QLineEdit; class QLabel; class QPlainTextEdit; class QPushButton; class QSpinBox; class QTableWidget; class QTcpSocket; class QResizeEvent; class PointCloudGLWidget; struct PointCloudSummary { quint64 frameIndex = 0; quint64 timestamp = 0; quint32 originalCount = 0; quint32 sampledCount = 0; quint32 lineStep = 0; quint32 pointStep = 0; double xMin = 0.0; double xMax = 0.0; double yMin = 0.0; double yMax = 0.0; double zMin = 0.0; double zMax = 0.0; }; struct PointCloudPoint { qint32 index = 0; double x = 0.0; double y = 0.0; double z = 0.0; }; class MainWindow final : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget* parent = nullptr); ~MainWindow() override; private slots: void connectToServer(); void disconnectFromServer(); void readConfig(); void setConfig(); void setRealtime(); void resetAlarm(); void restDetect(); void chooseOutputDir(); void onConnected(); void onDisconnected(); void onReadyRead(); void onSocketError(QAbstractSocket::SocketError error); protected: void closeEvent(QCloseEvent* event) override; void resizeEvent(QResizeEvent* event) override; private: void setupUi(); void updateConnectionControls(bool connected); void sendFrame(quint8 dataType, const QByteArray& payload = QByteArray()); void sendJsonMessage(const QJsonObject& message); void processFrames(); void processJsonFrames(); void processPointCloudFrames(); void handleFrame(quint8 dataType, const QByteArray& payload, int frameSize); void handleJsonPayload(quint8 dataType, const QByteArray& payload); void handleNewJsonPayload(const QByteArray& payload); void updateConfigControls(const QJsonObject& config); void requestProtocolInfo(); bool parsePointCloud(const QByteArray& payload, PointCloudSummary& summary, QVector& points, QString& error) const; void appendPoints(const PointCloudSummary& summary, const QVector& points); void saveImage(const QByteArray& payload); void saveCloudUtilsFrame(const PointCloudSummary& summary, const QVector& points); QString ensureOutputDir(); void logMessage(const QString& message); void logResultMessage(const QString& resultType, const QString& message, const QString& repeatKey); void recordError(const QString& message); void updatePointCloudStats(const PointCloudSummary& summary); void trimDisplayedPointClouds(); void updateRealtimeResult(const QJsonObject& object); void updateRealtimeImageDisplay(); QTcpSocket* m_socket = nullptr; QByteArray m_receiveBuffer; QLineEdit* m_hostEdit = nullptr; QSpinBox* m_portSpin = nullptr; QPushButton* m_connectButton = nullptr; QPushButton* m_disconnectButton = nullptr; QLabel* m_connectionLabel = nullptr; QDoubleSpinBox* m_scanXScaleSpin = nullptr; QDoubleSpinBox* m_scanYScaleSpin = nullptr; QDoubleSpinBox* m_differenceBinThresholdSpin = nullptr; QDoubleSpinBox* m_tearingMinLengthSpin = nullptr; QDoubleSpinBox* m_tearingMinWidthSpin = nullptr; QDoubleSpinBox* m_tearingMinDepthSpin = nullptr; QDoubleSpinBox* m_tearingMinGapSpin = nullptr; QDoubleSpinBox* m_sameGapThresholdSpin = nullptr; QSpinBox* m_gapCheckWindowSpin = nullptr; QLineEdit* m_cameraIpEdit = nullptr; QSpinBox* m_maxQueueSizeSpin = nullptr; QSpinBox* m_generationIntervalSpin = nullptr; QSpinBox* m_imageLineCountSpin = nullptr; QCheckBox* m_enabledCheck = nullptr; QSpinBox* m_lineStepSpin = nullptr; QSpinBox* m_pointStepSpin = nullptr; QPushButton* m_readConfigButton = nullptr; QPushButton* m_setConfigButton = nullptr; QCheckBox* m_realtimeCheck = nullptr; QPushButton* m_resetAlarmButton = nullptr; QPushButton* m_restDetectButton = nullptr; QPushButton* m_pointCloudClearButton = nullptr; QSpinBox* m_displayLineCountSpin = nullptr; QCheckBox* m_saveCloudUtilsCheck = nullptr; PointCloudGLWidget* m_cloudView = nullptr; QCheckBox* m_savePointsCheck = nullptr; QCheckBox* m_saveImagesCheck = nullptr; QLineEdit* m_outputDirEdit = nullptr; QLabel* m_linesValue = nullptr; QLabel* m_bytesValue = nullptr; QLabel* m_errorsValue = nullptr; QLabel* m_frameValue = nullptr; QLabel* m_countValue = nullptr; QLabel* m_stepsValue = nullptr; QLabel* m_xRangeValue = nullptr; QLabel* m_yRangeValue = nullptr; QLabel* m_zRangeValue = nullptr; QLabel* m_realtimeSummaryLabel = nullptr; QTableWidget* m_realtimeTearTable = nullptr; QLabel* m_realtimeImageLabel = nullptr; QImage m_realtimeImage; QPlainTextEdit* m_logEdit = nullptr; QString m_lastLogKey; QString m_lastLogTime; QString m_lastLogMessage; int m_lastLogRepeatCount = 0; QHash m_resultLogKeys; QHash m_resultLogMessages; QHash m_resultLogTimes; QHash m_resultLogBlocks; QHash m_resultLogRepeatCounts; qint64 m_receivedBytes = 0; int m_errorCount = 0; int m_pointLineCount = 0; int m_imageCount = 0; int m_pointCloudFrameCount = 0; }; #endif // BELTTEARINGTCPPROTOCOLTEST_MAINWINDOW_H