-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph.hpp
208 lines (208 loc) · 5.61 KB
/
graph.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <iostream>
using namespace std;
int vertex_id_count = 0;//顶点编号
int face_id_count = 0;//面编号
class face;
class vertex
{
public:
int direct;//顶点的定向数
int id;//顶点的编号
vertex()
{
direct = 0;
id = vertex_id_count;
vertex_id_count ++;
}
vertex* from_vertex[3];//向前顶点
vertex* to_vertex[3];//向后顶点
face* adjacent_face[3];//定向所在的面
~vertex()
{
for(int ii = 0; ii < 3; ii++)
{
from_vertex[ii] = NULL;
to_vertex[ii] = NULL;
adjacent_face[ii] = NULL;
}
delete from_vertex;
delete to_vertex;
delete adjacent_face;
}
};
class face
{
public:
int vertex_number;//面的顶点数
int id;//面的编号
int adjface_number;//构建平面图时,已经有的邻接面个数
int ccount;//解螺旋时,已经被选取的邻接面数
int counted;//解螺旋时,该面是否已被选取
int length;//构建平面图时,已经有的顶点数
face()
{
adjface_number = 0;
length = 0;
id = face_id_count;
face_id_count ++;
}
bool face_append(face* aa);//将面aa加入邻接面数组
bool vertex_push(vertex* aa);//将点aa加入顶点数组的最前方
bool vertex_append(vertex* aa);//将点aa加入顶点数组的最后方
bool array_create();//给顶点数组和邻接面数组分配空间
vertex* vertex_dop();//获取最后方的顶点
vertex* vertex_top();//获取最前方的顶点
vertex** vertices;//顶点数组
face** adj_face;//邻接面数组
~face()
{
for(int ii = 0; ii < vertex_number; ii++)
{
adj_face[ii] = NULL;
vertices[ii] = NULL;
}
delete adj_face;
delete vertices;
}
};
bool face :: array_create()
{
adj_face = new face*[vertex_number];
vertices = new vertex*[vertex_number];
for(int ii = 0;ii < vertex_number; ii++)
{
adj_face[ii] = NULL;
vertices[ii] = NULL;
}
}
bool face :: face_append(face* aa)
{
for(int ii = 0; ii < vertex_number; ii++)
{
if(adj_face[ii] == NULL)
{
adj_face[ii] = aa;
return 1;
}
}
}
bool face :: vertex_push(vertex* aa)
{
for(int ii = 0; ii < vertex_number; ii++)
{
if(vertices[ii] == NULL)
{
int jj;
for(jj = ii+1; jj < vertex_number; jj++)
{
if(vertices[jj] != NULL)
{
vertices[jj-1] = aa;
length ++;
return 1;
}
}
vertices[vertex_number-1] = aa;
length ++;
return 1;
}
}
}
bool face :: vertex_append(vertex* aa)
{
for(int ii = 0; ii < vertex_number; ii++)
{
if(vertices[ii] == NULL)
{
vertices[ii] = aa;
length ++;
break;
}
}
}
vertex* face :: vertex_top()
{
for(int ii = 0; ii < vertex_number; ii++)
{
if(vertices[ii] == NULL)
{
int jj;
for(jj = ii+1; jj < vertex_number; jj++)
{
if(vertices[jj] != NULL)
{
return vertices[jj];
}
}
return vertices[0];
}
}
return vertices[0];
}
vertex* face :: vertex_dop()
{
for(int ii = 1; ii < vertex_number; ii++)
{
if(vertices[ii] == NULL)
{
return vertices[ii-1];
}
}
return vertices[0];
}
vertex* begin_vertex(int mode,face* aa,face* bb)//寻找初始面aa和最后一个面bb的最后一个公共顶点,mode=1时正向,其他为反向
{
for(int ii = 0; ii < aa->vertex_number; ii++)
{
for(int jj = 0; jj < bb->vertex_number; jj++)
{
if(aa->vertices[ii] == bb->vertices[jj])
{
if(mode == 1)//正向
{
int cc = ii+1;
int dd = jj-1;
if(cc >= aa->vertex_number)
cc -= aa->vertex_number;
if(dd < 0)
dd += bb->vertex_number;
if(aa->vertices[cc] == bb->vertices[dd])
return aa->vertices[cc];
else
return aa->vertices[ii];
}
else//反向
{
int cc = ii-1;
int dd = jj+1;
if(dd >= bb->vertex_number)
dd -= bb->vertex_number;
if(cc < 0)
cc += aa->vertex_number;
if(aa->vertices[cc] == bb->vertices[dd])
return aa->vertices[cc];
else
return aa->vertices[ii];
}
}
}
}
return NULL;
}
bool connect(face* aa)//给面的顶点增加定向
{
int ii;
for(ii = 0; ii < aa->vertex_number-1; ii++)
{
aa->vertices[ii]->to_vertex[aa->vertices[ii]->direct] = aa->vertices[ii+1];
aa->vertices[ii+1]->from_vertex[aa->vertices[ii+1]->direct] = aa->vertices[ii];
aa->vertices[ii]->adjacent_face[aa->vertices[ii]->direct] = aa;
}
aa->vertices[ii]->to_vertex[aa->vertices[ii]->direct] = aa->vertices[0];
aa->vertices[0]->from_vertex[aa->vertices[0]->direct] = aa->vertices[ii];
aa->vertices[ii]->adjacent_face[aa->vertices[ii]->direct] = aa;
for(ii = 0; ii < aa->vertex_number; ii++)
{
aa->vertices[ii]->direct ++;
}
}