-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoRespacing.py
More file actions
762 lines (615 loc) · 28.7 KB
/
Copy pathautoRespacing.py
File metadata and controls
762 lines (615 loc) · 28.7 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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
from adjacentGenerator import set_streamline_id
from correspondingMethod import *
import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
import random
from main import *
SHAPE_FRAME = 10 # How many frame of streamline shape to interpolating
SHAPE_FACTOR = 0 # 0~1 -Shape Influence Factor When Repositioning Streamline
SLOPE_ANGLE_RANGE = 45 # Determine Streamline Slope Horizontal or Vertical
def slope(x1, y1, x2, y2):
if (x2 - x1) == 0:
return 90
else:
return (y2 - y1) / (x2 - x1)
def streamline_gradient(streamline):
center_point = int(len(streamline.streamPoint) / 2)
print("Length of streamline.streamPoint:", len(streamline.streamPoint))
print("Value of center_point:", center_point)
x1 = streamline.streamPoint[center_point - 1].x
x2 = streamline.streamPoint[center_point + 1].x
y1 = streamline.streamPoint[center_point - 1].y
y2 = streamline.streamPoint[center_point + 1].y
slopeA = slope(x1, y1, x2, y2)
angle_in_radians = math.atan(slopeA)
angle_in_degrees = math.degrees(angle_in_radians)
if -SLOPE_ANGLE_RANGE <= angle_in_degrees <= SLOPE_ANGLE_RANGE:
return 'horizontal', angle_in_degrees
else:
return 'vertical', angle_in_degrees
def resample(x, sampling_number, kind='linear'):
x = np.array(x)
f = interpolate.interp1d(np.linspace(0, 1, x.size), x, kind)
return f(np.linspace(0, 1, sampling_number)).tolist()
# Normalize Vector to -1~1
def normalize_vector(vector_x, vector_y):
if vector_x < 0:
normalize_x = -1
elif vector_x > 0:
normalize_x = 1
else:
normalize_x = 0
if vector_y < 0:
normalize_y = -1
elif vector_y > 0:
normalize_y = 1
else:
normalize_y = 0
return normalize_x, normalize_y
def interpolate_streamline(arrayA, arrayB, frame_number, kind='linear'):
if frame_number < 1:
print("Interpolate Number cannot less than 1")
return -1
pointsA = np.array(arrayA)
pointsB = np.array(arrayB)
line_interpolate = interpolate.interp1d([0, frame_number + 1], np.vstack([pointsA, pointsB]), axis=0, kind=kind)
line_list = []
i = 0
while i < frame_number:
line_list.append(line_interpolate(i + 1).tolist())
i += 1
return line_list # Return Interpolated Streamline_List[]
def generate_interpolate_line(streamlineA, streamlineB, generated_num):
streamline1_x = []
streamline1_y = []
streamline2_x = []
streamline2_y = []
temp_list_x = []
temp_list_y = []
# 1 Pre-load Streamline Information
if len(streamlineA.streamPoint) >= len(streamlineB.streamPoint):
max_point_number = len(streamlineA.streamPoint)
for p in range(len(streamlineB.streamPoint)):
temp_list_x.append(streamlineB.streamPoint[p].x)
temp_list_y.append(streamlineB.streamPoint[p].y)
for p in range(len(streamlineA.streamPoint)):
streamline2_x.append(streamlineA.streamPoint[p].x)
streamline2_y.append(streamlineA.streamPoint[p].y)
else:
max_point_number = len(streamlineB.streamPoint)
for p in range(len(streamlineA.streamPoint)):
temp_list_x.append(streamlineA.streamPoint[p].x)
temp_list_y.append(streamlineA.streamPoint[p].y)
for p in range(len(streamlineB.streamPoint)):
streamline2_x.append(streamlineB.streamPoint[p].x)
streamline2_y.append(streamlineB.streamPoint[p].y)
# 2 Resampling Not Enough Streamline Point
streamline1_x = resample(temp_list_x, sampling_number=max_point_number, kind='linear')
streamline1_y = resample(temp_list_y, sampling_number=max_point_number, kind='linear')
# 3 Generate In-between Streamline Number
interpolated_streamlines_x = interpolate_streamline(streamline1_x, streamline2_x, generated_num)
interpolated_streamlines_y = interpolate_streamline(streamline1_y, streamline2_y, generated_num)
# 4 Convert Points To Streamline Class
streamline_list = []
streamline_list.clear()
for i in range(len(interpolated_streamlines_x)):
points_list = []
points_list.clear()
for j in range(len(interpolated_streamlines_x[i])):
points = StreamPoint(interpolated_streamlines_x[i][j], interpolated_streamlines_y[i][j])
points_list.append(points)
temp_streamlines = Streamline(len(points_list), points_list)
streamline_list.append(temp_streamlines)
return streamline_list
def streamline_translate(streamline, translation_x, translation_y):
for i in range(len(streamline.streamPoint)):
streamline.streamPoint[i].x += translation_x
streamline.streamPoint[i].y += translation_y
return streamline
# Note: This Will Directly Change The Target Streamline Position (Not Shape), return Shape Curve Streamline
def auto_reposition_streamline(target_stl, adjacent_stl1, adjacent_stl2, shape_factor=SHAPE_FACTOR,
interpolate_frame=SHAPE_FRAME):
# 0 Pre-Generated Adjacent Interpolated Streamline
streamline_lists = generate_interpolate_line(adjacent_stl1, adjacent_stl2, 1)
interpolated_stl = streamline_lists[0]
# 1 Translating Position of Target Streamline
common_pointA, common_pointB, common_distance = minimum_point_distance(target_stl, interpolated_stl)
translation_x = interpolated_stl.streamPoint[common_pointB].x - target_stl.streamPoint[common_pointA].x
translation_y = interpolated_stl.streamPoint[common_pointB].y - target_stl.streamPoint[common_pointA].y
translated_stl = streamline_translate(target_stl, translation_x, translation_y)
# 2 Shape Factor Interpolation
if shape_factor == 0:
return translated_stl
elif shape_factor == 1:
return interpolated_stl
else:
factor = int((interpolate_frame - 1) * shape_factor)
streamline_lists = generate_interpolate_line(translated_stl, interpolated_stl, interpolate_frame)
return streamline_lists[factor]
def respacing_iteration(streamFrame, critical_id, shape_factor=SHAPE_FACTOR, shape_frame=SHAPE_FRAME):
# Right Streamline Reposition
current_stl = streamFrame.streamline[critical_id].right_id
current_left_stl = streamFrame.streamline[current_stl].left_id
current_right_stl = streamFrame.streamline[current_stl].right_id
new_stl = auto_reposition_streamline(streamFrame.streamline[current_stl],
streamFrame.streamline[current_left_stl],
streamFrame.streamline[current_right_stl], shape_factor, shape_frame)
new_stl.left_id = current_left_stl
new_stl.right_id = current_right_stl
streamFrame.streamline.pop(current_stl)
streamFrame.streamline.insert(current_stl, new_stl)
# Update Critical Streamline Position
current_stl = critical_id
current_left_stl = streamFrame.streamline[current_stl].left_id
current_right_stl = streamFrame.streamline[current_stl].right_id
new_stl = auto_reposition_streamline(streamFrame.streamline[current_stl],
streamFrame.streamline[current_left_stl],
streamFrame.streamline[current_right_stl], shape_factor, shape_frame)
new_stl.left_id = current_left_stl
new_stl.right_id = current_right_stl
streamFrame.streamline.pop(current_stl)
streamFrame.streamline.insert(current_stl, new_stl)
# Left Streamline Reposition
current_stl = streamFrame.streamline[critical_id].left_id
current_left_stl = streamFrame.streamline[current_stl].left_id
current_right_stl = streamFrame.streamline[current_stl].right_id
new_stl = auto_reposition_streamline(streamFrame.streamline[current_stl],
streamFrame.streamline[current_left_stl],
streamFrame.streamline[current_right_stl], shape_factor, shape_frame)
new_stl.left_id = current_left_stl
new_stl.right_id = current_right_stl
streamFrame.streamline.pop(current_stl)
streamFrame.streamline.insert(current_stl, new_stl)
# Update Critical Streamline Position
current_stl = critical_id
current_left_stl = streamFrame.streamline[current_stl].left_id
current_right_stl = streamFrame.streamline[current_stl].right_id
new_stl = auto_reposition_streamline(streamFrame.streamline[current_stl],
streamFrame.streamline[current_left_stl],
streamFrame.streamline[current_right_stl], shape_factor, shape_frame)
new_stl.left_id = current_left_stl
new_stl.right_id = current_right_stl
streamFrame.streamline.pop(current_stl)
streamFrame.streamline.insert(current_stl, new_stl)
def local_respacing(streamFrame, critical_id, adjacent_list, iteration=1, shape_factor=SHAPE_FACTOR,
shape_frame=SHAPE_FRAME):
i = 0
for a in range(len(adjacent_list)):
if critical_id == adjacent_list[a]:
left_point_id = a
right_point_id = a
while i < iteration:
while adjacent_list[right_point_id] != critical_id:
if right_point_id >= len(adjacent_list):
break
respacing_iteration(streamFrame, adjacent_list[right_point_id], shape_factor, shape_frame)
right_point_id -= 1
# Self Re-spacing
respacing_iteration(streamFrame, critical_id, shape_factor, shape_frame)
while adjacent_list[left_point_id] != critical_id:
if left_point_id < 0:
break
respacing_iteration(streamFrame, adjacent_list[left_point_id], shape_factor, shape_frame)
left_point_id += 1
# Self Re-spacing
respacing_iteration(streamFrame, critical_id, shape_factor, shape_frame)
i += 1
left_point_id -= i
right_point_id += i
# ! Warning ! Unbound Catcher
if right_point_id >= len(adjacent_list):
right_point_id = len(adjacent_list) - 1
if left_point_id < 0:
left_point_id = 0
def critical_local_respacing(streamFrame, critical_list, adjacent_listA, iteration=1, shape_factor=SHAPE_FACTOR,
shape_frame=SHAPE_FRAME):
for i in range(len(critical_list)):
critical_id = get_streamline_index(streamFrame, critical_list[i])
local_respacing(streamFrame, critical_id=critical_id, adjacent_list=adjacent_listA, iteration=iteration,
shape_factor=shape_factor, shape_frame=shape_frame)
# Random Seed Value Re-spacing (Doesn't Loop Every Streamline)
def random_global_respacing(streamFrame, adjacent_list, seed_num=5, iteration=1, shape_factor=SHAPE_FACTOR,
shape_frame=SHAPE_FRAME):
for i in range(seed_num):
rand_id = random.randint(0, len(adjacent_list) - 1)
critical_id = adjacent_list[rand_id]
local_respacing(streamFrame, critical_id=critical_id, adjacent_list=adjacent_list, iteration=iteration,
shape_factor=shape_factor, shape_frame=shape_frame)
# Loop All Adjacent Streamline Re-Spacing
# Need To Detect If Cycle Adjacent List
def global_respacing(streamFrame, adjacent_list, shuffle='false', iteration=1, shape_factor=SHAPE_FACTOR,
shape_frame=SHAPE_FRAME):
shuffle_list = adjacent_list[:]
if shuffle == 'true':
random.shuffle(shuffle_list)
for i in range(len(adjacent_list) - 1):
local_respacing(streamFrame, critical_id=shuffle_list[i], adjacent_list=adjacent_list, iteration=iteration,
shape_factor=shape_factor, shape_frame=shape_frame)
def get_adjacent_list(streamFrame):
# Loop For Right ID
loop_list = []
right_id_list = []
right_id = 0
while right_id != -1:
right_id_list.append(right_id)
right_id = streamFrame.streamline[right_id].right_id
loop = adjacent_match_error_detection(loop_list, right_id, "GetList Right ")
# print("right_id:"+str(right_id))
# Infinite Loop Detect
if loop == -1:
print("right")
print(loop_list)
print(right_id)
return -1
# Cycle Loop Detect
if right_id == right_id_list[0]:
break
# Loop For Left ID
loop_list = []
left_id_list = []
left_id = streamFrame.streamline[0].left_id
while left_id != -1:
left_id_list.append(left_id)
left_id = streamFrame.streamline[left_id].left_id
loop = adjacent_match_error_detection(loop_list, left_id, "GetList Left ")
# print("right_id:"+str(left_id))
# Infinite Loop Detect
if loop == -1:
print("left")
print(loop_list)
print(right_id)
return -1
# Cycle Loop Detect
if left_id == left_id_list[0]:
break
if len(left_id_list) == 0:
return right_id_list[:]
if len(right_id_list) == 0:
return left_id_list[:]
# Concat Left and Right List
left_id_list.reverse()
if left_id_list[0] == right_id_list[0]:
# Cycle Loop Adjacent
adjacent_list = right_id_list[:]
# Todo: Handle Cycle Loop Adjacent List
else:
# Not Loop Adjacent
adjacent_list = left_id_list[:] + right_id_list[:]
return adjacent_list
def find_adjacent_id(streamFrame):
for i in range(len(streamFrame.streamline)):
streamlineA = streamFrame.streamline[i]
min_dis = 999999
adjacent_id = -1
new_adjacent_id = -1
if len(streamlineA.streamPoint) == 1:
continue
# Find Streamline A Slope Value
streamlineA_type, slopeA = streamline_gradient(streamlineA)
# print(streamlineA_type)
# 1 Find Minimum Adjacent Streamline
for j in range(len(streamFrame.streamline)):
if i == j:
continue
streamlineB = streamFrame.streamline[j]
# ! Loop For More Point [Features]
pointA = int(len(streamlineA.streamPoint) / 2)
common_pointA, common_pointB, common_distance = streamline_point_distance(streamlineA, streamlineB, pointA)
if common_distance < min_dis:
min_dis = common_distance
vector_x = streamlineB.streamPoint[common_pointB].x - streamlineA.streamPoint[common_pointA].x
vector_y = streamlineB.streamPoint[common_pointB].y - streamlineA.streamPoint[common_pointA].y
adjacent_id = j
# 2 Normalize Adjacent Streamline Vector
normalize_vector_x, normalize_vector_y = normalize_vector(vector_x, vector_y)
# 3 Find Minimum Adjacent Streamline
min_dis = 999999
for j in range(len(streamFrame.streamline)):
if i == j or j == adjacent_id:
continue
streamlineB = streamFrame.streamline[j]
# ! Loop For More Point [Features]
pointA = int(len(streamlineA.streamPoint) / 2)
common_pointA, common_pointB, common_distance = streamline_point_distance(streamlineA, streamlineB, pointA)
if common_distance < min_dis:
vector_x = streamlineB.streamPoint[common_pointB].x - streamlineA.streamPoint[common_pointA].x
vector_y = streamlineB.streamPoint[common_pointB].y - streamlineA.streamPoint[common_pointA].y
new_normalize_vector_x, new_normalize_vector_y = normalize_vector(vector_x, vector_y)
# print((new_normalize_vector_x, new_normalize_vector_y))
if streamlineA_type == 'vertical':
if new_normalize_vector_x != normalize_vector_x:
min_dis = common_distance
new_adjacent_id = j
else:
if new_normalize_vector_y != normalize_vector_y:
min_dis = common_distance
new_adjacent_id = j
left_id = -1
right_id = -1
if streamlineA_type == 'vertical':
if normalize_vector_x < 0:
left_id = adjacent_id
right_id = new_adjacent_id
else:
left_id = new_adjacent_id
right_id = adjacent_id
else:
if normalize_vector_y < 0:
left_id = adjacent_id
right_id = new_adjacent_id
else:
left_id = new_adjacent_id
right_id = adjacent_id
streamlineA.left_id = left_id
streamlineA.right_id = right_id
print("----------")
print("Streamline:" + str(i))
print("Type:" + str(streamlineA_type) + " " + str(slopeA))
print("Normalize Vector:" + str(normalize_vector_x) + " " + str(normalize_vector_y))
print("Left ID:" + str(streamlineA.left_id))
# print("Index Left ID:" + str(get_streamline_index(streamFrame, streamlineA.left_id)))
print("Right ID:" + str(streamlineA.right_id))
# print("Index Right ID:" + str(get_streamline_index(streamFrame, streamlineA.right_id)))
def adjacent_match_error_detection(loop_id, current_id, text_display=""):
loop_insert = 0
for i in range(len(loop_id)):
if current_id == loop_id[i]:
loop_insert = 1
if loop_insert == 0:
loop_id.append(current_id)
return 1
else:
print("\033[31m---" + text_display + "Adjacent Loop Error Occurs---\x1b[0m")
print("These Streamline Adjacent May Match Wrong:")
print("1." + str(loop_id[-1]))
print("2." + str(current_id))
print("\033[31m---Adjacent Loop Error End---\x1b[0m")
return -1
def reverse_wrong_adjacent(streamFrame):
# Wrong Adjacent Pool Variable
loop_id = []
loop_id.clear()
# Loop For Right ID
right_id = 0
while right_id != -1:
current_right_id = streamFrame.streamline[right_id].right_id
next_right_id = streamFrame.streamline[current_right_id].right_id
next_next_right_id = streamFrame.streamline[next_right_id].right_id
error_occurs = adjacent_match_error_detection(loop_id, right_id, "Reverse Wrong Right")
if error_occurs == -1:
break
if current_right_id == next_next_right_id:
temp_id = streamFrame.streamline[next_right_id].left_id
streamFrame.streamline[next_right_id].left_id = next_next_right_id
streamFrame.streamline[next_right_id].right_id = temp_id
right_id = current_right_id
if right_id == 0:
break
# Loop For Left ID
loop_id.clear()
left_id = 0
while left_id != -1:
current_left_id = streamFrame.streamline[left_id].left_id
next_left_id = streamFrame.streamline[current_left_id].left_id
next_next_left_id = streamFrame.streamline[next_left_id].left_id
error_occurs = adjacent_match_error_detection(loop_id, left_id, "Reverse Wrong Left")
if error_occurs == -1:
break
if current_left_id == next_next_left_id:
temp_id = streamFrame.streamline[next_left_id].right_id
streamFrame.streamline[next_left_id].right_id = next_next_left_id
streamFrame.streamline[next_left_id].left_id = temp_id
left_id = current_left_id
if left_id == 0:
break
def get_corresponding_pointID(corresponding_list, indexA='none', indexB='none'):
if indexA != 'none':
for i in range(len(corresponding_list)):
if indexA == corresponding_list[i].indexA:
return corresponding_list[i].indexB
return -1
if indexB != 'none':
for i in range(len(corresponding_list)):
if indexB == corresponding_list[i].indexB:
return corresponding_list[i].indexA
return -1
def rematch_corresponding_list(corresponding_list, original_id, new_id, rematch_index='indexA'):
for i in range(len(corresponding_list)):
for j in range(len(original_id)):
if rematch_index == 'indexA':
if corresponding_list[i].indexA == original_id[j]:
corresponding_list[i].indexA = new_id[j]
elif rematch_index == 'indexB':
if corresponding_list[i].indexB == original_id[j]:
corresponding_list[i].indexB = new_id[j]
return corresponding_list
# Remove And Insert Unmatched Streamline
def reprocess_frameA_streamline(frameA, frameB, corresponding_list, reverse=-1):
# Remove Unmatched FrameA Streamline
left_unmatch_list.sort()
for i in range(len(left_unmatch_list)):
remove_index = get_streamline_index(frameA, left_unmatch_list[i])
frameA.streamline.pop(remove_index)
frameA.streamline_size -= 1
# Reset New Streamline ID and Rematched Corresponding List Pair ID
new_id = []
origin_id = []
for j in range(len(frameA.streamline)):
new_id.append(j)
origin_id.append(frameA.streamline[j].id)
corresponding_list = rematch_corresponding_list(corresponding_list, origin_id, new_id, 'indexA')
set_streamline_id(frameA)
# Insert Unmatched FrameB Streamline into FrameA
right_unmatch_list.sort()
unmatched_list = right_unmatch_list[:]
generated_list = []
pair_list = []
for i in range(len(unmatched_list)):
print(i)
if unmatched_list[i] in generated_list:
continue
critical_left_id = frameB.streamline[unmatched_list[i]].left_id
critical_right_id = frameB.streamline[unmatched_list[i]].right_id
frameA_left_id = get_corresponding_pointID(corresponding_list, indexB=critical_left_id)
frameA_right_id = get_corresponding_pointID(corresponding_list, indexB=critical_right_id)
# print(str(right_unmatch_list[i])+"->"+str(critical_left_id))
frameA_left_id = get_streamline_index(frameA, frameA_left_id)
frameA_right_id = get_streamline_index(frameA, frameA_right_id)
print(str(frameA_left_id) + "--" + str(frameA_right_id))
generation_num = 1
pair_list.clear()
pair_list.append(unmatched_list[i])
# Detect When Right Streamline Is Un-corresponding
while frameA_right_id == -1:
if reverse == 1:
pair_list.insert(0, critical_right_id)
else:
pair_list.append(critical_right_id)
critical_right_id = frameB.streamline[critical_right_id].right_id
if critical_right_id == -1:
print("Error: Reach The Right Streamline Boundary")
return -1
else:
frameA_right_id = get_corresponding_pointID(corresponding_list, indexB=critical_right_id)
generation_num += 1
# Detect When Left Streamline Is Un-corresponding
while frameA_left_id == -1:
if reverse == 1:
pair_list.append(critical_left_id)
else:
pair_list.insert(0, critical_left_id)
critical_left_id = frameB.streamline[critical_left_id].left_id
if critical_left_id == -1:
print("Error: Reach The Left Streamline Boundary")
return -1
else:
frameA_left_id = get_corresponding_pointID(corresponding_list, indexB=critical_left_id)
generation_num += 1
# Updated ID Index
frameA_left_id = get_streamline_index(frameA, frameA_left_id)
frameA_right_id = get_streamline_index(frameA, frameA_right_id)
streamlineA = frameA.streamline[frameA_left_id]
streamlineB = frameA.streamline[frameA_right_id]
new_stl = generate_interpolate_line(streamlineA, streamlineB, generated_num=generation_num)
# Debug
print("---Insertion Streamline---")
print("Generation Num:" + str(generation_num))
print("Pair List:")
print(pair_list)
print("Generate List:")
print(generated_list)
print("Unmatched List")
print(unmatched_list)
for j in range(len(pair_list)):
new_stl[j].id = len(frameA.streamline)
frameA.streamline.append(new_stl[j])
frameA.streamline_size += 1
new_correspondence = CorrespondingLine(new_stl[j].id, pair_list[j], distances=0)
corresponding_list.append(new_correspondence)
generated_list += pair_list[:]
return corresponding_list
# Remove And Duplicate Unmatched Streamline
import correspondingMethod
def duplicate_unmatched_streamline(frameA, corresponding_list, frame_num):
print("Entering")
# Remove Unmatched FrameA Streamline
print(left_unmatch_list)
left_unmatch_list.sort()
for i in range(len(left_unmatch_list)):
remove_index = get_streamline_index(frameA, left_unmatch_list[i])
frameA.streamline.pop(remove_index)
frameA.streamline_size -= 1
print("Remove")
# Reset New Streamline ID and Rematched Corresponding List Pair ID
new_id = []
origin_id = []
for j in range(len(frameA.streamline)):
new_id.append(j)
origin_id.append(frameA.streamline[j].id)
corresponding_list = rematch_corresponding_list(corresponding_list, origin_id, new_id, 'indexA')
set_streamline_id(frameA)
print("PauseLine")
# Insert Unmatched FrameB Streamline into FrameA
right_unmatch_list.sort()
unmatched_list = right_unmatch_list[:]
# Todo Work
#left_unmatch_list.clean()
#correspondingMethod.unmatched_trigger = 1
#correspondingMethod.fading_speed = frame_num
print("Return")
return corresponding_list
def autoRespacing_function():
# 1.Read Streamline KeyFrame
frameA = readStreamline("bird_stl_data/body/bird_0000_clip_2" + ".stl")
frameB = readStreamline("bird_stl_data/body/bird_0000_clip_2" + ".stl")
config_File = "bird_stl_data/wing1/Bird3032.config"
# 2.Set Streamline Initial ID
set_streamline_id(frameA)
set_streamline_id(frameB)
# 2.5 Moving Streamline Position
# m = Motion(50,100)
# streamline_motion_translation(frameA, m)
# showStreamline(frameA)
# 3.Find Corresponding Set , Refine Wrong Matching
corresponding_list = find_corresponding_set(frameA, frameB)
read_config(config_File, "corresponding1", corresponding_list=corresponding_list)
# m = Motion(0, -50)
# streamline_motion_translation(frameA, m)
# -- Stop Visualization 1
writeStreamline_svg("FrameTest.vec", corresponding_list, frameA, frameB, 32)
print(left_unmatch_list)
print(right_unmatch_list)
return
# 4.Find Adjacent FrameB
find_adjacent_id(frameB)
reverse_wrong_adjacent(frameB)
read_config(config_File, "adjacentB", streamFrame=frameB)
print(frameB.streamline[12].left_id)
print(frameB.streamline[13].left_id)
adjacent_listB = get_adjacent_list(frameB)
# Debug -- Fine Until Here
print(adjacent_listB)
return
# 6.Delete And Insert Unmatched Streamline | Bug: Sometime it will matched to -1 when adjacent is not in pair |
corresponding_list = reprocess_frameA_streamline(frameA, frameB, corresponding_list)
# writeStreamline_svg("FrameTest.vec", corresponding_list, frameA, frameB, 17)
print_corresponding_set(corresponding_list)
# 7.Updated Corresponding List Index
# corresponding_list = get_corresponding_list_index(corresponding_list, frameA, frameB)
# 8.Refine Corresponding List Streamline
# read_config(config_File, "corresponding2", corresponding_list=corresponding_list)
# Stop Visualization 2
# print(right_unmatch_list)
# writeStreamline_svg("FrameTest.vec", corresponding_list, frameA, frameB, 10)
# Read in Modified FrameA
frameA = readStreamline("torus_keyframe_stl/corresponding2/torus_0003_clip_1" + ".stl")
# read_config(config_File, "corresponding2", corresponding_list=corresponding_list)
# writeStreamline_svg("FrameTest.vec", corresponding_list, frameA, frameB, 10)
# 9.Find Adjacent FrameA
find_adjacent_id(frameA)
# 9.1 Refine Wrong Adjacent Streamline
read_config(config_File, "adjacentA", streamFrame=frameA)
reverse_wrong_adjacent(frameA)
print(left_unmatch_list)
print(right_unmatch_list)
adjacent_listA = get_adjacent_list(frameA)
print(adjacent_listA)
# return
# 10. Critical Streamline Local Re-spacing
critical_id_list = []
critical_num = len(frameA.streamline) - len(right_unmatch_list) - 1
for i in range(len(right_unmatch_list)):
critical_id_list.append(critical_num + i)
print(critical_id_list)
# critical_local_respacing(frameA, critical_id_list, adjacent_listA, iteration=2)
# 11.Global Re-spacing
global_respacing(frameA, adjacent_listA, shuffle='true', iteration=2)
# global_respacing(frameB, adjacent_listB, shuffle='true', iteration=2)
# 12. Write Out SVG FILE
writeStreamline_svg("FrameTest.vec", corresponding_list, frameA, frameB, 10)
return
print("Length of streamline.streamPoint:", len(streamline.streamPoint))
print("Value of center_point:", center_point)
if __name__ == '__main__':
autoRespacing_function()