-
Notifications
You must be signed in to change notification settings - Fork 8
/
mesh.hpp
109 lines (100 loc) · 2.76 KB
/
mesh.hpp
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
#ifndef __MESH_HPP__
#define __MESH_HPP__
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <string.h>
using namespace std;
struct Point{
float c[3];
int id;
vector<int> neighbours;
vector<double> mass;
vector<double> stiff;
Point( int _id, double *_c) {
id = _id;
for (int i=0; i<3; i++)
c[i] = (float)_c[i];
}
Point(){};
};
struct Tet{
int points[4];
int id;
Tet(int _id, int *_points){
id = _id;
vector<int> p(_points, _points + 4);
sort(p.begin(), p.end());
for (int i=0; i<4; i++)
points[i] = p[i];
}
Tet(){};
};
struct Facet{
int points[3];
int tet;
int num_tets;
float normal[3];
Facet(){};
Facet(int p1, int p2, int p3, int tet_id) {
vector<int> pvec(3);
pvec[0] = p1; pvec[1] = p2; pvec[2] = p3;
sort(pvec.begin(), pvec.end());
for (int i=0; i<3; i++)
points[i] = pvec[i];
tet = tet_id;
num_tets = 1;
}
bool operator==(Facet &f) {
return (points[0] == f.points[0]) &&
(points[1] == f.points[1]) && (points[2] == f.points[2]);
}
bool operator!=(Facet &f) {
return !(operator==(f));
}
};
class Mesh {
vector<Point> points;
vector<Tet> tets ;
vector<Facet> boundary_facets;
void read_points(string filename);
void read_tets(string filename);
float xrange[2];
float yrange[2];
float zrange[2];
public:
enum{
READ_MODE_TXT,
READ_MODE_BIN
};
Mesh(string filename, int read_mode);
void build_facets();
void read_mesh_binary(string filename);
vector<Point>& getPoints() { return points; }
vector<Facet>& getBoundaryFacets() { return boundary_facets; }
vector<Tet>& getTets() { return tets; }
void GetPoint(int id, float *c) {
memcpy(c,points[id].c,3*sizeof(float));
}
void normalizeForDrawing();
void saveMeshBinary(string filename);
void saveBoundaryFacets(string filename);
void calcBoundaryFacetsNormals();
float* GetPointC(int id) { return points[id].c; }
void find_neighbours();
void calc_fem_matrices();
float getXmin() {return xrange[0];}
float getXmax() {return xrange[1];}
float getYmin() {return yrange[0];}
float getYmax() {return yrange[1];}
float getZmin() {return zrange[0];}
float getZmax() {return zrange[1];}
float getXrange() {return xrange[1]-xrange[0];}
float getYrange() {return yrange[1]-yrange[0];}
float getZrange() {return zrange[1]-zrange[0];}
float getXcenter() {return (xrange[0]+xrange[1])/2.0;}
float getYcenter() {return (yrange[0]+yrange[1])/2.0;}
float getZcenter() {return (zrange[0]+zrange[1])/2.0;}
};
#endif