-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHalfEdgeDSRendering.cpp
126 lines (99 loc) · 3.45 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
#define RADPERDEG 0.0174533
#include "HalfEdgeDSRendering.h"
#include <GL/glut.h>
const float VDIAM = 0.10f;
const float EDIAM = 0.04f;
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 renderE(const Edge* e, const Vec3f& color)
{
glColor3f(color.x, color.y, color.z);
Vec3f p1 = e->he1->startV->coordinates;
Vec3f p2 = e->he2->startV->coordinates;
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(dir.x*dir.x + dir.y*dir.y), dir.z) / RADPERDEG, 0., 1., 0.);
}
else if (dir.z < 0) {
glRotated(180, 1., 0., 0.);
}
quadObj = gluNewQuadric();
gluQuadricDrawStyle(quadObj, GLU_FILL);
gluQuadricNormals(quadObj, GLU_SMOOTH);
gluCylinder(quadObj, EDIAM*0.5f, EDIAM*0.5f, length, 16, 1);
gluDeleteQuadric(quadObj);
glPopMatrix();
}
void renderHE(const HalfEdge* he, const Vec3f& color, const float dim)
{
Vec3f start = he->startV->coordinates;
Vec3f end = he->getEdgeSibling()->startV->coordinates;
glColor3f(color.x, color.y, color.z);
renderArrow(start, end, dim);
}
void renderV(const Vertex* v, const Vec3f& color)
{
glColor3f(color.x, color.y, color.z);
Vec3f p = v->coordinates;
GLUquadricObj *quadObj;
glPushMatrix();
glTranslated(p.x, p.y, p.z);
quadObj = gluNewQuadric();
gluQuadricDrawStyle(quadObj, GLU_FILL);
gluQuadricNormals(quadObj, GLU_SMOOTH);
gluSphere(quadObj, VDIAM * 0.5f, 16, 16);
gluDeleteQuadric(quadObj);
glPopMatrix();
}
void renderHEActive(const HalfEdge* he)
{
if(he)
renderHE(he, Vec3f(0.004f, 0.388f, 0.941f));
}
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(dir.x*dir.x+dir.y*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*diameter, 0.0, 4*diameter, 32, 1);
gluDeleteQuadric(quadObj);
quadObj = gluNewQuadric ();
gluQuadricDrawStyle (quadObj, GLU_FILL);
gluQuadricNormals (quadObj, GLU_SMOOTH);
gluDisk(quadObj, 0.0, 2*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*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 ();
}