-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataTransform.cs
127 lines (106 loc) · 5.38 KB
/
DataTransform.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
using System;
using System.Collections.Generic;
using System.Numerics;
namespace MerakiLocationVisualizer
{
internal class DataTransform
{
internal static List<List<string>> NormalizeCoordinates(List<List<string>> observationReports, float vpW, float vpH)
{
List<Vector4> v4NDC = new List<Vector4>();
List<List<string>> normalizedReports = new List<List<string>>();
// scaling hack
vpW = vpW / 0.43f;
vpH = vpH / 0.43f;
Matrix4x4 orthoTransform2D = new Matrix4x4(1.0f / vpW, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f / vpH, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
foreach(List<string> report in observationReports)
{
List<String> tempList = new List<string>();
for (int i = 0; i < report.Count; i += 5)
{
// ignore records with NaN coordinates
if (report[i] != "NaN" && report[i + 1] != "NaN")
{
Vector4 inXYZW = new Vector4(3.0f * Convert.ToSingle(report[i]), 3.0f * Convert.ToSingle(report[i + 1]), 0f, 1f);
Vector4 outXYZW = Vector4.Transform(inXYZW, orthoTransform2D);
// rogue clients will appear lower left, associated clients upper right
if (report[i + 4] == "")
{
tempList.Add(Convert.ToString(outXYZW.X * -1f * 20f));
tempList.Add(Convert.ToString(outXYZW.Y * -1f * 20f));
}
else
{
tempList.Add((outXYZW.X * 20f).ToString());
tempList.Add((outXYZW.Y * 20f).ToString());
}
tempList.Add(report[i + 2]);
tempList.Add(report[i + 3]);
}
}
normalizedReports.Add(tempList);
}
return normalizedReports; // x, y, ap, timestamp
}
// build quads from the x,y point data
public static float[] GenerateQuads(float[] vertices, float vpW, float vpH)
{
float halfWidth = 20.0f; // distance from center (x,y) of square to edge
List<float> inputCoordinates = new List<float>();
List<float> BLACK = new List<float> { 1.0f, 1.0f, 1.0f, 1.0f };
for (int index = 0; index < vertices.Length; index+=2)
{
float x, y;
// upper triangle (half of square) [X, Y, R, G, B, A, TXx, TXy]
x = (float)(vertices[index] - halfWidth / vpW);
y = (float)(vertices[index+1] - halfWidth / vpH);
inputCoordinates.Add((float)x); // lower left x,y
inputCoordinates.Add((float)y);
inputCoordinates.AddRange(BLACK);
inputCoordinates.Add(0.0f);
inputCoordinates.Add(0.0f);
x = (float)(vertices[index] - halfWidth / vpW);
y = (float)(vertices[index + 1] + halfWidth / vpH);
inputCoordinates.Add((float)x); // upper left x,y
inputCoordinates.Add((float)y);
inputCoordinates.AddRange(BLACK);
inputCoordinates.Add(0.0f);
inputCoordinates.Add(1.0f);
x = (float)(vertices[index] + halfWidth / vpW);
y = (float)(vertices[index + 1] + halfWidth / vpH);
inputCoordinates.Add((float)x); // upper right x,y
inputCoordinates.Add((float)y);
inputCoordinates.AddRange(BLACK);
inputCoordinates.Add(1.0f);
inputCoordinates.Add(1.0f);
// lower triangle (half of square)
x = (float)(vertices[index] - halfWidth / vpW);
y = (float)(vertices[index + 1] - halfWidth / vpH);
inputCoordinates.Add((float)x); // lower left x,y
inputCoordinates.Add((float)y);
inputCoordinates.AddRange(BLACK);
inputCoordinates.Add(0.0f);
inputCoordinates.Add(0.0f);
x = (float)(vertices[index] + halfWidth / vpW);
y = (float)(vertices[index + 1] - halfWidth / vpH);
inputCoordinates.Add((float)x); // lower right x,y
inputCoordinates.Add((float)y);
inputCoordinates.AddRange(BLACK);
inputCoordinates.Add(1.0f);
inputCoordinates.Add(0.0f);
x = (float)(vertices[index] + halfWidth / vpW);
y = (float)(vertices[index + 1] + halfWidth / vpH);
inputCoordinates.Add((float)x); // upper right x,y
inputCoordinates.Add((float)y);
inputCoordinates.AddRange(BLACK);
inputCoordinates.Add(1.0f);
inputCoordinates.Add(1.0f);
}
float[] returnVertices = inputCoordinates.ToArray();
return returnVertices;
}
}
}