-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmesh.cpp
104 lines (86 loc) · 2.11 KB
/
mesh.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
#include "mesh.h"
Mesh::Mesh()
{
}
Mesh::Mesh(const Mesh &m): nom(m.nom), geom(m.geom), topo(m.topo), norm(m.norm)
{
}
Mesh::Mesh(const QList<Vector3D> &v, const QList<int> &t, const QList<Vector3D> &n, const QString &no): nom(no), geom(v), topo(t), norm(n)
{
}
void Mesh::translate(const Vector3D &t)
{
QList<Vector3D>::iterator itv=geom.begin();
for(;itv!=geom.end();++itv){
(*itv)+=t;
}
}
void Mesh::rotate(const QMatrix3x3 &mat)
{
QList<Vector3D>::iterator itv=geom.begin();
for(;itv!=geom.end();++itv){
double x=(*itv).x()*mat(0,0)+(*itv).y()*mat(0,1)+(*itv).z()*mat(0,2);
double y=(*itv).x()*mat(1,0)+(*itv).y()*mat(1,1)+(*itv).z()*mat(1,2);
double z=(*itv).x()*mat(2,0)+(*itv).y()*mat(2,1)+(*itv).z()*mat(2,2);
(*itv).setX(x);
(*itv).setY(y);
(*itv).setZ(z);
}
}
void Mesh::homotecie(const Vector3D &c, double h)
{
QList<Vector3D>::iterator itv=geom.begin();
for(;itv!=geom.end();++itv){
(*itv)=(((*itv)-c)*h)+c;
}
}
void Mesh::merge(const Mesh &mesh)
{
QList<int> posv;
QList<int> posn;
for(int i=0;i<mesh.geom.size();i++){
int n=containsGeom(mesh.geom[i]);
if(n==-1){
n=geom.size();
geom.append(mesh.geom[i]);
}
posv.append(n);
}
for(int i=0;i<mesh.norm.size();i++){
int n=containsNorm(mesh.norm[i]);
if(n==-1){
n=norm.size();
norm.append(mesh.norm[i]);
}
posn.append(n);
}
for(int i=0;i<mesh.topo.size();i+=3){
topo.append(posv[mesh.topo[i]]);
topo.append(0);
topo.append(posn[mesh.topo[i+2]]);
}
}
int Mesh::containsGeom(const Vector3D &g)
{
return geom.indexOf(g);
}
int Mesh::containsNorm(const Vector3D &n)
{
return norm.indexOf(n);
}
const QList<Vector3D> &Mesh::getGeom() const{
return geom;
}
const QList<Vector3D> &Mesh::getNorm() const{
return norm;
}
const QList<int> &Mesh::getTopo() const{
return topo;
}
const QString &Mesh::getNom() const
{
return nom;
}
Mesh::~Mesh()
{
}