-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenderingCS.cs
1473 lines (1273 loc) · 48.1 KB
/
RenderingCS.cs
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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// #define USE_CUDA
#define USE_HMD
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Drawing;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Valve.VR;
using System.ComponentModel;
public class RenderingCS : MonoBehaviour
{
#if USE_CUDA
private const string NATIVE_LIBRARY_NAME = "cudaTest";
[DllImport(NATIVE_LIBRARY_NAME)]
private static extern int CudaParallelFor(byte[] IMG, byte[] LF, double Alloc_Angle_s, double times, int Y, int POS_Y, int POS_X, int LFUW, int DATAW, int WIDTH, int HEIGHT, int out_w, int dir, int LF_Len);
#endif
public static int WIDTH = 1024;
public static int HEIGHT = 512;
public static int DATAW = 50;
public static int LFUW = 100;
private GameObject LFS = null; // 3D 구의 LF Space
private Texture2D tex;
private static byte[] COL1;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL2;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL3;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL4;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL5;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL6;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL7;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL8;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL9;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL10;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL11;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL12;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL13;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL14;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL15;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL16;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL17;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] COL18;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW1;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW2;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW3;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW4;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW5;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW6;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW7;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW8;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW9;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW10;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW11;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW12;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW13;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static byte[] ROW14;// = new byte[HEIGHT * WIDTH * LFUW * 3];
private static string COL1_FILE = "Assets/Resources/1024x512/COL1.LF";
private static string COL2_FILE = "Assets/Resources/1024x512/COL2.LF";
private static string COL3_FILE = "Assets/Resources/1024x512/COL3.LF";
private static string COL4_FILE = "Assets/Resources/1024x512/COL4.LF";
private static string COL5_FILE = "Assets/Resources/1024x512/COL5.LF";
private static string COL6_FILE = "Assets/Resources/1024x512/COL6.LF";
private static string COL7_FILE = "Assets/Resources/1024x512/COL7.LF";
private static string COL8_FILE = "Assets/Resources/1024x512/COL8.LF";
private static string COL9_FILE = "Assets/Resources/1024x512/COL9.LF";
private static string COL10_FILE = "Assets/Resources/1024x512/COL10.LF";
private static string COL11_FILE = "Assets/Resources/1024x512/COL11.LF";
private static string COL12_FILE = "Assets/Resources/1024x512/COL12.LF";
private static string COL13_FILE = "Assets/Resources/1024x512/COL13.LF";
private static string COL14_FILE = "Assets/Resources/1024x512/COL14.LF";
private static string COL15_FILE = "Assets/Resources/1024x512/COL15.LF";
private static string COL16_FILE = "Assets/Resources/1024x512/COL16.LF";
private static string COL17_FILE = "Assets/Resources/1024x512/COL17.LF";
private static string COL18_FILE = "Assets/Resources/1024x512/COL18.LF";
private static string ROW1_FILE = "Assets/Resources/1024x512/ROW1.LF";
private static string ROW2_FILE = "Assets/Resources/1024x512/ROW2.LF";
private static string ROW3_FILE = "Assets/Resources/1024x512/ROW3.LF";
private static string ROW4_FILE = "Assets/Resources/1024x512/ROW4.LF";
private static string ROW5_FILE = "Assets/Resources/1024x512/ROW5.LF";
private static string ROW6_FILE = "Assets/Resources/1024x512/ROW6.LF";
private static string ROW7_FILE = "Assets/Resources/1024x512/ROW7.LF";
private static string ROW8_FILE = "Assets/Resources/1024x512/ROW8.LF";
private static string ROW9_FILE = "Assets/Resources/1024x512/ROW9.LF";
private static string ROW10_FILE = "Assets/Resources/1024x512/ROW10.LF";
private static string ROW11_FILE = "Assets/Resources/1024x512/ROW11.LF";
private static string ROW12_FILE = "Assets/Resources/1024x512/ROW12.LF";
private static string ROW13_FILE = "Assets/Resources/1024x512/ROW13.LF";
private static string ROW14_FILE = "Assets/Resources/1024x512/ROW14.LF";
private static bool COL1_FLAG = false;
private static bool COL2_FLAG = false;
private static bool COL3_FLAG = false;
private static bool COL4_FLAG = false;
private static bool COL5_FLAG = false;
private static bool COL6_FLAG = false;
private static bool COL7_FLAG = false;
private static bool COL8_FLAG = false;
private static bool COL9_FLAG = false;
private static bool COL10_FLAG = false;
private static bool COL11_FLAG = false;
private static bool COL12_FLAG = false;
private static bool COL13_FLAG = false;
private static bool COL14_FLAG = false;
private static bool COL15_FLAG = false;
private static bool COL16_FLAG = false;
private static bool COL17_FLAG = false;
private static bool COL18_FLAG = false;
private static bool ROW1_FLAG = false;
private static bool ROW2_FLAG = false;
private static bool ROW3_FLAG = false;
private static bool ROW4_FLAG = false;
private static bool ROW5_FLAG = false;
private static bool ROW6_FLAG = false;
private static bool ROW7_FLAG = false;
private static bool ROW8_FLAG = false;
private static bool ROW9_FLAG = false;
private static bool ROW10_FLAG = false;
private static bool ROW11_FLAG = false;
private static bool ROW12_FLAG = false;
private static bool ROW13_FLAG = false;
private static bool ROW14_FLAG = false;
private static byte[] LF_F = null;
private static byte[] LF_R = null;
private static byte[] LF_B = null;
private static byte[] LF_L = null;
private static int f, GLO_X, GLO_Y, POS_X, POS_Y, REGION, Loop, InKey, PREV_REGION, ROR;
private static double times, k;
private static int upperLimit_gloX = 200;
private static int lowerLimit_gloX = 0;
private static int upperLimit_gloY = 600;
private static int lowerLimit_gloY = 0;
private static int i = 0;
private static System.Diagnostics.Stopwatch sw_LoadLF = new System.Diagnostics.Stopwatch();
private static System.Diagnostics.Stopwatch sw_LFUpdate = new System.Diagnostics.Stopwatch();
private static System.Diagnostics.Stopwatch sw_Rendering = new System.Diagnostics.Stopwatch();
private static System.Diagnostics.Stopwatch sw_MainFunc = new System.Diagnostics.Stopwatch();
private static System.Diagnostics.Stopwatch sw_ParallelFor = new System.Diagnostics.Stopwatch();
private static Stopwatch sw_GC = new Stopwatch();
private static long ParallelFor_us = 0;
int w, d, s;
public static int REGION_G;
private static int rotationY;
private static int componentY, componentX;
private static int stride = 2;
private static Vector3 hmdPosition;
private static GameObject hmd;
private static HmdQuad_t rect;
private static float prevHmdPosX, prevHmdPosY;
private static float diffHmdPosX, diffHmdPosY;
// Start is called before the first frame update
void Start()
{
#if USE_HMD
hmd = GameObject.FindWithTag("sydHMD");
// SteamVR_PlayArea.GetBounds(Valve.VR.SteamVR_PlayArea.Size._300x225, ref rect);
prevHmdPosX = hmd.transform.position.z;
prevHmdPosY = hmd.transform.position.x;
#endif
LFS = GameObject.Find("LFSpace"); // LF
LFS.GetComponent<Renderer>().enabled = true;
LFS.GetComponent<Renderer>().material.shader = Shader.Find("Unlit/Pano360Shader");
// LFS.GetComponent<Renderer>().material.mainTexture = tex;
f = WIDTH / 8;
GLO_X = 50;
GLO_Y = 50;
POS_X = 0;
POS_Y = 0;
REGION = 0;
times = 270.0;
k = 0.30;
REGION = 0;
POS_X = GLO_X - 50;
POS_Y = GLO_Y - 50;
LFUpdate(REGION);
Loop = 1;
InKey = 0;
PREV_REGION = REGION;
ROR = 0;
w = d = s = 0;
sw_LoadLF.Reset();
sw_LFUpdate.Reset();
sw_Rendering.Reset();
sw_MainFunc.Reset();
sw_ParallelFor.Reset();
sw_GC.Reset();
}
// Update is called once per frame
void Update()
{
#if USE_HMD
transform.position = hmd.transform.position;
diffHmdPosX = (hmd.transform.position.z - prevHmdPosX) * 200;
diffHmdPosY = (hmd.transform.position.x - prevHmdPosY) * 200;
UnityEngine.Debug.Log("Component : (" + diffHmdPosX + ", " + diffHmdPosY + ")");
GLO_X += Mathf.RoundToInt(diffHmdPosX);
GLO_Y -= Mathf.RoundToInt(diffHmdPosY);
GLO_X = Mathf.Clamp(GLO_X, lowerLimit_gloX, upperLimit_gloX);
GLO_Y = Mathf.Clamp(GLO_Y, lowerLimit_gloY, upperLimit_gloY);
UnityEngine.Debug.Log("(" + GLO_X.ToString() + ", " + GLO_Y.ToString() + ") - REGION " + REGION);
SetRegion();
MainFunc(ref tex, ref LFS);
prevHmdPosX = hmd.transform.position.z;
prevHmdPosY = hmd.transform.position.x;
#else
rotationY = (int)Mathf.Round(CameraController.getRotationY()) % 360;
componentY = (int)Mathf.Round(stride * Mathf.Sin(rotationY * Mathf.Deg2Rad));
componentX = -1 * (int)Mathf.Round(stride * Mathf.Cos(rotationY * Mathf.Deg2Rad));
if (Input.GetKey(KeyCode.A))
{
GLO_Y += componentX;
GLO_X -= componentY;
GLO_Y = Mathf.Clamp(GLO_Y, lowerLimit_gloY, upperLimit_gloY);
GLO_X = Mathf.Clamp(GLO_X, lowerLimit_gloX, upperLimit_gloX);
SetRegion();
MainFunc(ref tex, ref LFS);
}
else if (Input.GetKey(KeyCode.D))
{
GLO_Y -= componentX;
GLO_X += componentY;
GLO_Y = Mathf.Clamp(GLO_Y, lowerLimit_gloY, upperLimit_gloY);
GLO_X = Mathf.Clamp(GLO_X, lowerLimit_gloX, upperLimit_gloX);
SetRegion();
MainFunc(ref tex, ref LFS);
}
else if (Input.GetKey(KeyCode.W))
{
GLO_Y += componentY;
GLO_X += componentX;
GLO_Y = Mathf.Clamp(GLO_Y, lowerLimit_gloY, upperLimit_gloY);
GLO_X = Mathf.Clamp(GLO_X, lowerLimit_gloX, upperLimit_gloX);
SetRegion();
MainFunc(ref tex, ref LFS);
}
else if (Input.GetKey(KeyCode.S))
{
GLO_Y -= componentY;
GLO_X -= componentX;
GLO_Y = Mathf.Clamp(GLO_Y, lowerLimit_gloY, upperLimit_gloY);
GLO_X = Mathf.Clamp(GLO_X, lowerLimit_gloX, upperLimit_gloX);
SetRegion();
MainFunc(ref tex, ref LFS);
}
#endif
// // UnityEngine.Debug.Log("View Position (X, Y) = (" + GLO_X + ", " + GLO_Y + ") -> (componentX, componentY) = ( " + componentX + ", " + componentY + ")" + "rotY : " + rotationY + "[" + i++);
long LoadLF_us = sw_LoadLF.ElapsedTicks / 10;
long LFUpdate_us = sw_LFUpdate.ElapsedTicks / 10;
long Rendering_us = sw_Rendering.ElapsedTicks / 10;
long MainFunc_us = sw_MainFunc.ElapsedTicks / 10;
long ParallelFor_us = sw_ParallelFor.ElapsedTicks / 10;
//using (System.IO.StreamWriter log_LoadLF = new System.IO.StreamWriter("C:/myUnity/timelog/LoadLF.txt", true))
// log_LoadLF.WriteLine(LoadLF_us.ToString());
//
//using (System.IO.StreamWriter log_LFUpdate = new System.IO.StreamWriter("C:/myUnity/timelog/LFUpdate.txt", true))
// log_LFUpdate.WriteLine(LFUpdate_us.ToString());
//
//using (System.IO.StreamWriter log_Rendering = new System.IO.StreamWriter("C:/myUnity/timelog/Rendering.txt", true))
// log_Rendering.WriteLine(Rendering_us.ToString());
//
//using (System.IO.StreamWriter log_MainFunc = new System.IO.StreamWriter("C:/myUnity/timelog/MainFunc.txt", true))
// log_MainFunc.WriteLine(MainFunc_us.ToString());
//using (System.IO.StreamWriter log_ParallelFor = new System.IO.StreamWriter("C:/myUnity/timelog/ParallelFor.txt", true))
// log_ParallelFor.WriteLine(ParallelFor_us.ToString());
//
//using (System.IO.StreamWriter log_GC = new System.IO.StreamWriter("C:/myUnity/timelog/GC.txt", true))
// log_GC.WriteLine((sw_GC.ElapsedTicks / 10).ToString());
//
sw_LoadLF.Reset();
sw_LFUpdate.Reset();
sw_GC.Reset();
}
public static void sub_LFUpdate_ROW(int R1, int R2, int R3, int R4, int R5, int R6, int R7, int R8, int R9, int R10, int R11, int R12, int R13, int R14)
{
if (R1 == 1)
{
if (!ROW1_FLAG)
{
ROW1 = LoadLF(ROW1_FILE, LFUW);
}
ROW1_FLAG = true;
}
else
{
if (ROW1_FLAG)
ROW1 = null;
ROW1_FLAG = false;
}
if (R2 == 1)
{
if (!ROW2_FLAG)
{
ROW2 = LoadLF(ROW2_FILE, LFUW);
}
ROW2_FLAG = true;
}
else
{
if (ROW2_FLAG)
ROW2 = null;
ROW2_FLAG = false;
}
if (R3 == 1)
{
if (!ROW3_FLAG)
{
ROW3 = LoadLF(ROW3_FILE, LFUW);
}
ROW3_FLAG = true;
}
else
{
if (ROW3_FLAG)
ROW3 = null;
ROW3_FLAG = false;
}
if (R4 == 1)
{
if (!ROW4_FLAG)
{
ROW4 = LoadLF(ROW4_FILE, LFUW);
}
ROW4_FLAG = true;
}
else
{
if (ROW4_FLAG)
ROW4 = null;
ROW4_FLAG = false;
}
if (R5 == 1)
{
if (!ROW5_FLAG)
{
ROW5 = LoadLF(ROW5_FILE, LFUW);
}
ROW5_FLAG = true;
}
else
{
if (ROW5_FLAG)
ROW5 = null;
ROW5_FLAG = false;
}
if (R6 == 1)
{
if (!ROW6_FLAG)
{
ROW6 = LoadLF(ROW6_FILE, LFUW);
}
ROW6_FLAG = true;
}
else
{
if (ROW6_FLAG)
ROW6 = null;
ROW6_FLAG = false;
}
if (R7 == 1)
{
if (!ROW7_FLAG)
{
ROW7 = LoadLF(ROW7_FILE, LFUW);
}
ROW7_FLAG = true;
}
else
{
if (ROW7_FLAG)
ROW7 = null;
ROW7_FLAG = false;
}
if (R8 == 1)
{
if (!ROW8_FLAG)
{
ROW8 = LoadLF(ROW8_FILE, LFUW);
}
ROW8_FLAG = true;
}
else
{
if (ROW8_FLAG)
ROW8 = null;
ROW8_FLAG = false;
}
if (R9 == 1)
{
if (!ROW9_FLAG)
{
ROW9 = LoadLF(ROW9_FILE, LFUW);
}
ROW9_FLAG = true;
}
else
{
if (ROW9_FLAG)
ROW9 = null;
ROW9_FLAG = false;
}
if (R10 == 1)
{
if (!ROW10_FLAG)
{
ROW10 = LoadLF(ROW10_FILE, LFUW);
}
ROW10_FLAG = true;
}
else
{
if (ROW10_FLAG)
ROW10 = null;
ROW10_FLAG = false;
}
if (R11 == 1)
{
if (!ROW11_FLAG)
{
ROW11 = LoadLF(ROW11_FILE, LFUW);
}
ROW11_FLAG = true;
}
else
{
if (ROW11_FLAG)
ROW11 = null;
ROW11_FLAG = false;
}
if (R12 == 1)
{
if (!ROW12_FLAG)
{
ROW12 = LoadLF(ROW12_FILE, LFUW);
}
ROW12_FLAG = true;
}
else
{
if (ROW12_FLAG)
ROW12 = null;
ROW12_FLAG = false;
}
if (R13 == 1)
{
if (!ROW13_FLAG)
{
ROW13 = LoadLF(ROW13_FILE, LFUW);
}
ROW13_FLAG = true;
}
else
{
if (ROW13_FLAG)
ROW13 = null;
ROW13_FLAG = false;
}
if (R14 == 1)
{
if (!ROW14_FLAG)
{
ROW14 = LoadLF(ROW14_FILE, LFUW);
}
ROW14_FLAG = true;
}
else
{
if (ROW14_FLAG)
ROW14 = null;
ROW14_FLAG = false;
}
}
public static void sub_LFUpdate_COL(int C1, int C2, int C3, int C4, int C5, int C6, int C7, int C8, int C9, int C10, int C11, int C12, int C13, int C14, int C15, int C16, int C17, int C18)
{
if (C1 == 1)
{
if (!COL1_FLAG)
{
COL1 = LoadLF(COL1_FILE, LFUW);
}
COL1_FLAG = true;
}
else
{
if (COL1_FLAG)
COL1 = null;
COL1_FLAG = false;
}
if (C2 == 1)
{
if (!COL2_FLAG)
{
COL2 = LoadLF(COL2_FILE, LFUW);
}
COL2_FLAG = true;
}
else
{
if (COL2_FLAG)
COL2 = null;
COL2_FLAG = false;
}
if (C3 == 1)
{
if (!COL3_FLAG)
{
COL3 = LoadLF(COL3_FILE, LFUW);
}
COL3_FLAG = true;
}
else
{
if (COL3_FLAG)
COL3 = null;
COL3_FLAG = false;
}
if (C4 == 1)
{
if (!COL4_FLAG)
{
COL4 = LoadLF(COL4_FILE, LFUW);
}
COL4_FLAG = true;
}
else
{
if (COL4_FLAG)
COL4 = null;
COL4_FLAG = false;
}
if (C5 == 1)
{
if (!COL5_FLAG)
{
COL5 = LoadLF(COL5_FILE, LFUW);
}
COL5_FLAG = true;
}
else
{
if (COL5_FLAG)
COL5 = null;
COL5_FLAG = false;
}
if (C6 == 1)
{
if (!COL6_FLAG)
{
COL6 = LoadLF(COL6_FILE, LFUW);
}
COL6_FLAG = true;
}
else
{
if (COL6_FLAG)
COL6 = null;
COL6_FLAG = false;
}
if (C7 == 1)
{
if (!COL7_FLAG)
{
COL7 = LoadLF(COL7_FILE, LFUW);
}
COL7_FLAG = true;
}
else
{
if (COL7_FLAG)
COL7 = null;
COL7_FLAG = false;
}
if (C8 == 1)
{
if (!COL8_FLAG)
{
COL8 = LoadLF(COL8_FILE, LFUW);
}
COL8_FLAG = true;
}
else
{
if (COL8_FLAG)
COL8 = null;
COL8_FLAG = false;
}
if (C9 == 1)
{
if (!COL9_FLAG)
{
COL9 = LoadLF(COL9_FILE, LFUW);
}
COL9_FLAG = true;
}
else
{
if (COL9_FLAG)
COL9 = null;
COL9_FLAG = false;
}
if (C10 == 1)
{
if (!COL10_FLAG)
{
COL10 = LoadLF(COL10_FILE, LFUW);
}
COL10_FLAG = true;
}
else
{
if (COL10_FLAG)
COL10 = null;
COL10_FLAG = false;
}
if (C11 == 1)
{
if (!COL11_FLAG)
{
COL11 = LoadLF(COL11_FILE, LFUW);
}
COL11_FLAG = true;
}
else
{
if (COL11_FLAG)
COL11 = null;
COL11_FLAG = false;
}
if (C12 == 1)
{
if (!COL12_FLAG)
{
COL12 = LoadLF(COL12_FILE, LFUW);
}
COL12_FLAG = true;
}
else
{
if (COL12_FLAG)
COL12 = null;
COL12_FLAG = false;
}
if (C13 == 1)
{
if (!COL13_FLAG)
{
COL13 = LoadLF(COL13_FILE, LFUW);
}
COL13_FLAG = true;
}
else
{
if (COL13_FLAG)
COL13 = null;
COL13_FLAG = false;
}
if (C14 == 1)
{
if (!COL14_FLAG)
{
COL14 = LoadLF(COL14_FILE, LFUW);
}
COL14_FLAG = true;
}
else
{
if (COL14_FLAG)
COL14 = null;
COL14_FLAG = false;
}
if (C15 == 1)
{
if (!COL15_FLAG)
{
COL15 = LoadLF(COL15_FILE, LFUW);
}
COL15_FLAG = true;
}
else
{
if (COL15_FLAG)
COL15 = null;
COL15_FLAG = false;
}
if (C16 == 1)
{
if (!COL16_FLAG)
{
COL16 = LoadLF(COL16_FILE, LFUW);
}
COL16_FLAG = true;
}
else
{
if (COL16_FLAG)
COL16 = null;
COL16_FLAG = false;
}
if (C17 == 1)
{
if (!COL17_FLAG)
{
COL17 = LoadLF(COL17_FILE, LFUW);
}
COL17_FLAG = true;
}
else
{
if (COL17_FLAG)
COL17 = null;
COL17_FLAG = false;
}
if (C18 == 1)
{
if (!COL18_FLAG)
{
COL18 = LoadLF(COL18_FILE, LFUW);
}
COL18_FLAG = true;
}
else
{
if (COL18_FLAG)
COL18 = null;
COL18_FLAG = false;
}
}
public static void LFUpdate(int REGION)
{
sw_LFUpdate.Reset();
sw_LFUpdate.Start();
if (REGION == 0)
{
sub_LFUpdate_ROW(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0); // 1, 2, 3, 4, 5, 6
sub_LFUpdate_COL(0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1); // 5, 6, 11, 12, 17, 18
}
else if (REGION == 1)
{
sub_LFUpdate_ROW(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0);
sub_LFUpdate_COL(0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1);
}
else if (REGION == 2)
{
sub_LFUpdate_ROW(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0);
sub_LFUpdate_COL(0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1);
}
else if (REGION == 3)
{
sub_LFUpdate_ROW(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0);
sub_LFUpdate_COL(0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1);
}
else if (REGION == 4)
{
sub_LFUpdate_ROW(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0);
sub_LFUpdate_COL(0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0);
}
else if (REGION == 5)
{
sub_LFUpdate_ROW(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0);
sub_LFUpdate_COL(0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0);
}
else if (REGION == 6)
{
sub_LFUpdate_ROW(0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0);
sub_LFUpdate_COL(0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0);
}
else if (REGION == 7)
{
sub_LFUpdate_ROW(0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0);
sub_LFUpdate_COL(0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0);
}
else if (REGION == 8)
{
sub_LFUpdate_ROW(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
sub_LFUpdate_COL(1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0);
}
else if (REGION == 9)
{
sub_LFUpdate_ROW(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
sub_LFUpdate_COL(1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0);
}
else if (REGION == 10)
{
sub_LFUpdate_ROW(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
sub_LFUpdate_COL(1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0);
}
else if (REGION == 11)
{
sub_LFUpdate_ROW(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
sub_LFUpdate_COL(1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0);
}
//auto end_u = std::chrono::system_clock::now();
//std::chrono::microseconds delta_u = std::chrono::duration_cast<std::chrono::microseconds>(end_u - start_u);
//printf("UPDATE : %d\n", delta_u.count());
sw_GC.Restart();
//System.GC.Collect();
sw_GC.Stop();
sw_LFUpdate.Stop();
// UnityEngine.Debug.Log("- LF Update : " + sw_LFUpdate.ElapsedTicks / 10 + " us");
// UnityEngine.Debug.Log("LOAD DONE !!");
}
public static byte[] LoadLF(string inFile, int N)
{
sw_LoadLF.Reset();
sw_LoadLF.Start();
byte[] imageData = System.IO.File.ReadAllBytes(inFile);
sw_LoadLF.Stop();
// UnityEngine.Debug.Log("LoadLF : " + sw_LoadLF.ElapsedTicks / 10 + " us");
return imageData;
}
public static byte inter8(byte[] LF, double P_r, int P_1, int P_2, double U_r, int U_1, int U_2, double H_r, int H_1, int H_2, int c)
{
if (P_r == -1 || U_r == -1 || H_r == -1)
{
return 0;
}
else
{
if (P_r == 1) P_1 = 0;
else if (P_r == 0) P_2 = 0;
if (U_r == 1) U_1 = 0;
else if (U_r == 0) U_2 = 0;
if (H_r == 1) H_1 = 0;
else if (H_r == 0) H_2 = 0;
if (c == 0)
{
return (byte)(
((1.0 - P_r) *
((1.0 - U_r) * ((1.0 - H_r) * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_1 * 3 + 0] + H_r * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_2 * 3 + 0]) +
((U_r) * ((1.0 - H_r) * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_1 * 3 + 0] + H_r * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_2 * 3 + 0])))) +
((P_r) *
((1.0 - U_r) * ((1.0 - H_r) * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_1 * 3 + 0] + H_r * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_2 * 3 + 0]) +
((U_r) * ((1.0 - H_r) * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_1 * 3 + 0] + H_r * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_2 * 3 + 0])))));
}
else if (c == 1)
{
return (byte)(
((1.0 - P_r) *
((1.0 - U_r) * ((1.0 - H_r) * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_1 * 3 + 1] + H_r * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_2 * 3 + 1]) +
((U_r) * ((1.0 - H_r) * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_1 * 3 + 1] + H_r * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_2 * 3 + 1])))) +
((P_r) *
((1.0 - U_r) * ((1.0 - H_r) * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_1 * 3 + 1] + H_r * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_2 * 3 + 1]) +
((U_r) * ((1.0 - H_r) * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_1 * 3 + 1] + H_r * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_2 * 3 + 1])))));
}
else
{
return (byte)(
((1.0 - P_r) *
((1.0 - U_r) * ((1.0 - H_r) * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_1 * 3 + 2] + H_r * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_2 * 3 + 2]) +
((U_r) * ((1.0 - H_r) * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_1 * 3 + 2] + H_r * LF[(P_1) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_2 * 3 + 2])))) +
((P_r) *
((1.0 - U_r) * ((1.0 - H_r) * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_1 * 3 + 2] + H_r * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_1 * (HEIGHT * 3) + H_2 * 3 + 2]) +
((U_r) * ((1.0 - H_r) * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_1 * 3 + 2] + H_r * LF[(P_2) * (HEIGHT * WIDTH * 3) + U_2 * (HEIGHT * 3) + H_2 * 3 + 2])))));
}
}
}
public static byte[] RenderingLF_SinglePixel(byte[] LF, int POS_X, int POS_Y, double f, double times, int order, int dir, ref int outputWidthLen, ref int a_FrontIdx)
{
double Alloc_Angle_s = 0.0;
double Alloc_Angle_e = 0.0;
Alloc_Angle_s = Math.Atan2((-1.0 * LFUW / 2 - POS_X), (LFUW / 2 - POS_Y));
Alloc_Angle_e = Math.Atan2((1.0 * LFUW / 2 - POS_X), (LFUW / 2 - POS_Y));
if (POS_Y == 50)
{
Alloc_Angle_s = -1 * Math.PI / 2;
Alloc_Angle_e = Math.PI / 2;
}
//Alloc_Angle_s = Alloc_Angle_s - 0.174533; //ABOUT 10 DEGREES
//Alloc_Angle_e = Alloc_Angle_e + 0.174533; //ABOUT 10 DEGREES
//if (Alloc_Angle_s < -1 * PI / 2) Alloc_Angle_s = -1 * PI / 2;
//if (Alloc_Angle_e > PI / 2) Alloc_Angle_e = PI / 2;
int Y = LFUW / 2;
int X_S = -1 * LFUW / 2;
int X_E = LFUW / 2;
a_FrontIdx = 0;
int out_w = 0;
for (double a = Alloc_Angle_s; a < Alloc_Angle_e; a = a + 0.0025)
{
double P = (double)(Y - POS_Y) * Math.Tan(a) + POS_X;
if (P >= X_S && P < X_E)
{
out_w++;
if (a <= 0) a_FrontIdx++;
}
} // a = 0일때의 값을 밖으로 뽑아내서, 그 부분까지 크롭 후 Left's Right로
outputWidthLen = out_w; // arg "outputWidthLen" is used to deliver the modified width to the Texture2D (082219)
//out_w = (int)((Alloc_Angle_e - Alloc_Angle_s) / 0.0025);
byte[] IMG = new byte[HEIGHT * outputWidthLen * 3];
//Mat IMG = new Mat(HEIGHT, out_w, MatType.CV_8UC3);
//Image IMG = new Bitmap(out_w, HEIGHT);
//Bitmap bmp = IMG as Bitmap;
sw_ParallelFor.Restart();
#if USE_CUDA
int errorCode = CudaParallelFor(IMG, LF, Alloc_Angle_s, times, Y, POS_Y, POS_X, LFUW, DATAW, WIDTH, HEIGHT, out_w, dir, LF.Length);