forked from abhijat96/Augmented-Reality-Visualizations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ARCameraScript.cs
1082 lines (930 loc) · 47.9 KB
/
ARCameraScript.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
class Restaurant
{
public Dictionary<string, string> features;
public Restaurant()
{
features = new Dictionary<string, string>();
}
}
class RestaurantObject
{
public GameObject restaurantGameObject;
public Restaurant restaurantDetails;
}
class CuisineCount
{
public string Name;
public int Count;
}
public class ARCameraScript : MonoBehaviour
{
string[] Features;
private string SelectedArea;
Dictionary<string, Dictionary<string, RestaurantObject>> BoroWiseDict;
Dictionary<string, RestaurantObject> curBoroRestaurantDict;
List<Color> barColors;
public GameObject ARText;
public GameObject ARAreaText;
public GameObject PlaneFinder;
public GameObject GroundPlaneStage;
public GameObject BrooklynPlane;
public GameObject BronxPlane;
public GameObject StatenIslandPlane;
public GameObject QueensPlane;
public GameObject ManhattanPlane;
public GameObject NYCPlane;
public GameObject BrooklynCollider;
public GameObject BronxCollider;
public GameObject QueensCollider;
public GameObject StatenIslandCollider;
public GameObject ManhattanCollider;
public GameObject Restaurant3DGameObject;
//TESTING
private GameObject destroyBar;
private bool IsTestObjectDestroyed = false;
private List<RestaurantObject> allVisibleCubes;
//IMAGE TARGET
public GameObject ImageTarget;
//BAR GRAPH
private GameObject curBarGraph;
public GameObject BarGraph;
public GameObject Bar;
public GameObject origin;
public GameObject curBar;
public GameObject YValueLabel;
public List<GameObject> BarGraphHeights1;
public List<GameObject> BarGraphHeights2;
public GameObject LineChartTrend1;
public GameObject LineChartTrend2;
private LineRenderer Trend1LineRenderer;
private LineRenderer Trend2LineRenderer;
//LINE CHART
private GameObject curLineChart;
public GameObject LineChart;
////UI
public GameObject FinalizePlaneButton;
public GameObject SelectAreaButton;
public GameObject ButtonZoomOut;
public Joystick LeftJoystick;
public Joystick RightJoystick;
public Slider slider;
public GameObject ButtonBrooklyn;
public GameObject ButtonManhattan;
public GameObject ButtonBronx;
public GameObject ButtonQueens;
public GameObject ButtonStatenIsland;
public GameObject currentObject;
private GameObject currentBoro;
//HALO EFFECT
private static float HaloChange = 0.005f;
//private int TouchCount = 0;
//MODES
private bool PlaneEstablished = false;
private bool ModePlaneSelection = true;
private bool ModeSelection = false;
private bool ModeBuild = false;
private bool ModePlay = false;
private bool InTransitionZoomIn = false;
private bool InTransitionZoomOut = false;
private bool ZoomedIn = false;
private Vector3 transitionTargetPosition;
public GameObject ImagePlane;
private GameObject BiggestPlane;
private bool HasZoomed = false;
private string selectedBoro;
private int selectedThreshold;
//DEBUGGING
private static bool ExceptionOccured = false;
private static string LastExceptionString = "Default";
void FinalizePlane()
{
PlaneEstablished = true;
PlaneFinder.SetActive(false);
ModePlaneSelection = false;
ModeSelection = true;
FinalizePlaneButton.SetActive(false);
SelectAreaButton.SetActive(true);
}
void MoveToSelectedArea()
{
if ((currentObject.transform.name.StartsWith("Brooklyn"))
||
(currentObject.transform.name.StartsWith("StatenIsland"))
||
(currentObject.transform.name.StartsWith("Bronx"))
||
(currentObject.transform.name.StartsWith("Queens"))
||
(currentObject.transform.name.StartsWith("Manhattan"))
)
{
InTransitionZoomIn = true;
ModeSelection = false;
transitionTargetPosition = new Vector3(transform.position.x,
transform.position.y - 7f,
transform.position.z);
}
}
void TransitionMapTowardsCamera()
{
if (!HasZoomed)
{
float ScaleSpeed = 0.2f;
if (BiggestPlane.transform.localScale.x < 2f)
{
BiggestPlane.transform.localScale = new Vector3(BiggestPlane.transform.localScale.x + ScaleSpeed, BiggestPlane.transform.localScale.y, ImagePlane.transform.localScale.z + ScaleSpeed);
}
else
{
HasZoomed = true;
currentObject.transform.parent = null;
ImagePlane.transform.parent = currentObject.transform;
BiggestPlane = currentObject;
}
}
else
{
float speed = 4f;
float step = speed * Time.deltaTime;
//transform.position = transitionTargetPosition;
if ((Math.Abs(BiggestPlane.transform.position.x - transitionTargetPosition.x) > 1f) ||
(Math.Abs(BiggestPlane.transform.position.y - transitionTargetPosition.y) > 1f) ||
(Math.Abs(BiggestPlane.transform.position.z - transitionTargetPosition.z) > 1f))
{
currentObject.transform.position = Vector3.MoveTowards(BiggestPlane.transform.position
, transitionTargetPosition, step);
}
else
{
InTransitionZoomIn = false;
ModeBuild = true;
ZoomedIn = true;
ImagePlane.transform.parent = GroundPlaneStage.transform;
currentObject.transform.parent = ImagePlane.transform;
BiggestPlane = ImagePlane;
ButtonZoomOut.SetActive(true);
}
}
}
void SwitchToZoomOutMode()
{
InTransitionZoomOut = true;
BiggestPlane = ImagePlane;
currentObject.transform.parent = ImagePlane.transform;
transitionTargetPosition = new Vector3(transform.position.x,
transform.position.y - 2f,
transform.position.z);
}
void ZoomOut()
{
if (BiggestPlane.transform.localScale.x > 0.5f)
{
BiggestPlane.transform.localScale = new Vector3(
BiggestPlane.transform.localScale.x - 0.05f,
BiggestPlane.transform.localScale.y,
BiggestPlane.transform.localScale.z - 0.05f);
}
else
{
if ((Math.Abs(BiggestPlane.transform.position.x - transitionTargetPosition.x) > 1f) ||
(Math.Abs(BiggestPlane.transform.position.y - transitionTargetPosition.y) > 1f) ||
(Math.Abs(BiggestPlane.transform.position.z - transitionTargetPosition.z) > 1f))
{
float speed = 4f;
float step = speed * Time.deltaTime;
BiggestPlane.transform.position = Vector3.MoveTowards(BiggestPlane.transform.position,
transitionTargetPosition,
step);
}
else
{
InTransitionZoomOut = false;
ModeSelection = true;
ImagePlane.transform.parent = GroundPlaneStage.transform;
HasZoomed = false;
ZoomedIn = false;
}
}
}
void SwitchToBuildMode()
{
ModeSelection = false;
ModeBuild = true;
ModePlay = false;
ARText.GetComponent<TextMesh>().text = "";
}
void SwitchToPlayMode()
{
ModeSelection = false;
ModeBuild = false;
ModePlay = true;
}
void ChangeThreshold(float sliderValue)
{
try
{
GameObject SliderLabel = slider.transform.Find("Label").gameObject;
int highestPossibleScore = 100;
selectedThreshold = (int)(((100 - sliderValue) / 100) * highestPossibleScore);
SliderLabel.GetComponent<Text>().text = "Threshold Score: " + selectedThreshold.ToString();
CreateAndPlaceCubesOnMap();
}
catch(Exception ex)
{
ExceptionOccured = true;
UnityEngine.Debug.Log("EXCEPTION!!!!!");
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
LastExceptionString = "THRESOLD change";
}
}
void ApplyBrooklynFilter()
{
selectedBoro = "BROOKLYN";
currentObject = BrooklynCollider;
currentBoro = BrooklynPlane;
CreateAndPlaceCubesOnMap();
}
void ApplyStatenIslandFilter()
{
selectedBoro = "STATEN ISLAND";
currentObject = StatenIslandCollider;
currentBoro = StatenIslandPlane;
CreateAndPlaceCubesOnMap();
}
void ApplyBronxFilter()
{
selectedBoro = "BRONX";
currentObject = BronxCollider;
currentBoro = BronxPlane;
CreateAndPlaceCubesOnMap();
}
void ApplyQueensFilter()
{
selectedBoro = "QUEENS";
currentObject = QueensCollider;
currentBoro = QueensPlane;
CreateAndPlaceCubesOnMap();
}
void ApplyManhattanFilter()
{
selectedBoro = "MANHATTAN";
currentObject = ManhattanCollider;
currentBoro = ManhattanPlane;
CreateAndPlaceCubesOnMap();
}
void CreateBarGraph(string[] XValues, float[] YValues, float YValueMax, string XAxisLabel, string YAxisLabel)
{
try
{
Destroy(curBarGraph);
curBarGraph = Instantiate(BarGraph);
curBarGraph.SetActive(true);
curBarGraph.transform.parent = ImageTarget.transform;
curBarGraph.transform.position = BarGraph.transform.position;
curBarGraph.transform.Find("XAxisText").gameObject.GetComponent<TextMesh>().text = XAxisLabel;
curBarGraph.transform.Find("YAxisText").gameObject.GetComponent<TextMesh>().text = YAxisLabel;
float lastYLabel = -1f;
BarGraph.SetActive(false);
//curBarGraph.transform.rotation = BarGraph.transform.rotation;
int barCount = YValues.Length;
int YDivisionCount = 10;
if (YValueMax == -1f)
{
foreach (float curValue in YValues)
{
if (curValue > YValueMax)
YValueMax = curValue;
}
}
YValueMax = YValueMax + (YValueMax * 0.1f);
origin = curBarGraph.transform.Find("Origin").gameObject;
GameObject XEnd = curBarGraph.transform.Find("XEnd").gameObject;
GameObject YEnd = curBarGraph.transform.Find("YEnd").gameObject;
float gapBetweenBars = (XEnd.transform.position.x - origin.transform.position.x) / barCount;
float YLabelOffset = (XEnd.transform.position.x - origin.transform.position.x) / 15;
float XOffset = gapBetweenBars / 1000;
float YOffset = gapBetweenBars / 10;
float gapBetweenYValueLabels = (YEnd.transform.position.y - origin.transform.position.y) / YDivisionCount;
for (int i = 0; i < YDivisionCount; i++)
{
GameObject curYLabel = Instantiate(YValueLabel);
curYLabel.transform.parent = curBarGraph.transform;
curYLabel.transform.position = new Vector3(origin.transform.position.x - YLabelOffset * 2,
origin.transform.position.y + gapBetweenYValueLabels + (gapBetweenYValueLabels * i),
origin.transform.position.z
);
curYLabel.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
curYLabel.transform.GetComponent<TextMesh>().text = ((int)((YValueMax / YDivisionCount) * i)).ToString();
}
for (int i = 0; i < barCount; i++)
{
curBar = Instantiate(Bar);
curBar.SetActive(true);
curBar.transform.parent = curBarGraph.transform;
curBar.transform.Find("CubeBase").Find("Cube").GetComponent<Renderer>().material.color = barColors[i];
curBar.transform.localScale = new Vector3(curBar.transform.localScale.x / 100,
curBar.transform.localScale.y / 100,
curBar.transform.localScale.z / 100);
curBar.transform.position = new Vector3(origin.transform.position.x + XOffset + (gapBetweenBars * (i + 1)), origin.transform.position.y + YOffset, origin.transform.position.z);
curBar.transform.Find("Label").GetComponent<TextMesh>().text = XValues[i];
float targetHeight = (YValues[i] / YValueMax) * (YEnd.transform.localPosition.y - 11.58f);
GameObject curCubeBase = curBar.transform.Find("CubeBase").gameObject;
GameObject curHeight = curCubeBase.transform.Find("BarHeightPosition").gameObject;
curHeight.transform.parent = curBarGraph.transform;
while (curHeight.transform.localPosition.y - 11.58f < targetHeight)
{
curHeight.transform.parent = curCubeBase.transform;
curCubeBase.transform.localScale = new Vector3(curCubeBase.transform.localScale.x,
curCubeBase.transform.localScale.y + 0.3f,
curCubeBase.transform.localScale.z);
curCubeBase.transform.localPosition = new Vector3(curCubeBase.transform.position.x,
(curCubeBase.transform.localScale.y / 2) - 0.5f,
curCubeBase.transform.position.z);
curHeight.transform.parent = curBarGraph.transform;
}
curHeight.transform.parent = curCubeBase.transform;
}
}
catch(Exception ex)
{
ExceptionOccured = true;
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
LastExceptionString = "Ex! Bar Graph!";
}
}
void CreateLineChart(string[] XValues, float[] YValues1, float[] YValues2, string XAxisLabel, string YAxisLabel)
{
Destroy(curLineChart);
curLineChart = Instantiate(LineChart);
curLineChart.transform.parent = ImageTarget.transform;
curLineChart.transform.position = LineChart.transform.position;
curLineChart.transform.Find("XAxisText").gameObject.GetComponent<TextMesh>().text = XAxisLabel;
curLineChart.transform.Find("YAxisText").gameObject.GetComponent<TextMesh>().text = YAxisLabel;
LineChart.SetActive(false);
curLineChart.SetActive(true);
BarGraphHeights1 = new List<GameObject>();
BarGraphHeights2 = new List<GameObject>();
int barCount = XValues.Length;
int YDivisionCount = 10;
int YValueMax = -1;
foreach(float curVal in YValues1)
{
if (curVal > YValueMax)
YValueMax = (int)curVal;
}
foreach (float curVal in YValues2)
{
if (curVal > YValueMax)
YValueMax = (int)curVal;
}
origin = curLineChart.transform.Find("Origin").gameObject;
GameObject XEnd = curLineChart.transform.Find("XEnd").gameObject;
GameObject YEnd = curLineChart.transform.Find("YEnd").gameObject;
float gapBetweenBars = (XEnd.transform.position.x - origin.transform.position.x) / barCount;
float XOffset = gapBetweenBars / 1000;
float YOffset = gapBetweenBars / 10;
#region Labelling Y Axis
float gapBetweenYValueLabels = (YEnd.transform.position.y - origin.transform.position.y) / YDivisionCount;
for (int i = 0; i < YDivisionCount; i++)
{
GameObject curYLabel = Instantiate(YValueLabel);
curYLabel.transform.parent = curLineChart.transform;
curYLabel.transform.position = new Vector3(origin.transform.position.x - gapBetweenBars*2,
origin.transform.position.y + gapBetweenYValueLabels + (gapBetweenYValueLabels * i),
origin.transform.position.z
);
curYLabel.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
curYLabel.transform.GetComponent<TextMesh>().text = ((YValueMax / YDivisionCount) * i).ToString();
}
#endregion
#region Trend 1
for (int i = 0; i < barCount; i++)
{
curBar = Instantiate(Bar);
curBar.transform.parent = curLineChart.transform;
curBar.transform.localScale = new Vector3(curBar.transform.localScale.x / 100,
curBar.transform.localScale.y / 100,
curBar.transform.localScale.z / 100);
curBar.transform.position = new Vector3(origin.transform.position.x + XOffset + (gapBetweenBars * (i + 1)), origin.transform.position.y + YOffset, origin.transform.position.z);
curBar.transform.Find("Label").GetComponent<TextMesh>().text = XValues[i];
float targetHeight = (YValues1[i] / YValueMax) * (YEnd.transform.localPosition.y - 11.58f);
GameObject curCubeBase = curBar.transform.Find("CubeBase").gameObject;
GameObject curHeight = curCubeBase.transform.Find("BarHeightPosition").gameObject;
curHeight.transform.parent = curLineChart.transform;
//Debug.Log(targetHeight);
while (curHeight.transform.localPosition.y - 11.58f < targetHeight)
{
curHeight.transform.parent = curCubeBase.transform;
curCubeBase.transform.localScale = new Vector3(curCubeBase.transform.localScale.x,
curCubeBase.transform.localScale.y + 0.1f,
curCubeBase.transform.localScale.z);
curCubeBase.transform.localPosition = new Vector3(curCubeBase.transform.position.x,
(curCubeBase.transform.localScale.y / 2) - 0.5f,
curCubeBase.transform.position.z);
curHeight.transform.parent = curLineChart.transform;
}
curHeight.transform.parent = curCubeBase.transform;
BarGraphHeights1.Add(curHeight);
curBar.transform.Find("CubeBase").gameObject.SetActive(false);
}
#endregion
#region Trend 2
for (int i = 0; i < barCount; i++)
{
curBar = Instantiate(Bar);
curBar.transform.parent = curLineChart.transform;
curBar.transform.localScale = new Vector3(curBar.transform.localScale.x / 100,
curBar.transform.localScale.y / 100,
curBar.transform.localScale.z / 100);
curBar.transform.position = new Vector3(origin.transform.position.x + XOffset + (gapBetweenBars * (i + 1)), origin.transform.position.y + YOffset, origin.transform.position.z);
curBar.transform.Find("Label").GetComponent<TextMesh>().text = XValues[i];
float targetHeight = (YValues2[i] / YValueMax) * (YEnd.transform.localPosition.y - 11.58f);
GameObject curCubeBase = curBar.transform.Find("CubeBase").gameObject;
GameObject curHeight = curCubeBase.transform.Find("BarHeightPosition").gameObject;
curHeight.transform.parent = curLineChart.transform;
//Debug.Log(targetHeight);
while (curHeight.transform.localPosition.y - 11.58f < targetHeight)
{
curHeight.transform.parent = curCubeBase.transform;
curCubeBase.transform.localScale = new Vector3(curCubeBase.transform.localScale.x,
curCubeBase.transform.localScale.y + 0.1f,
curCubeBase.transform.localScale.z);
curCubeBase.transform.localPosition = new Vector3(curCubeBase.transform.position.x,
(curCubeBase.transform.localScale.y / 2) - 0.5f,
curCubeBase.transform.position.z);
curHeight.transform.parent = curLineChart.transform;
}
curHeight.transform.parent = curCubeBase.transform;
BarGraphHeights2.Add(curHeight);
curBar.transform.Find("CubeBase").gameObject.SetActive(false);
}
#endregion
#region Line Chart Score Updation
float score = 0f;
float scoreSum = 0f;
float maxPossibleScore = 0f;
for(int i = 0; i < XValues.Length; i++)
{
if (YValues1[i] == 0)
continue;
scoreSum = scoreSum + (YValues1[i] - YValues2[i]);
maxPossibleScore = maxPossibleScore + (YValueMax-YValues2[i]);
}
score = scoreSum / maxPossibleScore;
//scoreSum = scoreSum / XValues.Length;
curLineChart.transform.Find("Score").Find("ScoreLabel").GetComponent<TextMesh>().text = score.ToString();
#endregion
}
// Start is called before the first frame update
void Start()
{
try
{
#region Setting colors for bar graph
barColors = new List<Color>();
barColors.Add(Color.red);
barColors.Add(Color.blue);
barColors.Add(Color.yellow);
barColors.Add(Color.gray);
barColors.Add(Color.green);
barColors.Add(Color.cyan);
barColors.Add(Color.white);
barColors.Add(Color.magenta);
barColors.Add(Color.grey);
barColors.Add(Color.black);
barColors.Add(Color.clear);
barColors.Add(Color.cyan);
barColors.Add(new Color(30,60,90));
barColors.Add(Color.red);
barColors.Add(Color.cyan);
barColors.Add(Color.yellow);
#endregion
selectedThreshold = 50;
selectedBoro = "QUEENS";
allVisibleCubes = new List<RestaurantObject>();
System.Random rand = new System.Random();
BoroWiseDict = new Dictionary<string, Dictionary<string, RestaurantObject>>();
BoroWiseDict["MANHATTAN"] = new Dictionary<string, RestaurantObject>();
BoroWiseDict["BRONX"] = new Dictionary<string, RestaurantObject>();
BoroWiseDict["STATEN ISLAND"] = new Dictionary<string, RestaurantObject>();
BoroWiseDict["BROOKLYN"] = new Dictionary<string, RestaurantObject>();
BoroWiseDict["QUEENS"] = new Dictionary<string, RestaurantObject>();
BiggestPlane = ImagePlane;
//test.csv
//Features = new string[] { "ID", "CAMIS", "DBA", "BORO", "BUILDING", "STREET", "ZIPCODE", "PHONE", "INSPECTIONDATE", "ACTION", "VIOLATIONCODE", "CRITICALFLAG", "SCORE", "GRADE", "GRADEDATE", "RECORDDATE", "INSPECTIONTYPE" };
//valid_data.csv
//Features = new string[] { "ID", "CAMIS", "DBA", "BORO", "BUILDING", "STREET", "ZIPCODE", "PHONE", "CUISINEDESCRIPTION", "INSPECTIONDATE", "ACTION", "VIOLATIONCODE", "VIOLATIONDESCRIPTION", "CRITICALFLAG", "SCORE", "GRADE", "GRADEDATE", "RECORDDATE", "INSPECTIONTYPE", "MONTH" };
//testnkTruncated.csv
Features = new string[] { "ID", "DBA", "BORO", "STREET", "ZIPCODE", "PHONE", "CUISINEDESCRIPTION", "INSPECTIONDATE", "VIOLATIONDESCRIPTION", "CRITICALFLAG", "SCORE", "GRADE", "MONTH" };
//dict = new Dictionary<string, List<Restaurant>>();
//PlacedGameObjects = new List<GameObject>();
Button btn = FinalizePlaneButton.GetComponent<Button>();
btn.onClick.AddListener(FinalizePlane);
Button btn2 = SelectAreaButton.GetComponent<Button>();
btn2.onClick.AddListener(MoveToSelectedArea);
Button btn3 = ButtonZoomOut.GetComponent<Button>();
btn3.onClick.AddListener(SwitchToZoomOutMode);
Button btn4 = ButtonManhattan.GetComponent<Button>();
btn4.onClick.AddListener(ApplyManhattanFilter);
Button btn5 = ButtonBronx.GetComponent<Button>();
btn5.onClick.AddListener(ApplyBronxFilter);
Button btn6 = ButtonBrooklyn.GetComponent<Button>();
btn6.onClick.AddListener(ApplyBrooklynFilter);
Button btn7 = ButtonQueens.GetComponent<Button>();
btn7.onClick.AddListener(ApplyQueensFilter);
Button btn8 = ButtonStatenIsland.GetComponent<Button>();
btn8.onClick.AddListener(ApplyStatenIslandFilter);
slider.onValueChanged.AddListener(ChangeThreshold);
using (var reader = new StreamReader(new MemoryStream((Resources.Load("test10kTruncated") as TextAsset).bytes)))
{
int rowCount = 0;
while (!reader.EndOfStream)
{
//Processing row
string[] fields = reader.ReadLine().Split(',');
if (rowCount == 0)
{
rowCount++;
continue;
}
Restaurant curRestaurant = new Restaurant();
int curFeatureIndex = 0;
foreach (string field in fields)
{
curRestaurant.features[Features[curFeatureIndex++]] = field;
}
RestaurantObject curRestaurantObject = new RestaurantObject();
curRestaurantObject.restaurantDetails = curRestaurant;
BoroWiseDict[curRestaurant.features["BORO"]]["RES:" + curRestaurant.features["ID"]] = curRestaurantObject;
rowCount++;
}
ARText.GetComponent<TextMesh>().text = "RESTAURANT COUNT:";
ARText.GetComponent<TextMesh>().text = ARText.GetComponent<TextMesh>().text + "\nManhattan: " + BoroWiseDict["MANHATTAN"].Count.ToString();
ARText.GetComponent<TextMesh>().text = ARText.GetComponent<TextMesh>().text + "\nBronx: " + BoroWiseDict["BRONX"].Count.ToString();
ARText.GetComponent<TextMesh>().text = ARText.GetComponent<TextMesh>().text + "\nQueens: " + BoroWiseDict["QUEENS"].Count.ToString();
ARText.GetComponent<TextMesh>().text = ARText.GetComponent<TextMesh>().text + "\nBrooklyn: " + BoroWiseDict["BROOKLYN"].Count.ToString();
ARText.GetComponent<TextMesh>().text = ARText.GetComponent<TextMesh>().text + "\nStaten Island: " + BoroWiseDict["STATEN ISLAND"].Count.ToString();
}
CreateAndPlaceCubesOnMap();
}
catch (Exception ex)
{
ExceptionOccured = true;
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
LastExceptionString = "??";
}
}
void CreateAndPlaceCubesOnMap()
{
try
{
System.Random rand = new System.Random();
#region Deleting previously visible cubes that don't fit the query.
List<RestaurantObject> toBeRemoved = new List<RestaurantObject>();
foreach (RestaurantObject curCubeObject in allVisibleCubes)
{
if ((Int32.Parse(curCubeObject.restaurantDetails.features["SCORE"]) < selectedThreshold) || !(curCubeObject.restaurantDetails.features["BORO"].Equals(selectedBoro)))
{
Destroy(curCubeObject.restaurantGameObject);
toBeRemoved.Add(curCubeObject);
//allVisibleCubes.Remove(curCubeObject);
}
}
foreach (RestaurantObject curCubeObject in toBeRemoved)
{
allVisibleCubes.Remove(curCubeObject);
}
#endregion
#region Restaurant 3D code
foreach (KeyValuePair<string, RestaurantObject> curPair in BoroWiseDict[selectedBoro])
{
RestaurantObject curRestaurantObject = curPair.Value;
Restaurant curRestaurant = curRestaurantObject.restaurantDetails;
if (Int32.Parse(curRestaurant.features["SCORE"]) > selectedThreshold)
{
if (!allVisibleCubes.Contains(curRestaurantObject))
{
curRestaurantObject.restaurantGameObject = Instantiate(Restaurant3DGameObject);
curRestaurantObject.restaurantGameObject.transform.parent = ImagePlane.transform;
curRestaurantObject.restaurantGameObject.transform.localScale = new Vector3(
Restaurant3DGameObject.transform.localScale.x,
Restaurant3DGameObject.transform.localScale.y + 0.1f,
Restaurant3DGameObject.transform.localScale.z);
curRestaurantObject.restaurantGameObject.SetActive(true);
GameObject targetPlane = BrooklynPlane;
if (curRestaurant.features["BORO"].Equals("BROOKLYN"))
targetPlane = BrooklynPlane;
else if (curRestaurant.features["BORO"].Equals("MANHATTAN"))
targetPlane = ManhattanPlane;
else if (curRestaurant.features["BORO"].Equals("BRONX"))
targetPlane = BronxPlane;
else if (curRestaurant.features["BORO"].Equals("STATEN ISLAND"))
targetPlane = StatenIslandPlane;
else if (curRestaurant.features["BORO"].Equals("QUEENS"))
targetPlane = QueensPlane;
float randomFactor = 0.2f;
if (targetPlane == ManhattanPlane)
randomFactor = 0.05f;
if (targetPlane == BronxPlane)
randomFactor = 0.1f;
if (ZoomedIn)
randomFactor = 3f;
float X_Offset = (float)(rand.NextDouble()) * randomFactor;
float Z_Offset = (float)(rand.NextDouble()) * randomFactor;
curRestaurantObject.restaurantGameObject.transform.position =
new Vector3(
targetPlane.transform.position.x + X_Offset,
targetPlane.transform.position.y,
targetPlane.transform.position.z + Z_Offset
);
if (curRestaurant.features["CRITICALFLAG"].Equals("Critical"))
curRestaurantObject.restaurantGameObject.transform.Find("3DModel").gameObject.GetComponent<Renderer>().material.color = new Color(100, 0, 0, 0.5f);
else
curRestaurantObject.restaurantGameObject.transform.Find("3DModel").gameObject.GetComponent<Renderer>().material.color = new Color(0, 100, 0, 50f);
curRestaurantObject.restaurantGameObject.transform.Find("3DModel").name = "RES:" + curRestaurant.features["ID"];
curRestaurantObject.restaurantGameObject.transform.Find("RestaurantLabel").GetComponent<TextMesh>().text = curRestaurant.features["DBA"];
allVisibleCubes.Add(curRestaurantObject);
}
}
}
#endregion
#region Graph Updation Calculations
int criticalYes = 0;
int criticalNo = 0;
Dictionary<int, int> monthCriticalCount = new Dictionary<int, int>();
Dictionary<int, int> monthInspectionCount = new Dictionary<int, int>();
Dictionary<string, int> cuisineCount = new Dictionary<string, int>();
for (int i = 1; i <= 12; i++)
{
monthCriticalCount[i] = 0;
monthInspectionCount[i] = 0;
}
foreach (RestaurantObject curCubeObject in allVisibleCubes)
{
if (curCubeObject.restaurantDetails.features["CRITICALFLAG"].Equals("Critical"))
{
criticalYes++;
monthCriticalCount[Int32.Parse(curCubeObject.restaurantDetails.features["MONTH"])]++;
}
else
criticalNo++;
//Debug.Log("1");
monthInspectionCount[Int32.Parse(curCubeObject.restaurantDetails.features["MONTH"])]++;
//Debug.Log("2");
if (cuisineCount.ContainsKey(curCubeObject.restaurantDetails.features["CUISINEDESCRIPTION"]))
{
//Debug.Log("3");
cuisineCount[curCubeObject.restaurantDetails.features["CUISINEDESCRIPTION"]]++;
//Debug.Log("4");
}
else
cuisineCount[curCubeObject.restaurantDetails.features["CUISINEDESCRIPTION"]] = 1;
}
List<CuisineCount> CuisineCountList = new List<CuisineCount>();
foreach (KeyValuePair<string, int> curCuisine in cuisineCount)
{
CuisineCount curCuisineCount = new CuisineCount();
curCuisineCount.Count = curCuisine.Value;
curCuisineCount.Name = curCuisine.Key;
CuisineCountList.Add(curCuisineCount);
}
//Debug.Log("5");
CuisineCountList.Sort((x, y) => y.Count - x.Count);
int CuisineGraphCount = 15;
string[] CuisineXLabels = new string[CuisineGraphCount];
float[] CuisineYLabels = new float[CuisineGraphCount];
if (CuisineCountList.Count < 15)
CuisineGraphCount = CuisineCountList.Count;
int labelCount = 0;
for (int i = 0; i < CuisineGraphCount - 1; i++)
{
if (CuisineCountList[i].Count == 0)
continue;
CuisineXLabels[labelCount] = CuisineCountList[i].Name;
CuisineYLabels[labelCount] = CuisineCountList[i].Count;
labelCount++;
}
CuisineXLabels[CuisineGraphCount - 1] = "Others";
CuisineYLabels[CuisineGraphCount - 1] = 0f;
for (int i = CuisineGraphCount - 1; i < CuisineCountList.Count; i++)
{
CuisineYLabels[CuisineGraphCount - 1] = CuisineYLabels[CuisineGraphCount - 1] + CuisineCountList[i].Count;
}
//Removing zero count cuisines
string[] CuisineXLabelsCleaned = new string[labelCount];
float[] CuisineYLabelsCleaned = new float[labelCount];
for (int i = 0; i < labelCount; i++)
{
CuisineXLabelsCleaned[i] = CuisineXLabels[i];
CuisineYLabelsCleaned[i] = CuisineYLabels[i];
}
//Debug.Log("8");
CreateBarGraph(CuisineXLabelsCleaned, CuisineYLabelsCleaned, CuisineYLabelsCleaned[0], "Cuisines", "Restaurant Count");
//CreateBarGraph(new string[] { "Critical", "Not Critical"}, new float[] { criticalYes, criticalNo }, criticalYes + criticalNo);
string[] monthsLabels = new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
float[] InspectionTrend = new float[12];
float[] CriticalTrend = new float[12];
for (int i = 1; i <= 12; i++)
{
if (monthInspectionCount.ContainsKey(i))
InspectionTrend[i - 1] = monthInspectionCount[i];
if (monthCriticalCount.ContainsKey(i))
CriticalTrend[i - 1] = monthCriticalCount[i];
}
CreateLineChart(monthsLabels, InspectionTrend, CriticalTrend, "Months", "Count");
#endregion
}
catch(Exception ex)
{
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
LastExceptionString = "ex! cube function!";
ExceptionOccured = true;
}
}
void UpdateLineChartPositions()
{
curLineChart.transform.rotation = new Quaternion(0, 0, 0, 0);
int barCount = 12;
Trend1LineRenderer = curLineChart.transform.Find("Trend1").GetComponent<LineRenderer>();
Trend1LineRenderer.positionCount = barCount;
Trend1LineRenderer.material = new Material(Shader.Find("Standard"));
Trend1LineRenderer.startColor = Color.red;
Trend1LineRenderer.endColor = Color.red;
Trend1LineRenderer.startWidth = 0.003f;
for (int i = 0; i < barCount; i++)
{
curBar = BarGraphHeights1[i];
Trend1LineRenderer.SetPosition(i, curBar.transform.position);
}
Trend2LineRenderer = curLineChart.transform.Find("Trend2").GetComponent<LineRenderer>();
Trend2LineRenderer.positionCount = barCount;
Trend2LineRenderer.startWidth = 0.003f;
for (int i = 0; i < barCount; i++)
{
curBar = BarGraphHeights2[i];
Trend2LineRenderer.SetPosition(i, curBar.transform.position);
}
}
// Update is called once per frame
void Update()
{
try
{
UpdateLineChartPositions();
if(curBarGraph != null)
{
curBarGraph.transform.position = BarGraph.transform.position;
curBarGraph.transform.rotation = new Quaternion(0, 0, 0, 0);
}
if(curLineChart != null)
{
curLineChart.transform.position = LineChart.transform.position;
curLineChart.transform.rotation = new Quaternion(0, 0, 0, 0);
}
if (ModeSelection)
{
if (Input.touchCount > 0)
{
if (EventSystem.current.IsPointerOverGameObject(0)) // is the touch on the GUI
{
return;
}
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit Hit;
if (Physics.Raycast(ray, out Hit, 20.0f))
{
if ((Hit.transform.name.StartsWith("BrooklynCollider") || (Hit.transform.name.StartsWith("StatenIslandCollider")) || (Hit.transform.name.StartsWith("ManhattanCollider")) || (Hit.transform.name.StartsWith("QueensCollider")) || (Hit.transform.name.StartsWith("BronxCollider"))))
{
currentObject = Hit.transform.gameObject;
}
if (Hit.transform.name.StartsWith("BrooklynCollider"))
{
currentBoro = BrooklynPlane;
curBoroRestaurantDict = BoroWiseDict["BROOKLYN"];
}
else if (Hit.transform.name.StartsWith("StatenIslandCollider"))
{
currentBoro = StatenIslandPlane;
curBoroRestaurantDict = BoroWiseDict["STATEN ISLAND"];
}
else if (Hit.transform.name.StartsWith("BronxCollider"))
{
currentBoro = BronxPlane;
curBoroRestaurantDict = BoroWiseDict["BRONX"];
}
else if (Hit.transform.name.StartsWith("ManhattanCollider"))
{
currentBoro = ManhattanPlane;
curBoroRestaurantDict = BoroWiseDict["MANHATTAN"];
}
else if (Hit.transform.name.StartsWith("QueensCollider"))
{
currentBoro = QueensPlane;
curBoroRestaurantDict = BoroWiseDict["QUEENS"];
}
}
}
}
else if (InTransitionZoomIn)
{
TransitionMapTowardsCamera();
}
else if (InTransitionZoomOut)
{
ZoomOut();
}
else if (ModeBuild)
{