-
Notifications
You must be signed in to change notification settings - Fork 0
/
Readin.cpp
158 lines (130 loc) · 3.6 KB
/
Readin.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "Readin.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <QDataStream>
#include <QString>
#include "Parameters.h"
Readin::Readin() {}
Readin::Readin(QString fName)
{
m_fileName = fName;
}
Readin::~Readin() {}
void Readin::StartReadTxt()
{
m_data = QVector< QVector<quint16> >(3);
if (!QFile::exists(m_fileName)) // 检查文件是否存在
{
qDebug() << "File doesnot exists, please check file: " << m_fileName;
return;
}
QFile file(m_fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Fail to open file, please check file: " << m_fileName;
return;
}
quint64 fileSize = file.size(); // 获取文件大小,用于计算进度
QTextStream in(&file);
int prePos = 0;
while (!in.atEnd())
{
QString line = in.readLine();
QStringList numbers = line.split(" ", QString::SkipEmptyParts);
if(3==numbers.size())
{
m_data[0].append(numbers[0].toInt());
m_data[1].append(numbers[1].toInt());
m_data[2].append(numbers[2].toInt());
}
else
{
qDebug() << "numbers size is not 3, data file is broken!";
continue;
}
int pos = qRound(100.0*file.pos()/fileSize);
if(pos>prePos)
{
emit currentPos(pos);
prePos = pos;
}
}
file.close();
emit finished();
}
void Readin::StartReadBin()
{
m_data = QVector< QVector<quint16> >(nCM*nBK);
// 检查文件是否存在
if (!QFile::exists(m_fileName))
{
qDebug() << "Fail to open file, please check file.";
return;
}
quint8 type; // type:[3:0], [7:4]保留
quint8 t_high; // t[15:8]
quint8 t_low; // t[7:0]
quint8 sectorID; // [7:4]CMID, [3:1]BKID
quint8 xPos; // x[8:1]
quint8 yPos; // y[8:1]
quint8 e_high; // [7]为x[0]; [6]为y[0], [3:0]为E[11:8]
quint8 e_low; // E[7:0]
QFile file(m_fileName);
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << "Error opening file!";
return;
}
quint64 fileSize = file.size(); // 获取文件大小,用于计算进度
QDataStream in(&file);
int prePos = 0;
while (!in.atEnd()) // 循环读取每个事例的数据
{
// 读取8个变量的数据
in >> type >> t_high >> t_low >> sectorID >>
xPos >> yPos >> e_high >> e_low;
// 处理读取的数据
if(type!=3)
{
qDebug() << "type is not 3. break \n";
continue;
}
int CMID = (sectorID >> 4);
if(CMID<0 || CMID>nCM)
{
qDebug() << "CMID is out of range! \n";
continue;
}
int BKID = ((sectorID >> 1) & 0x07);
if(BKID<0 || BKID>nBK)
{
qDebug() << "BKID is out of range! \n";
continue;
}
int iLine = CMID*nBK + BKID;
if(iLine<0 || iLine>nCM*nBK)
{
qDebug() << "total BKID is out of range! \n";
continue;
}
quint16 x = xPos*2 + (e_high>>7);
quint16 y = yPos*2 + ( (e_high>>6) & 0x01);
quint16 e = (e_high&0x0F)*std::pow(2,8) + e_low;
m_data[iLine].append(x);
m_data[iLine].append(y);
m_data[iLine].append(e);
int pos = qRound(100.0*file.pos()/fileSize);
if(pos>prePos)
{
emit currentPos(pos);
prePos = pos;
}
}
file.close();
emit finished();
}
QVector< QVector<quint16> > Readin::GetData()
{
return m_data;
}