-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
143 lines (125 loc) · 3.73 KB
/
main.cpp
File metadata and controls
143 lines (125 loc) · 3.73 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
/***********
//Code by Yanjie Li
//Oct. 2016
***********/
#include "Graph.h"
#include "FileFun.h"
#include <iomanip>
#include <unistd.h>
using namespace std;
class myComp3D
{
bool reverse;
Point3D p;
public:
myComp3D(Point3D pp, const bool& revparam)
{
p = pp;
reverse = revparam;
}
bool operator() (const std::pair<int, Point3D> & lhs, const std::pair<int, Point3D> &rhs) const
{
if (reverse) return (computePointDistance(p, lhs.second) > computePointDistance(p, rhs.second));
else return (computePointDistance(p, lhs.second) < computePointDistance(p, rhs.second));
}
};
//typedef std::priority_queue<std::pair<int, Point3D>, std::vector< std::pair<int, Point3D> >, myComp3D> mypq_type;
string extractFileName(string fileName){
int slashIndex = fileName.find_last_of('/');
size_t dotPos = fileName.find_last_of('.');
if (dotPos == string::npos)
return fileName.substr(slashIndex+1);
else
return fileName.substr(slashIndex + 1, dotPos - slashIndex - 1);
}
void printPersistentDiagramsWithDiameter(vector<string> files, string outputFolder){
unsigned int fileNum = files.size();
std::string fileName;
double delta;
vector<Point3D> vP;
//Debug
cout<<"Starting loop"<<endl;
for(size_t i=0;i<fileNum;i++){
fileName = files[i];
cout<<"process "<< i<<": "<< fileName << endl;
delta = 0.1;
std::ifstream ifs;
double x, y, z;
int i1, i2;
double d;
vP.clear();
ifs.open(fileName.c_str());
int countP, countF;
ifs >> countP >> countF;
cout<<"Starting pushback loop"<<endl;
for(int j = 0; j < countP; j++){
ifs >> x >> y >> z;
Point3D p;
p.x = x;
p.y = y;
p.z = z;
vP.push_back(p);
}
cout<<"pushback loop complete"<<endl;
cout<<delta;
std::printf("vp.size(): %llu countF: %llu\n", (unsigned long long) vP.size(), (unsigned long long) countF);
Graph ga(vP.size(), delta, countF);
ga.setVP(vP);
cout<<"Starting Edge loop"<<endl;
cout<<"Starting Edge loop"<<endl;
for(int j = 0; j < countF; j++){
ifs >> i1 >> i2;
ga.addEdge(i1, i2);
}
cout<<"Edge loop complete"<<endl;
cout<<"Starting setfuncloop"<<endl;
for(int j = 0; j < countP; j++){
ifs >> d;
ga.setFuncVal(j, d);
}
cout<<"setfuncloop loop complete"<<endl;
ifs.close();
ifs.clear();
vP.clear();
ga.outputPersistenceDiagramsOnlyData(outputFolder + extractFileName(fileName) + ".pdg");
}
cout<<"Outer loop complete"<<endl;
}
void getPersistentDiagrams(string filePath, string outputFolder){
vector<string> files;
getFiles(filePath, "des", files);
//vector<string> filesFixIndex = getFixIndexFiles(files);
printPersistentDiagramsWithDiameter(files, outputFolder);
}
int main(int argc, char **argv){
// if(argc != 3){
// cout << "usage: PDmain <input folder name> <output folder name>" << endl;
// return 0;
// }
// string euclideanWithFuncVal(argv[1]);
// string persistenceDiagramFolder(argv[2]);
if(argc != 3){
cout << "usage: main <input folder name> <output folder name>" << endl;
}
string inputFolder(argv[1]);
string outputFolder(argv[2]);
cout << inputFolder;
inputFolder = inputFolder +"/";
cout << outputFolder;
//string inputFolder = "C:\\FileCreator\\CPP\\Input\\";
//string outputFolder = "C:\\FileCreator\\CPP\\Output\\";
char buffer[FILENAME_MAX];
char *answer = getcwd(buffer, sizeof(buffer));
string s_cwd;
if (answer)
{
s_cwd = answer;
}
cout << s_cwd;
//string inputFolder = s_cwd + separator() + "temp" + separator();
//string outputFolder = s_cwd + separator() + "Output" + separator();
// if(outputFolder.find_last_of('\\') != outputFolder.size() - 1){
// outputFolder += '\\';
// }
getPersistentDiagrams(inputFolder, outputFolder);
}