135 lines
3.7 KiB
C++
135 lines
3.7 KiB
C++
|
|
#ifndef SPECPEAKSERVICE_H
|
|
#define SPECPEAKSERVICE_H
|
|
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <fstream>
|
|
#include <chrono>
|
|
#include "algorithmanalysis.h"
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
/* init_interval_index = [] 原始区间
|
|
init_interval_info = [] 未经过筛选的区间的信息
|
|
interval_index = [] 最终的结果区间索引 */
|
|
struct IntervalIndexStruct {
|
|
vector<vector<int>> interval_index;
|
|
vector<vector<int>> init_interval_index;
|
|
vector<vector<string>> init_interval_info;
|
|
};
|
|
|
|
|
|
struct ExtendedIntervalIndexStruct {
|
|
vector<vector<int>> extend_interval_index;
|
|
vector<map<string, int>> extend_interval_info;
|
|
};
|
|
|
|
struct MergeIntervalIndexStruct {
|
|
vector<vector<int>> merge_interval_index;
|
|
vector<vector<int>> merge_interval_info;
|
|
};
|
|
|
|
|
|
|
|
|
|
class SpecPeakService
|
|
{
|
|
public:
|
|
SpecPeakService();
|
|
|
|
vector<int> SpecPeak(vector<SpectrumChannelData> channelData);
|
|
|
|
//将下标转为为波长与强度
|
|
vector<SpectrumChannelData> mapInvertInt(vector<SpectrumChannelData> channelData, vector<int> mergedIndex);
|
|
|
|
private:
|
|
|
|
//函数声明
|
|
|
|
//数据平滑
|
|
vector<double> smooth(vector<double> intensity_data, int points_num = 5);
|
|
|
|
// 初始化波长强度
|
|
void initSpecWavelengthStrength();
|
|
|
|
// 计算归一化的绝对值
|
|
vector<double> absMaxNorm(vector<double> specList);
|
|
|
|
//判断两条线是否相交
|
|
bool isIntersect(double leftY1, double leftY2, double rightY1, double rightY2);
|
|
|
|
// 求导数以及绝对值 归一化
|
|
void spectralPretreatment(vector<SpectrumChannelData>);
|
|
|
|
// 差分
|
|
vector<double> diff(vector<double> xValueList, vector<double> yValueList, int n = 1);
|
|
|
|
//找出特征波长节点
|
|
vector<int> findFeatureIndex();
|
|
|
|
//去除连续波长节点中中间的节点
|
|
vector<int> featureIndexDelMiddle(vector<int> featuresIndexList);
|
|
|
|
//从相邻的波长节点中选择一个
|
|
vector<int> chooseFeatureIndex2of1(vector<int> featuresIndexList);
|
|
|
|
//将特征波长节点转化为区间索引,并进行条件判断,筛选出满足条件的区间
|
|
IntervalIndexStruct getIntervalIndex(vector<int> featuresIndex);
|
|
|
|
//扩展区间,使得区间包含整个峰
|
|
//从峰值开始,向左扩展至一阶导和二阶导的第二个交点,向右扩展至一阶导和二阶导的第二个交点
|
|
ExtendedIntervalIndexStruct extendedIntervalIndex(vector<vector<int>>);
|
|
|
|
//合并相交的区间
|
|
MergeIntervalIndexStruct mergeIntervalIndex(vector<vector<int>> intervalIndex, vector<map<string, int>> interval_info);
|
|
|
|
//将集合下标转化为vector集合
|
|
vector<int> mapInvertInt(MergeIntervalIndexStruct extendedIntervalIndexStruct);
|
|
|
|
// 1. 获取扣掉强峰的区间(强峰区间对整个波长范围取补集)
|
|
// 2. 筛选掉长度不足 50 个点的区间
|
|
vector<int> get_background_interval(MergeIntervalIndexStruct mergeIntervalIndexStruct);
|
|
|
|
//获取波动值
|
|
double get_background_wave(MergeIntervalIndexStruct mergeIntervalIndexStruct);
|
|
|
|
void getRes();
|
|
|
|
|
|
//变量声明
|
|
int specPointNum;
|
|
|
|
vector<double> intensityNorm;
|
|
|
|
vector<double> intensity_smooth;
|
|
// 最大波动值
|
|
double background_ptp = 0.2;
|
|
|
|
vector<double> wavelength;
|
|
vector<double> intensity;
|
|
|
|
//一阶导二阶导以及其绝对值
|
|
vector<double> d1;
|
|
vector<double> d1_2;
|
|
vector<double> d1_abs;
|
|
vector<double> d2;
|
|
vector<double> d2_2;
|
|
vector<double> d2_abs;
|
|
|
|
//一阶导二阶导归一化
|
|
vector<double> d1_norm;
|
|
vector<double> d1_2_norm;
|
|
vector<double> d1_abs_norm;
|
|
vector<double> d2_norm;
|
|
vector<double> d2_2_norm;
|
|
vector<double> d2_abs_norm;
|
|
|
|
MergeIntervalIndexStruct mergeIntervalIndexStruct;
|
|
};
|
|
|
|
#endif // SPECPEAKSERVICE_H
|