-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.h
127 lines (95 loc) · 2.44 KB
/
model.h
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
116
117
118
119
120
121
122
123
124
125
126
127
//------------------------------------------------------------------------------
// Copyright 2007-2009 by Jyh-Ming Lien and George Mason University
// See the file "LICENSE" for more information
//------------------------------------------------------------------------------
#ifndef _BF_MODEL_H_
#define _BF_MODEL_H_
#include <Point.h>
#include <Vector.h>
#include <Matrix.h>
#include <Quaternion.h>
using namespace mathtool;
#include <string>
#include <cassert>
#include <set>
using namespace std;
#include "objReader.h"
//shorten some notations
typedef unsigned int uint;
//a triangle of the model
struct triangle
{
triangle(){facet_id=0;}
uint v[3]; //vertex id
uint e[3]; //edge id
Vector3d n; //normal
uint facet_id; //id of the corresponding facet in kway-union.h
//backups
Vector3d bk_n;
};
//a vertex of the model
struct vertex
{
vertex(){ concave=false; }
Point3d p; //position
list<uint> m_f;
list<uint> m_e; //a list of edges
//backups
Point3d bk_p;
//if concave, set to true
bool concave;
};
//an edge of the model
struct edge
{
edge(){ type='x'; vid[0]=vid[1]=UINT_MAX; }
uint vid[2];
vector<uint> fid;
Vector3d v; //parallel vector
Vector3d in_n[2]; //inface normals
//backups
Vector3d bk_v; //parallel vector
Vector3d bk_in_n[2]; //inface normals
//type, c-convex, r-reflex, p-plane, b-border
char type;
};
struct model
{
//initialization
model()
{
v_size=e_size=t_size=0;
vertices=NULL;
edges=NULL;
tris=NULL;
for(int i=0;i<3;i++) for(int j=0;j<3;j++) current_rot[i][j]=0;
current_rot[0][0]=current_rot[1][1]=current_rot[2][2]=1;
}
~model(){}
void destroy()
{
delete [] tris; tris=NULL;
delete [] edges; edges=NULL;
delete [] vertices; vertices=NULL;
v_size=e_size=t_size=0;
}
//build this model
bool build(const string & name);
//rotate points
void rotate(const Matrix2x2& m);
void rotate(const Matrix3x3& M);
//scale the model
void scale(double s);
//negate point/facets ...
void negate();
//reverse facets ...
void reverse();
//data
vertex * vertices; //vertices
triangle * tris; //triangles
edge * edges; //edges
uint v_size, e_size, t_size;
//current orientation
double current_rot[3][3];
};
#endif //_BF_MODEL_H_