-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edge.cpp
287 lines (255 loc) · 7.16 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/**
* @file Edge.cpp
* @author Dan R. Lipsa
*
* Implementation of the Edge class
*/
#include "Attribute.h"
#include "AttributeCreator.h"
#include "AttributeInfo.h"
#include "Body.h"
#include "Debug.h"
#include "Edge.h"
#include "EvolverData_yacc.h"
#include "Foam.h"
#include "DataProperties.h"
#include "OrientedFace.h"
#include "OrientedEdge.h"
#include "ParsingDriver.h"
#include "Utils.h"
#include "Vertex.h"
// Methods
// ======================================================================
Edge::Edge (const boost::shared_ptr<Vertex>& begin,
const boost::shared_ptr<Vertex>& end,
const G3D::Vector3int16& endTranslation,
size_t id, Type type, ElementStatus::Enum duplicateStatus):
Element(id, duplicateStatus),
m_begin (begin), m_end (end),
m_endTranslation (endTranslation),
m_type (type)
{
}
Edge::Edge (const boost::shared_ptr<Vertex>& begin, size_t id, Type type) :
Element (id, ElementStatus::ORIGINAL),
m_begin (begin),
m_type (type)
{
}
Edge::Edge (const Edge& o) :
Element (o),
m_begin (o.GetBeginPtr ()), m_end (o.GetEndPtr ()),
m_endTranslation (o.GetEndTranslation ()),
m_adjacentOrientedFaces (o.m_adjacentOrientedFaces),
m_type (o.GetType ())
{
}
boost::shared_ptr<Edge> Edge::Clone () const
{
return boost::shared_ptr<Edge> (new Edge(*this));
}
G3D::Vector3 Edge::GetTranslatedBegin (const G3D::Vector3& newEnd) const
{
return newEnd + (GetBeginVector () - GetEndVector ());
}
void Edge::UpdateAdjacentEdge (const boost::shared_ptr<Edge>& edge)
{
GetBeginPtr ()->AddAdjacentEdge (edge);
GetEndPtr ()->AddAdjacentEdge (edge);
}
bool Edge::operator< (const Edge& other) const
{
return
GetId () < other.GetId () ||
(GetId () == other.GetId () && GetBegin () < other.GetBegin ());
}
bool Edge::operator== (const Edge& other) const
{
return GetId () == other.GetId () && GetBegin () == other.GetBegin ();
}
bool Edge::fuzzyEq (const Edge& other) const
{
return GetId () == other.GetId () &&
IsFuzzyZero (GetBeginVector () - other.GetBeginVector ());
}
void Edge::AddAdjacentOrientedFace (
boost::shared_ptr<OrientedFace> orientedFace, size_t edgeIndex)
{
m_adjacentOrientedFaces.insert (
AdjacentOrientedFace (orientedFace, edgeIndex));
}
string Edge::AdjacentFacesToString () const
{
ostringstream ostr;
const AdjacentOrientedFaces& aofs = GetAdjacentOrientedFaces ();
size_t facePartOfSize = aofs.size ();
ostr << "Edge " << GetStringId () << " is part of "
<< facePartOfSize << " faces: ";
ostream_iterator<AdjacentOrientedFace> output (ostr, " ");
copy (aofs.begin (), aofs.end (), output);
return ostr.str ();
}
bool Edge::IsPhysical (bool is2D) const
{
if (IsStandalone ())
return true;
else
{
boost::shared_ptr<OrientedFace> of =
GetAdjacentOrientedFaces ().begin ()->GetOrientedFace ();
if (of->IsStandalone ())
return true;
else
{
if (is2D)
return true;
else
{
if (m_adjacentOrientedFaces.size () < 4)
return false;
AdjacentOrientedFaces::const_iterator end =
m_adjacentOrientedFaces.end ();
AdjacentOrientedFaces::const_iterator begin;
AdjacentOrientedFaces::const_iterator next =
m_adjacentOrientedFaces.begin ();
size_t facesPartOfSize = 0;
do
{
begin = next;
next = m_adjacentOrientedFaces.equal_range (*begin).second;
++facesPartOfSize;
} while (next != end);
return facesPartOfSize == 3;
}
}
}
}
string Edge::ToString (const AttributesInfo* ai) const
{
ostringstream ostr;
ostr << "Edge " << GetStringId () << " "
<< GetDuplicateStatus () << " "
<< *m_begin << ", "
<< *m_end << " "
<< " Adjacent faces(" << m_adjacentOrientedFaces.size () << ")";
if (HasAttributes ())
{
ostr << " Edge attributes: ";
PrintAttributes (ostr, ai);
}
return ostr.str ();
}
boost::shared_ptr<Edge> Edge::GetDuplicate (
const OOBox& periods,
const G3D::Vector3& newBegin,
VertexSet* vertexSet, EdgeSet* edgeSet) const
{
boost::shared_ptr<Edge> searchDummy =
boost::make_shared<Edge>(
boost::make_shared<Vertex> (
newBegin, GetBegin ().GetId ()), GetId ());
EdgeSet::iterator it = edgeSet->find (searchDummy);
if (it != edgeSet->end ())
return *it;
boost::shared_ptr<Edge> duplicate = createDuplicate (
periods, newBegin, vertexSet);
edgeSet->insert (duplicate);
return duplicate;
}
boost::shared_ptr<Edge> Edge::createDuplicate (
const OOBox& periods,
const G3D::Vector3& newBegin, VertexSet* vertexSet) const
{
G3D::Vector3int16 translation = periods.GetTranslation (
GetBeginVector (), newBegin);
boost::shared_ptr<Vertex> beginDuplicate = GetBegin ().GetDuplicate (
periods, translation, vertexSet);
boost::shared_ptr<Vertex> endDuplicate = GetEnd ().GetDuplicate (
periods, translation, vertexSet);
boost::shared_ptr<Edge> duplicate = Clone ();
duplicate->setBegin (beginDuplicate);
duplicate->SetEnd (endDuplicate);
duplicate->SetDuplicateStatus (ElementStatus::DUPLICATE);
return duplicate;
}
void Edge::GetVertexSet (VertexSet* vertexSet) const
{
vertexSet->insert (GetBeginPtr ());
vertexSet->insert (GetEndPtr ());
}
float Edge::GetLength () const
{
size_t pointCount = GetPointCount ();
float length = 0;
G3D::Vector3 prev = GetPoint (0);
for (size_t i = 1; i < pointCount; ++i)
{
G3D::Vector3 p = GetPoint (i);
length += (p - prev).length ();
prev = p;
}
return length;
}
G3D::Vector3 Edge::GetPoint (size_t i) const
{
if (i == 0)
return GetBeginVector ();
else
return GetEndVector ();
}
size_t Edge::GetConstraintIndex (size_t i) const
{
return GetAttribute<IntegerArrayAttribute,
IntegerArrayAttribute::value_type> (
EdgeAttributeIndex::CONSTRAINTS)[i] - 1;
}
bool Edge::HasConstraints () const
{
return HasAttribute (EdgeAttributeIndex::CONSTRAINTS);
}
QColor Edge::GetColor (const QColor& defaultColor) const
{
if (HasAttribute (EdgeAttributeIndex::COLOR))
return Color::GetValue (
GetAttribute<ColorAttribute, ColorAttribute::value_type> (
EdgeAttributeIndex::COLOR));
else
return defaultColor;
}
G3D::Vector3 Edge::GetBeginVector () const
{
return GetBegin ().GetVector ();
}
G3D::Vector3 Edge::GetEndVector () const
{
return GetEnd ().GetVector ();
}
// Static and Friends Methods
// ======================================================================
short Edge::LocationCharToNumber (char sign)
{
switch (sign)
{
case '*':
return 0;
case '+':
return 1;
case '-':
return -1;
default:
RuntimeAssert (false, "Invalid sign: ", sign);
return 0;
}
}
G3D::Vector3int16 Edge::IntToLocation (int value)
{
G3D::Vector3int16 result;
const int DIMENSIONS = 3;
for (int i = 0; i < DIMENSIONS; i++)
{
// we store -1, 0 or 1
result[i] = (value % DOMAIN_INCREMENT_POSSIBILITIES) - 1;
value /= DOMAIN_INCREMENT_POSSIBILITIES;
}
return result;
}