-
Notifications
You must be signed in to change notification settings - Fork 0
/
2dmReader_Ifstream.cpp
115 lines (100 loc) · 3.85 KB
/
2dmReader_Ifstream.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
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <chrono>
#include <stdio.h>
using namespace std::chrono;
struct E3T {
uint32_t id, Node1, Node2, Node3, MaterialID;
};
struct E4Q {
uint32_t id, Node1, Node2, Node3, Node4, MaterialID;
};
struct Coords {
uint32_t id, MaterialID;
double X,Y;
float Z;
};
struct Mesh {
std::vector<E3T> triangles;
std::vector<E4Q> patches;
std::vector<Coords> pos;
};
struct MeshVector {
std::vector<std::vector<uint32_t>> triangles;
std::vector<std::vector<uint32_t>> patches;
std::vector<Coords> pos;
};
int main(int argc, char** argv)
{
// Get starting timepoint
auto start = high_resolution_clock::now();
if (argc == 1) {
std::cout << "Path to Mesh Data not provided!";
return 1;
}
std::ifstream mesh_path{argv[1]};
if (!mesh_path) {
std::cout << "Couldn't open Mesh file!";
return 1;
}
Mesh mesh;
mesh.triangles.reserve(20000000);
mesh.pos.reserve(10000000);
std::string card{};
std::string line{};
E3T triangle_i;
E4Q patch_i;
Coords pos_i;
while (!mesh_path.eof()){
std::getline(mesh_path,line);
if (line.substr(0,4) == "E3T "){
std::stringstream ss{line.substr(4)};
ss >> triangle_i.id >> triangle_i.Node1 >> triangle_i.Node2 >> triangle_i.Node3 >> triangle_i.MaterialID;
mesh.triangles.push_back(triangle_i);
} else if (line.substr(0,4) == "E4Q ") {
std::stringstream ss{line.substr(4)};
ss >> patch_i.id >> patch_i.Node1 >> patch_i.Node2 >> patch_i.Node3 >> patch_i.Node4 >> patch_i.MaterialID;
mesh.patches.push_back(patch_i);
} else if (line.substr(0,3) == "ND ") {
std::stringstream ss{line.substr(3)};
mesh_path >> pos_i.id >> pos_i.X >> pos_i.Y >> pos_i.Z ;
mesh.pos.push_back(pos_i);
}
// mesh_path >> card;
// if (card == "E3T"){
// mesh_path >> triangle_i.id >> triangle_i.Node1 >> triangle_i.Node2 >> triangle_i.Node3 >> triangle_i.MaterialID;
// mesh.triangles.push_back(triangle_i);
// } else if (card == "E4Q") {
// mesh_path >> patch_i.id >> patch_i.Node1 >> patch_i.Node2 >> patch_i.Node3 >> patch_i.Node4 >> patch_i.MaterialID;
// mesh.patches.push_back(patch_i);
// } else if (card == "ND") {
// mesh_path >> pos_i.id >> pos_i.X >> pos_i.Y >> pos_i.Z ;
// mesh.pos.push_back(pos_i);
// }
// std::getline(mesh_path,line);
// std::cout << "Card: " << card << std:: endl;
// std::cout << "Values: " << line << std:: endl;
// std::stringstream ss{line};
// if (card == "E3T"){
// ss >> triangle_i.id >> triangle_i.Node1 >> triangle_i.Node2 >> triangle_i.Node3 >> triangle_i.MaterialID;
// mesh.triangles.push_back(triangle_i);
// } else if (card == "E4Q") {
// ss >> patch_i.id >> patch_i.Node1 >> patch_i.Node2 >> patch_i.Node3 >> patch_i.Node4 >> patch_i.MaterialID;
// mesh.patches.push_back(patch_i);
// } else if (card == "ND") {
// ss >> pos_i.id >> pos_i.X >> pos_i.Y >> pos_i.Z ;
// mesh.pos.push_back(pos_i);
// }
}
mesh_path.close();
std::cout << "The Input mesh has \n\t" << mesh.triangles.size() << " triangles\n\t"
<< mesh.patches.size() << " patches\n\t" << mesh.pos.size() << " Nodes\n";
// Get ending timepoint
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
std::cout << "Time taken: " << duration.count() << " seconds" << std::endl;
return 0;
}