2026-03-03 18:15:34 +08:00
|
|
|
|
#include "MeasureAnalysisParticleCountPlotView.h"
|
|
|
|
|
|
#include "csv.h"
|
|
|
|
|
|
#include <QVector>
|
2026-03-04 21:16:35 +08:00
|
|
|
|
#include <GlobalDefine.h>
|
|
|
|
|
|
#include <QHBoxLayout>
|
2026-03-05 15:46:39 +08:00
|
|
|
|
#include <QwtPlot>
|
|
|
|
|
|
#include <QwtPlotCurve>
|
|
|
|
|
|
#include <QwtLegend>
|
|
|
|
|
|
#include <QwtPlotCanvas>
|
|
|
|
|
|
#include <QPen>
|
2026-03-04 21:16:35 +08:00
|
|
|
|
|
|
|
|
|
|
QColor getDistinctColorForManyCurves(int curveIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 1. 定义基础色相(覆盖不同主色系,0-360度)
|
|
|
|
|
|
const QList<int> baseHues = {
|
|
|
|
|
|
0, // 红色
|
|
|
|
|
|
30, // 橙色
|
|
|
|
|
|
60, // 黄色
|
|
|
|
|
|
90, // 黄绿色
|
|
|
|
|
|
120, // 绿色
|
|
|
|
|
|
150, // 青绿色
|
|
|
|
|
|
180, // 青色
|
|
|
|
|
|
210, // 天蓝色
|
|
|
|
|
|
240, // 蓝色
|
|
|
|
|
|
270, // 紫色
|
|
|
|
|
|
300, // 洋红色
|
|
|
|
|
|
330 // 玫红色
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 定义不同的饱和度/明度组合(避免颜色太暗/太灰)
|
|
|
|
|
|
const QList<QPair<int, int>> sVCombinations = {
|
|
|
|
|
|
{85, 90}, // 高饱和、高明度
|
|
|
|
|
|
{70, 85}, // 中高饱和、中高明度
|
|
|
|
|
|
{85, 75}, // 高饱和、中明度
|
|
|
|
|
|
{60, 80}, // 中饱和、中高明度
|
|
|
|
|
|
{75, 70}, // 中高饱和、中明度
|
|
|
|
|
|
{90, 80} // 极高饱和、中高明度
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 计算当前曲线对应的色相和饱和度/明度
|
|
|
|
|
|
int hueIndex = curveIndex % baseHues.size(); // 循环使用基础色相
|
|
|
|
|
|
int svIndex = (curveIndex / baseHues.size()) % sVCombinations.size(); // 循环使用饱和度/明度组合
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 获取HSV参数(色相0-360,饱和度0-255,明度0-255)
|
|
|
|
|
|
int hue = baseHues[hueIndex];
|
|
|
|
|
|
int saturation = sVCombinations[svIndex].first * 255 / 100; // 转换为0-255范围
|
|
|
|
|
|
int value = sVCombinations[svIndex].second * 255 / 100; // 转换为0-255范围
|
|
|
|
|
|
|
|
|
|
|
|
// 5. 生成并返回颜色(HSV转RGB)
|
|
|
|
|
|
QColor color;
|
|
|
|
|
|
color.setHsv(hue, saturation, value);
|
|
|
|
|
|
|
|
|
|
|
|
// 额外优化:避免极浅/极暗的颜色(保证曲线可见)
|
|
|
|
|
|
if (value < 50 * 255 / 100) {
|
|
|
|
|
|
value = 50 * 255 / 100;
|
|
|
|
|
|
color.setHsv(hue, saturation, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return color;
|
|
|
|
|
|
}
|
2026-03-03 18:15:34 +08:00
|
|
|
|
|
|
|
|
|
|
MeasureAnalysisParticleCountPlotView::MeasureAnalysisParticleCountPlotView(QWidget* parent)
|
|
|
|
|
|
: MeasureAnalysisView { parent }
|
|
|
|
|
|
{
|
2026-03-04 21:16:35 +08:00
|
|
|
|
this->setAnalyzeViewType(MeasureAnalysisViewType::CountSpectrum);
|
2026-03-03 18:15:34 +08:00
|
|
|
|
|
2026-03-04 21:16:35 +08:00
|
|
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
2026-03-05 15:46:39 +08:00
|
|
|
|
_plot = new QwtPlot(this);
|
|
|
|
|
|
layout->addWidget(_plot);
|
2026-03-04 21:16:35 +08:00
|
|
|
|
|
2026-03-05 15:46:39 +08:00
|
|
|
|
setupPlot();
|
2026-03-03 18:15:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-04 16:17:04 +08:00
|
|
|
|
void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
|
2026-03-03 18:15:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
for (auto it = data_files_set.begin(); it != data_files_set.end(); ++it) {
|
2026-03-04 21:16:35 +08:00
|
|
|
|
loadDataFromFile(it.key(), it.value().toString());
|
2026-03-03 18:15:34 +08:00
|
|
|
|
}
|
2026-03-05 15:46:39 +08:00
|
|
|
|
// _custom_plot->update();
|
2026-03-04 21:16:35 +08:00
|
|
|
|
this->update();
|
2026-03-03 18:15:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-05 15:46:39 +08:00
|
|
|
|
void MeasureAnalysisParticleCountPlotView::setupPlot()
|
2026-03-03 18:15:34 +08:00
|
|
|
|
{
|
2026-03-05 15:46:39 +08:00
|
|
|
|
_plot->setTitle(QString(QStringLiteral(u"粒子计数谱")));
|
|
|
|
|
|
|
|
|
|
|
|
_plot->setCanvasBackground(Qt::white);
|
|
|
|
|
|
QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(_plot->canvas());
|
|
|
|
|
|
canvas->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
|
|
|
|
|
|
|
_plot->setAxisTitle(QwtPlot::xBottom, QString(QStringLiteral(u"道址")));
|
|
|
|
|
|
_plot->setAxisTitle(QwtPlot::yLeft, QString(QStringLiteral(u"计数")));
|
|
|
|
|
|
// set axis auto scale
|
|
|
|
|
|
_plot->setAxisAutoScale(QwtPlot::xBottom, true);
|
|
|
|
|
|
_plot->setAxisAutoScale(QwtPlot::yLeft, true);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置QWT图例
|
|
|
|
|
|
QwtLegend *legend = new QwtLegend();
|
|
|
|
|
|
legend->setDefaultItemMode(QwtLegendData::Clickable);
|
|
|
|
|
|
_plot->insertLegend(legend, QwtPlot::RightLegend);
|
2026-03-03 18:15:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-04 21:16:35 +08:00
|
|
|
|
void MeasureAnalysisParticleCountPlotView::loadDataFromFile(const QString& data_name, const QString& filename)
|
2026-03-03 18:15:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
std::string address_str = QString(QStringLiteral(u"道址")).toStdString();
|
|
|
|
|
|
std::string count_str = QString(QStringLiteral(u"计数")).toStdString();
|
|
|
|
|
|
|
|
|
|
|
|
io::CSVReader<
|
|
|
|
|
|
2,
|
|
|
|
|
|
io::trim_chars<' ', '\t'>,
|
|
|
|
|
|
io::double_quote_escape<',', '"'>,
|
|
|
|
|
|
io::throw_on_overflow,
|
|
|
|
|
|
io::empty_line_comment
|
2026-03-04 21:16:35 +08:00
|
|
|
|
> reader(QStrToSysPath(filename));
|
2026-03-03 18:15:34 +08:00
|
|
|
|
reader.read_header(io::ignore_extra_column, address_str, count_str);
|
|
|
|
|
|
|
|
|
|
|
|
int address;
|
|
|
|
|
|
int particle_count;
|
2026-03-05 15:46:39 +08:00
|
|
|
|
QVector<float> x, y;
|
2026-03-03 18:15:34 +08:00
|
|
|
|
while (reader.read_row(address, particle_count)) {
|
|
|
|
|
|
x.push_back(address);
|
|
|
|
|
|
y.push_back(particle_count);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-05 15:46:39 +08:00
|
|
|
|
// 绘制曲线
|
|
|
|
|
|
QwtPlotCurve* curve = new QwtPlotCurve(data_name);
|
|
|
|
|
|
curve->setPen(QPen(getDistinctColorForManyCurves(0)));
|
|
|
|
|
|
curve->setSamples(x, y);
|
|
|
|
|
|
curve->attach(_plot);
|
2026-03-03 18:15:34 +08:00
|
|
|
|
|
2026-03-05 15:46:39 +08:00
|
|
|
|
// auto graph = _custom_plot->addGraph();
|
|
|
|
|
|
// graph->setName(data_name);
|
|
|
|
|
|
// graph->setPen(QPen(getDistinctColorForManyCurves(_custom_plot->graphCount())));
|
|
|
|
|
|
// graph->setData(x, y, true);
|
|
|
|
|
|
// graph->rescaleAxes();
|
|
|
|
|
|
|
|
|
|
|
|
// _custom_plot->replot();
|
2026-03-03 18:15:34 +08:00
|
|
|
|
}
|