-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathedge.cpp
254 lines (206 loc) · 4.37 KB
/
edge.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*!
* @file edge.cpp
* @brief Functions and implementations for edge class
*/
#include <iostream>
#include <cmath>
#include "edge.h"
namespace psalm
{
/*!
* Default constructor that creates and invalid edge.
*/
edge::edge()
{
set(NULL, NULL);
}
/*!
* Constructor that creates a new edge (u,v).
*
* @param u Pointer to start vertex
* @param v Pointer to end vertex
*/
edge::edge(vertex* u, vertex* v)
{
set(u,v);
}
/*!
* Sets start and end vertex of the edge.
*
* @param u Pointer to start vertex
* @param v Pointer to end vertex
*/
void edge::set(vertex* u, vertex* v)
{
this->u = u;
this->v = v;
if(u == v)
this->u = this->v = NULL;
f = g = NULL;
edge_point = NULL;
boundary = boost::logic::indeterminate;
}
/*!
* @return Pointer to start vertex
*/
vertex* edge::get_u()
{
return(const_cast<vertex*>(static_cast<const edge*>(this)->get_u()));
}
/*!
* @return Const pointer to start vertex
*/
const vertex* edge::get_u() const
{
return(u);
}
/*!
* Sets new start vertex. Does not alter remaining attributes.
*
* @param Pointer to new start vertex
*/
void edge::set_u(vertex* u)
{
this->u = u;
}
/*!
* @return Pointer to end vertex
*/
vertex* edge::get_v()
{
return(const_cast<vertex*>(static_cast<const edge*>(this)->get_v()));
}
/*!
* @return Const pointer to end vertex
*/
const vertex* edge::get_v() const
{
return(v);
}
/*!
* Sets new end vertex. Does not alter remaining attributes.
*
* @param Pointer to new end vertex
*/
void edge::set_v(vertex* v)
{
this->v = v;
}
/*!
* Sets pointer to first adjacent face.
*
* @param f Pointer to face
*
* @warning The function does not check if the current edge is really a
* part of the face.
*/
void edge::set_f(face* f)
{
this->f = f;
}
/*!
* Sets pointer to second adjacent face.
*
* @param g Pointer to face
*
* @warning The function does not check if the current edge is really a
* part of the face.
*/
void edge::set_g(face* g)
{
static bool warning_shown = false;
if( f != NULL && this->g != NULL &&
g != NULL) // warning is not shown if the second face is _reset_
{
if(!warning_shown)
{
std::cerr << "psalm: Warning: Mesh might be non-manifold.\n";
warning_shown = true;
}
return;
}
this->g = g;
}
/*!
* @return Pointer to first adjacent face.
*/
face* edge::get_f()
{
return(const_cast<face*>(static_cast<const edge*>(this)->get_f()));
}
/*!
* @return Constant pointer to first adjacent face
*/
const face* edge::get_f() const
{
return(f);
}
/*!
* @return Pointer to second adjacent face
*/
face* edge::get_g()
{
return(const_cast<face*>(static_cast<const edge*>(this)->get_g()));
}
/*!
* @return Constant pointer to second adjacent face
*/
const face* edge::get_g() const
{
return(g);
}
/*!
* Returns value of flag signalling whether the edge is a boundary edge.
* This flag may be set by the user, but the edge is also able to
* determine wether it is a boundary edge by taking a look at adjacent
* faces.
*
* The value of the flag is calculated if the boundary flag is set to be
* indeterminate.
*
* @return true if the edge is a boundary edge, else false
*/
bool edge::is_on_boundary()
{
if(boost::logic::indeterminate(boundary))
boundary = (f == NULL) || (g == NULL);
return(bool(boundary) == true);
}
/*!
* Sets value of flag signalling boundary edges. By default, the value of
* the flag is indeterminate.
*
* @param boundary Current value for boundary parameter (true by default)
*/
void edge::set_on_boundary(bool boundary)
{
this->boundary = boundary;
}
/*!
* Given another edge that is assumed to share one vertex with the current
* edge, calculate the interior angle between these two edges.
*
* @warning The result is undefined if both edges do _not_ share a common
* vertex.
*
* @return Interior angle between edge e and current edge
*/
double edge::calc_angle(const edge* e) const
{
// Check that both edges point into the _same_ direction -- otherwise
// the wrong angle would be calculated.
if( this->get_u() == e->get_u() ||
this->get_v() == e->get_v())
{
v3ctor a = this->get_u()->get_position() - this->get_v()->get_position();
v3ctor b = e->get_u()->get_position() - e->get_v()->get_position();
return(acos(a.normalize()*b.normalize()));
}
else
{
v3ctor a = this->get_u()->get_position() - this->get_v()->get_position();
v3ctor b = e->get_v()->get_position() - e->get_u()->get_position(); // swap second edge
return(acos(a.normalize()*b.normalize()));
}
}
} // end of namespace "psalm"