-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileiostream.cpp
73 lines (58 loc) · 1.92 KB
/
fileiostream.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
#include "fileiostream.h"
FileIOStream::FileIOStream(std::string file): m_istream(file.c_str())
{
if (!m_istream.is_open())
throw std::runtime_error("Error: cannot open file!");
}
FileIOStream::~FileIOStream()
{
if (m_istream.is_open())
m_istream.close();
}
int FileIOStream::getSizeDescriptor()
{
int size = 0;
if (!(m_istream >> size))
throw std::runtime_error("Error: invalid reading!");
return size;
}
int FileIOStream::getCountFeaturePoints()
{
int count = 0;
if (!(m_istream >> count))
throw std::runtime_error("Error: invalid reading!");
return count;
}
FeaturePoint FileIOStream::getNextFeaturePoint(const int size)
{
FeaturePoint tmp(size);
double bufValue = 0;
int bufId = 0;
if (m_istream >> bufValue) tmp.setX(bufValue);
else throw std::runtime_error("Error: cannot read x value.");
if (m_istream >> bufValue) tmp.setY(bufValue);
else throw std::runtime_error("Error: cannot read y value.");
if (m_istream >> bufValue) tmp.setFi(bufValue);
else throw std::runtime_error("Error: cannot read fi value.");
if (m_istream >> bufValue) tmp.setS(bufValue);
else throw std::runtime_error("Error: cannot read s value.");
if (m_istream >> bufId) tmp.setIdImage(bufId);
else throw std::runtime_error("Error: cannot read idImage value.");
bool flag = true;
for (int i = 0; i < size && flag; i++)
if (!(m_istream >> tmp.descriptor()[i]))
flag = false;
if (!flag) throw std::runtime_error("Error: cannot read descriptor!");
return tmp;
}
std::vector<FeaturePoint> FileIOStream::getFeaturePoints()
{
std::vector<FeaturePoint> buffer;
int sizeDescriptor = 0;
int countRecord = 0;
sizeDescriptor = getSizeDescriptor();
countRecord = getCountFeaturePoints();
for (int i = 0; i < countRecord; i++)
buffer.push_back(getNextFeaturePoint(sizeDescriptor));
return buffer;
}