-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHalfEdgeDSRendering.cpp
229 lines (193 loc) · 5.9 KB
/
HalfEdgeDSRendering.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#define RADPERDEG 0.0174533
#include "HalfEdgeDSRendering.h"
#include <GL/glut.h>
/**
* Render whole datastructure through Vertices and Edges
*/
void renderDS(const HalfEdgeDS& heDS)
{
for (auto const *v : heDS.getVertices()) renderV(v); // render all vertices as points
for (auto const *e : heDS.getEdges()) renderE(e); // render all edges as lines
}
void renderDS(const HalfEdgeDS& heDS, const HalfEdge* activeHE, const Loop* activeLoop, const Face* activeFace)
{
// render all vertices as points
for (const Vertex* v : heDS.getVertices()) renderV(v);
// render all unselected edges as normal lines lines
for (const Edge* e : heDS.getEdges()) {
//filter activeHE Edges
if (activeHE != nullptr && (e->he1 == activeHE || e->he2 == activeHE)) goto skip;
//filter activeLoop Edges
if (activeLoop != nullptr){
HalfEdge* he = activeLoop->toHE;
do {
if (e->he1 == he || e->he2 == he) goto skip;
he = he->nextHE;
} while (he != activeLoop->toHE);
}
//filter activeFace Edges
if (activeFace != nullptr) {
for (Loop* innerL : activeFace->innerLoops) {
HalfEdge* he = innerL->toHE;
do {
if (e->he1 == he || e->he2 == he) goto skip;
he = he->nextHE;
} while (he != innerL->toHE);
}
HalfEdge* he = activeFace->outerLoop->toHE;
do {
if (e->he1 == he || e->he2 == he) goto skip;
he = he->nextHE;
} while (he != activeFace->outerLoop->toHE);
}
renderE(e);
skip:;
}
// draw the selected stuff
if (activeLoop != nullptr) {
HalfEdge* he = activeLoop->toHE;
do {
renderE(he->toEdge, Vec3f(1, 1, 1));
he = he->nextHE;
} while (he != activeLoop->toHE);
}
if (activeFace != nullptr) {
if (activeFace->outerLoop != activeLoop)
{
HalfEdge* he = activeFace->outerLoop->toHE;
do {
renderE(he->toEdge, Vec3f(1, 1, 0));
he = he->nextHE;
} while (he != activeFace->outerLoop->toHE);
}
else
for (Loop* l : activeFace->innerLoops)
{
if (l == activeLoop) continue;
HalfEdge* he = l->toHE;
do {
renderE(he->toEdge, Vec3f(1, 1, 0));
he = he->nextHE;
} while (he != l->toHE);
}
}
if (activeHE != nullptr) renderHEActive(activeHE);
}
/**
* Render the Edge with given color-Vector
*
* @param e Edge passed to GL
* @param color to draw Edge in
*/
void renderE(const Edge* e, const Vec3f& color /*= Vec3f(0.0f, 1.0f, 0.0f)*/)
{
// TODO: render the edge with the given color
/// delimits a definition of a Line primitive
glBegin(GL_LINES);
// set the begin of the components for the Color
glColor3fv(&color.x);
/// define two vertices by their coordinates
// glVertex3f(e->he1->startV->coordinates.x, e->he1->startV->coordinates.y, e->he1->startV->coordinates.z);
glVertex3fv(&e->he1->startV->coordinates.x);
glVertex3fv(&e->he2->startV->coordinates.x);
/// first two Vertices will be grouped into a line
/// end of line definition
glEnd();
}
/**
* Render the HalfEdge with given Color Vector
*
* @param he HalfEdge passed to GL
* @param color to draw HalfEdge in
*/
void renderHE(const HalfEdge* he, const Vec3f& color /*= Vec3f(0.0f, 1.0f, 0.0f)*/)
{
// TODO: render the half-edge with the given color
/// delimits a definition of a Line primitive
glBegin(GL_LINES);
// set the begin of the components for the Color
glColor3fv(&color.x);
glVertex3fv(&he->startV->coordinates.x);
/// find start / end Vertex
Edge* e = he->toEdge;
if (e->he1->startV == he->startV)
glVertex3fv(&e->he2->startV->coordinates.x);
else
glVertex3fv(&e->he1->startV->coordinates.x);
/// first two Vertices will be grouped into a line
/// end of line definition
glEnd();
}
/**
* Render the Vertex with given Color Vector
*
* @param v Vertex passed to GL
* @param color to draw Vertex in
*/
void renderV(const Vertex* v, const Vec3f& color /*= Vec3f(1.0f, 0.0f, 1.0f)*/)
{
// TODO: render the vertex with the given color
/// delimits a definition of a Point primitive
glBegin(GL_POINTS);
// set the begin of the components for the Color
glColor3fv(&color.x);
// set the begin of the components for the Coordinates
glVertex3fv(&v->coordinates.x);
glEnd();
/// end of point definition
}
/**
* Render the active HalfEdge as a arrow
*
* @param he HalfEdge to be highlighted
*/
void renderHEActive(const HalfEdge* he)
{
// TODO: render the currently selected half-edge.
if (he == nullptr) return;
// use renderArrow method to visualize the direction of the half-edge
renderArrow(he->startV->coordinates, he->nextHE->startV->coordinates, 0.05f);
HalfEdge* heptr = he->nextHE;
while (heptr != he) {
renderHE(heptr, Vec3f(0.4f, 0.0f, 1.0f));
heptr = heptr->nextHE;
}
}
void renderArrow(const Vec3f& p1, const Vec3f& p2, float diameter)
{
Vec3f dir = p2 - p1;
float length = dir.length();
if (length < 0.00001f) return;
GLUquadricObj *quadObj;
glPushMatrix ();
glTranslated(p1.x, p1.y, p1.z);
if((dir.x!=0.)||(dir.y!=0.)) {
glRotated(atan2(dir.y,dir.x)/RADPERDEG,0.,0.,1.);
glRotated(atan2(sqrt(double (dir.x) * double(dir.x)+ double(dir.y) * double(dir.y)),dir.z)/RADPERDEG,0.,1.,0.);
} else if (dir.z<0){
glRotated(180,1.,0.,0.);
}
glTranslatef(0,0,length-4*diameter);
quadObj = gluNewQuadric ();
gluQuadricDrawStyle (quadObj, GLU_FILL);
gluQuadricNormals (quadObj, GLU_SMOOTH);
gluCylinder(quadObj, 2.0*diameter, 0.0, 4.0*diameter, 32, 1);
gluDeleteQuadric(quadObj);
quadObj = gluNewQuadric ();
gluQuadricDrawStyle (quadObj, GLU_FILL);
gluQuadricNormals (quadObj, GLU_SMOOTH);
gluDisk(quadObj, 0.0, 2.0*diameter, 32, 1);
gluDeleteQuadric(quadObj);
glTranslatef(0,0,-length+4*diameter);
quadObj = gluNewQuadric ();
gluQuadricDrawStyle (quadObj, GLU_FILL);
gluQuadricNormals (quadObj, GLU_SMOOTH);
gluCylinder(quadObj, diameter, diameter, length-4.0*diameter, 32, 1);
gluDeleteQuadric(quadObj);
quadObj = gluNewQuadric ();
gluQuadricDrawStyle (quadObj, GLU_FILL);
gluQuadricNormals (quadObj, GLU_SMOOTH);
gluDisk(quadObj, 0.0, diameter, 32, 1);
gluDeleteQuadric(quadObj);
glPopMatrix ();
}