-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileIOUtil.cpp
More file actions
81 lines (54 loc) · 1.97 KB
/
FileIOUtil.cpp
File metadata and controls
81 lines (54 loc) · 1.97 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
#include "FileIOUtil.h"
static double stringToDouble(const std::string& str) {
std::istringstream iss(str);
double result;
iss >> result;
return result;
}
std::vector<Point_3> FileIOUtil::LoadDataFF(std::string path)
{
std::vector<Point_3> points;
std::ifstream file(path);
std::string line;
if (file.is_open()) {
while (std::getline(file, line)) {
if (line.empty() || line[0] == '*') {
continue;
}
std::istringstream ss(line);
std::string token;
std::getline(ss, token, ',');
int number = std::stoi(token);
std::getline(ss, token, ',');
double x = stringToDouble(token);
std::getline(ss, token, ',');
double y = stringToDouble(token);
std::getline(ss, token, ',');
double z = stringToDouble(token);
points.push_back(Point_3(x, y, z));
}
file.close();
}
else {
std::cerr << "Unable to open file: " << path << std::endl;
}
return points;
}
void FileIOUtil::SaveDataIF(std::string path, Delaunay triangulation)
{
std::ofstream outputFile(path);
if (!outputFile.is_open()) {
std::cerr << "Error: Unable to open file " << path << " for writing." << std::endl;
return;
}
std::ostringstream dataStream;
int i = 0;
dataStream << "Elements:" << std::endl;
for (auto it = triangulation.finite_cells_begin(); it != triangulation.finite_cells_end(); ++it) {
i++;
dataStream << i << ", " << it->vertex(0)->point() << ", " << it->vertex(1)->point() << ", " << it->vertex(2)->point() << std::endl;
}
outputFile << dataStream.str() << std::endl;
outputFile.close();
std::cout << "Data saved to " << path << " successfully." << std::endl;
}