-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInputFileInfo.cpp
More file actions
112 lines (98 loc) · 3.03 KB
/
InputFileInfo.cpp
File metadata and controls
112 lines (98 loc) · 3.03 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
#include "InputFileInfo.h"
using namespace std;
using namespace cv;
InputFileInfo::InputFileInfo() {
// common info
binary = true; // if the input file is binary
source_mat = false; // input from mat instead of file path
verbose = false; // turn on/off text outputs
input_path = ""; // input file path
output_path = ""; // output file path
file_type = 0; // input file type (0: Image data; 1: Dense distance matrix; 2: sparse distance matrix)
// info for cubical image data
dimension = 0; // the data dimension, exclusively for cubical image data and general simplicial complex
// info for dense distance matrix
numPoints = 0; // number of points
dimPoints = 0; // dimension of each feature point
}
void InputFileInfo::source_from_file(const string &input_file_, const string &output_path_) {
input_path = input_file_;
source_mat = false;
if (output_path_ == "") output_path = input_path;
else {
vector<string> split_res = split(input_path, '/');
string file_name = split_res[split_res.size() - 1];
output_path = output_path_ + "/" + file_name;
}
if (input_path.find(".txt") != string::npos) // plain text file
{
binary = false;
fstream f(input_path.c_str());
if (!f.is_open())
cout << "Cannot find the file " << input_path << endl;
f >> file_type;
if (file_type == 0) // Image data
{
f >> dimension;
assert(dimension <= 8);
}
else if (file_type == 1) // Dense distance matrix
{
f >> numPoints;
f >> dimPoints;
}
else if (file_type == 2) // General simplicial complex
{
f >> dimension;
f >> numPoints;
f >> dimPoints;
}
f.close();
}
else // binary data file
{
binary = true;
fstream f(input_path.c_str(), ios::in | ios::binary);
if (!f.is_open())
cout << "Cannot find the file " << input_path << endl;
f.read(reinterpret_cast<char*>(&file_type), sizeof(int));
if (file_type == 0) // Image data
{
f.read(reinterpret_cast<char*>(&dimension), sizeof(int));
assert(dimension <= 8);
cout << "The dimension of input data: " << dimension << endl;
}
else if (file_type == 1) // Dense distance matrix
{
f.read(reinterpret_cast<char*>(&numPoints), sizeof(int));
f.read(reinterpret_cast<char*>(&dimPoints), sizeof(int));
}
else if (file_type == 2) // General simplicial complex
{
f.read(reinterpret_cast<char*>(&dimension), sizeof(int));
f.read(reinterpret_cast<char*>(&numPoints), sizeof(int));
f.read(reinterpret_cast<char*>(&dimPoints), sizeof(int));
}
f.close();
}
}
void InputFileInfo::source_from_mat(const string& output_path_, const Mat& t) {
// only image data is supported if pass from mat!!
file_type = 0;
source_mat = true;
output_path = output_path_;
t.convertTo(mat, CV_64F);
dimension = mat.dims;
assert(dimension <= 8);
}
vector<string> InputFileInfo::split(string strToSplit, char delimeter)
{
stringstream ss(strToSplit);
string item;
vector<string> splittedStrings;
while (getline(ss, item, delimeter))
{
splittedStrings.push_back(item);
}
return splittedStrings;
}