-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuadMesh.cpp
203 lines (176 loc) · 6.24 KB
/
QuadMesh.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
#include "QuadMesh.h"
#include "UtilityFunctions.h"
/**
* Reza Adhitya Saputra
* radhitya@uwaterloo.ca
*/
QuadMesh::QuadMesh()
{
}
QuadMesh::QuadMesh(AVector leftStartPt,
AVector leftEndPt,
AVector rightStartPt,
AVector rightEndPt,
AVector sharpPt,
bool isRightKite,
QuadMeshType quadMeshType)
{
this->_leftStartPt = leftStartPt;
this->_leftEndPt = leftEndPt;
this->_rightStartPt = rightStartPt;
this->_rightEndPt = rightEndPt;
this->_innerConcavePt = sharpPt;
this->_isRightKite = isRightKite;
this->_quadMeshType = quadMeshType;
//this->_isBoundaryRibConstrained = false;
}
QuadMesh::QuadMesh(AVector leftStartPt,
AVector leftEndPt,
AVector rightStartPt,
AVector rightEndPt,
QuadMeshType quadMeshType)
{
this->_leftStartPt = leftStartPt;
this->_leftEndPt = leftEndPt;
this->_rightStartPt = rightStartPt;
this->_rightEndPt = rightEndPt;
this->_quadMeshType = quadMeshType;
//this->_isBoundaryRibConstrained = false;
}
QuadMesh::~QuadMesh()
{
}
int QuadMesh::GetWidth() { return this->_psVertices.size(); }
int QuadMesh::GetHeight() { return this->_psVertices[0].size(); }
std::vector<AVector> QuadMesh::GetABoundary(int index, bool isXUnchanged, bool isOri)
{
// is this correct ?
std::vector<std::vector<PlusSignVertex>> psVertices = (isOri) ? _opsVertices : _psVertices;
std::vector<AVector> vertices;
if(isXUnchanged) // column
{
int meshHeight = GetHeight();
for(int yIter = 0; yIter < meshHeight; yIter++)
{ vertices.push_back(psVertices[index][yIter].position); }
}
else // row
{
int meshWidth = GetWidth();
for(int xIter = 0; xIter < meshWidth; xIter++)
{ vertices.push_back(psVertices[xIter][index].position); }
}
return vertices;
}
void QuadMesh::SetSlidingConstraintFlag(int index, bool boolValue, std::vector<AVector> &debugPoints)
{
int w = this->GetWidth();
int h = this->GetHeight();
if(this->_quadMeshType == QuadMeshType::MESH_KITE && this->_isRightKite)
{
for(int xIter = 0; xIter < w - index; xIter++)
{
_psVertices[xIter][index]._isSlideConstrained = boolValue;
if((xIter + index) == h - 1)
{
if(boolValue) debugPoints.push_back(_psVertices[xIter][index].position);
_psVertices[xIter][index].shouldMove = !boolValue;
}
}
for(int yIter = (index + 1); yIter < h; yIter++)
{
int xIndex = w - (index + 1);
_psVertices[xIndex][yIter]._isSlideConstrained = boolValue;
}
}
else if(this->_quadMeshType == QuadMeshType::MESH_KITE && !this->_isRightKite)
{
// invert
index = h - (index + 1);
for(int yIter = 0; yIter < h - index; yIter++)
{
_psVertices[index][yIter]._isSlideConstrained = boolValue;
if((index + yIter) == h - 1)
{
if(boolValue) debugPoints.push_back(_psVertices[index][yIter].position);
_psVertices[index][yIter].shouldMove = !boolValue;
}
}
for(int xIter = (index + 1); xIter < w; xIter++)
{
int yIndex = h - (index + 1);
_psVertices[xIter][yIndex]._isSlideConstrained = boolValue;
}
}
// edited
else if(this->_quadMeshType == QuadMeshType::MESH_LEFT_LEG || this->_quadMeshType == QuadMeshType::MESH_RIGHT_LEG)
{
for(int xIter = 0; xIter < w; xIter++)
{ _psVertices[xIter][index]._isSlideConstrained = boolValue; }
}
else if(this->_quadMeshType == QuadMeshType::MESH_RECTILINEAR)
{
for(int xIter = 0; xIter < w; xIter++)
{ _psVertices[xIter][index]._isSlideConstrained = boolValue; }
}
}
std::vector<AVector> QuadMesh::GetSideBoundary(int index)
{
std::vector<AVector> vertices;
int w = this->GetWidth();
int h = this->GetHeight();
if(this->_quadMeshType == QuadMeshType::MESH_KITE && this->_isRightKite)
{
for(int xIter = 0; xIter < w - index; xIter++)
{ vertices.push_back(_psVertices[xIter][index].position); }
for(int yIter = (index + 1); yIter < h; yIter++)
{
int xIndex = w - (index + 1);
vertices.push_back(_psVertices[xIndex][yIter].position);
}
}
else if(this->_quadMeshType == QuadMeshType::MESH_KITE && !this->_isRightKite)
{
// invert
index = h - (index + 1);
for(int yIter = 0; yIter < h - index; yIter++)
{ vertices.push_back(_psVertices[index][yIter].position); }
for(int xIter = (index + 1); xIter < w; xIter++)
{
int yIndex = h - (index + 1);
vertices.push_back(_psVertices[xIter][yIndex].position);
}
}
// edited
else if(this->_quadMeshType == QuadMeshType::MESH_LEFT_LEG || this->_quadMeshType == QuadMeshType::MESH_RIGHT_LEG)
{
for(int xIter = 0; xIter < w; xIter++)
{ vertices.push_back(_psVertices[xIter][index].position); }
}
else if(this->_quadMeshType == QuadMeshType::MESH_RECTILINEAR)
{
for(int xIter = 0; xIter < w; xIter++)
{ vertices.push_back(_psVertices[xIter][index].position); }
}
return vertices;
}
// not compatible with dirichlet boundary condition
AVector QuadMesh::GetClosestPointFromBorders(AVector pt)
{
AVector closestPt = pt;
float dist = std::numeric_limits<float>::max();
std::vector<ALine> borderLines;
borderLines.push_back(ALine(_leftStartPt, _rightStartPt));
borderLines.push_back(ALine(_leftEndPt, _rightEndPt));
borderLines.push_back(ALine(_leftStartPt, _leftEndPt));
borderLines.push_back(ALine(_rightStartPt, _rightEndPt));
for(uint a = 0; a < borderLines.size(); a++)
{
AVector cPt = UtilityFunctions::GetClosestPoint(borderLines[a].GetPointA(), borderLines[a].GetPointB(), pt);
if(pt.Distance(cPt) < dist)
{
dist = pt.Distance(cPt);
closestPt = cPt;
}
}
return closestPt;
}