优化粒子入射时间数据加载及交互
This commit is contained in:
parent
829b22d74e
commit
4ba9703c4d
|
|
@ -9,6 +9,9 @@ BusyIndicator::BusyIndicator(QWidget* parent)
|
|||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
|
||||
QLabel* icon = new QLabel;
|
||||
icon->resize(80, 80);
|
||||
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
icon->setSizePolicy(sizePolicy);
|
||||
_busy_movie = new QMovie(":gif/BusyIndicator.gif"); // 转圈 GIF
|
||||
icon->setMovie(_busy_movie);
|
||||
_busy_movie->start();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "ParticleInjectTimeAnalysisView.h"
|
||||
#include "ui_ParticleInjectTimeAnalysisView.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
|
@ -12,22 +11,61 @@
|
|||
#include <cmath>
|
||||
#include <QtMath>
|
||||
#include "CustomQwtPlot.h"
|
||||
#include <QDebug>
|
||||
#include <GlobalDefine.h>
|
||||
#include "csv.h"
|
||||
#include <QFileInfo>
|
||||
#include <QThread>
|
||||
#include "BusyIndicator.h"
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
ParticleInjectTimeAnalysisView::ParticleInjectTimeAnalysisView(QWidget *parent) :
|
||||
MeasureAnalysisView(parent),
|
||||
ui(new Ui::ParticleInjectTimeAnalysisView)
|
||||
MeasureAnalysisView(parent)
|
||||
{
|
||||
this->setViewType(PlotFrame);
|
||||
ui->setupUi(this);
|
||||
InitUi();
|
||||
|
||||
_plot = new CustomQwtPlot();
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->addWidget(_plot);
|
||||
|
||||
_plot->setCanvasBackground(Qt::white);
|
||||
QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(_plot->canvas());
|
||||
canvas->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
QFont font = this->font();
|
||||
font.setBold(false);
|
||||
QwtText particle_num_label = QStringLiteral(u"粒子序号");
|
||||
particle_num_label.setFont(font);
|
||||
QwtText time_label = QStringLiteral(u"粒子时间(ns)");
|
||||
time_label.setFont(font);
|
||||
_plot->setAxisTitle(QwtPlot::xBottom, particle_num_label);
|
||||
_plot->setAxisTitle(QwtPlot::yLeft, time_label);
|
||||
// set axis auto scale
|
||||
_plot->setAxisAutoScale(QwtPlot::xBottom, true);
|
||||
_plot->setAxisAutoScale(QwtPlot::yLeft, true);
|
||||
// 启用网格线
|
||||
_plot->enableAxis(QwtPlot::xBottom);
|
||||
_plot->enableAxis(QwtPlot::yLeft);
|
||||
|
||||
_plot->SetAxisDragScale(QwtPlot::xBottom, true);
|
||||
|
||||
// // 设置QWT图例
|
||||
// QwtLegend* legend = new QwtLegend();
|
||||
// legend->setDefaultItemMode(QwtLegendData::ReadOnly);
|
||||
// _plot->insertLegend(legend, QwtPlot::RightLegend);
|
||||
|
||||
_curve = new QwtPlotCurve();
|
||||
_plot->AddCurve(_curve);
|
||||
|
||||
this->_menu = new QMenu(this);
|
||||
setupMenu();
|
||||
|
||||
_busy_indicator = new BusyIndicator(this);
|
||||
}
|
||||
|
||||
ParticleInjectTimeAnalysisView::~ParticleInjectTimeAnalysisView()
|
||||
{
|
||||
delete ui;
|
||||
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysisView::InitViewWorkspace(const QString &project_name)
|
||||
|
|
@ -37,153 +75,83 @@ void ParticleInjectTimeAnalysisView::InitViewWorkspace(const QString &project_na
|
|||
|
||||
void ParticleInjectTimeAnalysisView::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
|
||||
{
|
||||
int energyStart = ui->label_energyStart->text().toInt();
|
||||
int energyEnd = ui->label_energyEnd->text().toInt();
|
||||
if(!data_files_set.isEmpty())
|
||||
{
|
||||
io::CSVReader<4> in(QStrToSysPath(data_files_set.first().toString()));
|
||||
in.read_header(io::ignore_extra_column, "板卡号", "通道号", "能量(KeV)", "时间计数");
|
||||
|
||||
int board, channel;
|
||||
double energy, time_count;
|
||||
int lineNumber = 0;
|
||||
QVector<double> x;
|
||||
QVector<double> y;
|
||||
double minValue = 0;
|
||||
double maxValue = 0;
|
||||
// 逐行读取
|
||||
while (in.read_row(board, channel, energy, time_count))
|
||||
{
|
||||
// qDebug()<<QStringLiteral(u"板卡号:")<<board<<QStringLiteral(u"通道号")<<channel<<QStringLiteral(u"能量(KeV)")<<energy<<QStringLiteral(u"时间计数")<<time_count;
|
||||
int detector = board + channel * 8;
|
||||
lineNumber++;
|
||||
if(detector > 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(energy <= energyStart || energy >= energyEnd)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
x.append(lineNumber);
|
||||
y.append(time_count);
|
||||
minValue = qMin(minValue, time_count);
|
||||
maxValue = qMax(maxValue, time_count);
|
||||
}
|
||||
// 创建曲线并设置数据
|
||||
QwtPlotCurve *curve = new QwtPlotCurve();
|
||||
curve->setSamples(x, y);
|
||||
// 将曲线添加到 CustomQwtPlot 中(会自动分配颜色)
|
||||
plot->AddCurve(curve);
|
||||
// 设置坐标轴范围和标题
|
||||
// plot->setAxisScale(QwtPlot::xBottom, 0, x.last());
|
||||
// plot->setAxisScale(QwtPlot::yLeft,minValue , maxValue);
|
||||
|
||||
LOG_INFO(QStringLiteral(u"%1数据读取完毕.").arg(this->GetViewName()));
|
||||
|
||||
// 刷新绘图
|
||||
plot->replot();
|
||||
// m_AllData = getParticleInjectTimeData(data_files_set.first().toString());
|
||||
// setData(m_AllData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysisView::setData(QVector<ParticleInjectTime *> data)
|
||||
{
|
||||
int energyStart = ui->label_energyStart->text().toInt();
|
||||
int energyEnd = ui->label_energyEnd->text().toInt();
|
||||
|
||||
QVector<double> x;
|
||||
QVector<double> y;
|
||||
|
||||
double minValue = 0;
|
||||
double maxValue = 0;
|
||||
for(auto info : data)
|
||||
{
|
||||
if(info->dEnergy <= energyStart || info->dEnergy >= energyEnd)
|
||||
{
|
||||
continue;
|
||||
const QString& data_filename = data_files_set.first().toString();
|
||||
if ( !data_filename.isEmpty() ) {
|
||||
if (QFileInfo(data_filename).exists()) {
|
||||
this->_data_filename = data_filename;
|
||||
this->updateData(true);
|
||||
}
|
||||
x.append(info->index);
|
||||
y.append(info->dTime);
|
||||
minValue = qMin(minValue, info->dTime);
|
||||
maxValue = qMax(maxValue, info->dTime);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建曲线并设置数据
|
||||
QwtPlotCurve *curve = new QwtPlotCurve();
|
||||
// curve->setRawSamples(x.data(),y.data(),x.size());
|
||||
curve->setSamples(x, y);
|
||||
// 将曲线添加到 CustomQwtPlot 中(会自动分配颜色)
|
||||
plot->AddCurve(curve);
|
||||
// 设置坐标轴范围和标题
|
||||
// plot->setAxisScale(QwtPlot::xBottom, 0, x.last());
|
||||
// plot->setAxisScale(QwtPlot::yLeft,minValue , maxValue);
|
||||
void ParticleInjectTimeAnalysisView::setupMenu()
|
||||
{
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &ParticleInjectTimeAnalysisView::customContextMenuRequested, [this](const QPoint& pos) {
|
||||
this->_menu->exec(this->mapToGlobal(pos));
|
||||
});
|
||||
QAction* action_plot_reset = this->_menu->addAction(QStringLiteral(u"还原"));
|
||||
action_plot_reset->setObjectName("plot_reset");
|
||||
connect(action_plot_reset, &QAction::triggered, [this]() {
|
||||
this->_plot->ResetPlot();
|
||||
});
|
||||
this->_menu->addSeparator();
|
||||
|
||||
LOG_INFO(QStringLiteral(u"%1数据读取完毕.").arg(this->GetViewName()));
|
||||
this->_menu->addSeparator();
|
||||
QAction* action_plot_config = this->_menu->addAction(QStringLiteral(u"图表配置"));
|
||||
action_plot_config->setObjectName("plot_config");
|
||||
connect(action_plot_config, &QAction::triggered, this, &ParticleInjectTimeAnalysisView::onActionPlotConfigure);
|
||||
}
|
||||
|
||||
// 刷新绘图
|
||||
plot->replot();
|
||||
void ParticleInjectTimeAnalysisView::updateData(bool b_init_update)
|
||||
{
|
||||
auto functionToRun = [this, b_init_update](){
|
||||
if(!_data_filename.isEmpty()) {
|
||||
_busy_indicator->Start();
|
||||
std::string board_id_str = QString(QStringLiteral(u"板卡号")).toStdString();
|
||||
std::string channel_id_str = QString(QStringLiteral(u"通道号")).toStdString();
|
||||
std::string energy_str = QString(QStringLiteral(u"能量(KeV)")).toStdString();
|
||||
std::string time_str = QString(QStringLiteral(u"时间计数")).toStdString();
|
||||
|
||||
io::CSVReader<4> in(QStrToSysPath(_data_filename));
|
||||
in.read_header(io::ignore_extra_column, board_id_str, channel_id_str, energy_str, time_str);
|
||||
|
||||
int particle_num = 0;
|
||||
QVector<double> x;
|
||||
QVector<double> y;
|
||||
|
||||
int board, channel;
|
||||
double energy;
|
||||
unsigned long long time_count;
|
||||
while (in.read_row(board, channel, energy, time_count)) {
|
||||
if ( !b_init_update && (energy <= _begin_enery || energy >= _end_energy)) {
|
||||
continue;
|
||||
}
|
||||
particle_num++;
|
||||
x.append(particle_num);
|
||||
y.append(time_count);
|
||||
}
|
||||
_curve->setSamples(x, y);
|
||||
_plot->replot();
|
||||
LOG_INFO(QStringLiteral(u"%1数据更新完毕.").arg(this->GetViewName()));
|
||||
_busy_indicator->Stop();
|
||||
}
|
||||
};
|
||||
QThread* load_data_thread = QThread::create(functionToRun);
|
||||
load_data_thread->start();
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysisView::onActionPlotConfigure()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVector<ParticleInjectTime *> ParticleInjectTimeAnalysisView::getParticleInjectTimeData(QString path)
|
||||
void ParticleInjectTimeAnalysisView::showEvent(QShowEvent *e)
|
||||
{
|
||||
QVector<ParticleInjectTime *> records;
|
||||
|
||||
io::CSVReader<4> in(QStrToSysPath(path));
|
||||
in.read_header(io::ignore_extra_column, "板卡号", "通道号", "能量(KeV)", "时间计数");
|
||||
|
||||
int board, channel;
|
||||
double energy, time_count;
|
||||
int lineNumber = 0;
|
||||
|
||||
// 逐行读取
|
||||
while (in.read_row(board, channel, energy, time_count))
|
||||
{
|
||||
// qDebug()<<QStringLiteral(u"板卡号:")<<board<<QStringLiteral(u"通道号")<<channel<<QStringLiteral(u"能量(KeV)")<<energy<<QStringLiteral(u"时间计数")<<time_count;
|
||||
int detector = board + channel * 8;
|
||||
lineNumber++;
|
||||
if(detector > 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ParticleInjectTime *rec = new ParticleInjectTime;
|
||||
rec->index = lineNumber;
|
||||
rec->dEnergy = energy;
|
||||
rec->dTime = time_count;
|
||||
records.append(rec);
|
||||
Q_UNUSED(e);
|
||||
if (_busy_indicator) {
|
||||
_busy_indicator->setGeometry(this->rect());
|
||||
this->update();
|
||||
}
|
||||
return records;
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysisView::InitUi()
|
||||
{
|
||||
plot = new CustomQwtPlot();
|
||||
setupPlot();
|
||||
ui->verticalLayout_2->addWidget(plot);
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysisView::setupPlot()
|
||||
{
|
||||
plot->setCanvasBackground(Qt::white);
|
||||
QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(plot->canvas());
|
||||
canvas->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
plot->setAxisTitle(QwtPlot::xBottom, QStringLiteral(u"粒子序号"));
|
||||
plot->setAxisTitle(QwtPlot::yLeft, QStringLiteral(u"粒子时间"));
|
||||
// set axis auto scale
|
||||
plot->setAxisAutoScale(QwtPlot::xBottom, true);
|
||||
plot->setAxisAutoScale(QwtPlot::yLeft, true);
|
||||
// 启用网格线
|
||||
plot->enableAxis(QwtPlot::xBottom);
|
||||
plot->enableAxis(QwtPlot::yLeft);
|
||||
|
||||
// // 设置QWT图例
|
||||
// QwtLegend* legend = new QwtLegend();
|
||||
// legend->setDefaultItemMode(QwtLegendData::ReadOnly);
|
||||
// plot->insertLegend(legend, QwtPlot::RightLegend);
|
||||
|
||||
plot->SetAxisDragScale(QwtPlot::xBottom, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +1,39 @@
|
|||
#ifndef PARTICLEINJECTTIMEANALYSISVIEW_H
|
||||
#define PARTICLEINJECTTIMEANALYSISVIEW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "qwt.h"
|
||||
#include "CustomQwtPlot.h"
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include "MeasureAnalysisView.h"
|
||||
#include "csv.h"
|
||||
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class ParticleInjectTimeAnalysisView;
|
||||
}
|
||||
class CustomQwtPlot;
|
||||
class QwtPlotCurve;
|
||||
class BusyIndicator;
|
||||
class QMenu;
|
||||
|
||||
class ParticleInjectTimeAnalysisView : public MeasureAnalysisView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ParticleInjectTimeAnalysisView(QWidget *parent = nullptr);
|
||||
virtual ~ParticleInjectTimeAnalysisView();
|
||||
|
||||
virtual void InitViewWorkspace(const QString& project_name) override final;
|
||||
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
|
||||
|
||||
void setData(QVector<ParticleInjectTime *> data);
|
||||
|
||||
//获取数据
|
||||
QVector<ParticleInjectTime *> getParticleInjectTimeData(QString path);
|
||||
private:
|
||||
void InitUi();
|
||||
void setupPlot();
|
||||
void setupMenu();
|
||||
void updateData(bool b_init_update);
|
||||
private slots:
|
||||
void onActionPlotConfigure();
|
||||
|
||||
protected:
|
||||
virtual void showEvent(QShowEvent* e) override final;
|
||||
|
||||
private:
|
||||
Ui::ParticleInjectTimeAnalysisView *ui;
|
||||
CustomQwtPlot *plot;
|
||||
QVector<ParticleInjectTime *> m_AllData;//存储的所有的粒子入射时间数据
|
||||
BusyIndicator* _busy_indicator = nullptr;
|
||||
CustomQwtPlot *_plot = nullptr;
|
||||
QwtPlotCurve *_curve = nullptr;
|
||||
QMenu* _menu = nullptr;
|
||||
double _begin_enery = 0.0f;
|
||||
double _end_energy = 0.0f;
|
||||
QString _data_filename;
|
||||
};
|
||||
|
||||
#endif // PARTICLEINJECTTIMEANALYSIS_H
|
||||
|
|
|
|||
|
|
@ -1,157 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ParticleInjectTimeAnalysisView</class>
|
||||
<widget class="QWidget" name="ParticleInjectTimeAnalysisView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>997</width>
|
||||
<height>307</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>ParticleInjectTimeAnalysis</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<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>
|
||||
<item>
|
||||
<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="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>粒子入射设置</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>起始能量:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_energyStart">
|
||||
<property name="text">
|
||||
<string>50</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>KeV</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>~</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>终止能量:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_energyEnd">
|
||||
<property name="text">
|
||||
<string>100</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>KeV</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<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="pushButton">
|
||||
<property name="text">
|
||||
<string>感兴趣区域(ROI)选择</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<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>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -149,7 +149,6 @@ FORMS += \
|
|||
ParticleCountPlotView/BatchEnergyScaleDialog.ui \
|
||||
MeasureDeviceParamsCfgForm.ui \
|
||||
NewMeasureAnalysisDlg.ui \
|
||||
ParticleInjectTimeView/ParticleInjectTimeAnalysisView.ui\
|
||||
ThreeDimensionalConformityAnalysisView/DetectorStatusSummary.ui \
|
||||
ThreeDimensionalConformityAnalysisView/ParticleDataStatistics.ui \
|
||||
ThreeDimensionalConformityAnalysisView/ThreeDDisplay.ui \
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user