-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnmrdata.cpp
More file actions
148 lines (127 loc) · 3.62 KB
/
Copy pathnmrdata.cpp
File metadata and controls
148 lines (127 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "nmrdata.h"
NMRData::NMRData(QObject * parent /*= nullptr*/)
: QObject(parent)
{
}
void NMRData::readAsCPMG(const QString& filepath)
{
QFile file(filepath);
if (file.open(QIODevice::ReadOnly))
{
QTextStream filestream(&file);
QString line;
QStringList splitted_line;
QRegExp spaces("(\\s+)");
this->A_.reserve(10000);
this->t_.reserve(10000);
while (!filestream.atEnd())
{
line = filestream.readLine();
line = line.trimmed();
if(line.begin() != line.end())
{
line.replace(',', '.');
splitted_line = line.split(spaces);
bool A_converted = false;
double A_value = splitted_line[1].toDouble(&A_converted);
bool t_converted = false;
double t_value = splitted_line[0].toDouble(&t_converted);
if(A_converted && t_converted)
{
this->A_.push_back(A_value);
this->t_.push_back(t_value);
}
}
}
file.close();
this->A_.shrink_to_fit();
this->t_.shrink_to_fit();
double max_element = *std::min_element(this->A_.begin(), this->A_.end());
for(auto A_it = A_.begin(); A_it < A_.end(); ++A_it)
{
*A_it = *A_it - max_element;
}
max_element = *std::max_element(this->A_.begin(), this->A_.end());
for(auto A_it = A_.begin(); A_it < A_.end(); ++A_it)
{
*A_it = *A_it / max_element;
}
NMRDataStruct raw_data;
raw_data.A = A_;
raw_data.t = t_;
raw_data.p = {};
raw_data.pt = {};
emit rawDataUpdated(raw_data);
}
}
void NMRData::setRawData(const NMRDataStruct& raw_data)
{
if(raw_data.A.size() == raw_data.t.size())
{
this->A_ = raw_data.A;
this->t_ = raw_data.t;
emit rawDataUpdated(raw_data);
}
else
{
emit wrongData();
}
}
void NMRData::setProcessedData(const NMRDataStruct& processed_data)
{
this->A_approximated_ = processed_data.A;
this->t_approximated_ = processed_data.t;
this->p_ = processed_data.p;
this->pt_ = processed_data.pt;
emit processedDataUpdated(processed_data);
}
void NMRData::setComponents(const NMRDataStruct& components)
{
M_ = components.A;
T_ = components.t;
emit componentsUpdated(components);
}
void NMRData::setNoise(const NMRDataStruct& components)
{
noise_ = components.p;
}
void NMRData::clearRawData()
{
this->A_.clear(); //Однако память выделенная под вектор не освобождается, чтобы при считывании новых данных не выделять паямть заного.
this->t_.clear();
NMRDataStruct raw_data = {
.A=this->A_,
.t=this->t_
};
emit rawDataUpdated(raw_data);
}
void NMRData::clearProcessedData()
{
this->A_approximated_.clear();
this->A_approximated_.clear();
this->p_.clear();
this->pt_.clear();
NMRDataStruct processed_data = {
.A = this->A_approximated_,
.t = this->t_approximated_,
.p = this->p_,
.pt = this->pt_
};
emit processedDataUpdated(processed_data);
}
void NMRData::clearComponents()
{
this->M_.clear();
this->T_.clear();
NMRDataStruct components = {
.A = this->M_,
.t = this->T_
};
emit componentsUpdated(components);
}
void NMRData::clearData()
{
this->clearRawData();
this->clearProcessedData();
this->clearComponents();
}