-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibration.cpp
132 lines (112 loc) · 2.91 KB
/
calibration.cpp
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
#include "calibration.h"
using namespace std;
void Calibration::ReadCalibration(string folderName)
{
string aFileName = folderName + "a.txt";
string bFileName = folderName + "b.txt";
string cFileName = folderName + "c.txt";
string tFileName = folderName + "t.txt";
ifstream aFile;
aFile.open(aFileName);
int x = 0;
int y = 0;
double value;
if (!aFile)
{
// Print an error and exit
cerr << "Uh oh, your file \"" << aFileName << "\" could not be opened for reading!" << endl;
}else{
//cout << "File \"" << m_name << "\" is open and ready for reading!" << endl;
while(aFile)
{
aFile >> value;
if (!aFile) break;
m_a[x][y] = value;
x++;
if (x == 512)
{
x = 0;
y++;
}
}
}
aFile.close();
ifstream bFile;
bFile.open(bFileName);
x = 0;
y = 0;
if (!bFile)
{
// Print an error and exit
cerr << "Uh oh, your file \"" << bFileName << "\" could not be opened for reading!" << endl;
}else{
//cout << "File \"" << m_name << "\" is open and ready for reading!" << endl;
while(bFile)
{
bFile >> value;
if (!bFile) break;
m_b[x][y] = value;
x++;
if (x == 512)
{
x = 0;
y++;
}
}
}
bFile.close();
ifstream cFile;
cFile.open(cFileName);
x = 0;
y = 0;
if (!cFile)
{
// Print an error and exit
cerr << "Uh oh, your file \"" << cFileName << "\" could not be opened for reading!" << endl;
}else{
//cout << "File \"" << m_name << "\" is open and ready for reading!" << endl;
while(cFile)
{
cFile >> value;
if (!cFile) break;
m_c[x][y] = value;
x++;
if (x == 512)
{
x = 0;
y++;
}
}
}
cFile.close();
ifstream tFile;
tFile.open(tFileName);
x = 0;
y = 0;
if (!tFile)
{
// Print an error and exit
cerr << "Uh oh, your file \"" << tFileName << "\" could not be opened for reading!" << endl;
}else{
//cout << "File \"" << m_name << "\" is open and ready for reading!" << endl;
while(tFile)
{
tFile >> value;
if (!tFile) break;
m_t[x][y] = value;
x++;
if (x == 512)
{
x = 0;
y++;
}
}
}
tFile.close();
}
double Calibration::CountEnergy(int x, int y, int tot)
{
double energy = (m_t[x][y]*m_a[x][y] + tot - m_b[x][y] + sqrt(pow(m_b[x][y] + m_t[x][y]*m_a[x][y] - tot,2) + 4*m_a[x][y]*m_c[x][y]))/(2*m_a[x][y]);
if (std::isnan(energy)) return 0;
return energy;
}