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