PeriDyno 1.0.0
Loading...
Searching...
No Matches
gmsh_helper.cpp
Go to the documentation of this file.
1#include "gmsh_helper.h"
2
3#include <string.h>
4#include <fstream>
5#include <iostream>
6#include <sstream>
7
8using namespace std;
9
10namespace dyno
11{
12
13void Gmsh::loadFile(string filename)
14{
15 fstream filein(filename);
16 if (!filein.is_open())
17 {
18 cout << "can't open Gmsh file:" << filename << endl;
19 exit(0);
20 }
21
22 int ignored_lines = 0;
23 bool version = false;
24 bool node = false;
25 //printf("YES\n");
26 std::string line;
27 while (!filein.eof()) {
28 std::getline(filein, line);
29 //std::cout << line << std::endl;
30 //.obj files sometimes contain vertex normals indicated by "vn"
31 if (line.substr(0, 1) != std::string("$")) {
32 if (!version)
33 {
34 version = true;
35 }
36 else
37 {
38 std::stringstream data(line);
39 int sum;
40 data >> sum;
41 //printf("sum = %d\n", sum);
42 if (!node)
43 {
44 node = true;
45 Real a, b, c;
46 int idx;
47 for (int i = 0; i < sum; i++)
48 {
49 //fscanf("%d%f%f%f", &idx, &a, &b, &c);
50
51 std::getline(filein, line);
52 std::stringstream data(line);
53 data >> idx >> a >> b >> c;
54 //std::cout << idx << ' ' << a << ' ' << b << ' ' << c << std::endl;
55 m_points.push_back(Vec3f(a,b,c));
56 }
57 //printf("outside 1\n");
58 }
59 else
60 {
61 int idx1, idx2, idx3, idx4, idx5;
62 int id1, id2, id3, id4;
63 //printf("sum2 = %d\n", sum);
64
65 for (int i = 0; i < sum; i++)
66 {
67 filein >> idx1 >> idx2 >> idx3 >> idx4 >> idx5;
68 if (idx2 == 4)
69 {
70 filein >> id1 >> id2 >> id3 >> id4;
71 //std::cout << id1 << ' ' << id2 << ' ' << id3 << ' ' << id4 << std::endl;
72 /*if(
73 (m_points[id1 - 1][0] < 0.85f || ((m_points[id1 - 1][2] > 0.7f * (m_points[id1 - 1][0] - 0.85f) || ((m_points[id1 - 1][2] < -0.7f * (m_points[id1 - 1][0] - 0.85f))))))
74 &&
75 (m_points[id2 - 1][0] < 0.85f || ((m_points[id2 - 1][2] > 0.7f * (m_points[id2 - 1][0] - 0.85f) || ((m_points[id2 - 1][2] < -0.7f * (m_points[id2 - 1][0] - 0.85f))))))
76 &&
77 (m_points[id3 - 1][0] < 0.85f || ((m_points[id3 - 1][2] > 0.7f * (m_points[id3 - 1][0] - 0.85f) || ((m_points[id3 - 1][2] < -0.7f * (m_points[id3 - 1][0] - 0.85f))))))
78 &&
79 (m_points[id4 - 1][0] < 0.85f || ((m_points[id4 - 1][2] > 0.7f * (m_points[id4 - 1][0] - 0.85f) || ((m_points[id4 - 1][2] < -0.7f * (m_points[id4 - 1][0] - 0.85f))))))
80 )*/
81 {
82 m_tets.push_back(TopologyModule::Tetrahedron(id1 - 1, id2 - 1, id3 - 1, id4 - 1));
83 }
84 }
85 else if (idx2 == 15)
86 {
87 filein >> id1;
88 }
89 else if (idx2 == 1)
90 {
91 filein >> id1 >> id2;
92 }
93 else
94 {
95 filein >> id1 >> id2 >> id3;
96 }
97 }
98 break;
99 }
100 }
101 //std::stringstream data(line);
102
103
104 //data >> point[0] >> point[1] >> point[2];
105 }
106 else {
107 ++ignored_lines;
108 }
109 }
110 //printf("outside\n");
111 filein.close();
112}
113
114} // namespace dyno
double Real
Definition Typedef.inl:23
std::vector< TopologyModule::Tetrahedron > m_tets
Definition gmsh_helper.h:17
void loadFile(std::string filename)
std::vector< Vec3f > m_points
Definition gmsh_helper.h:16
VectorND< PointType, 4 > Tetrahedron
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Vector< float, 3 > Vec3f
Definition Vector3D.h:93