-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfolding_helper.cpp
More file actions
209 lines (188 loc) · 6.3 KB
/
Copy pathfolding_helper.cpp
File metadata and controls
209 lines (188 loc) · 6.3 KB
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
#include <FronTier.h>
#include "spring_solver.h"
#include <unordered_map>
#include "../iFluid/ifluid_state.h"
#include "folding.h"
//helper functions to convert FronTier data structures
//to spring mesh
static void unsortIntfc(INTERFACE*);
static void unsortSurface(SURFACE*);
static void unsortCurve(CURVE*);
static void assemblePointsFromSurf(SURFACE*, std::vector<SpringVertex*>&,
std::unordered_map<POINT*, size_t>&);
static void assemblePointsFromCurve(CURVE*, std::vector<SpringVertex*>& pts,
std::unordered_map<POINT*, size_t>&);
static void assemblePointsFromNode(NODE*, std::vector<SpringVertex*>& pts,
std::unordered_map<POINT*, size_t>&);
static void setConnection(POINT* p1, POINT* p2, double length0, std::vector<SpringVertex*>& pts, std::unordered_map<POINT*, size_t>&);
static SpringVertex* FT_Point2SpringVertex(POINT*);
static bool isElasticCurve(CURVE* c) {
return (hsbdry_type(c) == STRING_HSBDRY ||
hsbdry_type(c) == MONO_COMP_HSBDRY ||
hsbdry_type(c) == GORE_HSBDRY);
}
static SpringVertex* FT_Point2SpringVertex(POINT* p) {
SpringVertex* spv = new SpringVertex();
STATE* state = (STATE*)left_state(p);
for (int i = 0; i < 3; ++i)
spv->ext_accel[i] = state->fluid_accel[i] +
state->other_accel[i];
spv->x = Coords(p);
spv->v = state->vel;
spv->org_vtx = (void*)p;
return spv;
}
extern void FT_Intfc2SpringMesh(INTERFACE* intfc, std::vector<SpringVertex*>&pts) {
//assemble tris list from input intfc
//this function should be called before
//spring interior dynamics computed
std::unordered_map<POINT*, size_t> ht;
//clear hash table and point list
ht.clear();
pts.clear();
unsortIntfc(intfc);
//clone points from surface
SURFACE** s;
intfc_surface_loop(intfc,s) {
if (wave_type(*s) == ELASTIC_BOUNDARY)
assemblePointsFromSurf(*s, pts, ht);
}
printf("#%lu num of points in surf\n",pts.size());
//clone points from curve
CURVE** c;
intfc_curve_loop(intfc,c) {
//do not assemble strings
if (hsbdry_type(*c) == STRING_HSBDRY) continue;
if (isElasticCurve(*c))
assemblePointsFromCurve(*c, pts, ht);
}
printf("#%lu num of points in curve\n",pts.size());
//clone points from node
NODE** n;
intfc_node_loop(intfc,n) {
assemblePointsFromNode(*n, pts, ht);
}
printf("#%lu num of points in nodes\n",pts.size());
}
static void assemblePointsFromSurf(SURFACE* s,
std::vector<SpringVertex*>& pts,
std::unordered_map<POINT*, size_t>& ht) {
TRI* tris[20];
TRI* tri;
surf_tri_loop(s,tri)
for (int i = 0; i < 3; ++i)
{
POINT* p = Point_of_tri(tri)[i];
if(Boundary_point(p) || sorted(p)) continue;
sorted(p) = YES;
int nt = 0;
PointAndFirstRingTris(p,Hyper_surf_element(tri),
Hyper_surf(s),&nt,tris);
for (int j = 0; j < nt; ++j)
for (int l = 0; l < 3; ++l)
if (Point_of_tri(tris[j])[l] == p)
{
POINT* p_nb = Point_of_tri(tris[j])[(l+1)%3];
setConnection(p,p_nb,tris[j]->side_length0[l], pts, ht);
}
}
}
static void assemblePointsFromCurve(CURVE *curve,
std::vector<SpringVertex*>& pts,
std::unordered_map<POINT*, size_t>& ht) {
//assemble from curve
for (BOND* b = curve->first; b != curve->last; b = b->next)
for (int i = 0; i < 2; ++i)
{
POINT* p = b->end;
POINT* p_nb = (i == 0) ? b->start : b->next->end;
double dist = (i == 0) ? b->length0 : b->next->length0;
setConnection(p,p_nb,dist, pts, ht);
}
//connect with btris
TRI** tris;
for (BOND* b = curve->first; b != curve->last; b = b->next)
{
POINT* p = b->end;
for (BOND_TRI** btris = Btris(b); btris && *btris; ++btris)
{
int nt = I_FirstRingTrisAroundPoint(p,(*btris)->tri,&tris);
for (int j = 0; j < nt; ++j)
{
for (int side = 0; side < 3; ++side)
{
if (p == Point_of_tri(tris[j])[side])
{
if (is_side_bdry(tris[j],side))
continue;
POINT* p_nb = Point_of_tri(tris[j])[(side+1)%3];
setConnection(p,p_nb,tris[j]->side_length0[side], pts, ht);
}
}
}
}
}
}
static void assemblePointsFromNode(NODE* n,
std::vector<SpringVertex*>& pts,
std::unordered_map<POINT*, size_t>& ht) {
for (CURVE** c = n->in_curves; c && *c; ++c)
{
if (!isElasticCurve(*c)) continue;
//do not fold strings
if (hsbdry_type(*c) == STRING_HSBDRY) continue;
BOND* b = (*c)->last;
POINT* p_nb = b->start;
setConnection(n->posn,p_nb,b->length0, pts, ht);
}
for (CURVE** c = n->out_curves; c && *c; ++c)
{
if (!isElasticCurve(*c)) continue;
//do not fold strings
if (hsbdry_type(*c) == STRING_HSBDRY) continue;
BOND* b = (*c)->first;
POINT* p_nb = b->end;
setConnection(n->posn,p_nb,b->length0, pts, ht);
}
}
static void setConnection(POINT* p1, POINT* p2, double length0,
std::vector<SpringVertex*>& pts,
std::unordered_map<POINT*, size_t>& ht) {
POINT* points[2] = {p1,p2};
for (int i = 0; i < 2; ++i) {
if (ht.find(points[i]) == ht.end()) {
//not inserted yet
ht[points[i]] = pts.size();
pts.push_back(FT_Point2SpringVertex(points[i]));
}
}
if (length0 < 0)
length0 = separation(p1,p2,3);
size_t ind = ht[p1];
size_t ind_nb = ht[p2];
pts[ind]->addNeighbor(ind_nb,length0);
}
static void unsortIntfc(INTERFACE* intfc) {
SURFACE** s;
intfc_surface_loop(intfc,s)
unsortSurface(*s);
CURVE** c;
intfc_curve_loop(intfc,c)
unsortCurve(*c);
}
static void unsortSurface(SURFACE* s) {
TRI* t;
surf_tri_loop(s,t) {
for (int i = 0; i < 3; ++i) {
POINT* p = Point_of_tri(t)[i];
sorted(p) = NO;
}
}
}
static void unsortCurve(CURVE* c) {
BOND* b;
curve_bond_loop(c,b) {
sorted(b->start) = NO;
sorted(b->end) = NO;
}
}