-
Notifications
You must be signed in to change notification settings - Fork 1
/
HalfEdgeDSElements.cpp
122 lines (97 loc) · 2.14 KB
/
HalfEdgeDSElements.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
#include "HalfEdgeDSElements.h"
#include <iostream>
#include <iomanip>
Solid::Solid()
: toFace(nullptr)
{
}
// TODO: create methods for creating and traversing its elements
Face::Face()
: toSolid(nullptr)
, outerLoop(nullptr)
, innerLoop(nullptr)
{
}
int Face::countInnerLoops() const
{
int count = 0;
if (innerLoop) {
auto iter = innerLoop;
do {
++count;
iter = iter->nextLoop;
} while (iter != innerLoop);
}
return count;
}
Loop::Loop()
: toFace(nullptr)
, nextLoop(this)
, prevLoop(this)
, toHE(nullptr)
{
}
HalfEdge * Loop::findHalfedgeStartingAt(Vertex * v)
{
HalfEdge* currentHE = this->toHE;
if (currentHE->startV == v)
return currentHE;
do {
currentHE = currentHE->nextHE;
} while (currentHE->startV != v && currentHE != this->toHE);
return currentHE->startV == v ? currentHE : nullptr;
}
void Loop::fixHEReferences()
{
HalfEdge* iter = toHE;
do {
iter->toLoop = this;
iter = iter->nextHE;
} while (iter != toHE);
}
void Loop::setNextLoop(Loop * next)
{
this->nextLoop = next;
next->prevLoop = this;
}
Edge::Edge()
: he1(nullptr)
, he2(nullptr)
{
}
Edge* Edge::CreateEdge(HalfEdge ** he1, HalfEdge ** he2)
{
Edge* e = new Edge();
e->he1 = new HalfEdge();
e->he2 = new HalfEdge();
if (he1) *he1 = e->he1;
if (he2) *he2 = e->he2;
e->he1->toEdge = e;
e->he2->toEdge = e;
return e;
}
// TODO: create methods for creating and traversing its elements
HalfEdge::HalfEdge()
: toLoop(nullptr)
, toEdge(nullptr)
, nextHE(nullptr)
, prevHE(nullptr)
, startV(nullptr)
{
}
void HalfEdge::setNextHE(HalfEdge * next)
{
this->nextHE = next;
next->prevHE = this;
}
HalfEdge * HalfEdge::getEdgeSibling() const
{
return (toEdge->he1 == this) ? toEdge->he2 : toEdge->he1;
}
// TODO: create methods for creating and traversing its elements
Vertex::Vertex()
: outgoingHE(nullptr)
, coordinates(Vec3f())
{
}
// TODO: create methods for creating and traversing its elements